需要写一个python程序来打印“在较大尺寸的文本文件中重复的单词,给输入一个数值”。
示例task.txt苹果篮苹果橙子苹果篮柠檬篮文本文件包含以空格分隔的不同单词
my python program
with open('task.txt') as f:
string = f.read()
string = string.lower();
n = int(input("enter number :"))
words = string.split(" ");
print("the words which are repeated given number of times : ");
for i in range(0, len(words)):
count = 1;
for j in range(i+1, len(words)):
if(words[i] == (words[j])):
count = count + 1;
words[j] = "0";
if(count == n and words[i] != "0"):
print(words[i]);
else:
print('no word found')
break;
输出
enter number :3
the words which are repeated at a given number of times :
apple
basket
代码工作正常,但问题是如果文件大小为100 GB,如何以块为单位读取数据
转载请注明出处:http://www.baquan404.com/article/20230526/2350254.html