lov*_*ate -3 python format list
全面问题:编写一个函数,该函数将字符串列表作为参数,并返回包含每个字符串长度的列表.也就是说,如果输入参数是["apple pie","brownies","chocolate","dulce de leche","eclairs"],你的函数应该返回[9,8,9,14,7].
我使用"累加器"接近这个程序,我将累积列表.
我的节目:
def accumulating():
List = []
Strings = input("Please enter a list of strings: ")
List = Strings.split(" ")
return List
def length(n):
r = []
for i in n:
r.append(len(n))
return r
def main():
y = accumulating()
x = length(y)
print(x)
main()
Run Code Online (Sandbox Code Playgroud)
def accumulating(strings):
return [len(i) for i in strings]
Run Code Online (Sandbox Code Playgroud)
就是这样.