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

 

my_len


Write a function,

 my_len(mappings) 
that, given a list of mappings representing a dictionary, first creates the corresponding dictionary and then computes the length of that dictionary. Recall that to create a dictionary you need the code
D = {}
for mapping in mappings:
  key = mapping[0]
  value = mapping[1]
  D[key] = value

# at this spot, outside the loop above, it's as if D was the parameter
Paste this code into the space below, then find the number of keys in D. Note that D could have fewer than 5 keys, because the latter mappings can overwrite the earlier ones. In the second example below, 'B' starts off mapped to 2, but then later it's mapped to 3 instead.

my_len([['A', 1], ['B', 2], ['C', 3], ['D', 4], ['E', 5]]) → 5
my_len([['A', 1], ['B', 2], ['C', 2], ['B', 3], ['C', 4]]) → 3
my_len([['A', 1], ['B', 1], ['B', 2], ['B', 2], ['B', 3]]) → 2

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

def my_len(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

Difficulty: 10

Copyright Nick Parlante 2017 - privacy