简体   繁体   中英

Update list element when list is a dictionary's value in python

Could you help me to update a specific element of a list when this list is a dictionary's value? Pattern: schema = {'name': ('newname', 'type', 'newtype')} For example:

schema = {'foo': ('foo', 'text', 'text')}
Should give:
schema = {'foo': ('newfoo', 'text', 'boolean')}

I can access value with (for example):

schema['foo'][2]

But can't assign new value because schema is a tuple

Thank you

As you can read here , tuples are unchangeable. If you want to update the values, you should use an actual list [].

schema = {'foo': ['foo', 'text', 'text']}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM