In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of December 7th
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #08 exercise sheet]
In this problem you should submit a function as described. Inside the function do not print anything that was not asked!
Arya Stark, training with the Faceless Men, has been given a challenge to prove her skills in analyzing texts. Her task is to extract the initial letters of all words from a given text, determine their frequency of appearance, and then create a (lowercase) string from these letters. The string should be sorted in descending order of frequency. If two letters have the same frequency, they should appear in alphabetical order.
Imagine for instance the text is "tark Lannister TaRgArYeN ARRYN tully". Regarding the initial letters, there are two t's, one a, one l and one s. The desired string should there be "tals", as t is the most frequent and them come a, l and s, all with frequency one, but sorted alphabetically.
Write a function sort_initials(text) that given a string text, returns a string made only by the lower case version of the initial letters of each word in the sentence (a word is a space separated sequence of chars). The letters should come in decreasing order of frequency and in case of a tie in increasing alphabetical order.
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ |text| ≤ 200 | length of text |
You can also be assured that the text will only be made by whitespace and upper and lowercase letters adn there will always exist at least one word.
Example Function Calls | Example Output |
print(sort_initials("stark Lannister TaRgArYeN ARRYN tully")) print(sort_initials("a girl has no name in Braavos")) print(sort_initials("pedro Pedro PEDRO")) |
tals nabghi p |