nestedloop(inputs, loop_order)[source]#

Zip list of lists in order

This function takes in a list of lists to iterate over, and their nesting order. It then yields tuples of items in the given order. Only tested for two levels but in theory supports an arbitrary number of items.

  • inputs (list) – List of lists. All lists should have the same length

  • loop_order (list) – Nesting order for the lists


Generator yielding tuples of items, one for each list

Example usage:

>>> list(sc.nestedloop([['a','b'],[1,2]],[0,1]))
[['a', 1], ['a', 2], ['b', 1], ['b', 2]]

Notice how the first two items have the same value for the first list while the items from the second list vary. If the loop_order is reversed, then:

>>> list(sc.nestedloop([['a','b'],[1,2]],[1,0]))
[['a', 1], ['b', 1], ['a', 2], ['b', 2]]

Notice now how now the first two items have different values from the first list but the same items from the second list.

From Atomica by Romesh Abeysuriya.

New in version 1.0.0.