I have who lists:
list_a = [['abc', 10],['def', 20],['ghj', 30]]
list_b = [['abc', 40],['def', 50],['ghj', 60],['klm', 70]]
and I want to go through list.b with list.a so I can remove the spare element "list.b[3]" and calculate with list members:
list_a[0][1] - list_b[0][1] = -30
list_a[1][1] - list_b[1][1] = -30
list_a[2][1] - list_b[2][1] = -30
What on earth I should do?
Use zip. It will automatically trim to the length of the shortest iterable. Here it is in a list comprehension:
[a_val[1] - b_val[1] for a_val, b_val in zip(a,b)]
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