What about itertools.combinations ?
Usage example:
>>> list(itertools.combinations([1, 2, 3, 4, 5, 6], 2)) [(1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (2, 3), (2, 4), (2, 5), (2, 6), (3, 4), (3, 5), (3, 6), (4, 5), (4, 6), (5, 6)]
The first argument is iterable, the second is r , the length of the returned subsequences.
Then you can easily concatenate the results using a map or understanding:
map(lambda x: x[0] + "_" + x[1], itertools.combinations(["cat", "dog", "fish"], 2)))
x in lambda is an r dimensional tuple.
Result above:
['cat_dog', 'cat_fish', 'dog_fish']