Python Forum
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dictionary questions
#9
When you have a problem that has you confused, sometimes you can use Python as a tool to examine your data to give you a clue on how to proceed. For example, the following code may help you get a better feel for the data. Combined with the clues above, you should be able to solve the problem.
di2={'GR':'Greece','IT':'Italy','ES':'Spain'}
print(di2.keys())
print(di2.values())
print(di2['GR'])
print("")
for i in di2:
    print(i)
    print(di2[i])

print("")
di={'A':['a',41],'B':['b',42],'C':['c',43]}
print(di.keys())
print(di.values())
s=0
for i in di:
    print("")
    print(di[i])
    print(di[i][0])
    print(di[i][1])
Output:
dict_keys(['ES', 'IT', 'GR']) dict_values(['Spain', 'Italy', 'Greece']) Greece ES Spain IT Italy GR Greece dict_keys(['B', 'C', 'A']) dict_values([['b', 42], ['c', 43], ['a', 41]]) ['b', 42] b 42 ['c', 43] c 43 ['a', 41] a 41
Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply


Messages In This Thread
dictionary questions - by atux_null - Nov-08-2017, 08:59 PM
RE: dictionary questions - by Larz60+ - Nov-08-2017, 10:09 PM
RE: dictionary questions - by atux_null - Nov-09-2017, 07:04 AM
RE: dictionary questions - by Larz60+ - Nov-09-2017, 01:13 PM
RE: dictionary questions - by atux_null - Nov-09-2017, 03:00 PM
RE: dictionary questions - by heiner55 - Nov-10-2017, 01:33 AM
RE: dictionary questions - by VlaDimitris - Jun-20-2018, 01:44 PM
RE: dictionary questions - by Nwb - Jun-20-2018, 03:45 PM
RE: dictionary questions - by ljmetzger - Jun-20-2018, 07:00 PM

Forum Jump:

User Panel Messages

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