Starting from:
$30

$24

Word Frequency Solution

Write a program to read data from a list of words and convert them into dictionary.

1) Write a function called word_freq(items) that accepts list of words and count number of words in the list and then create a

dictionary to hold words as keys and count as values (key-value pair). The word_freq returns a dictionary of word counts to the

main method.

2) Write a function called asc_word_freq() that accepts dictionary of words’ counts and returns a dictionary of word counts

in ascending order to the main method.

3) Write a function called desc_word_freq() that accepts dictionary of words’ counts and returns a dictionary of word counts in

descending order to the main method.

4) Write a function called size_dict( ) that accepts dictionary of words’ counts and size n and returns a subset of dictionary with n

most frequent words. oThe function size_dict() should returns a dictionary of size n that contains n words with highest value count.

oIf n size of input dictionary, then returns the input dictionaryoIf n<=0, then return an empty dictionary




For example: items = ["Liam", "Mason", "William", "Noah", "William", "James", "Sophia", "Logan", "Benjamin", "Mason",

"Elijah", "Oliver", "Jacob", "Emma", "Olivia", "Ava", "William", "Isabella", "Oliver", "Sophia", "Mia",

"Charlotte", "Amelia", "William", "Evelyn", "Abigail", "Olivia", "Ava", "Mason", "Isabella", "Noah", "William",

"James", "Olivia", "Amelia", "Oliver", "William"]

 

Names frequency: {'Liam': 1, 'Mason': 3, 'William': 6, 'Noah': 2, 'James': 2, 'Sophia': 2, 'Logan': 1, 'Benjamin': 1, 'Elijah': 1,

'Oliver': 3, 'Jacob': 1, 'Emma': 1, 'Olivia': 3, 'Ava': 2, 'Isabella': 2, 'Mia': 1, 'Charlotte': 1, 'Amelia': 2,

'Evelyn': 1, 'Abigail': 1}

 

Sorted names based on values: ([('Liam', 1), ('Logan', 1), ('Benjamin', 1), ('Elijah', 1), ('Jacob', 1), ('Emma', 1), ('Mia', 1),

('Charlotte', 1), ('Evelyn', 1), ('Abigail', 1), ('Noah', 2), ('James', 2), ('Sophia', 2), ('Ava', 2),

('Isabella', 2), ('Amelia', 2), ('Mason', 3), ('Oliver', 3), ('Olivia', 3), ('William', 6)])

More products