-
Notifications
You must be signed in to change notification settings - Fork 0
/
houses.py
37 lines (27 loc) · 864 Bytes
/
houses.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## Filters out duplicate houses using 'set'
# students = [
# {"name": "Hermione", "house": "Gryffindor"},
# {"name": "Harry", "house": "Gryffindor"},
# {"name": "Ron", "house": "Gryffindor"},
# {"name": "Draco", "house": "Slytherin"},
# {"name": "Padma", "house": "Ravenclaw"},
# ]
# houses = []
# for student in students:
# if student["house"] not in houses:
# houses.append(student["house"])
# for house in sorted(houses):
# print(house)
## Using 'set'
students = [
{"name": "Hermione", "house": "Gryffindor"},
{"name": "Harry", "house": "Gryffindor"},
{"name": "Ron", "house": "Gryffindor"},
{"name": "Draco", "house": "Slytherin"},
{"name": "Padma", "house": "Ravenclaw"},
]
houses = set()
for student in students:
houses.add(student["house"])
for house in sorted(houses):
print(house)