Find Relevant Top Hashtags Using Python -Part 1

K. N
The Startup
Published in
3 min readAug 12, 2020

--

Image Source

In the age of social media, it is all about getting more audience. One of the may ways of doing so is using hashtags. If you know what the top hashtags are, you can include them in your post and potentially get discovered by more audience who are looking at posts associated with those hashtags.

The source code can be found here.

The outline:

Here, we will write code that takes some text input from the user, converts it to a hashtag and then retrieves top tweets with that hashtag from twitter. The code will then scrape the retrieved tweets for other hashtag and finally return a list of all the hashtags for the user to review/use.

Getting user input

We will ask the user for input and save it to a variable “tag” after converting it to string.

tag =str(input(“Please enter your hashtag/text: “))

Cleaning user input

Hashtags are lower case with no space. Therefore, you have to consider the possibility that the user may provide text that may not be all lower case and may also contain spaces. We will write a function that takes the text, converts it to lower case and removes all spaces. It will also remove “#” from the beginning of the tag in case the user gave a hashtag as input.

--

--