3 ms·
For simple cases like this it doesn't even cost a couple lines as sum() can take a generator expression: sum(planet['moons'] for planet in target['system']['
by jeremiahwv 8y ago
For simple cases like this it doesn't even cost a couple lines as sum() can take a generator expression:
sum(planet['moons'] for planet in target['system']['planets'])
- divbzero 8y agoCombining ideas from parent and grandparent: sum(planet.get('moons', 0) for planet in target['system']['planets'])