Sail E0 Webinar
Question
What is the output of the following snippet of code?total={}def insert(items):    if items in total:        total[items] += 1    else:        total[items] = 1insert('Apple')insert('Ball')insert('Apple')print (len(total))
Options:
A .  3
B .  1
C .  2
D .  0
Answer: Option C


The insert() function counts the number of occurrences of the item being inserted into the dictionary. There are only 2 keys present since the key 'Apple' is repeated. Thus, the length of the dictionary is 2.



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers