3) f. Sets Examples (2)




At the beginning of the human race, we have known a few things about animals. You want to know what kind of animals are living in your area to be able to recognize them.
Write a program where you can track the seen animals. Keep only one from each species. For this database use set.

1
2
Output:
set(['cat', 'dog', 'tiger', 'fish', 'ape'])




You are following an international serial killer Rajesh. The agency is curious about who is meeting with Rajesh to be able to find it’s a real personality and the people who’re working for.
Write a program where you track the people who are meeting with Rajesh. Every person must appear only once in your database. Use set for the operation.

1
2
Output:
set(['Carlos', 'Emilian', 'Josh', 'James', 'Carol'])




You are working for the international animal saving corporation and you were asked to actualize their database about the endangered animals.
Write a program that removes the “Cat” animal species from the list, due to the fact that they are no longer endangered.

1
2
3
4
5
Output:
Before removing cat:
set(['cat', 'dog', 'tiger', 'fish', 'ape'])
After removing cat:
set(['dog', 'tiger', 'fish', 'ape'])




The World is started to spin slower. This causes a lot of flooding in the seaside cities. The World needs to know which city is safe and which is not.
Write a program to discard every city which is no longer habitable. At the moment Venice and Oslo are the only inhabitable cities.

1
2
Output:
Safe cities:  set(['Edinburg', 'New Orleans', 'Bangkok', 'Miami', 'Istanbul'])




You are a federal agent in Russia. Your task is to find put which American agents are known by the government. You also want to save them, so you need to remove every agent from the list of monitored persons.
Write a program that lists the monitored agents set and also remove them at the same time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Output:
Agents:
Rylee Mcloughlin
Nathanael Hagan
Toni Barlow
Giselle Charlton
Leonardo Easton
Daria Ali
Adaline Goodman
Paloma Reed
Cherie Rowe
Maya Hayden
Agent list after listing and removing:
set([])




You went to the military and just got promoted to lieutenant. One of your jobs is to know your unit name by name. You have one day to learn the names in alphabetical order, otherwise, you will be dismissed.
Write a program that keeps your unit in alphabetical order and lets a person enter his/her name only ones.

1
2
Output:
['Adaline Goodman', 'Cherie Rowe', 'Daria Ali', 'Giselle Charlton', 'Leonardo Easton', 'Maya Hayden', 'Nathanael Hagan', 'Paloma Reed', 'Rylee Mcloughlin', 'Toni Barlow']




A zombie outbreak is coming into your city. You have to know what kind of ammunition do you have for your weapons because when they arrive you will need to know if you have the ammunition or not. If you have loaded your 0.107 pistols with the right ammunition.
Create a program that tracks the types of ammunition you have by the diameter of them and search for the 0.107 diams Don’t forget! Your life depends on it!

1
2
3
4
Output:
set([0.092, 0.172, 0.183, 0.223, 0.205, 0.107, 0.12, 0.23])
Loading pistol with 0.107 ammunition
set([0.092, 0.172, 0.183, 0.223, 0.205, 0.12, 0.23])