10.2 Finding the Longest Protein

This was another problem that most people seemed to have trouble with. So, I thought that I would also present two approaches for this question:

10.2.2 Approach #2: Using sorted()

The sorted() function returns the sorted version of a list. Depending on what you want to do with the accession IDs and the associated protein lengths, the sorted() function may be ideal.

Nevertheless, I use an anonymous function to sort many_lists_copy by their protein lengths in reverse order (specified by the reverse = True argument):

longest = sorted(many_lists_copy, key = lambda x : len(x[-1]), reverse = True)[0]

print(f"The longest protein has accession {longest[0]} and length {len(longest[-1])}")

I then chose the first sublist returned by the sorted() function!