我JSON.Loads
从网站XHR请求中通过方法返回了一组嵌套列表:
[[[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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句