Created
February 20, 2010 02:26
-
-
Save j4mie/309453 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print all permutations formed by concatenating every word in a | |
# list with every other word in the same list. Good for generating | |
# idea/project/company names from a list of relevant words. The list | |
# will be sorted by word length. | |
from itertools import permutations | |
words = "spam eggs beans".split() | |
perms = ["".join(permutation) for permutation in permutations(words, 2)] | |
print "\n".join(sorted(perms, lambda a, b: len(a) - len(b))) | |
# Outputs: | |
# spameggs | |
# eggsspam | |
# spambeans | |
# eggsbeans | |
# beansspam | |
# beanseggs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment