Q. Write a program to move all duplicate values in a list to the end of the list.


You can understand by Watching video :-




Answer =


lst = eval(input("Enter a list :-"))
dup = [ ]
n = 1
while n < len(lst):
      for i in lst :
            if lst.count( i ) != 1 :
                  lst.remove( i )
                  dup.append(i)
      n += 1

lst.sort()
print("New list :- ",lst + dup)


Output :-

Enter a list :-[1,2,3,4,1,2,3,4,5,6]
New list :-  [1, 2, 3, 4, 5, 6, 1, 3, 2, 4]
>>> 

Enter a list :-[1,2,6,4,7,8,93,2,1,4,5,6,3,8,6]
New list :-  [1, 2, 3, 4, 5, 6, 7, 8, 93, 1, 6, 8, 2, 4, 6]

>>>

10 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. I am clear till the 7th line of the code. But sir why are you writing lst.remove(i)??

    ReplyDelete
    Replies
    1. lst.remove(i) here remove() is a function which is used to delete elements in lst.

      Delete
  2. you deleted the duplicated values, but its asked that you have to move at end

    ReplyDelete
  3. Thank you very much, you are awesome. 😊

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post