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
hello: str = 'Hello World!' | |
assert len(hello) == 12 | |
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 collections import UserList | |
class UniquesList(UserList): | |
""" | |
A List Class which works just like a list, except | |
that it only holds unique values - similar to a set. | |
>>> ul = UniquesList("The Jolly Green Giant") | |
>>> print("".join(ul)) |
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 typing | |
def get_indices(the_list: list, test_value: object) -> typing.Iterable[int]: | |
""" | |
Returns the indices of matching list items. | |
Uses a generator to create an iterator. | |
Args: | |
the_list: the list containing search elements | |
test_value: what we want to find |
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 functools | |
a = [5, 7, 9, 11] | |
b = [1, 20, 30, 40] | |
c = [3, 3, 3, 6] | |
answers = list(map(lambda x, y, z: (x + y) / z, a, b, c)) | |
assert answers == [2.0, 9.0, 13.0, 8.5] | |
summation = functools.reduce(lambda x, next_reduce: x + next_reduce, [2.0, 9.0, 13.0, 8.5]) |
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 collections import UserList | |
from urllib.parse import urlparse | |
import json | |
import requests | |
def recursive_key_values(dictionary): | |
for key, value in dictionary.items(): | |
i = 0 | |
if type(value) is 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
from collections import UserList | |
class AutoAppendList(UserList): | |
""" | |
AutoAppendList. Will append an item if you are off by one index assignment. | |
>>> aal: AutoAppendList = AutoAppendList() | |
>>> for i in range(10): | |
... aal[i] = i | |
>>> print(aal) |
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 collections.abc import Iterable | |
from collections import UserList | |
def immutable_decorator(f): | |
def wrapper(self, *args, **kwargs): | |
raise TypeError("Object is frozen") | |
return wrapper | |
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 itertools import chain | |
def flatten_nested_lists(*input_list: list) -> list: | |
"""flatten_nested_lists. | |
Args: | |
input_list: | |
Returns: |
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 typing | |
def get_indices(the_list: list, test_value: object) -> typing.Iterable[int]: | |
""" | |
Returns the indices of matching list items. | |
Uses a generator to create an iterator. | |
Args: | |
the_list: the list containing search elements | |
test_value: what we want to find |
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 collections import UserList | |
class UniquesList(UserList): | |
""" | |
A List Class which works just like a list, except | |
that it only holds unique values - similar to a set. | |
>>> ul = UniquesList("The Jolly Green Giant") | |
>>> print("".join(ul)) |