On Mar 12, 10:18 am, Gerdus van Zyl <[EMAIL PROTECTED]> wrote: > I have a list that looks like this: > [['3'], ['9', '1'], ['5'], ['4'], ['2', '5', '8']] > > how can I get all the combinations thereof that looks like as follows:
You could wait for Python 2.6, or download the current alpha: Python 2.6a1+ (trunk:61353M, Mar 12 2008, 11:21:13) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from itertools import product >>> for c in product(['3'], ['9', '1'], ['5'], ['4'], ['2', '5', '8']): print c ... ('3', '9', '5', '4', '2') ('3', '9', '5', '4', '5') ('3', '9', '5', '4', '8') ('3', '1', '5', '4', '2') ('3', '1', '5', '4', '5') ('3', '1', '5', '4', '8') If you can't wait, look at http://docs.python.org/dev/library/itertools.html where equivalent code is given. Mark -- http://mail.python.org/mailman/listinfo/python-list