Skip to content

Instantly share code, notes, and snippets.

@strawberryjello
Last active August 29, 2015 13:57
Show Gist options
  • Save strawberryjello/9527072 to your computer and use it in GitHub Desktop.
Save strawberryjello/9527072 to your computer and use it in GitHub Desktop.
Sample usage of Python's itertools.permutations()
#! /usr/bin/env python
"""Permutation generator
Just a sample usage of itertools.permutations() (Python 2.6 and later)
"""
import itertools
wordlist = list(itertools.permutations("estuyz"))
with open("permutations.txt", "wb") as f:
for word in wordlist:
for letter in word:
f.write(letter)
f.write("\n")
print "wrote", len(wordlist), "words"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment