Aug-14-2018, 10:02 AM
I have 3 dictionaries in which I am trying to update the values of the keys.
The keys of each dictionary are identical, so I thought I could simply cycle round the dictionaries using a 'For' condition.
"{'Bi': 0, 'Of': 0, 'Spd': 0}
Traceback (most recent call last):
File "C:\Users\Astrikor\Desktop\CyclePairs.py", line 23, in <module>
Pair['Bi'] = Pair + 'b'
TypeError: 'str' object does not support item assignment"
As I am still a (very) newbie, I am sure I have a misunderstanding somewhere here (maybe I should be using a Function ?)
Any help would be welcome
Many thanks
Astrikor
The keys of each dictionary are identical, so I thought I could simply cycle round the dictionaries using a 'For' condition.
A = {'Bi' : 0,'Of' : 0,'Spd' : 0} E = {'Bi' : 0,'Of' : 0,'Spd' : 0} U = {'Bi' : 0,'Of' : 0,'Spd' : 0} print(A) Ab = 24 Ao = 41 Eb = 67 Eo = 80 Ub = 15 Uo = 30 for i in range(3): if i == 0: Pair = 'A' elif i == 1: Pair = 'E' elif i == 2: Pair = 'U' Pair['Bi'] = Pair + 'b' Pair['Of'] = Pair + 'o' Pair['Spd'] = Pair + 'o' - Pair + 'b' print(Pair)However, when run I get only the first printout followed by an error message as follows:
"{'Bi': 0, 'Of': 0, 'Spd': 0}
Traceback (most recent call last):
File "C:\Users\Astrikor\Desktop\CyclePairs.py", line 23, in <module>
Pair['Bi'] = Pair + 'b'
TypeError: 'str' object does not support item assignment"
As I am still a (very) newbie, I am sure I have a misunderstanding somewhere here (maybe I should be using a Function ?)
Any help would be welcome
Many thanks
Astrikor