top of page
ToucanSway


PYTHON CODING
import numpy as np arr = np.array([3, 15, 8, 22, 7]) mask = arr < 10 arr[mask] = 0 print(np.sum(arr)) [Running] python3 -u...

waclaw_koscielniak
Aug 81 min read
Â
Â
Â


PYTHON CODING
def make_funcs(): return [lambda x: i * x for i in range(3)] funcs = make_funcs() results = [f(2) for f in funcs] print(results)...

waclaw_koscielniak
Aug 41 min read
Â
Â
Â


PYTHON CODING
from collections import Counter def letter_counts(word): c = Counter(word) for k, v in c.items(): yield k, v...

waclaw_koscielniak
Jul 311 min read
Â
Â
Â


PYTHON CODING
def flatten(lst): for item in lst: if isinstance(item, list): yield from flatten(item) else: yield item print(list(flatten([1,...

waclaw_koscielniak
Jul 231 min read
Â
Â
Â


PYTHON CODING
def track_yields(): for i in range(3): print(f"Yielding {i}") yield i print("Done") for val in track_yields(): pass [Running]...

waclaw_koscielniak
Jul 211 min read
Â
Â
Â


PYTHON CODING
def chooser(val): if val == "a": yield from [1, 2] else: yield from [3, 4] print(list(chooser("b"))) [Running] python3 -u...

waclaw_koscielniak
Jul 171 min read
Â
Â
Â


PYTHON CODING
def early_exit(): for i in range(10): if i > 3: return yield i print(list(early_exit())) [Running] python3 -u...

waclaw_koscielniak
Jul 161 min read
Â
Â
Â


PYTHON CODING
def values(): for i in range(10): yield i filtr = filter(lambda x: x % 2 == 0, values()) print(list(filtr)) [Running] python3 -u...

waclaw_koscielniak
Jul 131 min read
Â
Â
Â


PYTHON CODING
a = True b = False c = False if a or b and c: print("Correct") else: print("Incorrect") [Running] python3 -u...

waclaw_koscielniak
Jul 101 min read
Â
Â
Â


PYTHON CODING
def squares(): for i in range(1, 4): yield i*i s = squares() print(list(s)) [Running] python3 -u "/Users/name/test/test61.py" [1, 4,...

waclaw_koscielniak
Jul 101 min read
Â
Â
Â


PYTHON CODING
def g(): yield 1 yield 2 x = g() print(next(x)) print(next(x)) print(next(x)) [Running] python3 -u "/Users/name/test/test47.py" 1 2...

waclaw_koscielniak
Jul 91 min read
Â
Â
Â


PYTHON CODING
def string_only(f): def wrap(x): return f(x) if isinstance(x, str) else "Invalid" return wrap @string_only def echo(s): return s + s...

waclaw_koscielniak
Jul 81 min read
Â
Â
Â


PYTHON CODING
def pack(f): def wrap(x): return (f(x), x) return wrap @pack def square(x): return x ** 2 print(square(3)[1]) [Running] python3 -u...

waclaw_koscielniak
Jul 71 min read
Â
Â
Â


PYTHON CODING
def factory(n): return lambda x: x ** n square = factory(2) cube = factory(3) print(square(3), cube(2)) [Running] python3 -u...

waclaw_koscielniak
Jun 231 min read
Â
Â
Â


PYTHON CODING
import inspect def f(x, y=2): return x + y sig = inspect.signature(f) print(sig.parameters['y'].default) [Running] python3 -u...

waclaw_koscielniak
Jun 181 min read
Â
Â
Â
bottom of page