On 5 июн, 18:19, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> On Jun 5, 3:49 pm, Ivan Illarionov <[EMAIL PROTECTED]> wrote:
>
>
>
> > On 5 ÉÀÎ, 01:57, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> > wrote:
>
> > > Hi Everyone,
>
> > > 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,
> > >>> from itertools import repeat, izip
> > >>> coords = tuple((i,j,k) for i in xrange(1,5) for j in xrange(1,5) for k 
> > >>> in xrange(1,2))
> > >>> locals().update(("tuple%s" % i, coord) for i, coord  in 
> > >>> izip(xrange(1,11), repeat(coords)))
> > >>> tuple1
>
> > ((1, 1, 1), (1, 2, 1), (1, 3, 1), (1, 4, 1), (2, 1, 1), (2, 2, 1), (2,
> > 3, 1), (2
> > , 4, 1), (3, 1, 1), (3, 2, 1), (3, 3, 1), (3, 4, 1), (4, 1, 1), (4, 2,
> > 1), (4, 3
> > , 1), (4, 4, 1))
>
> > Does this help?
>
> > But I don't understand why you need this?
>
> > Ivan
>
> Hi,
>
> What i need is, for example:
>
> tuple 1=((1, 1, 1), (1, 2, 1), (1, 3, 1), (1, 4, 1))
>
> tuple 2=((2, 1, 1), (2, 2, 1), (2, 3, 1), (2, 4, 1))
>
> tuple 3=((3, 1, 1), (3, 2, 1), (3, 3, 1), (3, 4, 1))
>
> and so on. Please help me and sorry for not taking the time to post my
> questions properly.
>
> Victor




>>> coords = [(i, tuple((i,j,k) for j in range(1,5) for k in range(1,2))) for i 
>>> in range(1,5)]
>>> locals().update(("tuple_%s" % i, coord) for i, coord in coords)
>>> tuple_1
((1, 1, 1), (1, 2, 1), (1, 3, 1), (1, 4, 1))
>>> tuple_2
((2, 1, 1), (2, 2, 1), (2, 3, 1), (2, 4, 1))
>>> tuple_3
((3, 1, 1), (3, 2, 1), (3, 3, 1), (3, 4, 1))


Is this what you want?

Ivan
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to