Skip to content

Instantly share code, notes, and snippets.

View e-io's full-sized avatar
😺
Meow!

Pavel 宝尔米 e-io

😺
Meow!
View GitHub Profile
@e-io
e-io / request-authors-by-isbn-with-gbooks-api.py
Created September 21, 2023 10:32
Show authors of a book by ISBN with Google Books API (Python).
# How to run:
# python3 request-authors-by-isbn-with-gbooks-api.py
# just write required isbn in the "isbn = ..." line below
import json
import requests
# example of isbn. It can be 10 digits or 13 digits. It can be with hyphens or without them.
isbn = "978-1-119-70711-0"
@e-io
e-io / pandas_basics
Last active October 15, 2021 10:50
Creation of a data frame in pandas. Name of library is derived from derived from 'Panel Data'.
import pandas as pd
favorite_music = [
['Нейромонах Феофан', 'В душе драм, в сердце светлая Русь'],
['НТР', 'Тыжпрограммист'],
['LinDi', '裂帛'],
['Yann Tiersen', 'Amelie'],
['Баста', 'ЧП'],
]
@e-io
e-io / How_much_list_weight.py
Created October 12, 2021 11:37
How many elements of memory are reserved for python list (in standard CPython) by number of items.
list_size = 0
# memory_size means total memory for this list whithout header memory
memory_size = 0
last_memory_size = 0
# if one element takes eight bytes of memory total
# then list with 2**20 elements weights 8 megabytes
# (it should be true at least for list with several kinds of elements, like True/False or 0/.../9)
max_output = 2**20
output1 = 'Visible elements:'
@e-io
e-io / ASCII and random characters.py
Created October 8, 2021 12:05
ASCII and random characters
from random import randint
print('ASCII:')
for sym in range(128):
print(sym, f':c={sym:c}', sep='', end='\t')
print('\n\nRandom symbols:')
for i in range(100):
print(sym := randint(0, 0x11000 // 2), f':c={sym:c}', sep='', end='\t')
@e-io
e-io / string formatting.py
Created October 8, 2021 11:35
string formatting
from random import randint
for m in ['', 'd', 'b', 'o', 'x', 'X', 'e', 'E', '%']:
template = 'Hello {0}, your balance is {1:=+16' + m + '}:16{2}'
print(template.format('Adam', randint(-1000, 1000), m))
print(f'{randint(-1000, 1000):+}')