Skip to content

Instantly share code, notes, and snippets.

@taicki
Created July 11, 2011 15:57
Show Gist options
  • Save taicki/1076166 to your computer and use it in GitHub Desktop.
Save taicki/1076166 to your computer and use it in GitHub Desktop.
import sys
rl = lambda: sys.stdin.readline().strip()
def perm(strl):
if len(strl) == 1:
return [strl]
perms = []
for i in strl:
copied = strl[:]
copied.remove(i)
for j in perm(copied):
perms.append([i]+j)
return perms
def main():
for line in sys.stdin:
l = line.strip()
print [''.join(i) for i in perm(list(l))]
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment