如何将字段范围设置为python字典中的值?

ahj*_*ahj 1 python dictionary

我的输入文件如下所示:

1_10001 1       10001   1       342     0       0       0       342
1_10002 1       10002   3       426     379     34      0       13
1_10003 1       10003   2       506     480     0       0       26
1_10004 1       10004   1       562     0       562     0       0
Run Code Online (Sandbox Code Playgroud)

我想创建一个字典,其中第一个字段(1_10001等)是键,2:8是值.我试过这个:

d = {}
with open("test.in") as f:
     for line in f:
             sep = line.split()
             d[sep[1]] = sep[2:]
Run Code Online (Sandbox Code Playgroud)

它不会抛出错误,但d看起来像这样:

d {'1':['10010','1','634','0','634','0','0']}

我希望密钥是字符串"1_10001"等,而不是"1".另外,其余部分在哪里?我也试过把2:8放在一个列表中,但这给出了错误:

TypeError:list indices必须是整数,而不是list

我是python的新手,所以请原谅任何愚蠢.谢谢.

dck*_*ney 5

Python中的列表从0开始索引.

尝试:

d = {}
with open("test.in") as f:
     for line in f:
             sep = line.split()
             d[sep[0]] = sep[1:]
Run Code Online (Sandbox Code Playgroud)