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

 

bryce.hulett@hotmail.com > count_duplicates
prev  |  next  |  chance

Write a function named count_duplicates that accepts a list of integers as a parameter and that returns the number of duplicate values in the list. A duplicate value is a value that also occurs earlier in the list. For example, if a list named a contains [1, 4, 2, 4, 7, 1, 1, 9, 2, 3, 4, 1], then the call of count_duplicates(a) should return 6 because there are three duplicates of the value 1, one duplicate of the value 2, and two duplicates of the value 4. Constraints: The list could be empty or could contain only a single element in such cases, your function should return 0. Do not modify the contents of the list.


count_duplicates([1, 4, 2, 4, 7, 1, 1, 9, 2, 3, 4, 1]) → 6
count_duplicates([0, 0, -1, -1, -1, 5, 5, 5, 0, 0]) → 7
count_duplicates([42, 42, 42, 42]) → 3

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

def count_duplicates(lst):

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: 290 Post-solution available

Copyright Nick Parlante 2017 - privacy