Python traversing two lists -
I found this good statement in a tutorial:
for x, in y [ (X, y) for list Y in the list for y] B:] Now, for me, I was convinced that this statement will come in the list and list B and X is the value of list A and y is a value from listB. But in this example two lists had the same length. Will this statement also give me all the pairs, if one list is longer than the other, or do I have to use a different statement?
Thanks in advance.
For example, if input is , then "post-text" itemprop = "text"> code cartesian product (), 1,2,3] and [4,5] , the result is: (1,4) (1,5) (2, 4) (2,5) (3,4) (3,5) For comparison, the result of zip ([1, 2,3], [4, 5]) is : (1,4) (2,5) As As you can see, zip (or) now abandons additional items in more logic.
Its version replaces these missing elements with an uncontrolled value. For example, iterttools.izip_longest ([1,2,3], [4,5], 99) returns: (1,4) (2 , 5) (3, 99)
Comments
Post a Comment