Alim '
Alim '

Reputation: 33

Trying to find every combination possible for a partially known string

Im trying to write a code that would find every single combination possible using numbers and letters for a partially know string. So for example a string "a***2l". I want it to replace the stars with every possible letter/number, however the length of the string must stay the same. Maybe it is possible to achieve using the 'itertools' library? It seems really difficult for me to understand how it would work. Any help appreciated. Thank you!

Upvotes: 0

Views: 41

Answers (1)

Alex Hall
Alex Hall

Reputation: 36043

import string
import itertools

for tup in itertools.product(string.ascii_letters + string.digits, repeat=3):
    print("a" + "".join(tup) + "2l")

Upvotes: 4

Related Questions