Wednesday 15 August 2012

python - For loops and nested lists issue -



python - For loops and nested lists issue -

i have set of nested list beingness returned via json.loads method website xhr request:

[[[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 above nested list allocated variable responseri using next code:

for match in responser: num_events, team, events in match: y in events[0]: sub in y: print sub

this returns result 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 want numeric values within:

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

can tell me syntax need finish code off?

thanks

try this:

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

python list nested-lists

No comments:

Post a Comment