Skip to content

Instantly share code, notes, and snippets.

@r2k0
Created October 20, 2014 01:21
Show Gist options
  • Save r2k0/ad18d9a8dcbd7420133e to your computer and use it in GitHub Desktop.
Save r2k0/ad18d9a8dcbd7420133e to your computer and use it in GitHub Desktop.
itertools permutations example
>>> from itertools import permutations
>>> perms = [''.join(p) for p in permutations('hat')]
>>> perms
['hat', 'hta', 'aht', 'ath', 'tha', 'tah']
>>> print sorted(perms)
['aht', 'ath', 'hat', 'hta', 'tah', 'tha']
>>> print ','.join(sorted(perms))
aht,ath,hat,hta,tah,tha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment