30 seconds of python

  Back to Home

longest_item

liststringutilityintermediate

Takes any number of iterable objects or objects with a length property and returns the longest one. If multiple objects have the same length, the first one will be returned.

Use max() with len as the key to return the item with the greatest length.

def longest_item(*args):
  return max(args, key = len)