Last active
November 30, 2015 04:32
-
-
Save harishvc/5acd53d1679a1600a414 to your computer and use it in GitHub Desktop.
Find different combinations
This file contains 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
# Find different combinations | |
def combinations(n): | |
yield "" | |
for i, d in enumerate(n): | |
for combination in combinations(n[i+1:]): | |
yield d + combination | |
print([x for x in combinations("abc")]) | |
#output | |
['', 'a', 'ab', 'abc', 'ac', 'b', 'bc', 'c'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment