社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

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

Amanda Johnson • 4 年前 • 1016 次点击  

我是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
 
1016 次点击  
文章 [ 2 ]  |  最新文章 4 年前