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
asci_uppercase: dict = {i: chr(+i) for i in range(65, 91, 1)} | |
digits: dict = {i: chr(+i) for i in range(48, 58, 1)} | |
asci_lowercase: dict = {i: chr(+i) for i in range(97, 123, 1)} | |
asci_punctuation: dict = {i: chr(+i) for i in range(32, 48, 1)} | |
asci_punctuation.update({i: chr(+i) for i in range(123, 127, 1)}) | |
asci_punctuation.update({i: chr(+i) for i in range(91, 97, 1)}) | |
asci_punctuation.update({i: chr(+i) for i in range(58, 65, 1)}) | |
asci_extended: dict = {i: chr(+i) for i in range(128, 255, 1)} | |
asci_system: dict = {i: hex(i) for i in range(0, 32, 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 json | |
import requests | |
def get_key_by_value(dictionary: dict, val: str) -> object: | |
"""get_values_by_key. | |
Args: | |
dictionary (dict): dictionary | |
val (str): value |
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 json | |
import requests | |
def get_values_by_key(dictionary: dict, key: str) -> dict: | |
"""get_values_by_key. | |
Args: | |
dictionary (dict): dictionary | |
key (str): key |
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 dict_from_two_lists(keys: list, values: list) -> dict: | |
""" | |
Args: | |
keys: The list of keys for the dictionary | |
values: The list of values for the dictionary | |
Returns: A dictionary of key:value pairs | |
""" |
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 merge_dictionaries(left: dict, right: dict) -> dict: | |
"""Merge two dictionaries using a shallow copy.""" | |
temp: dict = left.copy() | |
temp.update(right) | |
return temp | |
countries: dict = { | |
"Taiwan": 36193, | |
"Canada": 9984670, |
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
""" | |
Sorting a dictionary to an Iterable of tuples. | |
https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_area | |
""" | |
countries: dict = { | |
"Taiwan": 36193, | |
"Canada": 9984670, | |
"United States": 9525067, | |
"Russia": 17098246, |
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 requests | |
import json | |
def recursive_key_values(dictionary): | |
"""recursive_key_values. | |
Print all keys and values anywhere in a dictionary | |
Args: | |
dictionary: any dictionary |
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 string | |
def has_character_classes(input_string: str) -> tuple: | |
has_uppercase = False | |
has_lowercase = False | |
has_digits = False | |
has_whitespace = 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
import re | |
def between(first: str = "", second: str = "", input_string="") -> str: | |
m = re.search(f"{first}(.+?){second}", input_string) | |
if m: | |
return m.group(1) | |
else: |
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 string | |
import secrets | |
def generate_random_string(length: int = 0) -> str: | |
result = "".join( | |
secrets.choice(string.ascii_letters + string.digits) | |
for _ in range(length)) | |
return result |