Created
June 4, 2016 01:19
-
-
Save d9k/f6e196bea6b40c4b272f84606a961b34 to your computer and use it in GitHub Desktop.
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
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