How to use 'the longest list' in Python

Every line of 'the longest list' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
10def find_longest_sub_list(list_of_lists):
11 """
12 Find the list having largest length
13 """
14 largest = []
15 if list_of_lists:
16 largest = list_of_lists[0]
17 for list in list_of_lists[1:]:
18 if len(list) > len(largest):
19 largest = list
21 return largest

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

69def longest(things: list):
70 lengths = [len(thing) for thing in things]
71 return sorted(lengths)[-1] if lengths else 0

Related snippets