A post summary split into functions

Write code · Challenge · §7.3, §8.3 Handing over ingredients

total_likes is already complete. Write popular_authors(posts, limit=100), which returns a list of the authors whose posts have limit or more likes. Also write best_author(posts), which returns the author with the most likes. Do the printing outside the functions.

Starter code

posts = [{"author": "mina", "likes": 120},
         {"author": "jun", "likes": 80},
         {"author": "sora", "likes": 200},
         {"author": "hana", "likes": 0}]

def total_likes(posts):
    total = 0
    for post in posts:
        total += post["likes"]
    return total

# Write popular_authors and best_author here

print(total_likes(posts), best_author(posts))
print(popular_authors(posts))
print(popular_authors(posts, limit=150))

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.