Created
September 19, 2020 06:11
-
-
Save brighteyed/6671aec2325e69742e64d07ec05abea4 to your computer and use it in GitHub Desktop.
Returns all permutations of a given list
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
def permutations(lst): | |
count = len(lst) | |
if count == 0: | |
yield lst | |
for i in range(count): | |
for l in permutations(lst[:i] + lst[i+1:]): | |
yield [lst[i]] + l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment