This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Sequence | |
| def print_sequence_elements(sequence: Sequence[str]): | |
| for i, s in enumerate(sequence): | |
| print(f"item {i}: {s}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def foo(x: int, y: int, func: Callable[[int, int], int]) -> int: | |
| output = func(x, y) | |
| return output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Callable | |
| def sum_numbers(x: int, y: int) -> int: | |
| return x + y | |
| def foo(x: int, y: int, func: Callable) -> int: | |
| output = func(x, y) | |
| return output | |
| foo(1, 2, sum_numbers) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import List | |
| NestedList = List[List[str]] | |
| my_list: NestedList = [["tomato", "carrot"], ["melon", "apples"]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import List | |
| def my_dummy_function(vector: List[float]): | |
| return sum(vector) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def my_dummy_function(l: list[float]): | |
| return sum(l) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person: | |
| first_name: str = "John" | |
| last_name: str = "Does" | |
| age: int = 31 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a: int = 3 | |
| b: float = 2.4 | |
| c: bool = True | |
| d: list = ["A", "B", "C"] | |
| e: dict = {"x": "y"} | |
| f: set = {"a", "b", "c"} | |
| g: tuple = ("name", "age", "job") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def add_numbers(x: type_x, y: type_y, z: type_z= 100) -> type_return: | |
| return x + y + z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from spacy.matcher import Matcher | |
| nlp = spacy.load("en_core_web_sm") | |
| doc = nlp("You should definitely buy Bitcoin") | |
| pattern = [ | |
| {"LEMMA": {"IN": ["buy", "sell"]}}, | |
| {"LOWER": {"IN": ["bitcoin", "dogecoin"]}}, | |
| ] |