如何在列表中找到最长的列表? [英] How to find the longest list in a list?
本文介绍了如何在列表中找到最长的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定一个列表列表,最长列表的长度可以通过以下代码找到.
Given a list of lists, the length of the longest list can be found with the following code.
values = [['a','a'], ['a','b','b'], ['a','b','b','a'], ['a','b','c','a']]
longest = 0
for value in values:
longest = max(longest, len(value))
print(longest)
[out]: 4
如何在没有循环的情况下找到最长列表的长度,或最长列表.
How can the length of the longest list, or the longest list be found, without a loop.
推荐答案
这将返回列表中最长的列表values
:
This will return the longest list in the list values
:
max(values, key=len)
这篇关于如何在列表中找到最长的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文