Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accessing value in Dict
#3
you subscript the dictionary by key to get the value, so coins['Fifty'] will return 50. Unfortunately, the reverse does not work as values are not guaranteed to be unique. You can create a dynamic view with coins.items(), this will give you a list of tuples which then can be accessed as a pair
for coin, value in coins.items():
    print(coin,'=',value)
Output
Output:
Fifty = 50 Twenty = 20 Ten = 10 Five = 5 One = 1
Reply


Messages In This Thread
Accessing value in Dict - by Pioden - Apr-10-2020, 02:48 PM
RE: Accessing value in Dict - by deanhystad - Apr-10-2020, 03:24 PM
RE: Accessing value in Dict - by TomToad - Apr-10-2020, 03:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a dict in dict cherry_cherry 4 75,852 Apr-08-2020, 12:25 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

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