python - Removing this value from a deeply nested list -



python - Removing this value from a deeply nested list -

i have next info construction returned json object:

[[[13, u'arsenal', [[6.125, [[u'assist', u'cross', [3]], [u'normal', u'cross', [198]], [u'normal', u'longball', [326]], [u'assist', u'short', [5]], [u'normal', u'short', [4726]], [u'assist', u'throughball', [1]], [u'normal', u'throughball', [35]]]]]]]]

i having problem converting construction dictionary. dictionary has set of tuples keys, made text objects in above nested lists (i.e. ('assist', u'cross')). code using is:

for match in responser: num_events, team, events in match: regex = {tuple(sub[:2]): sub[2][0] y in events[0] sub in y}

however returns next error:

exceptions.typeerror: 'float' object not iterable

the reason seems value 6.125,. how can remove nested list structure, maintain same number of brackets allow code converts nested list dictionary maintain working?

thanks

you can't iterate on float, if @ variable events:

events[0] = [6.125, [[u'assist', u'cross', [3]], [u'normal', u'cross', [198]], [u'normal', u'longball', [326]], [u'assist', u'short', [5]], [u'normal', u'short', [4726]], [u'assist', u'throughball', [1]], [u'normal', u'throughball', [35]]]]

notice element 0 = 6.125

change code to:

regex = {tuple(sub[:2]): sub[2][0] y in events[0][1:] sub in y}

notice specification events -- skip element 0 , take rest.

output regex then:

{(u'assist', u'cross'): 3, (u'assist', u'short'): 5, (u'assist', u'throughball'): 1, (u'normal', u'cross'): 198, (u'normal', u'longball'): 326, (u'normal', u'short'): 4726, (u'normal', u'throughball'): 35}

python json list nested-lists

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -