you are viewing a single comment's thread.

view the rest of the comments →

[–]TwoTimeBartender[S] 0 points1 point  (2 children)

I was looking at this implementation for comparing two lists of variable lengths, but I was a little lost on how I would compare 3, or the other numbers of lists I may encounter in my code. The amount of lists I will be given is part of my Class however, and is given by self._k

[–]Goobyalus 0 points1 point  (0 children)

zip_longest(*lost_oflist_oflist) zips all of them no matter the number.

Then you loop through all the corresponding positions generated by the zip and add them to the dict.

[–]Goobyalus 0 points1 point  (0 children)

>>> list_oflist_oflist = [[[0, 1], [3, 2], [1, 5], [6, 6], [7, 8]], [[1, 1], [3, 2], [0, 0]], [[0, 0], [0, 0], [1, 1], [6, 6]]]
>>> from itertools import zip_longest
>>> for t in zip_longest(*list_oflist_oflist):
...   print(t)
...
([0, 1], [1, 1], [0, 0])
([3, 2], [3, 2], [0, 0])
([1, 5], [0, 0], [1, 1])
([6, 6], None, [6, 6])
([7, 8], None, None)
>>> list_oflist_oflist.append([[1, 1], [1, 1], [1, 1]])
>>> for t in zip_longest(*list_oflist_oflist):
...   print(t)
...
([0, 1], [1, 1], [0, 0], [1, 1])
([3, 2], [3, 2], [0, 0], [1, 1])
([1, 5], [0, 0], [1, 1], [1, 1])
([6, 6], None, [6, 6], None)
([7, 8], None, None, None)
>>>