我需要你的帮助。在
我有一个文本文件包含一行的列表,每行代表一个项目列表。我需要提取频率为>;=2的所有项目并将它们输出到另一个项目中文件。这里一个例子。在
['COLG-CAD-406', 'CSAL-CAD-030', 'COLG-CAD-533', 'COLG-CAD-188']
['COLG-CAD-188']
['CSAL-CAD-030']
['EPHAG-JAE-004']
['COLG-CAD-188', 'CEM-SEV-004']
['COL-CAD-188', 'COLG-CAD-406']
输出应该是
^{2}$以此类推直到文件结束
事先非常感谢你的帮助。在
关于:
其中
f
是您的文件这是一个完整的脚本,它使用regex实现您想要的功能:
这可以简化为:
^{pr2}$如果您使用的是Python2.7及更高版本,使用以下输入(称为
list1.txt
):这个python程序:
^{pr2}$你得到你想要的:
相关问题 更多 >
编程相关推荐