143k views
0 votes
The file includes 4993 tweets including the keyword 'election'. Each tweet is represented in a separate line. Write a program to open the file and read through its lines, then only if a tweet includes a hashtag (a term beginning by the

1 Answer

3 votes

Answer:

import re

with open("../../Downloads/Tweets.txt","r", encoding="utf-8") as tweets:

myfile = tweets.readlines()

for item in myfile:

item = item.rstrip()

mylist = re.findall("^RT (.*) ", item)

if len(mylist) !=0:

for line in mylist:

if line.count("#") >=1:

ln = line.split("#")

dm = ln[1]

print(f"#{dm}")

Step-by-step explanation:

The python source code filters the document file "Tweets" to return all tweets with a hashtag flag, discarding the rest.

User DEBENDRA DHINDA
by
5.5k points