You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromaddictimportDictasdda=dd()
a.a.a[0] =1a.a.a[0] =123# here 0 is a keyprinta# {'a': {'a': {0: 123}}}a=dd()
a.a.a= [1,2,3]
a.a.a[0] ='asd'# here 0 is a indexprinta# {'a': {'a': ['asd', 2, 3]}}
How to handle this thing? if not read context, nobody know '0' is a key or a index.
The text was updated successfully, but these errors were encountered:
Hi @lpnueg4,
Code is best read with context. In your second example, you explicitly set a.a.a to be a list, hence I don't see a problem with addict here. In fact, you could create the equivalent example with a normal dictionary
>>>a= {'a': {'a': {0: 1}}}
>>>a['a']['a'][0] =123# here 0 is a key>>>print(a)
{'a': {'a': {0: 123}}}
>>>a= {'a': {'a': [1, 2, 3]}}
>>>a['a']['a'][0] ='asd'# here 0 is an index>>>print(a)
{'a': {'a': ['asd', 2, 3]}}
How to handle this thing? if not read context, nobody know '0' is a key or a index.
The text was updated successfully, but these errors were encountered: