- [Instructor] In this self check exercise
I'd like you to use the techniques
that I just demonstrated to you in the preceding video
to show the top three trending topics for today
in the United States.
And for that purpose you'll use this WOEID.
So go ahead and give that a shot
then come back to see the answer.
Okay let's start revealing the answer to this exercise.
So first up we want to acquire the U.S. trends
so again this is going to be a list
containing one dictionary for the United States
which has the WOEID that you see here.
So we'll go ahead and grab that.
And you might have noticed there was a little delay there
while that executed to get us the results.
We want to acquire from that dictionary
the trends list for the United States
so we go into element zero of the list
that was returned back here
then we access that dictionary's trends key
which gives us back the trends that we need.
And once again we're going to filter those tweets
by tweet volume
and we're going to sort them in descending order
by only those tweets that have the value 10,000 or more.
So again this value will be none
if it's fewer than 10,000 tweets
anything with 10,000 tweets or more
will have an actual tweet count.
So we'll first filter out anything that doesn't have
or filter out anything that does have none in it
so we have only trends with 10,000 tweets or more
then we'll go ahead and sort those
once again by that tweet volume key in reverse order.
So that will give us the list in the format that we need
and then finally we wanted to show just the top three
trends for the United States today
so we'll go ahead and execute this loop
which accesses a slice of the U.S. list
and as you can see we have today's top three topics
as of right now when I'm performing this video recording
for the United States.
And if you execute this code again on a different day
when you're watching the video,
you'll get whatever the current trending topics are
and if you do it at multiple times during the day
it is possible based on the virality of the trends
that the order of these will change
or that the topics themselves will change as well.