1
tags = {'stream', 'auth'} 
tags['stream']= {}
tags["stream"]["path"]= ["/streams"]
tags['stream']['attribute']= ['id', 'secure', 'cpcode', 'format', 'event_pattern']

The above code throws an error:

    tags["stream"]= {} 
TypeError: 'set' object does not support item assignment

How to create a dictionary of dictionary of list?

2 Answers 2

5

You created a set, not a dictionary. You need to specify key-value pairs:

tags = {'stream': None, 'auth': None} 

or specify the nested dictionary in literal notation in-place:

tags = {
    'stream': {
        'path': ["/streams"],
        'attribute': ['id', 'secure', 'cpcode', 'format', 'event_pattern'],
    }, 
    'auth': None,
} 

The {value, value, value} syntax (no keys) is the set literal notation.

Sign up to request clarification or add additional context in comments.

Comments

4

{'stream', 'auth'} is a set literal, not a dictionary.

Use a dictionary literal:

tags = {'stream': {}, 'auth': {}}
tags["stream"]["path"]= ["/streams"]
tags['stream']['attribute']= ['id', 'secure', 'cpcode', 'format', 'event_pattern']

>>> type({'stream', 'auth'})
<type 'set'>
>>> type({'stream': {}, 'auth': {}})
<type 'dict'>
>>>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.