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 math | |
| def integrate(f, a, b, *, n_jobs=1, n_iter=10000000): | |
| acc = 0 | |
| step = (b - a) / n_iter | |
| for i in range(n_iter): | |
| acc += f(a + i * step) * step | |
| return acc |
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 cpu_foobar import superfoo, ultrabar | |
| import time | |
| if __name__ == '__main__': | |
| start = time.time() | |
| foo = superfoo(100) | |
| bar = ultrabar(100) | |
| print(f"Time: {time.time() - start:.4f}s") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 time | |
| import os | |
| import datetime | |
| from collections import namedtuple | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import pandas as pd | |
| import sklearn.preprocessing | |
| import torch |
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
| """Converts .py file with delimiters '# %%' and '# %% md' to .ipynb file | |
| Run as: python make_ipynb_from_py.py my_script.py my_notebook.ipynb | |
| """ | |
| import sys | |
| import nbformat | |
| from nbformat.v4 import new_notebook, new_code_cell, new_markdown_cell | |
| def create_cell(t, code_lines): | |
| listing = '\n'.join(code_lines).rstrip().lstrip() |
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 sys | |
| class Trie: | |
| class Node: | |
| def __init__(self, symbol, is_end=False): | |
| self.leafs = {} | |
| self.symbol = symbol | |
| self.word = '' | |
| self.is_end = is_end |
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
| # Version 0.1 working, but not so pretty as I want | |
| from random import uniform | |
| def size(T): return 0 if T is None else T.size | |
| class Treap(): | |
| def __init__(self, k): |
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 types | |
| import sys | |
| import functools | |
| DEBUG = True | |
| def trace(func=None, *, stream=sys.stdout): | |
| if not DEBUG: | |
| return func | |
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
| # Если в теле функции есть присваивание (smth = ..., smth += ...) или определение функции (def smth...) или класса (class smth...) - такое имя считается локальным | |
| # Если есть объявление global smth - имя глобальное, ищется на самом верхнем уровне (текущего модуля/скрипта) | |
| # Если есть объявление nonlocal smth - имя заимствовано из охватывающей функции (и только из функции, и только на 1 уровень выше) | |
| # Иначе имя ищется по правилу legb - local -> enclosing -> global -> built-in. | |
| # G, F, B - по имени функции или global | |
| # A - конфликтующие имена (ambiguous) | |
| G, A1, A2, A3, A4, A5, A6 = ['g··']*7 | |
| def foo(): |
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 minion_game(string): | |
| s = string | |
| n = len(s) | |
| stuart = kevin = 0 | |
| for i in range(n): | |
| if s[i] in 'AEIOU': | |
| kevin += n - i | |
| else: | |
| stuart += n - i | |
| if kevin == stuart: |
NewerOlder