-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (31 loc) · 1.08 KB
/
main.py
File metadata and controls
45 lines (31 loc) · 1.08 KB
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
38
39
40
41
42
43
44
45
from dataclasses import dataclass
from functools import reduce
import operator
@dataclass(frozen=True)
class LatLon:
lat: float
lon: float
@dataclass(frozen=True)
class Metropolis:
name: str
country_code: str
population: float
coord: LatLon
metro_data: list[Metropolis] = [
Metropolis("Tokyo", "JP", 36.933, LatLon(35.689722, 139.691667)),
Metropolis("Delhi NCR", "IN", 21.935, LatLon(28.613889, 77.208889)),
Metropolis("Mexico City", "MX", 20.142, LatLon(19.433333, -99.133333)),
Metropolis("New York-Newark", "US", 20.104, LatLon(40.808611, -74.020386)),
Metropolis("São Paulo", "BR", 19.649, LatLon(-23.547778, -46.635833)),
]
for metro in sorted(metro_data, key=operator.attrgetter("population")):
print(metro)
print(f"{'*' * 50}")
print(operator.itemgetter(1, 2)(metro_data))
print(f"{'*' * 50}")
print(reduce(operator.and_, [True, True, False], True))
print(reduce(operator.and_, [True, True, True], True))
print(reduce(operator.add, [1, 2, 3, 4], 5))
print(f"{'*' * 50}")
s = "Elahe Dastan"
print(operator.methodcaller("upper")(s))