[英]Tuples and nested lists
x =[(34, 55), (1, 75), (5, 36), (1, 49), (1, 186), [(3, 47), (131, 167)], (7, 434)]
y= [(77, 98), (109, 183), (77, 108), (1, 49), (1, 185), [(45, 78), (45, 84)], (3, 429)]
I'd like to obtain the following from the above lists. 我想从以上列表中获得以下内容。
q:34-55 h:77-98
q:1-75 h:109-183
q:5-36 h:77-108
q:1-49 h:1-49
q:1-186 h:1-185
q:3-47 h:45-78 q:131-167 h:45, 84
q:7-434 h:3-429
any suggestions on how to get it done? 关于如何完成工作的任何建议? Thanks in advance
提前致谢
I tried the following: 我尝试了以下方法:
for i in x:
if type(i) != list:
print "q:%d-%d" % (i[0], i[1])
q:34-55
q:1-75
q:5-36
q:1-49
q:1-186
q:7-434
Try with this: 试试这个:
x =[(34, 55), (1, 75), (5, 36), (1, 49), (1, 186), [(3, 47), (131, 167)], (7, 434)]
y= [(77, 98), (109, 183), (77, 108), (1, 49), (1, 185), [(45, 78), (45, 84)], (3, 429)]
tmpl = "\tq: {0}\th: {1}"
for q, h in zip(x, y):
if isinstance(q, list):
for q2, h2 in zip(q, h):
print tmpl.format(q2, h2),
print
else:
print tmpl.format(q, h)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.