小编use*_*145的帖子

在文件中查找重复的行并计算每行复制的时间长度?

假设我有一个类似于以下的文件:

123 
123 
234 
234 
123 
345
Run Code Online (Sandbox Code Playgroud)

我想找出'123'重复多少次,重复'234'多少次等等.理想情况下,输出结果如下:

123  3 
234  2 
345  1
Run Code Online (Sandbox Code Playgroud)

file lines count find duplicates

491
推荐指数
7
解决办法
49万
查看次数

在python中,如何根据特定值将文件解析为列表?

我有一个大的制表符分隔文本文件,例如,将其命名为john_file:

1 john1 23 54 54
2 john2 34 45 66
3 john3 35 43 54
4 john2 34 54 78

5 john1 12 34 65
6 john3 34 55 66

什么是基于名称(john1,2或3)将此文件解析为3个列表的快速方法?

fh=open('john_file.txt','r').readlines()
john1_list=[]
for i in fh:
 if i.split('\t')[1] == "john1":
  john1_list.append(i)
Run Code Online (Sandbox Code Playgroud)

提前致谢

python parsing file list

1
推荐指数
1
解决办法
2194
查看次数

标签 统计

file ×2

count ×1

duplicates ×1

find ×1

lines ×1

list ×1

parsing ×1

python ×1