在字典中打开文本文件-Python
文本文件读取在字典中打开文本文件-Python,python,file,dictionary,load,tuples,Python,File,Dictionary,Load,Tuples,文本文件读取 1 2 3 4, Eric Wont, 1/1/10, 1,2,10 5 6, John Smith, 2/2/10, 2/2/11 我想把它存储在一个字典中,数字作为键,名称和日期作为元组 {4: (Eric Wont, 1/1/10, 1,2,10)} 它看起来是这样的: val_dict = {} for line in open('a.txt'): vals = line.strip().split(', ', 3)
1
2
3
4, Eric Wont, 1/1/10, 1,2,10
5
6, John Smith, 2/2/10, 2/2/11
我想把它存储在一个字典中,数字作为键,名称和日期作为元组
{4: (Eric Wont, 1/1/10, 1,2,10)}
它看起来是这样的:
val_dict = {}
for line in open('a.txt'):
vals = line.strip().split(', ', 3)
val_dict[vals[0]] = tuple(vals[1:])
但这看起来并不是什么大问题,更像是一个家庭作业:)欢迎光临!当您在这里发布问题时,请确保包含一个简短的代码片段,向我们展示您迄今为止的尝试。帮助我们更准确地定位您的问题。