I\'m working with a list
of dict
objects that looks like this (the order of the objects differs):
[
{\'name\': \'Foo\', \'score
This is the simplest way I can think of:
names = set(d['name'] for d in my_dicts)
new_dicts = []
for name in names:
d = dict(name=name)
d['score'] = max(d['score'] for d in my_dicts if d['name']==name)
new_dicts.append(d)
#new_dicts
[{'score': 2, 'name': 'Baz'},
{'score': 3, 'name': 'Foo'},
{'score': 3, 'name': 'Bar'}]
Personally, I prefer not to import modules when the problem is too small.