This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def day_of_week(date): | |
""" get weekday from date (as instance 2022-12-31 iso format) """ | |
# | |
year = int(date[0:4]) | |
month = int(date[5:7]) | |
day = int(date[8:10]) | |
offset = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334] | |
week = ['Sunday', | |
'Monday', | |
'Tuesday', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def estimate_timedelta(td): | |
"""returns estimate timedelta in format 'YY year MM mon DD day'. consider plural form or absence y/m/d""" | |
if td.days > 0: | |
y, rem = divmod(td.days, 365) | |
m, d = divmod(rem, 31) | |
dict_ = {'year': y, 'mon': m, 'day':d } | |
return " ".join([f"{dict_[k]} {k}" + ("s" if dict_[k] > 1 else "") for k in dict_ if dict_[k] > 0 ]) | |
else: | |
return str(td) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import permutations | |
from functools import reduce | |
import re | |
import operator | |
_DEBUG = False | |
_DEBUG_PRINT_PER_TRIES = 1000 | |
def infix_postfix(command): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import requests | |
from bs4 import BeautifulSoup | |
def get_html(url): | |
r = requests.get(url=url) | |
return r.text | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import groupby | |
def solution(args): | |
# [-3,-2,-1,2,10,15,16,18,19,20] -> [[-3, -2, -1], [2], [10], [15, 16], [18, 19, 20]] | |
grps = ([v[1] for v in g] for _,g in groupby(enumerate(args), lambda p: p[1]-p[0])) | |
#[[-3, -2, -1], [2], [10], [15, 16], [18, 19, 20]] -> -3--1,2,10,15,16,18-20 | |
return ','.join('{}{}{}'.format(g[0],'-'if len(g)>2 else',',g[-1]) | |
if len(g)>1 else str(g[0]) for g in grps) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.codewars.com/kata/56a1c074f87bc2201200002e/ | |
# modified merge sort counting left > right cases | |
def countsort(arr, cntarr, cntdict): | |
if len(arr) > 1: | |
mid = len(arr) // 2 | |
left = arr[:mid] | |
leftcount = cntarr[:mid] | |
right = arr[mid:] | |
rightcount = cntarr[mid:] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
regexp: https://regex101.com/r/iqfDq3/5 | |
((eth|v)\d+|(en|sl|wl|ww|ib)(o|s\d+(f\d+)?d(\d+)?|(P\d+)?((p\d+)(s\d+)|(?<!s\d)(p\d+)|(s\d+)(?!p\d))((f\d+)?((u\d+){1,4})?(i\d)?|(d\d+)?)|x[0-9a-f]{12})) | |
/* | |
* Predictable network interface device names based on: | |
* - firmware/bios-provided index numbers for on-board devices | |
* - firmware-provided pci-express hotplug slot index number | |
* - physical/geographical location of the hardware | |
* - the interface's MAC address |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy import stats | |
import math | |
def confidence_interval(sd, mean, n, target_interval): | |
"""sd - выборочное среднее значение | |
mean - среднее выборки | |
n - размер выборки | |
target interval - 0..1, например 0.95, 0.99 | |
""" | |
alpha = 1 - target_interval | |
z = abs(stats.norm.ppf(alpha/2)) |