#100DaysOfCode in Python Transcripts
Chapter: Days 58-60: Twitter data analysis with Python
Lecture: Identify the most popular tweets

Login or purchase this course to watch this video and the rest of the course contents.
0:00 And let's see, in particular,
0:03 what tweets were most popular.
0:05 And I'm going to first use a list comprehension,
0:08 which I showed you on Day 16,
0:10 to exclude the retweets.
0:15 And a retweet is easy to see
0:18 because it always starts with a RT.
0:21 Next, let's get the top 10.
0:25 And for that I need to do some sorting.
0:33 Okay, so how does sorted work?
0:35 You give it a sequence, which is the list of tweets
0:38 and we use the key argument that can take a function
0:41 or callable and we give it a lambda,
0:43 which is basically a just a simple function in a one-liner.
0:46 And we give it a tweet,
0:47 and then it will average
0:49 of the number of likes and retweets.
0:51 That's sorts the list of tweets by highest average.
0:55 And if you then do it reversed=True,
0:57 you get the highest at the top.
0:59 Alright?
1:00 Got already with this format.
1:02 So, let's try the for loop to make it nicer.
1:05 First, I'll do a specify a format,
1:09 which I will then use for every row.
1:15 I got a column of five.
1:19 Separator...
1:23 Another column of five...
1:26 And the text.
1:28 You can use f-strings.
1:30 When I was preparing this notebook,
1:31 I will still using the older formats,
1:33 so I'm going with that for now.
1:36 Besides, if you're not on 3.6, you might still need it.
1:40 I use some nice icons.
1:44 Then I do a dashed line
1:48 which I can just say
1:50 dash times 100
1:52 and then the loop.
1:53 For tweet in top 10,
1:57 I'm going to print, format, format,
2:01 and then I can just fit in those keyboard arguments
2:04 likes...
2:08 and just for the fun of it,
2:09 let's use a return icon instead of the new line.
2:14 Oops.
2:19 And I have to close this.
2:21 Look at that.
2:22 Our first tweet was the launch of our co-tennis platform.
2:25 And the second one was our Flash course, etc, etc.
2:30 So we have the likes, number of retweets
2:33 and the text of the tweets.
2:35 So here you already see the benefits
2:37 of doing a bit of data analysis to explore your data set.
2:40 And it's not taking that much of code.
2:43 Once we have the data loaded in, it's fairly easy.