I am trying to find out how to read a string for names with no spaces ex.
(我正在尝试找出如何读取不带空格的名字的字符串。)
robbybobby I want it to search the string and separate them into there own groups (robbybobby我希望它搜索字符串并将它们分成自己的组)
def wordcount(filename, listwords):
try:
file = open(filename, "r")
read = file.readline()
file.close()
for word in listwords:
lower = word.lower()
count = 0
for letter in read:
line = letter.split()
for each in line:
line2 = each.lower()
line2 = line2.strip(".")
if lower == line2:
count += 1
print(lower, ":", count)
except FileExistsError:
print("no")
wordcount("teststring.txt", ["robby"])
with this code it will only find robby if there is a space afterwards
(使用此代码,只有在以后有空格的情况下,它才会发现robby)
ask by Xtyfi translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…