Python: accessing dictionary values with tuple keys [closed]

  dictionary, key, python, tuples

I have a dictionary dict with keys of tuple type (s1,s2), and values as list of dictionaries [{ }].

When I try to access dictionary values with tuple keys like below it outputs error:

new_dict = {}
for s in dict:
    if s[1] not in new_dict:        
        new_dict[s[1]] = [ ]
    new_dict[s[1]].append(dict[s])


TypeError: list indices must be integers or slices, not tuple

Why it is OK in s in dict but not in dict[s]?

Source: Python Questions

LEAVE A COMMENT