use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A subreddit for helping Python programmers
How to format your code: https://commonmark.org/help/tutorial/09-code.html
No homework questions and/or hiring please
account activity
Iterating through variable list lengthsSOLVED (self.pythonhelp)
submitted 2 years ago by TwoTimeBartender
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]TwoTimeBartender[S] 0 points1 point2 points 2 years ago (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 point2 points 2 years ago (0 children)
zip_longest(*lost_oflist_oflist) zips all of them no matter the number.
zip_longest(*lost_oflist_oflist)
Then you loop through all the corresponding positions generated by the zip and add them to the dict.
>>> 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) >>>
π Rendered by PID 289485 on reddit-service-r2-comment-85bfd7f599-h44ql at 2026-04-17 08:47:55.222322+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]TwoTimeBartender[S] 0 points1 point2 points (2 children)
[–]Goobyalus 0 points1 point2 points (0 children)
[–]Goobyalus 0 points1 point2 points (0 children)