I would like to write a short Python function that will detect the duplicate number in a list of integers and print out that number to standard output. The input 5;0,1,2,3,0 is generated by these lines already:
import sys for line in sys.stdin: print line,
And I am wondering whether I could use the following code (part of the above for loop) to get the desired output of "0":
seen = set()
for num in line:
if num in seen:
print num
else:
seen.add(num)
So far this gives me the output: 5;0,1,2,3,0 , , , 0
I just need to get rid of the comma lines and keep the 0... This is for Python in general, not necessarily Python 3.