Can anyone solve this?
rdudfield at my-deja.com
rdudfield at my-deja.com
Mon Jun 26 04:11:41 EDT 2000
Hi,
I've got a problem here which I just can't figure out.
a = [1,2,3]
b = ["c",32]
c = [1,2]
inputlist = [a,b,c]
Inputlist can have any number of lists in it. The lists in it can have
any number of elements in them.
I need the code to give every possible combination of the lists in
inputlist.
This is what the answer should be for the inputlist above.
outputlist = [[1, 'c', 1], [1, 'c', 2], [1, 32, 1], [1, 32, 2], [2, 'c',
1], [2, 'c', 2], [2, 32, 1], [2, 32, 2], [3, 'c', 1], [3, 'c', 2], [3,
32, 1], [3, 32, 2]]
[]
Here is some code which works for three lists:
outputlist = []
for i in a:
for j in b:
for k in c:
outputlist.append([i,j,k])
Anyone able to solve this?
Rene.
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list