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
""" | |
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
""" | |
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
""" | |
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
fruits_dict: dict = dict() | |
citrusfruit: set = {"oranges", "lemons", "limes", "satsumas", "nectarines"} | |
treefruit: set = {"apples", "pears", "cherries", "plums", "peaches", "plums", | |
"cherries", "oranges", "lemons", "limes"} | |
stonefruit: set = {"cherries", "plums", "peaches", "nectarines"} | |
for fruit in citrusfruit.union(stonefruit).union(treefruit): | |
fruits_dict.setdefault(fruit, []) |
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 module illsutrating storing a key-value pair in a dictionary. | |
""" | |
import collections | |
import json | |
Book: collections.namedtuple = collections.namedtuple("Book", ["isbn", "title", "author"]) | |
books_as_list: list = list() | |
books_as_dict: dict = dict() |
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 module illsutrating storing a key-value pair in a dictionary. | |
""" | |
import collections | |
Book: collections.namedtuple = collections.namedtuple("Book", ["isbn", "title", "author"]) | |
books_as_list: list = list() | |
books_as_dict: dict = dict() | |
books_as_list.append( |
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 module illsutrating storing a key-value pair in a dictionary. | |
""" | |
import collections | |
Book: collections.namedtuple = collections.namedtuple("Book", ["isbn", "title", "author"]) | |
books_as_list: list = list() | |
books_as_dict: dict = dict() | |
books_as_list.append( |
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 module illsutrating storing a key-value pair in a dictionary. | |
""" | |
import collections | |
Book: collections.namedtuple = collections.namedtuple("Book", ["isbn", "title"]) | |
books_as_list: list = list() | |
books_as_dict: dict = dict() | |
books_as_list.append( |