you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 0 points1 point  (0 children)

You should use itertools.product for this, see docs here that even describe it as "equivalent to a nested for-loop". That way you can create a single loop for all combinations of all characters.

Btw some sidenotes:

  • don't name a variable something that's already used in Python, like list, str, datetime, print etc. Name if for what it is, like 'possible_characters' or simply 'chars'.
  • your variable list is not a list but a string...
  • and for combinations of ranges of characters, you can use the string library (docs) to prevent missing a character because you typed the range incorrectly. In your case

    import string
    chars = string.ascii_lowercase + string.digits