Q. Predict the output:
(a)
fruit = {}
L1 = ['Apple', 'banana', 'apple']
for index in L1 :
if index in fruit :
fruit [index] += 1
else :
fruit [index] = 1
print (len(fruit))
print (fruit)
(b)
arr = {}
arr [1] = 1
arr ['1'] = 2
arr[1] += 1
sum = 0
for k in arr :
sum += arr[1]
print (sum)
Answer =
Output: -
(a)
3
{'Apple': 1, 'banana': 1, 'apple': 1}
>>>
(b)
4
>>>
Finally answer is complete
ReplyDeleteWhich answer.
Deletecan u tell me how the output came?
ReplyDeleteJust copy the code and paste it in your IDLE Python
DeleteCan you please explain it?
ReplyDeleteWhich one.
Deletecan u plz explain (B).
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )