Last active
August 29, 2015 14:05
-
-
Save rohit-jamuar/b8c71409486f541befbc to your computer and use it in GitHub Desktop.
Yields all subsequences of input string
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
| #!/usr/bin/python | |
| from itertools import combinations | |
| def get_subsequences(input_str): | |
| ''' | |
| Yields all subsequences of size in range [1, len(input_str)] | |
| ''' | |
| if type(input_str) == str: | |
| for length in range(1, len(input_str)+1): | |
| for elems in combinations(input_str, length): | |
| yield ','.join(elems) | |
| else: | |
| raise GeneratorExit | |
| if __name__ == '__main__': | |
| for output in get_subsequences('hello'): | |
| print output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment