Python has 4 basic inbuilt data structures: Lists, Tuples, Sets, and Dictionaries.
Lists, tuples, and sets are used to keep single elements in collections. Dictionaries, on the other hand, are used to keep key-value pairs. Similar to real-world dictionaries, where each word corresponds to its translation or explanation, Python dictionaries use keys to map them to their corresponding values. We can keep a dictionary of countries and their capitals:
To define a dictionary, we first open a curly bracket {, then put each key on the left side of the colon :, and the value on the right side. Each key-value pair is separated by a comma, and the dictionary definition ends with a closing curly bracket }.
Both keys and values can be of different types. We can keep the city population in a dictionary:
In the case of lists and tuples, we could access the individual elements by their index [2]. When working with dictionaries, the access to elements is done through keys:
If the key does not exist in the dictionary, Python raises an error telling that the key is not in the dictionary.
Challenge
Google translate is great but can you create a simpler version of it?
You are helping your friend to study the French class. He is an English speaker, so you want to write a program for him that given an English word or a phrase would print the corresponding phrase in French. Below are the phrases that he’s currently studying:
English
French
Thank you
Merci
How are you?
Comment ca va?
Hello everyone
Bonjour à tous
This is delicious
C'est délicieux
amazing
étonnante
tasty
savoureux
Note: Don’t use if/else statements. It’s much shorter and easier to do this with dictionaries.
The input contains a single line - the phrase in English.
The program should print the corresponding French sentence.