Tuple of coordinates

victor.herasme at gmail.com victor.herasme at gmail.com
Wed Jun 4 23:55:28 CEST 2008


On 29 mayo, 17:45, Gary Herron <gher... at islandtraining.com> wrote:
> victor.hera... at gmail.com 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- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -

Hi ,

i have another question. What if i wanted to make n tuples, each with
a list of coordinates. For example :


coords = list()
for h in xrange(1,11,1):
   for i in xrange(1, 5, 1) :
      for j in xrange(1, 5, 1) :
         for k in xrange(1,2,1) :
            coords.append((i,j,k))
            lista+str(h)= tuple coords
print tuple(coords)


so that i will have tuple1, tuple2,..., tupleN, etc. I am trying to do
it the way i show you above but it is not working properly. I wish you
could help me with that. Thanks again,



More information about the Python-list mailing list