This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Write code to find out how many lines are in the file emotion_words.txt as shown above. Save this value to the variable num_lines. Do not use the len method. | |
file = open("emotion_word.txt","r") | |
count = 0 | |
for aline in file.readlines(): | |
count += 1 | |
num_lines = count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p_phrase = "was it a car or a cat I saw" | |
r_phrase = p_phrase[::-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stopwords = ['to', 'a', 'for', 'by', 'an', 'am', 'the', 'so', 'it', 'and', 'The'] | |
sent = "The water earth and air are vital" | |
acro = "" | |
lst = sent.split() | |
for i in lst: | |
if i in stopwords: | |
lst.remove(i) | |
for j in lst: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. The textfile, travel_plans.txt, contains the summer travel plans for someone with some commentary. | |
# Find the total number of characters in the file and save to the variable num. | |
fileref = open("travel_plans.txt","r") | |
num = 0 | |
for i in fileref: | |
num += len(i) | |
fileref.close() | |
# 2. We have provided a file called emotion_words.txt that contains lines of words that describe emotions. |