Is there a smart way to iterate over two lists in Python (without using list comprehension)?
I mean, something like this:
# (a, b) is the cartesian product between the two lists' elements for a, b in list1, list2: foo(a, b)
instead:
for a in list1: for b in list2: foo(a, b)
itertools.product() does just that:
itertools.product()
for a, b in itertools.product(list1, list2): foo(a, b)
It can handle an arbitrary number of iterations, and in this sense is more general than a nested for loop.
for
Source: https://habr.com/ru/post/914739/More articles:Maven Dependency Error in Eclipse - javaRelease the "ownership" of the COM object in .NET. - c #In tsql, the value of tablename (1) means - sqlConvert Google Date graph frame to UNIX timestamp - phpWhen all the previous fields are completed, add a new input field - javascripthttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/914740/cant-add-git-submodule-to-repository&usg=ALkJrhi-O2iV6nTcIyIHBHJQNorDXyFGPQMap reduces in RavenDb more than 2 collections with a children's collection - c #Resources for drawable-xlarge-mdpi AND drawable-sw600dp-mdpi without duplication - androidHow to provide various Android widgets for 1.6 and 3.0+? - androidhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/914744/adding-months-to-datetime-with-dateinterval-changes-original-date-to-match-new-date&usg=ALkJrhjQ5FNvAjUVQa2TlMMxGiMc-VufpgAll Articles