Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
The keys in a dictionary are guaranteed to be unique, but the values are not. Write a function called count_values that takes a single dictionary as an argument and returns the number of distinct values it contains. For example,given the input {’red’:1,
def count_values(dict):
values_count = {}
for key in dict:
values_count[dict[key]] = dict[key]
return len(values_count)
dict = {'red':1, 'green':1, 'blue':2}
print "Unique Values in Dictionary : %d" % count_values(dict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.