Skip to content

Instantly share code, notes, and snippets.

@mofas
Created November 18, 2018 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mofas/041df2b78c222ab58e4d705c44feba05 to your computer and use it in GitHub Desktop.
Save mofas/041df2b78c222ab58e4d705c44feba05 to your computer and use it in GitHub Desktop.
seq = ['A', 'B', 'C']
current = []
next = []
for char in seq:
for c in current:
next.append(c + char)
next.append(char + c)
next.append(char)
current = current + next
next = []
print(current)
# ['A', 'AB', 'BA', 'B', 'AC', 'CA', 'ABC', 'CAB', 'BAC', 'CBA', 'BC', 'CB', 'C']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment