Skip to content

Instantly share code, notes, and snippets.

@f-f
Created December 24, 2014 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save f-f/bd1174ab37d229b6de0a to your computer and use it in GitHub Desktop.
Save f-f/bd1174ab37d229b6de0a to your computer and use it in GitHub Desktop.
Recursive alphabetical combinations
import string
import itertools as it
chars=list(string.ascii_lowercase)
def gen_expansion(inp, length=1):
if not length:
return inp
if isinstance(inp, str):
accodati = [inp+c for c in chars]
if length == 1:
return accodati
else:
return gen_expansion(accodati, length-1)
else:
return list(it.chain.from_iterable([gen_expansion(s, length) for s in inp]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment