It might be simple but im just a beginner. If i have this dictionary;
ds = {\"ABab\": 6.25, \"aBab\": 6.25, \"Abab\": 6.25, \"abab\": 6.25, \"ABab\": 6.25, \"aBa
As noted already, you can't store this data in a dictionary. You could store it in some other form such as a list of tuples.
ds = [("ABab", 6.25), ("aBab", 6.25), ("Abab", 6.25), ("abab", 6.25),
("ABab", 6.25), ("aBab", 6.25), ("Abab", 6.25), ("abab", 6.25),
("ABab", 6.25), ("aBab", 6.25), ("Abab", 6.25), ("abab", 6.25),
("ABab", 6.25), ("aBab", 6.25), ("Abab", 6.25), ("abab", 6.25)]
Then you can make a dictionary of the totals by first finding the unique keys and then summing the values of the tuples which have that key as their first value.
keys = set(k for k, _ in ds)
totals = {unique_key: sum(v for k, v in ds if k==unique_key)
for unique_key in keys}
Or another way (probably better)
totals = {}
for key, value in ds:
totals[key] = totals.get(key, 0) + value
You cannot have the same key twice in python. Every key in the dictionary must be unique. Review the documentation:
If a key occurs more than once, the last value for that key becomes the corresponding value in the new dictionary.
Your dictionary is automaticity not regarding the duplicate keys, it will always evaluate the last assigned key.
duplicate_keys = {"ABab": 6.25, "aBab": 6.25, "Abab": 6.25, "abab": 6.25, "ABab": 6.25, "aBab": 6.25, "Abab": 6.25, "abab": 6.25, "ABab": 6.25, "aBab": 6.25, "Abab": 6.25, "abab": 6.25, "ABab": 6.25, "aBab": 6.25, "Abab": 6.25, "abab": 6.25}
unique_keys = {"ABab": 6.25, "aBab": 6.25, "Abab": 6.25, "abab": 6.25}
duplicate_keys == unique_keys # True