id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

wordFrequency


Write a function wordFrequency(text) that computes a dictionary containing the frequency of each word in the string text. For example, wordFrequency('I am I.') should return the dictionary {'I': 2, 'am': 1}. (Hint: the split and strip string methods will be useful, as you need to remove punctuation; use split first, then strip on each word in the resulting list). Once you have computed the dictionary D, return [D], i.e. return a one-item list containing the dictionary D. Without this, codingbat doesn't know how to check correctness.


wordFrequency('I am I.') → [{'I': 2, 'am': 1}]
wordFrequency('Capitalization matters: A a a, see?') → [{'A': 1, 'a': 2, 'see': 1, 'matters': 1, 'Capitalization': 1}]
wordFrequency('All work and no play; all work and no play? All work and no play!') → [{'All': 2, 'all': 1, 'play': 3, 'no': 3, 'and': 3, 'work': 3}]

...Save, Compile, Run (ctrl-enter)

def wordFrequency(text):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Copyright Nick Parlante 2017 - privacy