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

 

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

Write a function called

count_duplicates(mappings)
that takes a list of mappings (specifying a dictionary), creates the dictionary, and returns the number of values in the dictionary that appear two or more times. 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_duplicates([['A', 1], ['B', 2], ['C', 3], ['D', 4], ['E', 5]]) → 0
count_duplicates([['A', 1], ['B', 2], ['C', 2], ['D', 3], ['E', 4]]) → 1
count_duplicates([['A', 1], ['B', 1], ['C', 2], ['D', 2], ['E', 3]]) → 2

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

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