Skip to content

Instantly share code, notes, and snippets.

@animatedlew
Created March 3, 2019 22:22
Show Gist options
  • Save animatedlew/d8e608afae714fdf981bb06291223e9c to your computer and use it in GitHub Desktop.
Save animatedlew/d8e608afae714fdf981bb06291223e9c to your computer and use it in GitHub Desktop.
from typing import List
def perm(input: str) -> List[str]:
return [
head + p
for i, head in enumerate(input)
for p in perm(input[:i] + input[i+1:])
] if input else [input]
print(perm('abc'))
@animatedlew
Copy link
Author

animatedlew commented Mar 4, 2019

timeit(
  "perm('abcd')",
  setup="import gc; gc.enable()",
  globals=globals(),
  number=100000
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment