我有两个不同语言的文本文件,它们是逐行对齐的。一、 e.textfile1中的第一行对应于textfile2中的第一行,以此类推。
有没有办法同时逐行读取这两个文件?
下面是文件的外观示例,假设每个文件的行数约为1000000。
文本文件1:
This is a the first line in English
This is a the 2nd line in English
This is a the third line in English
文本文件2:
C'est la première ligne en Français
C'est la deuxième ligne en Français
C'est la troisième ligne en Français
期望输出
This is a the first line in English\tC'est la première ligne en Français
This is a the 2nd line in English\tC'est la deuxième ligne en Français
This is a the third line in English\tC'est la troisième ligne en Français
这个Read two textfile line by line simultaneously -java有一个Java版本,但是Python不使用逐行读取的bufferedreader。那怎么办呢?
输出:
在Python 3中,用内置的
zip
替换itertools.izip
。Python允许您逐行读取,甚至是默认的行为—您只需遍历文件,就像遍历列表一样。
wrt/同时遍历两个iterables,itertools.izip是您的朋友:
相关问题 更多 >
编程相关推荐