python - Replace Nested For Loops... or not -


I have a script that saves four (or less) characters through a series of strings. For example:

  aaa aa aaac aaad  

if it has been implemented equally with nested:

  chars = string.digits + string.uppercase + string.lowercase: printed '% s' in% b characters: print '% s% s' in% (a, b) for characters: In the print '% s% s% s'% (a, b, c, d)  

Is this type of loop being a nest of bad things, and if so, So what is the better way to complete what I am doing?

  import string import import ittotools chars = string.digits + string.letters MAX_CHARS = 4 range (MAX_CHARS) for nletters: itertools.product (chars, repeat = nletters + 1): print ('' .joy (word))  

all that 15018570 You will print the words. If you want more / less words, just replace the MAX_CHARS variable. For any number of characters, there will still be two for s, and you do not have to repeat yourself and it is very readable.


Comments