简体   繁体   English

对于循环和嵌套列表问题

[英]For loops and nested lists issue

I have a set of nested list being returned via the JSON.Loads method from a website XHR request: 我有一组嵌套列表从网站XHR请求通过JSON.Loads方法返回:

[[[13, u'Arsenal', [[[[0, 1], [1, 18], [7, 1], [8, 1], [[[u'fk_foul_lost', [82]], 
[u'total_red_card', [0]], [u'total_yel_card', [21]]]]]]]], 
    ...
    ...
    ...
[184, u'Burnley', [[[[1, 11], [9, 1], [[[u'fk_foul_lost', [78]], [u'total_red_card', [0]], 
[u'total_yel_card', [12]]]]]]]], [259, u'Swansea', [[[[0, 3], [1, 14], [[[u'fk_foul_lost', [99]], 
[u'total_red_card', [2]], [u'total_yel_card', [13]]]]]]]]]]

Where the above nested list is allocated to the variable responser I am using the following code: 在上面的嵌套列表分配给变量responser我使用以下代码:

for match in responser: 
    for num_events, team, events in match:

        for y in events[0]:
            for sub in y:
            print sub

This returns a result like this: 这将返回如下结果:

[0, 1]
[1, 18]
[7, 1]
[8, 1]
[[[u'fk_foul_lost', [82]], [u'total_red_card', [0]], [u'total_yel_card', [21]]]]
...
...
...
[1, 11]
[9, 1]
[[[u'fk_foul_lost', [78]], [u'total_red_card', [0]], [u'total_yel_card', [12]]]]
[0, 3]
[1, 14]
[[[u'fk_foul_lost', [99]], [u'total_red_card', [2]], [u'total_yel_card', [13]]]]

However what I want is just the numeric values within: 但是我想要的只是其中的数值:

[[[u'fk_foul_lost', [99]], [u'total_red_card', [2]], [u'total_yel_card', [13]]]]

Can anyone tell me the syntax I need to finish this code off? 谁能告诉我完成此代码所需的语法?

Thanks 谢谢

Try this: 尝试这个:

for match in responser: 
    for num_events, team, events in match:

        for y in events[0]:
            for sub in y:
                if isinstance(sub[0], list):
                    print sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM