Created
December 3, 2021 10:55
-
-
Save shiva-karthick/4ed6a2323613406f0ad2fc55c508f7ad to your computer and use it in GitHub Desktop.
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
## How to get all possible combinations of a list’s elements? | |
def combs(a): | |
if len(a) == 0: | |
return [[]] | |
cs = [] | |
for c in combs(a[1:]): | |
cs += [c, c+[a[0]]] | |
return cs | |
combs([1,2,3,4,5]) | |
## [[], [1], [2], [2, 1], [3], [3, 1], [3, 2], ..., [5, 4, 3, 2, 1]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment