我有以下文件文本。text:- 你知道吗
2013年6月8日05:04:02
2013年6月8日05:04:02
2013年6月8日05:04:02
2013年6月8日05:04:03
2013年6月8日05:04:03
2013年6月8日05:05:23
2013年6月8日05:05:23
2013年6月8日05:05:23
2013年6月8日05:05:23
我想用p打印这样的东西ython:- 你知道吗
2013年6月8日05:04:02-----3
2013年6月8日05:04:03----------2
2013年6月8日05:05:23----------4
这是我做的,我是这里的新手:-
"
import re
pattern = re.compile("\d+-\w+-\d+\s\d+:\d+:\d+")
open_file=open('mytest.txt')
for line in open_file:
four_letter_words = pattern.findall(line)
fp_len = len(pattern.findall(line))
for word in four_letter_words:
print four_letter_words , fp_len
"
不需要
regex
。您可以使用collectionsmodul中的counter,如下所述SO already answered
相关问题 更多 >
编程相关推荐