我有两个文本文件,其中包含如下所示的数据,我想以Python中描述的格式显示输出。我将PyCharm IDE与python3.0结合使用。我还尝试在Python中使用dictionary和list,但未能正确获得它。你知道吗
[文件1.txt]
2|Stacey|Tucker 4|Simi|Mirza 9|Naved|Singh 6|Ram|Patel 7|Joe|Pruth
[文件2.txt]
2|26 6|17 9|30 4|31 7|35
所需打印输出:
2 Tucker,Stacey 26 4 Mirza,Simi 31 9 Singh,Naved 30 6 Patel,Ram 17 7 Pruth,Joe 35
谁能给我一个建议吗?你知道吗
如果文件不是很大,可以读取每个文件,将行附加到一个列表中(每个文件一个)。然后拆分“|”上的行。这将为您提供要匹配的索引[0]。因此,您可以将每个列表的各个部分合并到一个新的列表中进行输出。 新列表中的[0]来自任一列表,[2]来自file1list+“,”+[1]来自filelist1+[1]来自filelist2。你知道吗
相关问题 更多 >
编程相关推荐