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

 

konstans@stuy.edu > categorize
prev  |  next  |  chance

You are given a list of words, each with a 3 letter animal prefix. The rest of the word is the suffix. Process all of the words, adding each new prefix to a dictionary with a list of all suffixes found for that prefix.

You can check if a key is already in a dict using the same 'value in list' style syntax: 'key in dict' (without quotes)

WARNING Codingbat has issues with formatting so you have to return a list with your dictionary inside of it. You must return [D] where D is your dictionary.


categorize(['yaktreat', 'yakbread', 'yakfood']) → [{'yak': ['treat', 'bread', 'food']}]
categorize(['yakfood', 'catfood', 'dogfood']) → [{'yak': ['food'], 'cat': ['food'], 'dog': ['food']}]
categorize(['ramsalad', 'yaktreat', 'yakbread']) → [{'yak': ['treat', 'bread'], 'ram': ['salad']}]

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

def categorize(words):

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