元组第2部分 [英] Tuples part 2

查看:77
本文介绍了元组第2部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有另一个问题。如果我想制作n个元组,每个元素都带有

坐标列表,该怎么办?例如:

coords = list()
$ x $ b for x in xrange(1,11,1):

for i in xrange(1 ,5,1):
$ x $ b for x in xrange(1,5,1):

for x in xrange(1,2,1):

coords.append((i,j,k))

lista + str(h)= tuple coords

打印元组(coords)

这样我就会有tuple1,tuple2,...,tupleN等等。我正在尝试这样做,因为我在上面展示你的方式但是它运行不正常。我希望你能帮助我b $ b。再次感谢,

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,

推荐答案

victor.hera ... @ gmail.com:


你的意思是这样的事情? (注意许多格式化

差异,在你的代码中使用类似于这个格式的格式)


coords = []

$ x $ b for i in xrange(1,5):

for j in xrange(1,5):

for k in xrange(1,2):

coords.append((i,j,k))


coords * = 10

print coords


再见,

bearophile
victor.hera...@gmail.com:

Do you mean something like this? (notice the many formatting
differences, use a formatting similar to this one in your code)

coords = []

for i in xrange(1, 5):
for j in xrange(1, 5):
for k in xrange(1, 2):
coords.append( (i, j, k) )

coords *= 10
print coords

Bye,
bearophile


On5éà?,01:57," victor.hera .. 。@ gmail.com" < victor.hera ... @ gmail.com>

写道:
On 5 éà?, 01:57, "victor.hera...@gmail.com" <victor.hera...@gmail.com>
wrote:

大家好,


i有另一个问题。如果我想制作n个元组,每个元素都带有

坐标列表,该怎么办?例如:


coords = list()
$ x $ b for x in xrange(1,11,1):

for i在xrange(1,5,1):
$ x $ b for x in xrange(1,5,1):

for x in xrange(1,2,1):

coords.append((i,j,k))

lista + str(h)= tuple coords

print tuple(coords)


这样我就会有tuple1,tuple2,...,tupleN等等。我正在尝试做

就像我给你看的那样但是它工作不正常。我希望你能帮助我b $ b。再次感谢,
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,


>>来自itertools import repeat,izip
coords = tuple((i,j,k)for x in xrange(1,5)for j in xrange(1,5)for kin xrange(1,2))
locals()。update ((tuple%s,%i,coord)for i,coord in izip(xrange(1,11),repeat(coords)))
tuple1
>>from itertools import repeat, izip
coords = tuple((i,j,k) for i in xrange(1,5) for j in xrange(1,5) for kin 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))


这有帮助吗?


但我不明白为什么你需要这个?


Ivan

((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


6月5日下午3:49, Ivan Illarionov< ivan.illario ... @ gmail.comwrote:
On Jun 5, 3:49 pm, Ivan Illarionov <ivan.illario...@gmail.comwrote:

On5éà?,01:57," victor.hera ... @ gmail 。C OM" < victor.hera ... @ gmail.com>

写道:
On 5 éà?, 01:57, "victor.hera...@gmail.com" <victor.hera...@gmail.com>
wrote:

大家好,
Hi Everyone,


i有另一个问题。如果我想制作n个元组,每个元素都带有

坐标列表,该怎么办?例如:
i have another question. What if i wanted to make n tuples, each with
a list of coordinates. For example :


coords = list()
$ x $ b for x in xrange(1,11,1):

for x in xrange(1,5,1):
$ x $ b for x in xrange(1,5,1):

for x in xrange (1,2,1):

coords.append((i,j,k))

lista + str(h)= tuple coords

打印元组(coords)
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)


这样我就会有tuple1,tuple2,...,tupleN等等我试图做

就像我给你看的那样,但是它运行不正常。我希望你能帮助我b $ b。再次感谢,
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,

>来自itertools import repeat,izip
coords = tuple((i,j,k)for i in xrange(1,5 )for x in xrange(1,5)fork in xrange(1,2))
locals()。update((" tuple%s"%i,coord)for i,coord in izip(xrange( 1,11),重复(coords)))
tuple1
>from itertools import repeat, izip
coords = tuple((i,j,k) for i in xrange(1,5) for j in xrange(1,5) fork 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))


这有帮助吗?


但是我不明白你为什么需要这个?


伊凡


((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






我需要的是,例如:


元组1 =((1,1,1),(1,2,1),(1,3,1),(1,4,1))


元组2 =((2,1,1),(2,2,1),(2,3,1),(2,4,1))


元组3 =( (3,1,1),(3,2,1),(3,3,1),(3,4,1))


等等。请帮助我,抱歉没有花时间正确发布我的

问题。


Victor

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


这篇关于元组第2部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆