> David Gibb: > > For example: if my values are ['a', 'b', 'c'], then all possible lists > > of length 2 would be: aa, ab, ac, ba, bb, bc, ca, cb, cc. > > >>> from itertools import product > >>> list(product("abc", repeat=2)) > [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'b'), ('b', > 'c'), ('c', 'a'), ('c', 'b'), ('c', 'c')] > > Bye, > bearophile
Certainly possible with list comprehensions. >>> a = "abc" >>> [(x, y) for x in a for y in a] [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'b'), ('b', 'c'), ('c', 'a'), ('c', 'b'), ('c', 'c')] But I like bearophile's version better. Cheers, Drea -- http://mail.python.org/mailman/listinfo/python-list