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
""" | |
Zipping two lists to a dictionary as an example of dict comprehension. | |
""" | |
import typing | |
def dict_from_list(keys: [typing.Hashable], values: [])-> typing.Dict: | |
""" | |
Zips two lists. Returns: dict | |
""" | |
if len(keys) != len(values): |
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 simple class example. | |
""" | |
class Book: | |
""" | |
A simple book class. | |
""" | |
def __init__(self, isbn: str, title: str, author: 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
""" | |
A simple class example. | |
""" | |
class Book: | |
""" | |
A simple book class. | |
""" | |
def __init__(self, isbn: str, title: str, author: 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
""" | |
A versioned class example. | |
""" | |
__version__: str = "0.1" | |
class Book: | |
""" | |
A sinple book class. | |
""" | |
counter: int = 0 |
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 sub_00(haystack: str="", needle:str="") -> bool: | |
return needle in haystack | |
assert sub_00("the quick brown fox jumped over the lazy dog", "lazy") == True | |
assert sub_00("the quick brown fox jumped over the lazy dog", "lazys") == False |
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 string_reverse(forward: str = "") -> str: | |
return forward[::-1] | |
assert string_reverse("hello") == "olleh" | |
assert string_reverse("goodbye") != "goodbye" |
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 are_equal(first_comparator: str = "", second_comparator: str = "") -> bool: | |
return first_comparator == second_comparator | |
assert are_equal("thing one", "thing two") is False | |
assert are_equal("a thing", "a " + "thing") is True |
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 to_uppercase(input_string:str) -> str: | |
return input_string.upper() | |
def to_lowercase(input_string:str) -> str: | |
return input_string.lower() | |
def to_sentencecase(input_string:str) -> str: | |
return input_string.capitalize() | |
def to_titlecase(input_string:str) -> 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
def to_leetspeak(normal_speak:str="") -> str: | |
leet_mapping = str.maketrans("iseoau", "1530^Ü") | |
return normal_speak.translate(leet_mapping).title().swapcase() | |
assert to_leetspeak("the quick brown fox jumped over the lazy dogs") == \ | |
"tH3 qÜ1cK bR0wN f0x jÜMP3d 0v3r tH3 l^zY d0g5" |
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 remove_unwanted(original: str = "", | |
unwanted: str = "", | |
replacement: str = "") -> str: | |
return original.replace(unwanted, replacement) | |
assert remove_unwanted(original="M'The Real String'", | |
unwanted="M") == "'The Real String'" |