Skip to content

Instantly share code, notes, and snippets.

@brighteyed
Created September 19, 2020 06:11
Show Gist options
  • Save brighteyed/6671aec2325e69742e64d07ec05abea4 to your computer and use it in GitHub Desktop.
Save brighteyed/6671aec2325e69742e64d07ec05abea4 to your computer and use it in GitHub Desktop.
Returns all permutations of a given list
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