相关疑难解决方法(0)

在字典中添加新密钥?

创建后,是否可以在Python字典中添加密钥?它似乎没有.add()方法.

python lookup dictionary

2427
推荐指数
18
解决办法
320万
查看次数

在Python中将列表转换为字典

假设我a在Python中有一个列表,其条目可以方便地映射到字典.每个偶数元素代表字典的键,以下奇数元素是值

例如,

a = ['hello','world','1','2']
Run Code Online (Sandbox Code Playgroud)

我想把它转换成字典b,在那里

b['hello'] = 'world'
b['1'] = '2'
Run Code Online (Sandbox Code Playgroud)

什么是语法上最干净的方法来实现这一目标?

python dictionary list

177
推荐指数
5
解决办法
45万
查看次数

标签 统计

dictionary ×2

python ×2

list ×1

lookup ×1