python - Is it possible to turn this code snippet in a list comprehension? How? -


 = 0 b = {'a': [(1, 'a'), (2, 'b'), (3, 'c')], 'b': [(4, 'd'), (5, 'e')]}  c, d in b.iteritems():     e, f in d:         += e  // = 15 

tried several ways. want know way (if possible) simplify sum list comprehension:

a = sum(...)

thank in advance, pf.me

a = sum(e d in b.itervalues() e, _ in d) works in python 2.7.

a = sum([e d in b.itervalues() e, _ in d]) works in python 2.3.

i haven't tried it, a = sum(e d in b.values() e, _ in d) should python 3.0 equivalent.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -