|
| 1 | +from dataclasses import dataclass |
| 2 | +from typing import List |
| 3 | + |
| 4 | +@dataclass(frozen=True) |
| 5 | +class Person: |
| 6 | + name: str |
| 7 | + age: int |
| 8 | + preferred_operating_systems: List[str] |
| 9 | + |
| 10 | + |
| 11 | +@dataclass(frozen=True) |
| 12 | +class Laptop: |
| 13 | + id: int |
| 14 | + manufacturer: str |
| 15 | + model: str |
| 16 | + screen_size_in_inches: float |
| 17 | + operating_system: str |
| 18 | + |
| 19 | + |
| 20 | +def find_possible_laptops(laptops: List[Laptop], person: Person) -> List[Laptop]: |
| 21 | + possible_laptops = [] |
| 22 | + for laptop in laptops: |
| 23 | + if laptop.operating_system == person.preferred_operating_systems: |
| 24 | + possible_laptops.append(laptop) |
| 25 | + return possible_laptops |
| 26 | + |
| 27 | + |
| 28 | +people = [ |
| 29 | + Person(name="Imran", age=22, preferred_operating_systems=["Ubuntu"]), |
| 30 | + Person(name="Eliza", age=34, preferred_operating_systems=["Arch Linux"]), |
| 31 | +] |
| 32 | + |
| 33 | +laptops = [ |
| 34 | + Laptop(id=1, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system="Arch Linux"), |
| 35 | + Laptop(id=2, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="Ubuntu"), |
| 36 | + Laptop(id=3, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="ubuntu"), |
| 37 | + Laptop(id=4, manufacturer="Apple", model="macBook", screen_size_in_inches=13, operating_system="macOS"), |
| 38 | +] |
| 39 | + |
| 40 | +for person in people: |
| 41 | + possible_laptops = find_possible_laptops(laptops, person) |
| 42 | + print(f"Possible laptops for {person.name}: {possible_laptops}") |
0 commit comments