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

 

david.white@denison.edu cs111fall2019 > count_values
prev  |  next  |  chance

The keys in a dictionary are guaranteed to be unique, but the values are not. Write a function called

 count_values(mappings) 
that takes a list of mappings representing a single dictionary as an argument and, after converting the list to its corresponding dictionary, computes and returns the number of distinct values contained in the dictionary. Recall that to create a dictionary from mappings 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 solve the problem with the dictionary D.

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

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

def count_values(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: 100

Copyright Nick Parlante 2017 - privacy