Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 元组和嵌套列表_Python_Python 2.7 - Fatal编程技术网

Python 元组和嵌套列表

Python 元组和嵌套列表,python,python-2.7,Python,Python 2.7,我想从上面的列表中获得以下信息 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)] 有没有关于如何完成的建议?提前谢谢 我尝试了以下方法: q:34-55 h:77-98 q:1-

我想从上面的列表中获得以下信息

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)]
有没有关于如何完成的建议?提前谢谢

我尝试了以下方法:

    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
试试这个:

 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

你能说得具体点吗。你只需要打印,或者你需要把它们放在另一个列表中?到目前为止你做了什么尝试?基本上,它应该可以做一些循环谢谢你们所有人的响应…我想把它写入一个文件,就像打印它一样简单。。。
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)