Python Forum

Full Version: program help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Find out duplicate number between 1 to N numbers. (anyone have a code)
You could try to add them to a set(), if a number fails, it is a duplicate.
Paul
2 basic ways :
list1 = [1,2,3,4,5,6,1,2,3]
set1 = set(list1)
print(list(set1))
or
list2 = [1,3,5,7,9,1,3]
list3 = []
for i in list2:
    if i not in list3:
        list3.append(i)
print(list3)
Unfortunately, you've been given solutions by now, but in future please try to come up with a solution before asking for help (pen and paper are great tools!). You need to develop problem solving skills as a programmer.