如何在 python 中滑动字符串?
How to slide a string in python?
我想滑动一个字符串,但是程序输出错误。
Traceback (most recent call last):
File "<tmp 3>", line 28, in <module>
print_hell(sentence)
File "<tmp 3>", line 23, in print_hell
print(i)
TypeError: 'list' object is not callable
我该怎么办?
'''
sentence = "hello, how are you doing. I am doing good how are you. the work I am doing is hellish. please help me escape this hell. I will try my best. But oh hell no. this is too hard"
def string2list(text):
''' devide the list into smaller interval for easy to work '''
final_text = []
k = text.split(".")
for i in range(len(k)):
v = k[i].split()
final_text.append(v)
# return something like this [["",""],["",""]]
return final_text
def print_hell(text):
"print the sentence with the word 'hell', even the word like 'hello' with hell in it "
khn = string2list(text)
for i in range(len(khn)):
for l in range(len(khn[i])):
for c in range(len(khn[i][l])-4):
# 4 because the word hell has 4
if khn[i][l][c:4] == "hell":
print(i)
if __name__ == '__main__':
#print(string2list(text))
print_hell(sentence)
# v = string2list(text)
# print(text[1][2])
'''
谢谢,
essay = "print the sentence with the word 'hell'. Even the word like 'hello' with hell in it. And even hellooo. Not this though "
list_of_sentences = essay.split(".")
for sentence in list_of_sentences:
if "hell" in sentence.lower():
print(sentence)
这样你首先将文章转换为句子列表,然后检查列表中的每个句子是否包含字母“hell”的组合
我想滑动一个字符串,但是程序输出错误。
Traceback (most recent call last):
File "<tmp 3>", line 28, in <module>
print_hell(sentence)
File "<tmp 3>", line 23, in print_hell
print(i)
TypeError: 'list' object is not callable
我该怎么办?
'''
sentence = "hello, how are you doing. I am doing good how are you. the work I am doing is hellish. please help me escape this hell. I will try my best. But oh hell no. this is too hard"
def string2list(text):
''' devide the list into smaller interval for easy to work '''
final_text = []
k = text.split(".")
for i in range(len(k)):
v = k[i].split()
final_text.append(v)
# return something like this [["",""],["",""]]
return final_text
def print_hell(text):
"print the sentence with the word 'hell', even the word like 'hello' with hell in it "
khn = string2list(text)
for i in range(len(khn)):
for l in range(len(khn[i])):
for c in range(len(khn[i][l])-4):
# 4 because the word hell has 4
if khn[i][l][c:4] == "hell":
print(i)
if __name__ == '__main__':
#print(string2list(text))
print_hell(sentence)
# v = string2list(text)
# print(text[1][2])
'''
谢谢,
essay = "print the sentence with the word 'hell'. Even the word like 'hello' with hell in it. And even hellooo. Not this though "
list_of_sentences = essay.split(".")
for sentence in list_of_sentences:
if "hell" in sentence.lower():
print(sentence)
这样你首先将文章转换为句子列表,然后检查列表中的每个句子是否包含字母“hell”的组合