Aug-15-2018, 01:43 PM
Thanks Guys,
I am slowly learning!
I have removed the parentheses (j.crater), and also adopted ichabod801's suggestion to combine the three dictionaries.
The printout is as follows:
"{'A': {'Bi': 0, 'Of': 0, 'Spd': 0}, 'E': {'Bi': 0, 'Of': 0, 'Spd': 0}, 'U': {'Bi': 0, 'Of': 0, 'Spd': 0}}
{'A': {'Bi': 'Ab', 'Of': 'Ao', 'Spd': 0}, 'E': {'Bi': 'Eb', 'Of': 'Eo', 'Spd': 0}, 'U': {'Bi': 'Ub', 'Of': 'Uo', 'Spd': 0}}"
Which whilst it runs correctly, it does not load the values of the variables
e.g instead of 'Ab' I need it to load the value of Ab (i.e 24) for the key 'Bi' etc...
If I try replacing
Pairs[key]['Bi'] = key + 'b'
with
Pairs[key]['Bi'] = float(key + 'b')
this error shows up:
ValueError: could not convert string to float: 'Ab'
I have searched on line for this error, but can't see how apply a correction.
Any further suggestions?
Sorry to test your patience....
Astrikor
I am slowly learning!
I have removed the parentheses (j.crater), and also adopted ichabod801's suggestion to combine the three dictionaries.
A = {'Bi' : 0,'Of' : 0,'Spd' : 0} E = {'Bi' : 0,'Of' : 0,'Spd' : 0} U = {'Bi' : 0,'Of' : 0,'Spd' : 0} Ab = 24 Ao = 41 Eb = 67 Eo = 80 Ub = 15 Uo = 30 Pairs = {'A': A, 'E': E, 'U': U} print(Pairs) for key in Pairs: Pairs[key]['Bi'] = key + 'b' Pairs[key]['Of'] = key + 'o' print(Pairs)It's concise code and a very nice improvement on the original.
The printout is as follows:
"{'A': {'Bi': 0, 'Of': 0, 'Spd': 0}, 'E': {'Bi': 0, 'Of': 0, 'Spd': 0}, 'U': {'Bi': 0, 'Of': 0, 'Spd': 0}}
{'A': {'Bi': 'Ab', 'Of': 'Ao', 'Spd': 0}, 'E': {'Bi': 'Eb', 'Of': 'Eo', 'Spd': 0}, 'U': {'Bi': 'Ub', 'Of': 'Uo', 'Spd': 0}}"
Which whilst it runs correctly, it does not load the values of the variables
e.g instead of 'Ab' I need it to load the value of Ab (i.e 24) for the key 'Bi' etc...
If I try replacing
Pairs[key]['Bi'] = key + 'b'
with
Pairs[key]['Bi'] = float(key + 'b')
this error shows up:
ValueError: could not convert string to float: 'Ab'
I have searched on line for this error, but can't see how apply a correction.
Any further suggestions?
Sorry to test your patience....
Astrikor