[英]For loops and nested lists issue
我有一组嵌套列表从网站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]]]]]]]]]]
在上面的嵌套列表分配给变量responser
我使用以下代码:
for match in responser:
for num_events, team, events in match:
for y in events[0]:
for sub in y:
print sub
这将返回如下结果:
[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]]]]
但是我想要的只是其中的数值:
[[[u'fk_foul_lost', [99]], [u'total_red_card', [2]], [u'total_yel_card', [13]]]]
谁能告诉我完成此代码所需的语法?
谢谢
尝试这个:
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.