Skip to content

Instantly share code, notes, and snippets.

View ahmedbesbes's full-sized avatar
💭
Building things, one line of code at a time 💻

Ahmed BESBES ahmedbesbes

💭
Building things, one line of code at a time 💻
View GitHub Profile
from typing import Sequence
def print_sequence_elements(sequence: Sequence[str]):
for i, s in enumerate(sequence):
print(f"item {i}: {s}")
def foo(x: int, y: int, func: Callable[[int, int], int]) -> int:
output = func(x, y)
return output
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)
from typing import List
NestedList = List[List[str]]
my_list: NestedList = [["tomato", "carrot"], ["melon", "apples"]]
from typing import List
def my_dummy_function(vector: List[float]):
return sum(vector)
def my_dummy_function(l: list[float]):
return sum(l)
class Person:
first_name: str = "John"
last_name: str = "Does"
age: int = 31
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")
def add_numbers(x: type_x, y: type_y, z: type_z= 100) -> type_return:
return x + y + z
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"]}},
]