Skip to content

Instantly share code, notes, and snippets.

View chuanconggao's full-sized avatar
🧑‍💻

Chuancong Gao chuanconggao

🧑‍💻
  • AWS
View GitHub Profile
@chuanconggao
chuanconggao / anagrams.py
Last active May 14, 2020 19:17 — forked from jmuzsik/anagrams.py
Code for computing anagrams that works on both string and list.
def anagrams(s):
return [s] if len(s) == 0 else [
w[:pos] + s[:1] + w[pos:]
for w in anagrams(s[1:])
for pos in range(len(w) + 1)
]
anagrams("abc")
# returns ['abc', 'bac', 'bca', 'acb', 'cab', 'cba']