小编MrR*_*ken的帖子

Python,如何使用文件中的行作为字典中的键,使用下一行的值?

我有这样一个文件:

   Ben
   0 1 5 2 0 1 0 1
   Tim
   3 2 1 5 4 0 0 1
Run Code Online (Sandbox Code Playgroud)

我想创建一个如下所示的字典:

    {Ben: 0 1 5 2 0 1 0 1, Tim : 3 2 1 5 4 0 0 1}
Run Code Online (Sandbox Code Playgroud)

所以我想的是:

   for line in file:
       dict[line] = line + 1
Run Code Online (Sandbox Code Playgroud)

但你不能遍历这样的文件,那么我该如何去做呢?

python dictionary file

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

标签 统计

dictionary ×1

file ×1

python ×1