| 1 | 2 | 3 |
|---|---|---|
| 4 | 5 | 6 |
| 1 | 2 | 3 | 4 |
|---|---|---|---|
| 5 | 6 | 7 | 8 |
| 9 | 10 | 11 |
| 1 | 2 | 3 |
|---|---|---|
| 4 | 5 | 6 |
| 1 | 2 | 3 | 4 |
|---|---|---|---|
| 5 | 6 | 7 | 8 |
| 9 | 10 | 11 |
| from timeit import repeat | |
| from statistics import mean | |
| def stats(stmt, r=100): | |
| res = repeat(stmt, globals=globals(), repeat=r) | |
| print(f'Avg: {mean(res)}\nMin: {min(res)}\nMax: {max(res)}') | |
| """ | |
| def foo(): | |
| return 1+1 |
| def positives(n): | |
| yield n | |
| yield from positives(n+1) | |
| def primes(s): | |
| n = next(s) | |
| yield n | |
| yield from primes(i for i in s if i%n != 0) | |
| def next_(n, x): | |
| return (x + n / x) / 2 | |
| # Repeats infinitely | |
| def repeat(f, a): | |
| yield a | |
| for v in repeat(f, f(a)): | |
| yield v | |
| # Delimiter |
| import bisect | |
| import random | |
| # bisect() | |
| def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'): | |
| i = bisect.bisect(breakpoints, score) | |
| return grades[i] | |
| [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]] | |
| # ['F', 'A', 'C', 'C', 'B', 'A', 'A'] |
| from datetime import datetime | |
| import calendar | |
| def calc_last_month_range(date: datetime) -> tuple: | |
| if date.month == 1: | |
| ini_date = datetime(date.year - 1, 12, 1) | |
| else: | |
| ini_date = datetime(date.year, date.month - 1, 1) | |
| end_date = datetime( |
| from socket import * | |
| def createServer(): | |
| serversocket = socket(AF_INET, SOCK_STREAM) | |
| try: | |
| serversocket.bind(('localhost',9000)) | |
| print('Starting server at http://127.0.0.1:9000/') | |
| serversocket.listen(5) | |
| while(1): | |
| (clientsocket, address) = serversocket.accept() |
| import unicodedata | |
| def normalize_str(string: str) -> str: | |
| non_ascii = ( | |
| unicodedata.normalize("NFKD", string).encode("ascii", "ignore").decode() | |
| ) | |
| string = non_ascii.lower().replace(" ", "_") | |
| fn print_type<T>(_: &T) { | |
| println!("{}", std::any::type_name::<T>()) | |
| } |