我试图使用split()
方法返回列表索引的句子长度<=
。如果我输入某个索引的确切长度,这是可行的,但是<
似乎没有任何作用。这是我的密码:
stories = [['With bloody hands, I say good-bye.'],
['TIME MACHINE REACHES FUTURE!!! ... nobody there ...'],
["Not In My Job Description: Make sure it's done by the end of the day Jones.\nBut, sir, it's not in my ....\nJust do it, and remember, no blood."]]
def len_sentence():
search = int(input("Enter int"))
for i in stories:
len1 = (i[0][0:].split(' '))
if len(len1) <= search:
print(i)
len_sentence()
用户输入的整数1-5不返回任何结果。如果我用>=
替换<=
,这就行了。为什么<
什么都不做?你知道吗
您尝试的输入太小。最短的故事有6个词长,所以输入1-5将不匹配任何东西。代码看起来不错,不过,这只是你的搜索输入。你知道吗
相关问题 更多 >
编程相关推荐