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 | |
from functools import singledispatch | |
class Square: | |
length: int | |
def __init__(self, length=0): | |
self.length = length |
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 functools import singledispatch | |
@singledispatch | |
def area(any_object): | |
raise NotImplementedError | |
@area.register | |
def _(any_object: Circle): | |
return math.pi * (math.pow(any_object.radius, 2)) |
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 functools import singledispatch | |
@singledispatch | |
def fancy_print(s): | |
raise NotImplementedError | |
@fancy_print.register(int) | |
def _ints(s): |
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 functools import singledispatch | |
@singledispatch | |
def fancy_print(s): | |
raise NotImplementedError | |
@fancy_print.register(int) | |
def _ints(s): |
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 functools import singledispatchmethod | |
class Dog: | |
@singledispatchmethod | |
def bark(self, quality): | |
raise NotImplementedError | |
@bark.register |
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
"""A package for Morse encoding and decoding.""" | |
from collections import UserDict | |
from time import sleep | |
from typing import NamedTuple | |
from pysinewave import SineWave | |
class MorseDict(UserDict): | |
def __init__(self, dictionary=None): |
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 typing import NamedTuple, List | |
class Chemical_Structure(NamedTuple): | |
name: str | |
synonyms: List[str] | |
iupac_name: str | |
pubchem_cid: str | |
inchi: str | |
inchi_key: str |
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 random | |
from typing import NamedTuple | |
class Card(NamedTuple): | |
suit: str | |
face: str | |
face_value: int | |
@property | |
def description(self): |
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 random | |
from collections import Counter | |
from enum import Enum, IntEnum, unique | |
@unique | |
class Outcome(Enum): | |
COMPUTER = 2 | |
TIED = 0 | |
PLAYER = 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
import more_itertools | |
def get_data(filename: str) -> list: | |
with open(filename, 'r') as f: | |
return [int(line.rstrip('\n')) for line in f] | |
def make_couples(singles: list) -> list: | |
return zip(singles, singles[1:]) |