小编use*_*566的帖子

从列表中创建字典

所以我创建了一个这样的列表:

list = [line.strip() for line in open('file.txt','r')]
Run Code Online (Sandbox Code Playgroud)

这是我的列表的片段.

[
 '1 2',
 '2 3',
 '2 3',
 '4 3 1',
 '3 4',
 '5 4 2 1',
 '4 4',
 '8 3 5 2',
 '5 7',
 '15 11 8 9 6 3 4',
]
Run Code Online (Sandbox Code Playgroud)

我想创建一个字典,其中第一个数字是键,后面的数字是值,但我希望它以int形式.

我不知道如何使用字典中涉及的类.

python dictionary list

0
推荐指数
1
解决办法
109
查看次数

标签 统计

dictionary ×1

list ×1

python ×1