Can you use the .sort() method to find most upvotes?

Just out of curiosity could you use the “key” parameter in the .sort(key=func) method to sort python_top_articles by upvotes?

Screen Link:
Challenge: Working With APIs Using Python | Dataquest

My Code:

Replace this line with your code

What I expected to happen:

What actually happened:

Replace this line with the output/error
1 Like

You should definitely try to explore your curiosity and play around with the code! Try it out or check out the documentation to confirm if it’s feasible or not.

1 Like

This is what I initially did, using a lambda function with the sorted(dict.items(), key= lambda item:item[1])

Then I looked at the solution because I was 100% sure that I could solve it with a for loop and frankly I wasn’t wrong.