Skip to content Skip to sidebar Skip to footer

Python, For Loops Depending On Int

I have some code which prints every possible letter combination for a word length of 3. letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t'

Solution 1:

You itertools.product with a *repeat=n* where n is how many loops:

from itertools import  product
for p in product(letters,repeat=3):
    print(p)

Post a Comment for "Python, For Loops Depending On Int"