Loops are common program constrol structure, including nested loops. In python, there are alternative ways to write nested for-loops, which makes the indentation in your code more flat and increases readibility.
One technique is to use list comprehension (assuming lists are independent of each other), for example:
The code above is doing cartesian product of two lists, which brings us to another technique that is provided
by Python standard library
Less code, more readible; more importantly,
itertools.product returns a generator/iterator, which is more memory
efficient if you only want to iterate through the results. Isn’t it beautiful?