faqts : Computers : Programming : Languages : Python : Common Problems : Maths

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

Hi, I have few arrays, i want all the possible combination of elelents

May 10th, 2006 15:27
stephen brown, Satish Mishra,


This can be done with nested loops or list comprehensions:
>>> a = range(3)
>>> b = 'abc'
>>> [(x, y) for x in a for y in b]
[(0, 'a'), (0, 'b'), (0, 'c'), (1, 'a'), (1, 'b'), (1, 'c'), (2, 'a'),
(2, 'b'), (2, 'c')]
>>>