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

 

david.white@denison.edu cs112fall2015 > list2dict
prev  |  next  |  chance

Codingbat is unable to pass a dictionary as a parameter. It can, however, pass a list as a parameter. A dictionary is just a mapping from keys to values, so it's the same information as a list of pairs

[[key1,value1],[key2,value2],...]
Write a function
 list2dict(mappings) 
that takes as parameter a list of mappings like the above, and computes the corresponding dictionary, D. Then, because codingbat also can't return a dictionary, you must return [D], i.e. a one-element list containing D. Note that the items of mappings are themselves lists, and each mapping in mappings contains a key = mapping[0], and a value = mapping[1]

list2dict([['cow', 'moose'], ['chicago', 1], ['cs109', 'awesome']]) → [{'cs109': 'awesome', 'cow': 'moose', 'chicago': 1}]
list2dict([[0, 7], [1, 'spaceship'], ['data', 42]]) → [{0: 7, 1: 'spaceship', 'data': 42}]
list2dict([[True, 2], [False, 9], ['string', 5]]) → [{'string': 5, False: 9, True: 2}]

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

def list2dict(mappings):

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

Post-solution available

Copyright Nick Parlante 2017 - privacy