Count Unique Words X82641


Statement
 

pdf   zip   main.py

thehtml

Write a function that given a text as a list of sentences (sublists, see below), counts for each sentence, the number of unique words that contain the last letter of the last word of the sentence. For example, a text could be:

[["Or", "if", "it", "do", "not", "from", "those", "lips", "of", "thine"], 
["Even", "so", "being", "full", "of", "your", "neer-cloying", "sweetness"], 
["Growing", "a", "bath", "and", "healthful", "remedy"], 
["Each", "changing", "place", "with", "that", "which", "goes", "before"]]

The output should be a list with a pair (letter, number) for each sentence, containing the lowercase form of the last letter of the last word of the sentence, and the number of unique words in the sentence that contain that letter.

A few considerations:

  • The text is a list of sentences, which might be empty.
  • As per usual, each sublist of the list is a sentence.
  • The sentences will not be empty, neither the words will be empty strings.
  • Uppercase and lowercase versions of the letters should be considered the same letter.
Sample session
>>> count_unique_words([['therefore', 'to', 'your', 'fair', 'no', 'painting', 'set']])
[('t', 4)]
>>> count_unique_words([['I', 'found', 'or', 'thought', 'I', 'found', 'you', 'did', 'exceed'], ['And', 'therefore', 'to', 'your', 'fair', 'no', 'painting', 'set']])
[('d', 3), ('t', 4)]
>>> count_unique_words([['A', 'a', 'B', 'b', 'a']])
[('a', 1)]
>>> count_unique_words([['Or', 'if', 'it', 'do', 'not', 'from', 'those', 'lips', 'of', 'thine'], ['Even', 'so', 'being', 'full', 'of', 'your', 'neer-cloying', 'sweetness'], ['Growing', 'a', 'bath', 'and', 'healthful', 'remedy'], ['Each', 'changing', 'place', 'with', 'that', 'which', 'goes', 'before']])
[('e', 2), ('s', 2), ('y', 1), ('e', 4)]
Information
Author
Ferriol Calvet
Language
English
Official solutions
Python
User solutions
Python