Question 25:Find the output of the following program:
counter = {}
def addToCounter(country):
if country in counter:
counter[country] + = 1
else :
counter[country] = 1
addToCounter( 'China' )
addToCounter( 'Japan' )
addToCounter( 'china' )
print ( len (counter))
|
(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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
17 Sep, 2020
Like Article
Save Article