Emily Dickinson Experiment

1. Lets' read some poety, and see what we can do...

https://repl.it/@JimSkon/EmilyDickinson1

2. Could we count the number of times each vowel is used?

3. Can we break the lines into words?

https://repl.it/@JimSkon/EmilyDickinson2

4. Can we make a function countWords(word) to ask for a word and then count it?

5. What if we search for "see"? How about "see;"? How about "say", "say,', "Say", and "Say,"? What could we do about this?

6. Use the code from #3 to count the "was", and "was,". Why is there a difference? Consider the code below:

def removePunctuation(s):
  import string
  for c in string.punctuation:
    s= s.replace(c,"")
  return s

What does this code do? Call this on every line and search for "was". What changed?

7. Consider the function s.lower(), where s is a string. What does it do? How might this be useful to counts words?

8. Can you find and display all the lines that have a repeated word? Can you include the word, and the number of occurances in the line for each repeated word?

9. What would it take to create a list of all of the unique words and write them to a file, one word per line? Try it.

10. Comment your code and thurn it in.

Solutions

Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r4 - 2019-02-09 - JimSkon
 
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback