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.

2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post