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 functools import partial | |
import tkinter as tk | |
class GameTable(tk.Tk): | |
def __init__(self): | |
super().__init__() | |
for i in range(4): | |
label = tk.Label(self, text=f'Lap {i + 1}') |
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
# coding: utf-8 | |
""" | |
A móka odalent, a __main__-ben kezdődik. | |
Néhány gondolat: | |
Semmi kedvem nem volt indexekkel szórakozni, meg állandóan kétdimenziós tömböket bejárni, | |
ezért az volt az ötletem, hogy minden sejt egy objektum, aminek referenciája van a szomszédjaira. | |
Bár a sejtek bejárása nem e referenciák mentén történik, de ilyen szempontból egy nagy | |
láncolt lista az egész program. |
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 collections | |
def smallest_unique_number(numbers: list) -> int: | |
try: | |
least_common, population = collections.Counter(numbers).most_common()[-1] | |
assert population == 1 | |
return least_common | |
except (AssertionError, IndexError): | |
return -1 |
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 re | |
def patch(match): | |
incremented = str(int(match.group(0)) + 1) | |
padded = incremented.zfill(len(match.group(0))) | |
return padded | |
def increment_if_ends_with_int(text): | |
patched = re.sub('(\d+)$', patch, text) | |
if not patched[-1].isdigit(): |
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 collections | |
def scramble(word, chars): | |
word_char_count = collections.Counter(word) | |
chars_char_count = collections.Counter(chars) | |
chars_char_count.subtract(word_char_count) | |
return all(chars_char_count[word_char] >= 0 for word_char in word_char_count.keys()) | |
print(scramble('door', 'abcdeooor')) |
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 collections | |
def josephus_survivor(n, k): | |
population = collections.deque(range(1, n + 1)) | |
retval = None | |
while population: | |
population.rotate(1 - k) | |
retval = population.popleft() | |
return retval |
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 longest_palindrome(text): | |
text_length = len(text) | |
def find(longest_possible): | |
for window in range(text_length - longest_possible + 1): | |
subtext = text[window:window + longest_possible] | |
if subtext == subtext[::-1]: | |
return longest_possible | |
else: | |
return find(longest_possible - 1) |
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 re | |
items = ('burger', 'fries', 'chicken', 'pizza', 'sandwich', 'onionrings', 'milkshake', 'coke') | |
def get_order(s): | |
words = re.findall('|'.join(items), s, flags=re.IGNORECASE) | |
words.sort(key=items.index) | |
return ' '.join(map(str.capitalize, words)) |
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
# coding: utf-8 | |
import json | |
import argparse | |
import os | |
import re | |
from pathlib import Path | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wimm.settings") |
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
# coding: utf-8 | |
import requests | |
from lxml.html import fromstring | |
from requests_toolbelt.multipart.encoder import MultipartEncoder | |
def extract(soup): | |
for elem in soup.cssselect('.rc h3 a'): | |
href = elem.get('href') | |
if 'parom.hu' not in href: |
NewerOlder