# CODING EXERCISE # # Create a python class called KeywordTracker that tracks the occurrences of specific keywords. # It will require at least these methods: # # add_keyword: takes a string and adds it to the tracked keywords. # # track: takes a string, counts the occurrences of the specified keywords and returns an integer representing the # number of keyword instances in the string. # # results: returns a dictionary representing all keyword usage data. # # Here is an example of how it will be used and what the output should look like. # # >>> keyword_tracker = KeywordTracker('red', 'green') # # # >>> keyword_tracker.track('My favorite color is red.') # 1 # # >>> keyword_tracker.track('Red and green make yellow.') # 2 # # >>> keyword_tracker.track('The ball is blue.') # 0 # # >>> keyword_tracker.add_keyword('blue') # # >>> keyword_tracker.track('The American flag is red, white and blue.') # 2 # # >>> keyword_tracker.track('The sky looks extra blue today.') # 1 # # >>> keyword_tracker.results() # {'blue': 2, 'green': 1, 'red': 3} # Start your code here:
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question