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!

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:

  1. Take variable n to add n no. of elements into the list – n
  2. Declare an empty list – l
  3. Use for loop to accept n no. of values – for i in range(n)
  4. Take an input variable inside the for a loop to insert different values – val
  5. Append individual value to the list – l.append(val)
  6. Print the original list – print(l)
  7. Declare two individual empty lists to add duplicate and unique elements into two different lists – l_uni, l_dup
  8. Traverse the list object – l
  9. Apply if condition to check element is present into unique list or not – if i not in l_uni:
  10. Now append the i – l_uni.append(i)
  11. Now add the remaining values into duplicate elements – i_dup.append(i)
  12. 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

Class 11 Practical Python Program

Thank you for reading this article.

Follow this link for more list programs:

Python List program

Leave a Reply