__slots__
и namedtuple
должно натолкнуть на эти размышления.def cmp(x):
x = x.split('x')
return int(x[0]) * int(x[1])
sorted(SIZES, key=cmp)
SIZES = ('1920x1080', '1600x1200', '1400x1050', '1280x1024', '1280x960', '1152x864', '1024x768',
'3840x2400', '3840x2160', '3840x1200', '2560x1600', '2560x1440', '2560x1080', '2560x1024',
'2048x1152', '1920x1200', '1680x1050', '1600x900', '1440x900', '1280x800', '1280x720', '2160x3840',
'1440x2560', '1366x768', '1080x1920', '1024x600', '960x544', '800x1280', '800x600', '720x1280',
'540x960', '480x854', '480x800', '400x480', '360x640', '320x480', '320x240', '240x400', '240x320',
'2732x2732', '2048x2048', '1024x1024', '750x1334', '640x1136', '640x960', '1280x900')
dct = {int(size.split('x')[0]): size for size in SIZES}
dct_sorted = sorted(dct.items())
for size in dct_sorted:
print(size[1])
from PIL import Image
img = Image.open("img.jpg")
w5 = (img.size[0] // 100) * 5
h5 = (img.size[1] // 100) * 5
croped = img.crop(
(
w5,
h5,
img.size[0] - w5,
img.size[1] - h5
)
)
croped.save("croped.jpg")
from PIL import Image
from PIL import ImageOps
img = Image.open("img.jpg")
w5 = (img.size[0] // 100) * 5
croped = ImageOps.crop(img, w5)
croped.save("croped.jpg")
>>> text = ['1', '12', '123', '11', '1', '12', '12']
>>> from collections import Counter
>>> text_counts = Counter(text)
>>> text_counts
Counter({'12': 3, '1': 2, '11': 1, '123': 1})
>>> top_two = text_counts.most_common(2)
>>> top_two
[('12', 3), ('1', 2)]
sql_insert = "INSERT INTO user_te (user_t, text_t) VALUES (?, ?)"
c.execute(sql_insert, (id, text))
from datetime import datetime, date
from dateutil.relativedelta import relativedelta
birthday_date = datetime.strptime("01.02.1990", "%d.%m.%Y").date()
if birthday_date > date(1990, 1, 1) and birthday_date < date(1995 1, 31):
birthday_date += relativedelta(years=146)