flat = [ n for m in united_scores for n in m ]
ids = set(n['id'] for n in flat)
grouped = [ { 'id': n, 'score': sum(m['score'] for m in flat if m['id'] == n) } for n in ids ]
key = lambda item: (item[0], item[3])
keys = set(map(key, list_in))
list_out = [ [ k[0], sum(int(n[2]) for n in list_in if k == key(n)), k[1] ] for k in keys ]
ids = set(n['id'] for n in arr)
grouped = [ (i, [ n['qty'] for n in arr if n['id'] == i ]) for i in ids ]
summed = [ { 'id': k, 'qty': sum(v), 'id_count': len(v) } for k, v in grouped ]
def countCarsByBrand(cars, brands):
return sum(len(v.keys()) for k, v in cars.items() if k in brands)
print(countCarsByBrand(cars, [ 'Audi', 'BMW' ]))
range(length - 1, -1, -1)
), а ещё лучше вообще не модифицируйте список, а создавайте новый:sentences = [ n for n in sentences if n ]
for (name, items) in cook_book:
print('\n%s:' % name.capitalize())
for (ingredient, quantity, unit) in items:
print('%s, %d %s' % (ingredient, quantity * person, unit))