当列表由搅拌组成时,如何跨列表内容执行功能?

问题描述 投票:0回答:1

我正在尝试为以下基本想法创建一个函数:

test_var = "He rose from bed in a scurry, and CRIED HIMSELF TO SLEEP"
var2 = test_var.strip()
print(var2) 
var3 = var2.split()
print(var3)

print(len(str(var3[0]))) #This is the goal function, something that gives me information on an items individual character length

def length():
    for i,word in var3:
        if len(str(set(var3[i]))) >4:
            return(True)
        else: 
            return(False)
length()

这显然不起作用,但我不知道该去哪里。我知道枚举函数是一回事,但我也不完全确定它是如何工作的。

python list function for-loop return
1个回答
0
投票

你的大部分代码是完全不必要的。

gibberish = "He rose from bed in a scurry, and CRIED HIMSELF TO SLEEP"

def length(data:str):
    for word in data.split():
        print(word, len(word) > 4)

length(gibberish)
© www.soinside.com 2019 - 2024. All rights reserved.