Repeated Short Words X96096


Statement
 

pdf   zip

thehtml
  1. Write a function: repeated_short(lw) that given a list of words lw, returns a list with those words that are shorter than 5 letters and appear more than once in the list. The returned list must be alphabetically sorted.
    def repeated_short(lw): ''' >>> repeated_short(['easy','come','easy','go','will','you','let','me','go']) ['easy', 'go'] >>> repeated_short(['I','can','see','it','can','you','see','it']) ['can', 'it', 'see'] >>> repeated_short(['unbelievable','unbelievable']) [] '''
  2. Write a main program that reads lines from the input, and prints the number of repeated word shorter than 5 letters in each line, and the list of those words. The main program must use the repeated_short(lw) function defined above.

Input

The input is a series of lines, each containing one or more words.

Output

  • The result returned by function repeated_short(lw) must be a sorted list with all repeated short words in the line.
  • The output printed by the main program must be –for each line in the input– the number of short repeated words followed by the alphabetically sorted list of those words, in the format shown in the examples below.
Public test cases
  • Input

    the quick brown fox jumps over the lazy dog
    easy come easy go will you let me go
    tea for two and two for tea
    the cat sat on his mat
    I can see it can you see it

    Output

    1 the
    2 easy go
    3 for tea two
    0 
    3 can it see
    
  • Input

    uh repeat please repeat what you said
    hello
    bye bye and forever bye
    unbelievable unbelievable
    Oh mamma mia mamma mia mamma mia let me go
    everyone has some idea or has no idea
    

    Output

    0 
    0 
    1 bye
    0 
    1 mia
    2 has idea
    
  • Information
    Author
    Language
    English
    Official solutions
    Python
    User solutions