count - Python 3.6 - reading the the values of rows from two lists after a conditional statement -
hi here code looks values repeat 3 or more times in list a:
a = ['1','1','1','2','2','3'] b = ['4','5','1','7','8','4'] d = [item item in if a.count(item) >= 3] print(d) # ['1', '1', '1'] so question how can read corresponding values in list b. list , b same size. desired output should be:
output: [['1', '1', '1'], ['4', '5', '1']] thank you!
you can solve using zip:
>>> list(zip(*[(ai, bi) ai, bi in zip(a, b) if a.count(ai) >= 3])) [('1', '1', '1'), ('4', '5', '1')]
Comments
Post a Comment