Problem

3/9

Dictionaries. Built-in Methods

Theory Click to read/hide

Built-in Dictionary Methods

Some of the methods you learned about strings, lists, and tuples also work with dictionaries. For example, the in (or not in) method allows you to determine if a particular key exists. in the dictionary.

And also allows you to go through all the keys of the dictionary. for key in dict_country: print(key) You can also iterate over key-value pairs using the items() method. for key, value in dict_country.items(): print(key, value) Other commonly used methods are listed in the table.
  The The The The
Name Method Description (example)
dictionary size len() returns the number of elements in the dictionary 
len(dict_country)
updating dictionary update() allows you to update several dictionary pairs at once
dict_country.update({'Russia': 'Moscow', 'Armenia': 'Yerevan'})< /pre>
get value by key get() allows you to get the value by the specified key. Can be used to check if a particular key exists in a dictionary
dict_country.get('Russia') # returns value by key,
                              # if there is no such key, it will return None
dict_country.get('Russa', 0) # if there is no Russia key, it will return 0
                                # (instead of 0, you can set any value
remove key pop() pop() method removes a key and returns its corresponding value.
dict_country.pop('Bahamas')
dictionary keys  keys() keys() method returns a collection of keys in a dictionary.
dict_country.keys()
dictionary values values()Method values() returns a collection of values ​​in a dictionary.
dict_country.values()
dictionary pairs items() items() method returns a collection of values ​​in a dictionary.
dict_country.items()

Problem

An alphabetical-frequency dictionary is a frequency dictionary in which words with their frequency (occurrence) are arranged alphabetically.
Build a dictionary where the to the right of each word is the number of times it occurs in the source text.
The sign of the end of the text is  a string with the single word "END!". The order in which words are printed does not matter.

Input
Lines of text are given as input. The last line contains one single word "END!" and is a sign of the end of the text.

Imprint
Display all the words on the screen, indicating, separated by a space, how many times this word occurs in the text. Each word on a separate line.

 
Examples
# Input Output
1 Eat more of those soft French rolls
END!
Eat 1
1 more
these 1
soft 1
French 1
roll 1