Q. Find the errors:
(a)
text = "abracadbra"
counts = {}
for word in text :
counts[word] = counts [word] + 1
(b)
my_dict = {}
my_dict[1, 2, 4] = 8
my_dict[[4, 2, 1]] = 10
print (my_dict)
Answer :-
(a) Error in line 4. At first time, value of counts [word] is nothing. So, correct code:-
text = "abracadbra" counts = {} for word in text : counts[word] = 0 for word in text : counts[word] = counts [word] + 1 print( counts )
(b) Error in line 2 & 3 because here list is as key which is not acceptable.
Can u give reason why error is in 4th line
ReplyDeleteok, I have explained.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )