In this article, I am going to give a complete program or Class 11 Practical Python Program to add duplicate and unique items of a given list into 2 different lists. Here we go!
Topics Covered
Class 11 Practical Python Program
Let us begin with the steps required to follow for the Class 11 Practical Python Program to add duplicate and unique items of a given list into 2 different lists. The steps are as follows:
- Take variable n to add n no. of elements into the list – n
- Declare an empty list – l
- Use for loop to accept n no. of values – for i in range(n)
- Take an input variable inside the for a loop to insert different values – val
- Append individual value to the list – l.append(val)
- Print the original list – print(l)
- Declare two individual empty lists to add duplicate and unique elements into two different lists – l_uni, l_dup
- Traverse the list object – l
- Apply if condition to check element is present into unique list or not – if i not in l_uni:
- Now append the i – l_uni.append(i)
- Now add the remaining values into duplicate elements – i_dup.append(i)
- Print both lists at the end
Class 11 Practical Python Program code
n=int(input("Enter no of elements:"))
l=[]
for i in range(n):
val=int(input("Enter value to insert into the list:"))
l.append(val)
print("Original List:",l)
l_uni=[]
l_dup=[]
for i in l:
if i not in l_uni:
l_uni.append(i)
else:
l_dup.append(i)
print("Unique Elements:",l_uni)
print("Duplicate Elements:",l_dup)
Output
Thank you for reading this article.
Follow this link for more list programs: