I'd like to know how i can find the two longest strings from a list(array) of strings or how to find the second longest string from a list. thanks
I'd like to know how i can find the two longest strings from a list(array) of strings or how to find the second longest string from a list. thanks
You can do this using the standard heapq module:
>>> lst = ['hello', 'blah', 'boo', 'braininess']
>>> heapq.nlargest(2, lst, key=len)
['braininess', 'hello']