0
related to letter counter
dict={} for i in range(20): if i>0: dict['m']=1 print(dict) output: ['m':1] why it does not output 'm':1 20 times ??
3 Answers
+ 1
Keys in a dictionary are unique, so there can only be one entry with key 'm'. First time 'm': 1 is added to the dictionary, then that entry is set to 1 19 times (no change)
+ 1
Because keys are unqiue in dictionary
0
kushal
because a key in a dict is unique...
to store the count of a letter in a dict use:
if key in dict:
dict[key] += 1
else:
dict[key] = 1
so if key exist in dictionary value is increased by one, else it is initialized to one ^^