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

 

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

Create a dictionary that has keys 2,3,5,7,11 each of which has a value that is an empty list. Look at the list of number, and append each number to the lists of the keys that evenly divide the number. You can loop over a dictionary keys using 'for k in dict' / 'for k in dict.keys()' without quotes.

e.g. Given a list [6,30] the 6 would be appended to the d[2] and d[3]. 30 would be appended to d[2], d[3], and d[5]. etc.

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.


divisibilityDict([6, 30]) → [{2: [6, 30], 3: [6, 30], 5: [30], 7: [], 11: []}]
divisibilityDict([]) → [{2: [], 3: [], 5: [], 7: [], 11: []}]
divisibilityDict([57]) → [{2: [], 3: [57], 5: [], 7: [], 11: []}]

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

def divisibilityDict(nums):

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