Python-Quizzes | Python Dictionary Quiz | Question 25

Question 25:Find the output of the following program:

filter_none

edit
close

play_arrow

link
brightness_4
code

counter = {} 
  
def addToCounter(country): 
    if country in counter: 
        counter[country] += 1
    else
        counter[country] = 1
  
addToCounter('China'
addToCounter('Japan'
addToCounter('china'
  
print (len(counter))

chevron_right


(A) 0
(B) 1
(C) 2
(D) 3


Answer: (D)

Explanation: The task of “len” function is to return the number of keys in a dictionary. Here 3 keys are added to the dictionary “country” using the “addToCounter” function. The keys to a dictionary are case sensitive.

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.