相关疑难解决方法(0)

列表中最长单词的长度

获得最长单词长度的pythonic方法是什么:

len(max(words, key=len))

要么:

max(len(w) for w in words)

或者是其他东西? words是一个字符串列表.我发现我需要经常这样做,并且在使用几个不同的样本大小计时之后,第一种方式似乎始终更快,尽管看起来表面效率较低(len被调用两次的冗余看起来并不重要 - 更多发生在这种形式的C代码?).

python string performance coding-style list

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

coding-style ×1

list ×1

performance ×1

python ×1

string ×1