atomica.utils.nested_loop¶
- atomica.utils.nested_loop(inputs, loop_order)[source]¶
Zip list of lists in order
This is used in
plot_bars()
to control whether ‘times’ or ‘results’ are the outer grouping. 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 (which are all that get used inplot_bars()
but in theory supports an arbitrary number of items.- Parameters:
inputs – List of lists. All lists should have the same length
loop_order – Nesting order for the lists
- Returns:
Generator yielding tuples of items, one for each list
Example usage:
>>> list(nested_loop([['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(nested_loop([['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.