List of Longest Words X39240


Statement
 

pdf   zip   main.py

html

Write a function longest(h) that, given a list of words h, returns the list of those words in h that attain the longest length, sorted in alphabetical order. The words are arbitrary strings. The output may include repeated words if they appear repeated in h and fulfill the length condition.

Observation

Only the function will be evaluated. If your submission includes a main program (e.g. with testmod), it must be either commented out or inside a condition if __name__ == ’__main__’

Sample session
>>> longest( ['you', 'may', 'find', 'only', 'short', 'words', 'in', 'some', 'lists'] )
['lists', 'short', 'words']
>>> longest( ['returns', 'the', 'list', 'of', 'words', 'that', 'achieve', 'the', 'longest', 'length'] )
['achieve', 'longest', 'returns']
>>> longest( ['mirala', 'mirala', 'la', 'puerta', 'de', 'alcala'] )
['alcala', 'mirala', 'mirala', 'puerta']
>>> longest( ['often', 'texts', 'bring', 'longer', 'and', 'lengthier', 'unendingly', 'growing', 'words'] )
['unendingly']
>>> longest( [] )
[]
>>> longest( ['', ''] ) + longest( ['a'] )
['', '', 'a']
Information
Author
José Luis Balcázar
Language
English
Official solutions
Python
User solutions
Python