tut 12 correction
This commit is contained in:
@ -249,8 +249,6 @@ def has_cycle(graph: Graph[Any]) -> bool:
|
||||
- **statische Typisierung** überprüft die gegebenen Typen zur **Übersetzungszeit**
|
||||
- also während wir den Quellcode übersetzen
|
||||
|
||||
### Was ist nun Python?
|
||||
|
||||
---
|
||||
|
||||
## Type annotations - Typisierung
|
||||
@ -262,11 +260,15 @@ def has_cycle(graph: Graph[Any]) -> bool:
|
||||
|
||||
### Was ist nun Python?
|
||||
|
||||
---
|
||||
|
||||
### Was ist nun Python?
|
||||
|
||||
- **dynamisch typisiert**
|
||||
- wir müssen unsere `.py` Datei ausführen bevor wir wissen ob alles korrekt ist
|
||||
- **Pylance** ist ein eigenes Programm
|
||||
- es soll beim Schreiben bereits **Typverletzungen** erkennen
|
||||
- **unvollständige** Typüberprüfung
|
||||
- **unvollständige** Typüberprüfung, es soll nur den Entwickler unterstützen
|
||||
|
||||
---
|
||||
|
||||
@ -524,7 +526,7 @@ print(add_but_variable(3, 2)) # 5
|
||||
def filter[T](predicate: Callable[[T], bool], xs: Iterable[T]) -> Iterable[T]:
|
||||
return [x for x in xs if predicate(x)]
|
||||
|
||||
predicate: Callable[[int | None] bool] = lambda e: bool(e)
|
||||
predicate: Callable[[int | None] bool] = lambda e: e is not None
|
||||
none_free_list: list[int] = list(filter(predicate, [1, 2, 3, None, 5, 6]))
|
||||
print(none_free_list) # [1, 2, 3, 5, 6] - kein None
|
||||
```
|
||||
|
Binary file not shown.
@ -48,8 +48,9 @@ def main():
|
||||
# f(g(h(0))) <=> ((0 - 3) ** 2) + 42 = 51
|
||||
assert (tmp := fhg(0)) == 51
|
||||
assert compose(f, g, h)(0) == 51
|
||||
assert list(filter(lambda e: bool(e), [1, 2, 3, None, 5, 6])) == [1, 2, 3, 5, 6]
|
||||
assert list(filter(lambda e: not bool(e), [1, 2, 3, None, 5, 6])) == [None]
|
||||
predicate = lambda e: e
|
||||
assert list(filter(predicate, [1, 2, 3, None, 5, 6])) == [1, 2, 3, 5, 6]
|
||||
assert list(filter(lambda e: e is None, [1, 2, 3, None, 5, 6])) == [None]
|
||||
|
||||
assert list(map(lambda e: str(e), [1, 2, 3, 4, 5, 6, "hello_functional"])) == ["1", "2", "3", "4", "5", "6", "hello_functional"]
|
||||
|
||||
|
Reference in New Issue
Block a user