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
| name1 = input('Name of first person: ').casefold() | |
| name2 = input('Name of second person: ').casefold() | |
| def flames(name1, name2): | |
| n1 = sum(letter not in name2 for letter in name1) | |
| n2 = sum(letter not in name1 for letter in name2) | |
| results = 'friend love affection marriage enemy'.split() | |
| index = (n1 + n2) % len(results) - 1 | |
| return results[index] |
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 collections import Counter | |
| bandwidth_totals, server_counter = Counter(), Counter() | |
| if server is None: | |
| for entry in daily_log: | |
| items = entry.split() | |
| server_name, bandwidth = items[1], items[15] | |
| if bandwidth != 'NULL': # ignore older logs that don't have current format | |
| bandwidth_totals[server_name] += int(bandwidth) | |
| server_counter[server_name] += 1 |
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
| class Equivalence(list): | |
| def __call__(self, *args, **kw): | |
| result = self[0](*args, **kw) | |
| for i, impl in enumerate(self): | |
| assert impl(*args, **kw) == result, f"Wrong implementation #{i}" | |
| return result | |
| def equivalent(f): | |
| fs = globals().setdefault(f.__qualname__, Equivalence()) | |
| fs.append(f) |
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 a(p, q): | |
| d = [p, q] | |
| while len(d) > 1: | |
| if not d[-2]: d[-1] = d.pop() + 1 | |
| elif not d[-1]: d[-2] -= 1; d[-1] = 1 | |
| else: d.append(d[-1] - 1); d[-2] = d[-3]; d[-3] -= 1 | |
| return d.pop() |
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
| for i in range(len(a) >> 1): | |
| for j in range(len(a[i])+1 >> 1): | |
| a[i][j], a[j][~i], a[~i][~j], a[~j][i] = \ | |
| a[j][~i], a[~i][~j], a[~j][i], a[i][j] |
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 contextlib | |
| def second_index(text: str, symbol: str): | |
| """Second index of a symbol in a given text.""" | |
| with contextlib.suppress(ValueError): | |
| manhattan = text.index(symbol) | |
| berlin = text.index(symbol, manhattan + 1) | |
| return berlin |
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
| # http://www.catonmat.net/blog/generate-random-json-data-structures/ | |
| from random import choice, randrange, random, choices | |
| def random_JSON(max_depth): | |
| types = [number, string, boolean] + [array, object]*bool(max_depth) | |
| return choice(types)(max_depth) | |
| def number(_, max_num=1<<32): | |
| num = random() * max_num if randrange(2) else randrange(max_num) |
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 itertools, tkinter, weakref | |
| from tkinter import ttk | |
| def is_coord(index): | |
| return isinstance(index, tuple) and len(index) == 2 | |
| def rangify(coord): | |
| if isinstance(coord, slice): |
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 dataclasses | |
| @dataclasses.dataclass | |
| class Between: | |
| down: ... | |
| up: ... | |
| def __set_name__(self, cls, name): self.name = name | |
| def __get__(self, instance, owner): return vars(instance)[self.name] | |
| def __set__(self, instance, value): |
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 functools, itertools | |
| ceste = set('ABCDE') | |
| rb_ceste = sorted(ceste).index | |
| putovi = {odakle + kamo for odakle in ceste - {'C'} | |
| for kamo in ceste - {'E', odakle}} | |
| def kružno(put): | |
| odakle, kamo = put | |
| return sorted([rb_ceste(odakle) * 2, rb_ceste(kamo) * 2 + 1]) |