小编Gb *_*sha的帖子

计算列表中字符串的字符并分组

使用Python 3计算列表(字符串)的长度直方图的最佳方法是什么?

该程序将计算所有元素的长度,具有相同长度的组元素并返回每个组的大小,与该组中元素的长度配对.

对于以下输入列表:

lis = [ "this" , "is" , "what" , "i" , "have" , "to" , "do" ]
Run Code Online (Sandbox Code Playgroud)

预期的结果是:

Letters per word:

3 with 4 letters
3 with 2 letters
1 with 1 letters
Run Code Online (Sandbox Code Playgroud)

是否有内置的容器或功能,以促进这一点?

python python-3.x

-3
推荐指数
1
解决办法
1940
查看次数

标签 统计

python ×1

python-3.x ×1