[EMAIL PROTECTED] wrote:
Hi,
i am using a software which uses python as its scripting language. I
want to generate a list of coordinates more or less this way:
for i in (beg, end, step):
for j in (beg, end, step):
for k in (beg, end, step):
.........
Coords = ((i1,j1,k1), (i2,j2,k2), ...,(in,jn.kn))
Your statement of the problem makes it look like all three coordinates
cover the same sequence of values. Is that true? Or does i's range
(beg, end, step) differ from j's and k's. If they differ, are they
all the same length?
You pseudo-code makes it look like you want all combinations, but your
sample output does not indicate that. Which is it, [(1,1,1), (2,2,2)]
or [(1,1,1), (1,1,2),(1,2,1),(1,2,2), ...]?
Depending on the answers to those questions, one of the following list
comprehensions may demonstrate how to achieve a solution.
>>> a = range(2,6,2)
>>> b = range(3,7,2)
>>> c = range(10,14,2)
>>> print a,b,c
[2, 4] [3, 5] [10, 12]
>>> [(i,j,k) for i,j,k in zip(a,b,c)] # Using zip process three lists
in lock-step
[(2, 3, 10), (4, 5, 12)]
>>> [(i,j,k) for i in a for j in b for k in c] #Nested loop give
all possible combos.
[(2, 3, 10), (2, 3, 12), (2, 5, 10), (2, 5, 12), (4, 3, 10), (4, 3, 12),
(4, 5, 10), (4, 5, 12)]
>>>
Gary Herron
Can anyone give me some advice on how to achieve this ? I got a little
idea, but still need to keep working til i get it. Thanks in advance,
Victor
--
http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list