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
class SimplyDataloader(DataLoader): | |
def batch_load_fn(self, keys): | |
""" | |
batch_load_fn accept list of keys and should return list of promises. | |
assert len(keys) == len(promises) | |
It calls only one time, with all the keys from the .load(key) calls. | |
""" | |
# heavy calculations will be here. | |
ret = 5 | |
return Promise.resolve([ret]) |
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 unidecode import unidecode | |
unidecode('жопа негра') -> 'zhopa negra' |
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 transform(value): | |
return {'True':True, 'False':False}.get(value, value) | |
d = {'str1': 'True','str2':'string','str3':10} | |
d2 = {key:transform(value) for key, value in d.items()} | |
assert d2 == {'str1': True,'str2':'string','str3':10} | |
print('OK') |
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 collections import defaultdict, Counter | |
def build_chain(words): | |
""" build Markov chain from the list of words """ | |
chain = defaultdict(Counter) | |
for idx, current_word in enumerate(words[:-1]): | |
next_word = words[idx+1] | |
chain[current_word].update([next_word]) | |
return chain |
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
class Foo: | |
x = 2 | |
@classmethod | |
def multy_cls(cls, y): | |
return cls.x * y | |
def multy(self, y): | |
return self.x * y | |
f1 = Foo() |
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
Microsoft Windows [Version 6.1.7601] | |
Zagrebelin-PI@ZAGREBELIN-PC C:\Users\zagrebelin-pi | |
> cd %temp% | |
Zagrebelin-PI@ZAGREBELIN-PC C:\Users\ZAGREB~1\AppData\Local\Temp | |
> mkdir dja | |
Zagrebelin-PI@ZAGREBELIN-PC C:\Users\ZAGREB~1\AppData\Local\Temp | |
> cd Dja |
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
#! /usr/bin/python3.6 | |
import datetime | |
import itertools | |
def show_progress(start, idx, total): | |
if idx == 0: | |
return | |
now = datetime.datetime.now() | |
speed = idx / (now - start).total_seconds() |
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 | |
""" | |
Дан словарь английского языка (несколько прилагательных, глаголов, существительных, наречий). | |
Нужно сформировать несколько случайных предложений, выбрав для каждого один шаблон из двух: | |
"the прилагатльное существительное глагол" или | |
"the прилагатльное существительное наречие глагол" | |
🌟 доп. условие: список шаблонов фраз сколько угодно большой, каждая фраза может включать несколько существительных и прилагательных. | |
🌟🌟 доп. условие 2: список частей речи может меняться. | |
""" |
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 dis | |
dis.dis(""" | |
try: | |
print(2) | |
except ValueError as e: | |
print(1)""") | |
2 0 SETUP_EXCEPT 14 (to 17) | |
3 3 LOAD_NAME 0 (print) |
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 vake(list_of_keys,list_of_values): | |
if len(list_of_values) >= len(list_of_keys): | |
return {x[0]:x[1] for x in zip(list_of_keys,list_of_values)} | |
else: | |
list_of_values = list_of_values + [None]*(len(list_of_keys) - len(list_of_values)) | |
return {x[0]:x[1] for x in zip(list_of_keys,list_of_values)} |
NewerOlder