获得最长单词长度的pythonic方法是什么:
len(max(words, key=len))
要么:
max(len(w) for w in words)
或者是其他东西? words是一个字符串列表.我发现我需要经常这样做,并且在使用几个不同的样本大小计时之后,第一种方式似乎始终更快,尽管看起来表面效率较低(len被调用两次的冗余看起来并不重要 - 更多发生在这种形式的C代码?).
words
len
python string performance coding-style list
coding-style ×1
list ×1
performance ×1
python ×1
string ×1