Problem 1. "The Most Frequent Word"

You are given a text. Print the word that occurs the most often in this text. If there are several such words, print the one that is comes first in lexicographical order.

Example

Input data:

the eastern green mamba dendroaspis angusticeps is a highly venomous snake species of the mamba genus dendroaspis native to the coastal regions of southern east africa described by scottish surgeon and zoologist andrew smith in it has a slender build with bright green upperparts and yellowgreen underparts the adult female averages around metres ft in length and the male is slightly smaller a shy and elusive species the eastern green mamba is rarely seen this elusiveness is usually attributed to the species green colouration which blends with its environment and its arboreal lifestyle it has also been observed to use sitandwait or ambush predation like many vipers unlike the active foraging style typical of other elapid snakes the eastern green mamba preys on birds eggs bats and rodents such as mice rats and gerbils

Output:

the

To solve this task, as well as similar tasks, you have to write code that checks if some value is already used in a dictionary as a key. If it's used, you modify it and if there is no such key, you create it.

In [ ]:
# Example of how to check whether a key is in a dictionary
example_dict = {'key1' : 1, 'key2' : 10}
existing_key = 'key1'
another_new_key = 'key4'
# for key, value in example_dict.items()

# modify a value of a key
example_dict[existing_key] = example_dict[existing_key] * 2
# create a key and value
example_dict[another_new_key] = 0

# alternative
example_dict[existing_key] = example_dict.get(existing_key, 123) * 10

new_key = 'key3'
if new_key in example_dict:
    print('The value of {} is {}'.format(new_key, example_dict[new_key]))
else:
    print('There is no key "{}"'.format(new_key))
    

if existing_key in example_dict:
    print('The value of {} is {}'.format(existing_key, example_dict[existing_key]))
else:
    print('There is no key "{}"'.format(existing_key))
    
{'key1': 1, 'key2': 10}
{'key1': 2, 'key2': 10, 'key4': 0}
There is no key "key3"
The value of key1 is 2

Problem 2. "Frequency Analysis"

You are given a text. Print all the words in the text, one word in a line. Words should be sorted in descending order of their appearance in the text, and if they appear the same number of times, in lexicographical order.

After you create a dictionary of all words, you will want to sort the list of all words by their frequency of occurence. You can achieve this by creating a list with elements that are tuples of two elements: the number of occurences of the word and the word itself. For example, [(2, 'hi'), (1, 'what'), (3, 'is')]. Then the standard sort function will sort the list of tuples, and the tuples will be compared by the first element, and if they are equal, then by the second one. This is almost what is required in the task.

Example

Input data:

the eastern green mamba dendroaspis angusticeps is a highly venomous snake species of the mamba genus dendroaspis native to the coastal regions of southern east africa described by scottish surgeon and zoologist andrew smith in it has a slender build with bright green upperparts and yellowgreen underparts the adult female averages around metres ft in length and the male is slightly smaller a shy and elusive species the eastern green mamba is rarely seen this elusiveness is usually attributed to the species green colouration which blends with its environment and its arboreal lifestyle it has also been observed to use sitandwait or ambush predation like many vipers unlike the active foraging style typical of other elapid snakes the eastern green mamba preys on birds eggs bats and rodents such as mice rats and gerbils

Output (first 20 lines):

the
and
green
is
mamba
a
eastern
of
species
to
dendroaspis
has
in
it
its
with
active
adult
africa
also

Problem 3. "Countries and cities"

Solve the problem "Countries and cities" from the 6th contest.