chore: initialize containerized Python learning workbook (2026 DevOps/SRE)
This commit is contained in:
commit
ae4c421815
63 files changed
+1273
No files matched your search
@@ -0,0 +1,11 @@
|
||||
# 05 — Comprehensions, Generatory i Styl Funkcyjny
|
||||
|
||||
## Zadania (`functional_ex.py`)
|
||||
1. `even_squares(nums: list[int]) -> list[int]` — kwadraty liczb parzystych przez list comprehension.
|
||||
2. `invert_dict(mapping: dict[str, int]) -> dict[int, str]` — odwrócenie słownika przez dict comprehension.
|
||||
3. `fibonacci_gen(limit: int) -> Iterator[int]` — generator zwracający `limit` pierwszych liczb Fibonacciego (`0, 1, 1, 2, 3, ...`).
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test MOD=01-core/05-comprehensions-functional
|
||||
```
|
||||
@@ -0,0 +1,13 @@
|
||||
from collections.abc import Iterator
|
||||
|
||||
|
||||
def even_squares(nums: list[int]) -> list[int]:
|
||||
raise NotImplementedError("Zwróć listę kwadratów liczb parzystych")
|
||||
|
||||
|
||||
def invert_dict(mapping: dict[str, int]) -> dict[int, str]:
|
||||
raise NotImplementedError("Zamień klucze z wartościami w słowniku")
|
||||
|
||||
|
||||
def fibonacci_gen(limit: int) -> Iterator[int]:
|
||||
raise NotImplementedError("Wygeneruj limit liczb Fibonacciego używając yield")
|
||||
@@ -0,0 +1,14 @@
|
||||
from functional_ex import even_squares, fibonacci_gen, invert_dict
|
||||
|
||||
|
||||
def test_even_squares() -> None:
|
||||
assert even_squares([1, 2, 3, 4, 5]) == [4, 16]
|
||||
|
||||
|
||||
def test_invert_dict() -> None:
|
||||
assert invert_dict({"a": 1, "b": 2}) == {1: "a", 2: "b"}
|
||||
|
||||
|
||||
def test_fibonacci_gen() -> None:
|
||||
assert list(fibonacci_gen(0)) == []
|
||||
assert list(fibonacci_gen(6)) == [0, 1, 1, 2, 3, 5]
|
||||
Reference in new issue
Block a user