Define a function named build_dictionary(words_list) that takes a list of words as a parameter. The function creates a dictionary by looping through each element in the list and creating a corresponding key: value item.
The keys consist of integers and the values are lists of unique words in lowercase where the length of each word equals the key value.
Notes
• You can assume there will be no punctuation characters in the words in the parameter words_list (i.e., only letters). However, you should convert all words to lower case.
• You can assume that the file only contains unique words.
• Each list of words must be sorted in ascending order.
Pass examples
Input
Output
data = ['The', 'heavy', 'rain', 'is', 'to', 'one', 'tonight', 'however', 'further', 'showers', 'Are', 'expected', 'tomorrow']
2 ['is', 'to']
a_dict = build_dictionary(data)
for key in sorted(a_dict):
print(key, a_dict[key])
3 ['are', 'the']
4 ['one', 'rain']
5 ['heavy']
7 ['further', 'however', 'showers', 'tonight']
8 ['expected', 'tomorrow']
data = ['cat', 'tow', 'eye', 'the', 'ant', 'ton', 'Ted', 'ape', 'dog', 'CAT', 'red']
a_dict = build_dictionary(data)
for key in sorted(a_dict):
print(key, a_dict[key])
3 ['ape', 'ant', 'cat', 'dog', 'eye', 'red', 'ten', 'ted', 'ton', 'the']