I want to only print out the line count and hashtag count only if the line starts with "RT" AND has at least 1 hashtag in it. i.e. there should be no lines of code that print out as "49 : 0"
PLEASE HELP - feel like I'm nearly there but need to add some more code into the second for loop. I'm getting confused with my indentation.
enter code herehashtag_count = 0 enter code hereline_count = 0 enter code herefor line in open("tweets.txt"): enter code hereline_split = line.split() enter code herehashtag_count = 0 enter code hereif line.startswith("RT "): enter code herefor word in line_split: enter code hereif "#" in word: enter code herehashtag_count += 1 enter code hereprint(str(line_count) + " : " + str(hashtag_count)) enter code hereline_count += 1
Aucun commentaire:
Enregistrer un commentaire