相关疑难解决方法(0)

在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 ×1

list ×1

python ×1