Created
December 24, 2014 17:51
-
-
Save f-f/bd1174ab37d229b6de0a to your computer and use it in GitHub Desktop.
Recursive alphabetical combinations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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