Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dictionary question
#1
Hi I'm currently learning the basic python course, dictionary.

Item = {‘Apple’ : 10, ‘Banna’ : {‘Apple’ : 5, ‘Banna’ : 20}} here is the code that is given.
1. The question is about finding the Apple value and explain the reason for the result.
2. What code should I write in order to use 'Apple' that is in the 'Banna' value.

Thanks.!
Reply
#2
The Apple that you want is the first element in the Banana dictionary not the first element in the Item dictionary. Sooo....

Item = {'Apple' : 10, 'Banana' : {'Apple' : 5, 'Banana' : 20}}
print (Item ['Banana']['Apple'])
stereokim123 likes this post
Reply
#3
(Apr-01-2021, 09:17 PM)BashBedlam Wrote: The Apple that you want is the first element in the Banana dictionary not the first element in the Item dictionary. Sooo....

Item = {'Apple' : 10, 'Banana' : {'Apple' : 5, 'Banana' : 20}}
print (Item ['Banana']['Apple'])

you saved ma life bro thx
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dictionary question kam_uk 7 3,026 Nov-22-2020, 05:43 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020