0
How to compare 2 lists, element for element([0] with [0] etc) and add element to a third list if condition is met?
Comparing with <=, and both lists contain 7 elements (numbers).
5 Respuestas
+ 4
for x, y in zip(list1, list2):
if x<=y:
list3.append(x)
+ 4
Yeah. The function zip combines two iterables (in this case lists) and groups them to pairs (or trios, quartets etc.)
With x, y you unpack each of these little pair packages, and then you can compare them one by one.
Important is that you try it with your own hands and test the result and see for yourself.
+ 2
HonFu Thanks, will see if it works 👍🏻
+ 1
HonFu will it compare the list on a lndivual level? list1[0] with list2[0], list1[1] with list[2] and so forth?
+ 1
Yep