Python - compare list elements and return the value -
how check elements in list
example:
>>> l [1, 2, 3, 4, 1, 2]
i want compare l[0]
& l[1]
elements , return me 1 , 2 if match other elements in list.
if l.count(l[0]) > 1 , l.count(l[1]) > 1: print l[0], l[1] elif l.count(l[0]): print l[0] elif l.count(l[1]): print l[1]
or list comprehension
[i in l[:2] if l.count(i) > 1]
Comments
Post a Comment