5) f. Lambda Expressions Examples



You are working for the World Car Safety Association. You were asked to find out the most dangerous car in the world because they want to band a dangerous model in every month from now.
Write a program that lists the car models and the number of deaths caused by an accident with that model in descending order. Find out which car is the most dangerous.

1
2
Output:
[('Dacia Logan', 9841564), ('Smart For Four', 164894), ('Tesla Roadster', 146546), ('Toyota Prius', 50026), ('Audi A4', 1986), ('Tesla Model S', 1985), ('BMW I3', 1984), ('Volvo S60', 0)]



You are going to go on a vacation, but your girlfriend got mad because she can’t decide where to go. She has started throwing things in your direction.
Write a program as soon as possible, that provides her the ordered list of possible places in ascending order by their star rate.

1
2
Output:
[('China', 3.49), ('Ibiza', 3.5), ('Transilvania', 3.58), ('Austria', 3.59), ('Hungary', 3.76), ('Switzerland', 4.01)]



The International Space Federation needs to know the possibility of being attacked by alien species. You must count the population of every known colony all around the Universe.
Create a program that tracks the population of the different species using dictionaries, where the key is the planet’s name and the value is the population of that planet. Order the planets by their population to know which one is a threat and which one is not.

1
2
3
4
5
6
Output:
('Saturn', 15654431)
('Exo Planet 3', 15546648)
('Earth', 8965845)
('Jupyter', 3005165)
('Haumea', 1564456)







You are at your girlfriend’s house and you have to answer a few questions for her otherwise she will lock you in her basement. Meanwhile, she ou searched her computer and found two files, one with the questions and one with the answers.
To be able to answer as quickly as possible, write a function that gets the content of the two files (two lists of sentences) and returns a list of tuples with the questions and answers (the answer for the n-th question is the n-th element of the answer list).

1
2
3
4
Output:
('Who are you?', 'Your boyfriend')
('Where is the capital of France?', 'In Paris')
('Who is the most important in your life?', 'You')