top of page
ToucanSway


PYTHON CODING
from PIL import Image, ImageDraw import random w,h,l = 1000,1000,333 img = Image.new("RGB", (w,h), "black") draw = ImageDraw.Draw(img)...

waclaw_koscielniak
Sep 251 min read
Â
Â
Â


PYTHON CODING
import os from pathlib import Path p = Path("sample.txt") p.write_text("Hello") print(os.path.isfile("sample.txt"), p.stat().st_size)...

waclaw_koscielniak
Sep 231 min read
Â
Â
Â


PYTHON CODING
import glob, os with open("a.txt", "w") as f: f.write("A") with open("b.txt", "w") as f: f.write("B") print(len(glob.glob("*.txt")))...

waclaw_koscielniak
Sep 221 min read
Â
Â
Â


PYTHON CODING
from fractions import Fraction f1 = Fraction(3, 4) f2 = Fraction(2, 3) result = f1 * f2 + Fraction(1, 6) print(result, float(result))...

waclaw_koscielniak
Sep 191 min read
Â
Â
Â


PYTHON CODING
import numpy as np import matplotlib.pyplot as plt number = 500 x = np.random.rand(number)*10 y = np.random.rand(number)*10 sizes =...

waclaw_koscielniak
Sep 171 min read
Â
Â
Â


PYTHON CODING
import asyncio async def double(x): await asyncio.sleep(0.05) return x * 2 async def main(): results = await asyncio.gather(double(3),...

waclaw_koscielniak
Sep 161 min read
Â
Â
Â


PYTHON CODING
import json data = {"x": 5, "y": 10} js = json.dumps(data) parsed = json.loads(js) parsed["z"] = parsed["x"] * parsed["y"]...

waclaw_koscielniak
Sep 151 min read
Â
Â
Â


PYTHON CODING
from functools import reduce nums = [1, 2, 3, 4] res = reduce(lambda x, y: x * y, nums, 2) print(res) nums.append(5) res2 = reduce(lambda...

waclaw_koscielniak
Sep 131 min read
Â
Â
Â


PYTHON CODING
nums = [1, 2, 3, 4] ref = nums copy = nums[:] ref[0] = 99 copy[1] = 100 print(nums, copy) [Running] python3 -u...

waclaw_koscielniak
Sep 121 min read
Â
Â
Â


PYTHON CODING
def gen(): for i in range(3): yield i * i g = gen() print(next(g)) print(sum(g)) [Running] python3 -u "/Users/name/test/test823.py" 0...

waclaw_koscielniak
Sep 111 min read
Â
Â
Â


PYTHON CODING
def outer(x): def inner(y): return x + y return inner f = outer(5) print(f(3)) print(outer(10)(2)) [Running] python3 -u...

waclaw_koscielniak
Sep 101 min read
Â
Â
Â


PYTHON CODING
import weakref class A: pass a = A() r = weakref.ref(a) print(r() is a) del a print(r() is None) [Running] python3 -u...

waclaw_koscielniak
Sep 81 min read
Â
Â
Â


PYTHON CODING
import heapq nums = [5, 1, 8, 3] heapq.heapify(nums) heapq.heappush(nums, 0) print(heapq.heappop(nums), nums[0]) [Running] python3 -u...

waclaw_koscielniak
Sep 61 min read
Â
Â
Â


PYTHON CODING
import asyncio async def f(): return 10 async def g(): x = await f() return x + 5 print(asyncio.run(g())) [Running] python3 -u...

waclaw_koscielniak
Sep 51 min read
Â
Â
Â


PYTHON CODING
from dataclasses import dataclass @dataclass class Point: x: int y: int = 0 p = Point(5) print(p) [Running] python3 -u...

waclaw_koscielniak
Sep 31 min read
Â
Â
Â


PYTHON CODING
import itertools a = [1,2] b = itertools.count(3) c = itertools.chain(a,b) print([next(c) for _ in range(5)]) [Running] python3 -u...

waclaw_koscielniak
Aug 301 min read
Â
Â
Â


PYTHON CODING
def f(a, L=[]): L.append(a) return L print(f(1)) print(f(2, [])) print(f(3)) [Running] python3 -u "/Users/name/test/test67.py" [1] [2]...

waclaw_koscielniak
Aug 291 min read
Â
Â
Â


PYTHON CODING
class Meta(type): def __new__(cls, name, bases, dct): dct["id"] = 99 return super().__new__(cls, name, bases, dct) class...

waclaw_koscielniak
Aug 281 min read
Â
Â
Â


PYTHON CODING
def append_item(item, container=[]): container.append(item) return container print(append_item(1), append_item(2)) [Running] python3 -u...

waclaw_koscielniak
Aug 181 min read
Â
Â
Â


PYTHON CODING
import pandas as pd s = pd.Series([5, 8, 12, 18, 22]) s[s < 10] *= 2 print(s.sum()) [Running] python3 -u "/Users/name/test/test95.py" 78...

waclaw_koscielniak
Aug 151 min read
Â
Â
Â
bottom of page