This file contains 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 calc_seq(seq): | |
rep = {'(': 1, ')': -1, } | |
seq_sum = 0 | |
for s in seq: | |
seq_sum += rep[s] | |
if seq_sum < 0: | |
return False | |
if seq_sum > 0: | |
return False | |
return True |
This file contains 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 os | |
import zipfile | |
from logging.handlers import TimedRotatingFileHandler | |
class ZipTimedRotatingFileHandler(TimedRotatingFileHandler): | |
def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None, delay=False, utc=False): | |
super(ZipTimedRotatingFileHandler, self).__init__(filename, when, interval, backupCount, encoding, delay, utc) |
This file contains 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 os | |
import zipfile | |
from logging.handlers import TimedRotatingFileHandler | |
class ZipTimedRotatingFileHandler(TimedRotatingFileHandler): | |
""" | |
ZipTimedRotatingFileHandler is class based on TimedRotatingFileHandler for saving old logs files | |
to zip-archive instead of themself deleting |
This file contains 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 string | |
import itertools | |
import time | |
def brute(count_symb, lenght_max = 6, fill = 'a'): | |
s = string.ascii_letters | |
for s in itertools.product(s, repeat=count_symb): | |
yield '{}{}'.format(''.join(s), (lenght_max - count_symb) * fill if count_symb < lenght_max else '') | |
def brute_2(count = 10000): |
This file contains 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 random | |
from timench import Timench | |
# Setup | |
a3 = [v for v in range(0, 3)] | |
b3 = [v for v in range(0, 3)] | |
a1000 = [v for v in range(0, 1000)] | |
b1000 = [v for v in range(0, 1000)] | |
ar3 = [random.randint(0, 3) for _ in range(0, 3)] | |
br3 = [random.randint(0, 3) for _ in range(0, 3)] |
This file contains 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 list_replace(lst, value_search, value_replace): | |
res = [] | |
for item in lst: | |
if isinstance(item, (list, set, tuple)): | |
res.append(list_replace(item, value_search, value_replace)) | |
else: | |
res.append(item if item != value_search else value_replace) | |
return type(lst)(res) | |
# Example |
This file contains 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 timench import Timench | |
# Setup | |
lst_1 = [[i, i + 1] for i in range(100)] | |
lst_2 = [[i, i + 1] for i in range(1000)] | |
lst_3 = [[i, i + 1] for i in range(10000)] | |
tmnch = Timench() |