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]
>>>
Please explain this also
ReplyDeleteI am trying to make video very soon.
DeletePython??
ReplyDeleteYes, This is program of python.
DeleteI am clear till the 7th line of the code. But sir why are you writing lst.remove(i)??
ReplyDeletelst.remove(i) here remove() is a function which is used to delete elements in lst.
Deleteyou deleted the duplicated values, but its asked that you have to move at end
ReplyDeleteOk : )
DeleteThank you very much, you are awesome. 😊
ReplyDeleteWelcome : )
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )