austen_string = open('../Data/Austen_PrideAndPrejudice.txt', encoding='utf-8').read()
alcott_string = open('../Data/Alcott_GarlandForGirls.txt', encoding='utf-8').read()

"""
Explanation: Working with Texts in Python
Below is my solution to the exercises posed in the notebook 01-WorkingWithTexts.
As a reminder, you were asked to:
Run the cell below to read in the text of "Pride and Prejudice" and assign it to the variable "austen_string" and read in the text of Louisa May Alcott's "A Garland for Girls," a children's book, and assugn it to the variable "aclott_string." With these variables, print the answer to the following questions

How many words are in each novel?
How many words in each novel appear in title case?
What is the approximate average word length in each novel?
How many words longer than 7 characters are in each novel? (don't worry about punctuation for now)
What proportion of the total words are the long words in each novel?
End of explanation
"""


austen_words = austen_string.split()
alcott_words = alcott_string.split()
print(austen_words[:10])
print(alcott_words[:10])

"""
Explanation: First, create variables that split the strings into lists of words. I'll print out the first 10 words to make sure everything looks good.
End of explanation
"""


#How many words are in each novel?
print("Number of words in Pride and Prejudice:")
print(len(austen_words))
print("Number of words in A Garland for Girls")
print(len(alcott_words))

"""
Explanation: To count the number of words, simply take the length of each list and print the result. You can add print statements to make the output look prett.
End of explanation
"""


#How many words in each novel appear in title case?
print("Number of words in title case in Pride and Prejudice:")
print(len([word for word in austen_words if word.istitle()]))
print("Number of words in title case in A Garland for Girls:")
print(len([word for word in alcott_words if word.istitle()]))

"""
Explanation: To count the number of words that are in title case we can use list comprehension.
End of explanation
"""


austen_word_length = [len(word) for word in austen_words]
print(austen_word_length[:10])
alcott_word_length = [len(word) for word in alcott_words]
print(alcott_word_length[:10])
print("Average word length in Pride and Prejudice:")
print(sum(austen_word_length)/len(austen_word_length))
print("Average word length in A Garland for Girls:")
print(sum(alcott_word_length)/len(alcott_word_length))

"""
Explanation: To get the average length of the words in each novel we first transform each word into its length, using the len function and list comprehension. I'll print out the first 10 word length to make sure we did it right. We can then sum the list and divide by the total number of words.
End of explanation
"""


##     How many words longer than 7 characters are in each novel? (don't worry about punctuation for now)
##     What proportion of the total words are the long words in each novel

austen_long = [word for word in austen_words if len(word)>7]
print("Number of long words in Pride and Prejudice:")
print(len(austen_long))

alcott_long = [word for word in alcott_words if len(word)>7]
print("Number of long words in A Garland for Girls:")
print(len(alcott_long))

print("Proportion of words that are long in Pride and Prejudice:")
print(len(austen_long)/len(austen_words))
print("Proportion of words that are long in A Garland for Girls:")
print(len(alcott_long)/len(alcott_words))

dir()
locals()

"""
Explanation: To count the number of long words I create two new variables and use list comprehension to keep only words longer than 7 characters. I then divide the length of these lists by the total number of words, to get proportion.
End of explanation
"""


