Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary my best option?
#2
Quote:As a beginner, I have used a dictionary to ".get" one variable associated with a unique key.

However, what if I need to .get 47 variables based on the two-letter unique key?  Is that possible with a dictionary?  Is it easy to grab/identify each variable with some kind of loop or something? 
yes a for loop. 

You can also just return a list of keys via MY_DICTIONARY.keys() and a list of values with MY_DICTIONARY.values()

If you need to specify the key and not get all you can just loop them and insert an if condition to get the key/value pairs you want

for k,v in MY_DICTIONARY.items():
    #insert if condition here to check key for more filtering
    #k is the key
    #v is the value of that key
Post your code for more explicit help
Recommended Tutorials:
Reply


Messages In This Thread
Dictionary my best option? - by birdieman - Dec-31-2016, 01:20 AM
RE: Dictionary my best option? - by metulburr - Dec-31-2016, 02:02 AM
RE: Dictionary my best option? - by birdieman - Dec-31-2016, 02:37 AM
RE: Dictionary my best option? - by wavic - Dec-31-2016, 06:16 AM
RE: Dictionary my best option? - by Skaperen - Dec-31-2016, 10:25 AM
RE: Dictionary my best option? - by wavic - Dec-31-2016, 10:29 AM
RE: Dictionary my best option? - by Skaperen - Dec-31-2016, 10:37 AM
RE: Dictionary my best option? - by ichabod801 - Dec-31-2016, 02:49 PM
RE: Dictionary my best option? - by Skaperen - Jan-01-2017, 07:44 AM

Forum Jump:

User Panel Messages

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