当列表是 python 中的字典值时更新列表元素



当列表是字典的值时,您能帮我更新列表的特定元素吗?模式:schema = {'name': ('newname', 'type', 'newtype')}例如:

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

我可以访问值(例如):

schema['foo'][2]

但是不能赋新值,因为schema是一个元组

谢谢

正如您在这里看到的,元组是不可更改的。如果你想更新这些值,你应该使用一个实际的列表[]。

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

最新更新