by iterating through list of lists trying count of first field lists in list , implement if else logic. not sure if possible in iterator.
input :- [ [1,'a'],[1,'b'],[2,'c'],[-1,'d'],[-1,'d'] ] output :- invalid row invalid row valid row invalid row invalid row comments :-
if count more 1 value such rows invalid otherwise rows valid.
from collections import counter counts = counter() l in mylist: counts[l[0]] += 1 l in mylist: if counts[l[0]] > 1: print("invalid row") else: print("valid row")
Comments
Post a Comment