Skip to content

Instantly share code, notes, and snippets.

@d9k
Created June 4, 2016 01:19
Show Gist options
  • Save d9k/f6e196bea6b40c4b272f84606a961b34 to your computer and use it in GitHub Desktop.
Save d9k/f6e196bea6b40c4b272f84606a961b34 to your computer and use it in GitHub Desktop.
scramble = lambda word: [''.join(x) for c in range(len(word)) for x in itertools.combinations(word,c)]
# example:
# >>> scramble('sample')
# ['', 's', 'a', 'm', 'p', 'l', 'e', 'sa', 'sm', 'sp', 'sl', 'se', 'am', 'ap', 'al', 'ae', 'mp', 'ml', 'me', 'pl', 'pe', 'le', 'sam', 'sap', 'sal', 'sae', 'smp', 'sml', 'sme', 'spl', 'spe', 'sle', 'amp', 'aml', 'ame', 'apl', 'ape', 'ale', 'mpl', 'mpe', 'mle', 'ple', 'samp', 'saml', 'same', 'sapl', 'sape', 'sale', 'smpl', 'smpe', 'smle', 'sple', 'ampl', 'ampe', 'amle', 'aple', 'mple', 'sampl', 'sampe', 'samle', 'saple', 'smple', 'ample']
# inspired by http://sahandsaba.com/thirty-python-language-features-and-tricks-you-may-not-know.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment