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 __future__ import annotations | |
from enum import CONFORM, Flag, auto | |
class Allergies(Flag, boundary=CONFORM): | |
EGGS = auto() | |
PEANUTS = auto() | |
SHELLFISH = auto() | |
STRAWBERRIES = auto() | |
TOMATOES = auto() |
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 getpass import getpass | |
def print_line(line_count: int = 1) -> None: | |
"""Print a number of newlines.""" | |
print('\n' * line_count, end='') | |
def ask_guess(used: list[str], answer: list[str]) -> str: | |
while True: |
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 __future__ import annotations | |
from collections.abc import Callable | |
from typing import Any | |
class Node: | |
def __init__(self, value: object): | |
self.value = value | |
self.next_node: Node | None = None |
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
"""Tic-Tac-Toe implementation""" | |
from typing import Literal, get_args | |
# Custom type annotations | |
PlayerSymbol = Literal['X', 'O'] | |
BoardSymbol = Literal[' ', PlayerSymbol] | |
Board = list[list[BoardSymbol]] | |
BOARD_WIDTH = 3 |
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
"""Powerball Lottery Simulator""" | |
import json | |
import random | |
POSSIBLE_WHITE_VALUES = range(1, 70) | |
POSSIBLE_RED_VALUES = range(1, 27) | |
WHITE_DRAWS = 5 | |
RED_DRAWS = 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
""" | |
Experimenting with the Powers of 2 problem | |
https://www.youtube.com/watch?v=IPoh5C9CcI8 | |
""" | |
import itertools | |
from math import log2 | |
def is_power_of_2(num: int) -> bool: |
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
LOGO = """ | |
_ | |
| | | |
| |__ __ _ _ __ __ _ _ __ ___ __ _ _ __ | |
| '_ \ / _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ | |
| | | | (_| | | | | (_| | | | | | | (_| | | | | | |
|_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| | |
__/ | | |
|___/ | |
""" |
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/env python3 | |
"""Downloads sticker images from the LINE store""" | |
from pathlib import Path | |
import requests | |
DESTINATION = Path.home() / 'line_stickers' | |
IMAGE_ID_RANGE = range(345806894, 345806934) # Default: Kemomimi set 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
from typing import Generator, Iterable, T, Tuple | |
def my_enumerate(iterable: Iterable[T], start: int=0) -> Generator[Tuple[int, T], None, None]: | |
""" | |
Mimics the built-in enumerate-function, accepting any iterable, | |
and yielding incremented indices and values from it. | |
""" | |
idx = start | |
for value in iterable: |
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/env python3 | |
# -*- coding: utf-8 -*- | |
# The above two lines specify two things. The order must always be the same if both are used. | |
# The first line is a shebang, used by Unix-like systems to determine how to run a file. | |
# The second is a way to specify the encoding used by the file. | |
# Neither are necessary, especially the second one, since Python 3 is UTF-8 by default. | |
""" |
NewerOlder