Py学习  »  Python

在字符串Python中查找数组的平均长度

Amanda Johnson • 4 年前 • 1004 次点击  

我是python的新手,我不知道如何编写一个函数来计算字符串中数组的平均长度。任何帮助或指导都将不胜感激。 我们得到了

def mean_length(lst):

测试是

assert mean_length(['fee','freed',free']) == 4
assert mean_length(['alpha', 'beta', 'gamma', 'delta', 'epsilon']) == 5.2
assert mean_length([]) == 0

我试过了

def mean_length(lst):
    x = lst.count(''.join(lst))
    y = int(3)
    mean = x / y
    return mean
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50909
 
1004 次点击  
文章 [ 2 ]  |  最新文章 4 年前