KnowledgeBoat Logo

Computer Science

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

Python

Python List Manipulation

41 Likes

Answer

l = eval(input("Enter the list: "))
dedup = []
dup = []
for i in l:
    if i in dedup:
        dup.append(i)
    else:
        dedup.append(i)

l = dedup + dup

print("Modified List:")
print(l)

Output

Enter the list: [20, 15, 18, 15, 7, 18, 12, 13, 7]
Modified List:
[20, 15, 18, 7, 12, 13, 15, 18, 7]

Answered By

18 Likes


Related Questions