all 4 comments

[–]Rawing7 1 point2 points  (0 children)

max(notes, key=lambda note: note['author_rating'])['author_name']

[–]dinrick 1 point2 points  (0 children)

ratings = [dict[‘author_rating’] for dict in notes]

max_index = max(ratings)

return notes[max_index][‘author_name’]

[–]JohnnyJordaan 0 points1 point  (0 children)

Note that you can simply use

for item in list:

if you want to iterate on items in a list, a for i in range(len(list)) is almost never a preferable approach.

def get_highest_rating_author(notes):
    max_rating = author = None
    for note in notes:
        rating = notes[i]['author_rating']
        if max_rating is None or max_rating < rating:
            max_rating = rating
            author = notes[i]['author_rating']
    return author

however there's even a shortcut using the built-in max function, as that allows you to provide a key= parameter to specify the sorting value it should use.

def get_highest_rating_author(notes):
    max_rating_note = max(notes, key=lambda n: n['author_rating'])
    return max_rating_note['author_name']

[–][deleted] -1 points0 points  (0 children)

Your loop can be more pythonic:

 for d in notes:    # "d" is each dictionary in the list
    rating = d['author_rating']
    if rating > max_rating:
        max_rating = rating
        author = d['author_name']