I have a dictionary that looks like this:
d = {'A':110, 'a':100, 'T':50, 't':5}
I want to change the keys to uppercase and combine A+a and T+t and add their values ββso that the resulting dictionary looks like this:
d = {'A': 210, T: 55}
This is what I tried:
for k, v in d.items(): k.upper(), v
and the result:
('A', 110) ('A', 100) ('T', 50) ('t', 5)
I look like tuples, but I want to change it in the dictionary, so I tried to write a function:
def Upper(d): for k, v in d.items: k.upper(), v return d
but it returns the dictionary unchanged.
After I changed the keys to uppercase, I found this solution how to add key values ββto the dictionary:
dict([(x, a[x] + b[x]) if (x in a and x in b) else (x, a[x]) if (x in a) else (x, b[x])
but first i need to get the keys in uppercase!
source share