列表索引拆分

2024-04-26 09:39:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用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不返回任何结果。如果我用>=替换<=,这就行了。为什么<什么都不做?你知道吗


Tags: the方法in密码列表searchlenwith