Python Forum

Full Version: list problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
а = [10,20,30,20,10,50,60,40,80,50,40]

dup_items = set()
uniq_items = []
for x in a:
    if x not in dup_items:
        uniq_items.append(x)
        dup_items.add(x)

print(dup_items)
Hi can anyone explain the above code for me?
It creates a new list and a new set, each of which has only one instance of each item in the original list.