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 remove_umlaut(string): | |
""" | |
Removes umlauts from strings and replaces them with the letter+e convention | |
:param string: string to remove umlauts from | |
:return: unumlauted string | |
""" | |
u = 'ü'.encode() | |
U = 'Ü'.encode() | |
a = 'ä'.encode() | |
A = 'Ä'.encode() |
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 dive_into_dict(path, dic): | |
path = path.split("/") | |
key = path[0] | |
result = dic[key] | |
if isinstance(result, dict): | |
result = dive_into_dict("/".join(path[1:]), result) | |
return result |
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
class Disabled: | |
"""Class that absorbs all attribute and method calls on it""" | |
def __init__(self, *args, **kwargs): | |
pass | |
def __getattr__(self, item): | |
return self | |
def __call__(self, *args, **kwargs): |
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 copy import deepcopy | |
from typing import List | |
def propagate_color(matrix: List[List[str]], color: str) -> List[List[str]]: | |
"""Propagates color to all same colors that neighbor the color at [0,0] | |
Note: only works for square matrices! | |
""" | |
to_change: str = matrix[0][0] |
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 logging | |
LOG = logging.getLogger(__name__) | |
class Singleton: | |
"""Abstract class that forces only one instance of the child to be created.""" | |
#: Singleton controller; True if an instance of this class has already been created | |
created = False |
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 argparse | |
from typing import Any, Dict, List, Optional | |
class FillDict(argparse.Action): | |
"""Argparse action that fills in a dictionary with nargs. | |
General usecase: | |
Subclass this and set custom_keys and defaults (if there are any). | |
Set that subclass as the action of an argparse argument, with nargs="+". |