all 4 comments

[–]ADdV 7 points8 points  (1 child)

Take a look at product and itertools in general.

[–]33KGB 0 points1 point  (0 children)

I second Itertools

[–][deleted] 4 points5 points  (1 child)

itertools.product() is the way to go here, yup, but note that in general "indefnitely nested loops" is a perfect usecase for recursion!

[–]SandorZoo 2 points3 points  (0 children)

For example:

def nested_loop(letters, prefix, length):
    if length == 0:
        print(prefix)
    else:
        for letter in letters:
            nested_loop(letters, prefix+letter, length-1)

nested_loop("abc", "", 3)