Hi here is my code that looks for values that repeat 3 or more times in list a:
a = ['1','1','1','2','2','3']
b = ['4','5','1','7','8','4']
d = [item for item in a if a.count(item) >= 3]
print(d)
# ['1', '1', '1']
So my question is how can I also read the corresponding values in list b. Also list a and b are always the same size. My desired output should be:
output: [['1', '1', '1'], ['4', '5', '1']]
thank you!
You can solve this using zip:
>>> list(zip(*[(ai, bi) for ai, bi in zip(a, b) if a.count(ai) >= 3]))
[('1', '1', '1'), ('4', '5', '1')]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With