Python Select Lowest Score In Each Group
I have the following in my database in an object called 'item' and I want to write some python that will select the lowest score from each group of student_id....I am a total pytho
Solution 1:
groupby
does what you want:
from itertools import groupby
data = getResultFromDatabase()
for id, items in groupby(data, lambda s: s['student_id']):
lowest_score_entry = min(items, key=lambda i: i['score'])
print lowest_score_entry['score'], lowest_score_entry['_id']
Post a Comment for "Python Select Lowest Score In Each Group"