source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
code_exercise_27k
5,013
Write a Python function to calculate the sum of squares of a given list of numbers. The function should take a list of integers as input and return the sum of the squares of each number in the list. The code should start with: ```python from typing import List def sum_of_squares(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_squares(numbers: List[int]) -> int: """ Calculate the sum of squares of a given list of numbers. Args: numbers (List[int]): A list of integers. Returns: int: The sum ...
code_exercise_27k
5,015
Write a Python function to find the intersection of two frozen sets. The function should return a new frozen set containing elements that are common to both input sets. The function should also handle cases where the input sets are empty or have no common elements. The code should start with: ```python def find_interse...
Here is the Python code to solve the given problem in the markdown block: ```python def find_intersection(set1: frozenset, set2: frozenset) -> frozenset: """ Find the intersection of two frozen sets. Args: set1 (frozenset): The first frozen set. set2 (frozenset): The second frozen set. ...
code_exercise_27k
5,017
Write a Python function to find the maximum element in a given frozen set. The function should handle the case where the frozen set is empty by raising a `ValueError`. The code should start with: ```python def find_maximum_element(frozen_set: frozenset) -> object: ```
Here is the Python code to solve the given problem in the markdown block: ```python def find_maximum_element(frozen_set: frozenset) -> object: """ Find the maximum element in a given frozen set. Args: frozen_set (frozenset): A frozen set of comparable elements. Returns: object: The max...
code_exercise_27k
5,018
Write a Python function to sort a list of dictionaries based on a specific key. The function should handle cases where the key might not be present in some dictionaries by placing those dictionaries at the end of the sorted list. The function should also handle cases where the key's value is `None` by placing those dic...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def sort_list_of_dicts(list_dicts: List[Dict], sort_key: str) -> List[Dict]: """ Sorts a list of dictionaries based on a specific key. Dictionaries that do not contain the key or have a None value ...
code_exercise_27k
5,019
Write a Python function to find the app with the highest rating from a given dictionary of app ratings. The dictionary keys represent app names, and the values represent app ratings. The function should return the name of the app with the highest rating. If the input dictionary is empty, the function should raise a `Va...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def get_highest_rated_app(app_ratings: Dict[str, float]) -> str: """ Returns the app with the highest rating from a given dictionary of app ratings. Args: app_ratings (Dict[str, float]): A d...
code_exercise_27k
5,021
Write a Python function to remove all elements from a given frozen set and return an empty frozen set. The function should handle the case where the input is not a frozen set by raising a `TypeError`. The code should start with: ```python def remove_elements_from_frozen_set(frozen_set: frozenset) -> frozenset: ```
Here is the Python code to solve the given problem in the markdown block: ```python def remove_elements_from_frozen_set(frozen_set: frozenset) -> frozenset: """ Remove all elements from a given frozen set and return an empty frozen set. Args: frozen_set (frozenset): The frozen set from which elemen...
code_exercise_27k
5,022
Write a Python function to filter and return a list of keys from a given dictionary where the corresponding values are greater than a specified number. The function should handle both integer and floating-point numbers as values in the dictionary. The code should start with: ```python from typing import Dict, List, Uni...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Union def get_keys_with_values_greater_than(data: Dict[str, Union[int, float]], num: Union[int, float]) -> List[str]: """ Returns a list of keys from the given dictionary where the corresponding v...
code_exercise_27k
5,023
Write a Python function to sort a list of strings by their length in ascending order. If two strings have the same length, they should remain in the order they appeared in the original list. The function should return a new list with the sorted strings. The code should start with: ```python from typing import List de...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_strings_by_length(strings: List[str]) -> List[str]: """ Sorts a list of strings by their length in ascending order and returns a new list. Args: strings (List[str]): A list of s...
code_exercise_27k
5,024
Write a Python function to create a frozen set from a given list of integers. The function should handle the following: 1. If the input list is empty, return an empty frozen set. 2. If the input list contains duplicate elements, the frozen set should only contain unique elements. 3. The function should be able to handl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def create_frozen_set_from_list(numbers: List[int]) -> frozenset: """ Create a frozen set from a given list of integers. This function takes a list of integers and returns a frozen set containing th...
code_exercise_27k
5,028
Write a Python function to determine if two frozen sets have any common elements. The function should return `True` if there is at least one common element between the two sets, and `False` otherwise. The code should start with: ```python def have_common_elements(set1: frozenset, set2: frozenset) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def have_common_elements(set1: frozenset, set2: frozenset) -> bool: """ Determine if two frozen sets have any common elements. Args: set1 (frozenset): The first frozen set. set2 (frozenset): The second froze...
code_exercise_27k
5,031
Write a Python function to find the product with the highest price from a given dictionary of product prices. The dictionary keys are product names, and the values are their respective prices. The function should return the name of the product with the highest price. If the dictionary is empty, the function should rais...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def find_product_with_highest_price(product_prices: Dict[str, float]) -> str: """ Find the product with the highest price from the given dictionary of product prices. Args: product_prices (d...
code_exercise_27k
5,032
Write a Python function to remove duplicates from a given list and return a new list with unique elements while preserving the order of their first occurrence. The function should start with: ```python from typing import List def remove_duplicates_preserve_order(input_list: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_preserve_order(input_list: List[int]) -> List[int]: """ Remove duplicates from a list while preserving the order of their first occurrence. Args: input_list (List[int])...
code_exercise_27k
5,033
Write a Python function to filter out prime numbers from a given list of integers. The function should return a new list containing only the prime numbers found in the original list. The function should be efficient and handle edge cases such as an empty list or a list with non-prime numbers. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_prime_numbers(numbers: List[int]) -> List[int]: """ Filters out prime numbers from a given list of integers and returns a new list containing only the prime numbers. Args: numbers...
code_exercise_27k
5,034
Write a Python function to check if a given frozen set is a proper subset of another frozen set. A proper subset is defined as a subset that contains fewer elements than the superset. The function should return `True` if the first frozen set is a proper subset of the second frozen set, and `False` otherwise. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_proper_subset(subset: frozenset, superset: frozenset) -> bool: """ Check if a given frozen set is a proper subset of another frozen set. A proper subset is defined as a subset that contains fewer elements than the su...
code_exercise_27k
5,036
Write a Python function to find the word(s) that occur the most frequently in a given dictionary. The dictionary will have words as keys and their corresponding occurrences as values. The function should return a list containing the word(s) that occur the most frequently. If the input dictionary is empty, the function ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def find_most_frequent_words(word_occurrences: Dict[str, int]) -> List[str]: """ Finds the word(s) that occur the most frequently in a given dictionary. Args: word_occurrences (dict): ...
code_exercise_27k
5,037
Write a Python function to determine if a given string is a palindrome. The function should ignore non-alphanumeric characters and be case-insensitive. The code should start with: ```python def is_palindrome(string: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(string: str) -> bool: """ Check if a string is a palindrome or not. A palindrome is a string that reads the same forward and backward, ignoring non-alphanumeric characters and case. Args: stri...
code_exercise_27k
5,040
Write a Python function to find the common keys in two dictionaries and return a new dictionary with the common keys and their corresponding values from both dictionaries. If a key is present in both dictionaries, the value in the new dictionary should be a tuple containing the values from both dictionaries. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def find_common_keys_with_values(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]: """ Finds the common keys in two dictionaries and returns a new dictionary with the common keys and ...
code_exercise_27k
5,044
Write a Python function to filter a list of dictionaries based on a specific key-value pair. The function should return a new list containing only the dictionaries that have the specified key-value pair. The code should start with: ```python from typing import List, Dict, Any def filter_dicts(dicts_list: List[Dict[str...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def filter_dicts(dicts_list: List[Dict[str, Any]], key: str, value: Any) -> List[Dict[str, Any]]: """ Filters a list of dictionaries and returns a new list containing only the dictionaries tha...
code_exercise_27k
5,045
Write a Python function to extract a specific attribute's values from a dictionary of student information. The dictionary contains student names as keys, and each student's information is stored as a dictionary of attributes. The function should return a list of all the values for the specified attribute across all stu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Any def get_attribute_values(student_info: Dict[str, Dict[str, Any]], attribute: str) -> List[Any]: """ Extracts and returns a list of all the values for a specified attribute across all students ...
code_exercise_27k
5,046
Write a Python function to sort a list of integers in descending order. The function should handle input validation to ensure that the input is a list of integers. If the input is not a list or if any element in the list is not an integer, the function should raise a `TypeError`. The code should start with: ```python f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_list_desc(numbers: List[int]) -> List[int]: """ Sorts a list of integers in descending order. Args: numbers (List[int]): The list of integers to be sorted. Returns: Lis...
code_exercise_27k
5,048
Write a Python function to compute the union of two frozen sets. The function should return a new frozen set containing all unique elements from both input sets. The function should also handle cases where the input sets are not frozen sets by raising a `TypeError`. The code should start with: ```python def union_of_f...
Here is the Python code to solve the given problem in the markdown block: ```python def union_of_frozen_sets(set1: frozenset, set2: frozenset) -> frozenset: """ Compute the union of two frozen sets. Parameters: set1 (frozenset): The first input frozen set. set2 (frozenset): The second input frozen ...
code_exercise_27k
5,050
Write a Python function to sort a list of strings in alphabetical order, considering both uppercase and lowercase letters. The function should be case-insensitive, meaning that 'Apple' and 'apple' should be treated as the same string. The function should also maintain the original case of the strings in the sorted list...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_strings_case_insensitive(strings: List[str]) -> List[str]: """ Sorts a list of strings in alphabetical order in a case-insensitive manner, while maintaining the original case of the strings....
code_exercise_27k
5,052
Write a Python function to sort a list of tuples based on the second element of each tuple. The function should handle lists of tuples where each tuple contains exactly two elements: a string and an integer. The sorting should be done in ascending order based on the integer value. The code should start with: ```python...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def sort_tuples_by_second_element(lst: List[Tuple[str, int]]) -> List[Tuple[str, int]]: """ Sorts a list of tuples based on the second element of each tuple. Args: lst (List[Tuple[str...
code_exercise_27k
5,053
Write a Python function to find the symmetric difference between two frozen sets. The symmetric difference between two sets is the set of elements which are in either of the sets but not in both. The function should return a new frozen set containing the symmetric difference. The code should start with: ```python def ...
Here is the Python code to solve the given problem in the markdown block: ```python def find_symmetric_difference(set1: frozenset, set2: frozenset) -> frozenset: """ Find the symmetric difference between two frozen sets. Args: set1 (frozenset): The first frozen set. set2 (frozenset): The se...
code_exercise_27k
5,054
Write a Python function to validate whether a given string is a valid email address according to a simplified set of rules. The function should check for the presence of a single '@' symbol, ensure the local part (before '@') is not empty, and the domain part (after '@') contains at least one period and does not have c...
Here is the Python code to solve the given problem in the markdown block: ```python def is_valid_email(email: str) -> bool: """ Validate whether a given string is a valid email address according to a simplified set of rules. Parameters: email (str): The email address string to check. Returns: ...
code_exercise_27k
5,057
Write a Python function to check if two given frozen sets are disjoint. The function should return `True` if the sets have no common elements, and `False` otherwise. The function should also raise a `TypeError` if either of the inputs is not a `frozenset`. The code should start with: ```python def are_disjoint(frozen_...
Here is the Python code to solve the given problem in the markdown block: ```python def are_disjoint(frozen_set1: frozenset, frozen_set2: frozenset) -> bool: """ Check if two given frozen sets are disjoint. Args: frozen_set1 (frozenset): The first frozen set. frozen_set2 (frozenset): The se...
code_exercise_27k
5,060
Write a Python function to filter out numbers from a given list that are not in the Fibonacci sequence. The function should return a new list containing only the numbers that are part of the Fibonacci sequence. The code should start with: ```python from typing import List def filter_fibonacci_numbers(numbers: List[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_fibonacci_numbers(numbers: List[int]) -> List[int]: """ Filters out numbers from the given list that are not in the Fibonacci sequence. Args: numbers (List[int]): A list of intege...
code_exercise_27k
5,061
Write a Python function to compare two frozen sets for equality. The function should return `True` if the two frozen sets are equal, and `False` otherwise. The function should handle cases where the input is not a frozen set by returning `False`. The code should start with: ```python def compare_frozen_sets(set1, set2)...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_frozen_sets(set1, set2) -> bool: """ Compare two frozen sets for equality. Args: set1: The first set to compare. set2: The second set to compare. Returns: bool: True if both inputs a...
code_exercise_27k
5,062
Write a Python function to calculate the total revenue generated from each customer based on the provided sales data. The sales data is a dictionary where each key is a customer name and the value is another dictionary containing the sales data for that customer. The sales data dictionary for each customer has product ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def calculate_total_revenue(sales_data: Dict[str, Dict[str, float]]) -> Dict[str, float]: """ Calculate the total revenue generated from each customer based on the provided sales data. Args: ...
code_exercise_27k
5,064
Write a Python function to find the largest element in a given frozen set. The function should handle the case where the frozen set is empty by raising a `ValueError`. The code should start with: ```python def find_largest_element(frozen_set: frozenset) -> Any: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any def find_largest_element(frozen_set: frozenset) -> Any: """ Finds the largest element in a given frozen set. Args: frozen_set (frozenset): The frozen set to search for the largest element. ...
code_exercise_27k
5,065
Write a Python function to merge a list of dictionaries into a single dictionary, where each key in the resulting dictionary should have the value from the last dictionary in the list that contains that key. The function should handle dictionaries with different keys and values efficiently. The code should start with:...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def merge_dicts(list_of_dicts: List[Dict[Any, Any]]) -> Dict[Any, Any]: """ Merges a list of dictionaries into a single dictionary, where each key in the resulting dictionary has the value...
code_exercise_27k
5,066
Write a Python function to sort a list of lists based on the sum of their elements. The function should handle an empty list by raising a `ValueError`. The code should start with: ```python from typing import List def sort_list_of_lists(lst: List[List[int]]) -> List[List[int]]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_list_of_lists(lst: List[List[int]]) -> List[List[int]]: """ Sorts a list of lists based on the sum of their elements. Args: lst (List[List[int]]): The list of lists to be sorted. ...
code_exercise_27k
5,068
Write a Python function to check if a given set is a proper subset of another set. A proper subset is a subset that is not equal to the superset. The function should take two sets as input and return a boolean indicating whether the first set is a proper subset of the second set. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_proper_subset(set1: set, set2: set) -> bool: """ Check if a set is a proper subset of another set. Args: set1 (set): The potential proper subset. set2 (set): The potential superset. Returns: ...
code_exercise_27k
5,071
Write a Python function to sort a list of names in reverse alphabetical order, ensuring that the sorting is case-insensitive. The function should return the sorted list of names. The code should start with: ```python from typing import List def sort_names_reverse_case_insensitive(names: List[str]) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_names_reverse_case_insensitive(names: List[str]) -> List[str]: """ Sorts a list of names in reverse alphabetical order, ensuring case-insensitivity. Args: names (List[str]): A list ...
code_exercise_27k
5,073
Write a Python function to find the symmetric difference between two frozen sets. The symmetric difference between two sets is defined as the set of elements that are in either of the sets but not in both. The function should return a new frozen set containing the symmetric difference. The code should start with: ```p...
Here is the Python code to solve the given problem in the markdown block: ```python def find_symmetric_difference(set1: frozenset, set2: frozenset) -> frozenset: """ Finds the symmetric difference between two frozen sets. Args: set1 (frozenset): The first input frozen set. set2 (frozenset):...
code_exercise_27k
5,074
Write a Python function to calculate the factorial of a given number using an iterative approach. The function should handle non-negative integers only and return the factorial of the input number. The code should start with: ```python def factorial_iterative(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def factorial_iterative(n: int) -> int: """ Calculates the factorial of a given non-negative integer using an iterative approach. Args: n (int): The non-negative integer for which the factorial needs to be calculate...
code_exercise_27k
5,075
Write a Python function to sort a list of integers in descending order, ignoring negative numbers. The function should return a new list containing only the positive integers from the input list, sorted in descending order. The code should start with: ```python from typing import List def sort_positive_descending(numb...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def sort_positive_descending(numbers: List[int]) -> List[int]: """ Sorts a list of integers in descending order, ignoring negative numbers. Args: numbers (List[int]): List of integers to b...
code_exercise_27k
5,078
Write a Python function to sort a list of tuples based on both the second and third elements. If the second elements are equal, the tuples should be sorted by the third elements. The function should return a new list of tuples sorted according to this criteria. The code should start with: ```python from typing import ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def sort_tuples_by_second_and_third(list_of_tuples: List[Tuple[int, int, int]]) -> List[Tuple[int, int, int]]: """ Sorts a list of tuples based on both the second and third elements. Args: ...
code_exercise_27k
5,080
Write a Python function to remove a specific key-value pair from a given dictionary using the `pop()` method. The function should return the value associated with the removed key. If the key is not found in the dictionary, the function should raise a `KeyError`. The code should start with: ```python def remove_key_val...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_key_value(dictionary: dict, key) -> any: """ Remove a specific key-value pair from a dictionary using the pop() method. Parameters: dictionary (dict): The dictionary from which to remove the key-value pair. ...
code_exercise_27k
5,082
Write a Python function to find the element(s) that occur(s) most frequently in a given list. The function should return a list of the most frequent element(s). If there are multiple elements with the same highest frequency, the function should return all of them. The code should start with: ```python from typing impo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_most_frequent_elements(elements: List[int]) -> List[int]: """ Finds the element(s) that occur(s) most frequently in a given list. Args: elements (List[int]): A list of integers for ...
code_exercise_27k
5,084
Write a Python function to check if a given value exists in a nested dictionary. The function should be able to handle nested dictionaries of arbitrary depth. If the value is found at any level of the nested dictionary, the function should return `True`. Otherwise, it should return `False`. The code should start with:...
Here is the Python code to solve the given problem in the markdown block: ```python def check_value_in_nested_dict(value, nested_dict): """ Check if a given value exists in a nested dictionary of arbitrary depth. Args: value: The value to check. nested_dict: The nested dictionary to search ...
code_exercise_27k
5,092
Write a Python function to compute the Cartesian product of two frozen sets. The Cartesian product of two sets \( A \) and \( B \) is the set of all ordered pairs \( (a, b) \) where \( a \) is in \( A \) and \( b \) is in \( B \). The function should return the result as a set of tuples. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import FrozenSet, Set, Tuple from itertools import product def cartesian_product(set1: FrozenSet[int], set2: FrozenSet[int]) -> Set[Tuple[int, int]]: """ Computes the Cartesian product of two frozen sets of integers...
code_exercise_27k
5,093
Write a Python function to convert a string representation of a number to its integer equivalent. The function should handle both positive and negative integers. If the input string contains non-digit characters (except for a leading minus sign for negative numbers), the function should raise a `ValueError`. The functi...
Here is the Python code to solve the given problem in the markdown block: ```python def string_to_integer(string: str) -> int: """ Convert a string representation of a number to its integer equivalent. Parameters: - string (str): The string to be converted. Returns: - int: The converted intege...
code_exercise_27k
5,094
Write a Python function to sort a list of integers using the bubble sort algorithm. The function should be able to handle lists of varying lengths and should return the sorted list. The code should start with: ```python from typing import List def bubble_sort(arr: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the bubble sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: Li...
code_exercise_27k
5,095
Write a Python function to increment the value of a specific key in the "inventory" dictionary. If the key does not exist in the dictionary, the function should add the key with the specified increment value. The function should handle both positive and negative increments. The code should start with: ```python def in...
Here is the Python code to solve the given problem in the markdown block: ```python def increment_inventory_item(inventory: dict, item_name: str, increment: int) -> dict: """ Increment the value of a specific key in the 'inventory' dictionary. If the key does not exist, add the key with the specified increm...
code_exercise_27k
5,096
Write a Python function to calculate the sum of all elements in a given frozen set. The function should handle both integer and floating-point numbers. The code should start with: ```python def sum_of_frozen_set(frozen_set: frozenset) -> int | float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_frozen_set(frozen_set: frozenset) -> int | float: """ Calculates the sum of all elements in a frozen set. Args: frozen_set (frozenset): The frozen set for which the sum is calculated. Returns: ...
code_exercise_27k
5,097
Write a Python function to check if a given inventory dictionary contains a specific item. The function should return `True` if the item is found in the inventory, and `False` otherwise. The inventory dictionary maps item names (strings) to their quantities (integers). The code should start with: ```python from typing...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def is_item_in_inventory(inventory: Dict[str, int], item: str) -> bool: """ Check if a specific item is in the inventory dictionary. Args: inventory (Dict[str, int]): The dictionary represen...
code_exercise_27k
5,098
Write a Python function to convert a float to an integer. The function should handle both positive and negative float numbers and should raise a `TypeError` if the input is not a float. The function should also handle special float values such as `NaN` (Not a Number) and `inf` (infinity) by returning `None` for these c...
Here is the Python code to solve the given problem in the markdown block: ```python def float_to_int(number: float) -> int: """ Convert a float to an integer. Args: number (float): The float number to be converted. Returns: int: The integer representation of the given float number. ...
code_exercise_27k
5,100
Write a Python function to convert an integer to its English words representation. The function should handle both positive and negative integers within the range of -999,999,999 to 999,999,999. The code should start with: ```python def integer_to_english_words(number: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def integer_to_english_words(number: int) -> str: """ Converts an integer to its English words representation. Args: number (int): The integer to be converted. Must be within the range -999,999,999 to 999,999,999. ...
code_exercise_27k
5,102
Write a Python function to calculate the average value of elements in a frozen set. The function should handle the following cases: 1. If the frozen set is empty, raise a `ValueError` with the message "Frozen set is empty." 2. If the frozen set contains non-numerical elements, raise a `ValueError` with the message "Fro...
Here is the Python code to solve the given problem in the markdown block: ```python def average_frozen_set(frozen_set: frozenset) -> float: """ Calculate the average value of numerical elements in a frozen set. Args: frozen_set (frozenset): A frozen set containing numerical elements. Returns: ...
code_exercise_27k
5,103
Write a Python function to convert a boolean value to an integer. The function should return 1 if the boolean value is `True`, and 0 if the boolean value is `False`. The function should handle both `True` and `False` values and should be able to handle cases where the input is not a boolean by raising a `TypeError`. T...
Here is the Python code to solve the given problem in the markdown block: ```python def boolean_to_integer(value: bool) -> int: """ Converts a boolean value to an integer. Parameters: value (bool): The boolean value to be converted. Returns: int: The converted integer value. Returns 1 ...
code_exercise_27k
5,105
Write a Python function to find the person with the highest age from a given dictionary of people's ages. If there are multiple people with the same highest age, return the first one encountered in the dictionary. The function should handle an empty dictionary by raising a `ValueError`. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def find_oldest_person(ages: Dict[str, int]) -> str: """ Finds the person with the highest age from a given dictionary of people's ages. Args: ages (Dict[str, int]): A dictionary where the k...
code_exercise_27k
5,107
Write a Python function to convert a list of elements into a single string, where each element is separated by a specified delimiter. The function should handle lists containing various data types, converting each element to a string before joining them. The code should start with: ```python from typing import List, An...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def list_to_string(lst: List[Any], delimiter: str = ' ') -> str: """ Convert a list of elements into a single string, with each element separated by a specified delimiter. Args: lst (Li...
code_exercise_27k
5,114
Write a Python function to convert a tuple to a list. The function should take a tuple as input and return a list containing the same elements as the tuple. The code should start with: ```python from typing import Tuple, List def tuple_to_list(my_tuple: Tuple) -> List: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, List def tuple_to_list(my_tuple: Tuple) -> List: """ Convert a tuple to a list. Args: my_tuple (Tuple): The tuple to be converted. Returns: List: The converted list containing...
code_exercise_27k
5,118
Write a Python function to convert a string to a float, handling various edge cases such as invalid input strings and scientific notation. The function should raise a `ValueError` if the input string cannot be converted to a float. The code should start with: ```python def string_to_float(string_number: str) -> float: ...
Here is the Python code to solve the given problem in the markdown block: ```python def string_to_float(string_number: str) -> float: """ Convert a string to a float, handling various edge cases and raising a ValueError for invalid input. Parameters: string_number (str): The string representation of a ...
code_exercise_27k
5,119
Write a Python function to calculate the average grade of all the students in a list of dictionaries. Each dictionary represents a student and contains 'name' and 'grade' keys. The function should handle the following cases: 1. If the list of students is empty, raise a `ValueError` with the message "The students list c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def calculate_average_grade(students: List[Dict[str, any]]) -> float: """ Calculate the average grade of all the students in a list of dictionaries. Args: students (List[Dict[str, any]...
code_exercise_27k
5,121
Write a Python function to sort a list of dictionaries based on the sum of specified values in each dictionary. The function should take two arguments: a list of dictionaries and a list of keys. Each dictionary in the list should contain the keys specified in the second argument. The function should return a new list o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def sort_dict_list_by_sum(dict_list: List[Dict[str, int]], keys: List[str]) -> List[Dict[str, int]]: """ Sorts a list of dictionaries based on the sum of specified values in each dictionary. A...
code_exercise_27k
5,123
Write a Python function to find the city with the largest population from a given dictionary where keys are city names and values are their respective populations. If the input dictionary is empty, raise a `ValueError`. The code should start with: ```python from typing import Dict def get_largest_city(city_population...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def get_largest_city(city_populations: Dict[str, int]) -> str: """ Find the city with the largest population from a given dictionary. Args: city_populations (Dict[str, int]): A dictionary wh...
code_exercise_27k
5,125
Write a Python function to convert a float to a string representation with a specified number of decimal places. The function should handle both positive and negative floats, and should round the number to the nearest value if necessary. The code should start with: ```python def float_to_string_with_precision(num: floa...
Here is the Python code to solve the given problem in the markdown block: ```python def float_to_string_with_precision(num: float, precision: int) -> str: """ Convert a float to a string with a specified number of decimal places. Args: num (float): The float number to convert. precision (in...
code_exercise_27k
5,127
Write a Python function to convert a string to a list of characters, while also handling special cases such as an empty string and strings with special characters. The function should start with: ```python from typing import List def string_to_list(string: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def string_to_list(string: str) -> List[str]: """ Converts a string to a list of characters. Args: string (str): The input string to be converted. Returns: List[str]: A list c...
code_exercise_27k
5,130
Write a Python function to sort a list of strings based on their lexicographic rank. The function should handle lists of varying lengths and strings of varying lengths. The function should also ensure that the input is a list of strings and raise a `ValueError` if the input is not valid. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def lexicographic_rank_sort(strings: List[str]) -> List[str]: """ Sort a list of strings based on their lexicographic rank. Args: strings (List[str]): A list of strings to be sorted. Re...
code_exercise_27k
5,131
Write a Python function to generate a set of all the unique vowels found in a given string. The function should be case-insensitive, meaning both uppercase and lowercase vowels should be considered. The code should start with: ```python def get_unique_vowels(string: str) -> set: ```
Here is the Python code to solve the given problem in the markdown block: ```python def get_unique_vowels(string: str) -> set: """ Generates a set of all the unique vowels found in a given string. Args: string (str): The input string to search for vowels. Returns: set: A set containing...
code_exercise_27k
5,134
Write a Python function to convert a list to a tuple. The function should ensure that the input is a list and raise a `TypeError` if it is not. The function should return the tuple created from the list. The code should start with: ```python def list_to_tuple(lst: list) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def list_to_tuple(lst: list) -> tuple: """ Converts a list to a tuple. Args: lst (list): The list to be converted to a tuple. Returns: tuple: The tuple created from the list. Raises: TypeEr...
code_exercise_27k
5,136
Write a Python function to merge two dictionaries such that the resulting dictionary contains keys from both dictionaries, and the values for each key are lists of corresponding values from both dictionaries. If a key exists in only one dictionary, the value should be a list containing the single value from that dictio...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Any def merge_dicts(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, List[Any]]: """ Merge two dictionaries and return a new dictionary with keys from both dictionaries and values as a l...
code_exercise_27k
5,137
Write a Python function to generate a set of unique characters from a given string, while preserving the order of their first occurrence in the string. The function should use a set comprehension to achieve this. The code should start with: ```python def generate_unique_characters_set(string: str) -> set: ```
Here is the Python code to solve the given problem in the markdown block: ```python def generate_unique_characters_set(string: str) -> set: """ Generates a set of unique characters from a given string, preserving the order of their first occurrence. Args: string (str): The input string from which t...
code_exercise_27k
5,140
Write a Python function to convert a given string to uppercase, ensuring that the function handles various edge cases such as empty strings, strings with numbers, and strings with special characters. The function should also raise a `TypeError` if the input is not a string. The code should start with: ```python def co...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_uppercase(string: str) -> str: """ Convert a given string to uppercase. This function takes a string as input and returns the string in uppercase. If the input is not a string, a TypeError is raised. ...
code_exercise_27k
5,144
Write a Python function to convert a list of integers to a string, ensuring that the function handles various edge cases such as empty lists, lists with negative integers, and lists with zero. The function should also validate the input to ensure it is a list of integers and raise a `TypeError` if the input is invalid....
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_list_to_string(int_list: List[int]) -> str: """ Convert a list of integers to a string. Args: int_list (List[int]): A list of integers to be converted. Returns: str:...
code_exercise_27k
5,145
Write a Python function to find the common elements between two given lists using set comprehension. The function should return a set containing the common elements. The code should start with: ```python from typing import List, Set def find_common_elements(list1: List[int], list2: List[int]) -> Set[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Set def find_common_elements(list1: List[int], list2: List[int]) -> Set[int]: """ Find the common elements between two lists using set comprehension. Args: list1 (List[int]): The first list...
code_exercise_27k
5,146
Write a Python function to convert a given string to lowercase, while also handling special cases such as strings with non-alphabetic characters, empty strings, and strings with only numeric characters. The function should return the lowercase version of the input string. The code should start with: ```python def conv...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_lowercase(string: str) -> str: """ Convert a given string to lowercase. This function takes a string as input and returns its lowercase version. Non-alphabetic characters and numeric characters remain unc...
code_exercise_27k
5,147
Implement a randomized quicksort algorithm to sort a list of integers. The function should be able to handle lists of varying lengths, including empty lists and lists with duplicate elements. The code should start with: ```python from typing import List import random def randomized_quicksort(arr: List[int]) -> List[in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def randomized_quicksort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the randomized quicksort algorithm. Args: arr (List[int]): The list of integers to be ...
code_exercise_27k
5,148
Write a Python function to find the product with the lowest price in a given dictionary where the keys represent the products and the values represent their prices. The function should return the product name with the lowest price. If the input dictionary is empty, the function should raise a `ValueError`. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python def find_lowest_price(product_prices: dict) -> str: """ Find the product with the lowest price in the given dictionary. Args: product_prices (dict): A dictionary where the keys represent the products and the values ...
code_exercise_27k
5,150
Write a Python function to convert a tuple to a string, where each element of the tuple is separated by a specified delimiter. The function should handle tuples containing elements of different data types, including integers, strings, floats, and booleans. The code should start with: ```python from typing import Tuple,...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Any def tuple_to_string(t: Tuple[Any], delimiter: str = ', ') -> str: """ Convert a tuple to a string with elements separated by a specified delimiter. Args: t (Tuple[Any]): The input tupl...
code_exercise_27k
5,153
Write a Python function to convert a given string into a list of words, where each word is separated by any whitespace character (space, tab, newline). The function should handle multiple consecutive whitespace characters by treating them as a single delimiter. The function should also handle leading and trailing white...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def string_to_words(string: str) -> List[str]: """ Converts a given string into a list of words, where each word is separated by any whitespace character. Args: string (str): The input strin...
code_exercise_27k
5,156
Write a Python function to convert a given string to title case. The function should capitalize the first letter of each word in the string while converting all other letters to lowercase. The function should handle various edge cases, such as strings with multiple spaces, leading/trailing spaces, and special character...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_title_case(string: str) -> str: """ Converts a given string to title case. Title case means that the first letter of each word is capitalized, and all other letters are converted to lowercase. Args: ...
code_exercise_27k
5,157
Write a Python function to sort a list of integers using the merge sort algorithm. The function should be optimized for performance and should handle edge cases such as empty lists and lists with a single element. The code should start with: ```python from typing import List def optimized_merge_sort(arr: List[int]) ->...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def optimized_merge_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the merge sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: ...
code_exercise_27k
5,160
Write a Python function to convert a hexadecimal number to its decimal representation. The function should handle both uppercase and lowercase hexadecimal digits and should return the decimal equivalent of the given hexadecimal number. The code should start with: ```python def hex_to_decimal(hex_num: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def hex_to_decimal(hex_num: str) -> int: """ Converts a hexadecimal number to its decimal representation. Args: hex_num (str): The hexadecimal number to be converted. It can contain both uppercase and lowercase lett...
code_exercise_27k
5,167
Write a Python function to extract a specific attribute's values from a dictionary containing company information. The dictionary has company names as keys and their respective information as values. The function should return a list of all the attribute values for the given attribute across all companies. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Any def get_attribute_values(company_info: Dict[str, Dict[str, Any]], attribute: str) -> List[Any]: """ Extracts and returns a list of attribute values for all companies in the given company_info ...
code_exercise_27k
5,169
Write a Python function to generate a set of leap years between two given years, inclusive. The function should use set comprehension to efficiently generate the set of leap years. The code should start with: ```python def generate_leap_years(start_year: int, end_year: int) -> set: ```
Here is the Python code to solve the given problem in the markdown block: ```python def generate_leap_years(start_year: int, end_year: int) -> set: """ Generate a set of leap years between the start_year (inclusive) and end_year (inclusive). Args: start_year (int): The starting year. end_ye...
code_exercise_27k
5,171
Write a Python function to convert a hexadecimal number to its binary representation. The function should handle both uppercase and lowercase hexadecimal characters and return the binary string without the '0b' prefix. The code should start with: ```python def hex_to_binary(hex_number: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def hex_to_binary(hex_number: str) -> str: """ Convert a hexadecimal number to its binary representation. Args: hex_number (str): The hexadecimal number to be converted. It can include digits 0-9 and letters A-F (or...
code_exercise_27k
5,174
Write a Python function to generate a set of the first `n` Fibonacci numbers using set comprehension. The function should be efficient and concise. The code should start with: ```python def generate_fibonacci_set(n: int) -> set: ```
Here is the Python code to solve the given problem in the markdown block: ```python def generate_fibonacci_set(n: int) -> set: """ Generates a set of the first n Fibonacci numbers using set comprehension. Args: n (int): The number of Fibonacci numbers to generate. Returns: set: A set c...
code_exercise_27k
5,177
Write a Python function to convert a list of strings into a single string with a specified delimiter. The function should join the elements of the list using the provided delimiter. If the delimiter is not provided, it should default to an empty string. The code should start with: ```python from typing import List, Op...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def convert_list_to_string(lst: List[str], delimiter: Optional[str] = None) -> str: """ Converts a list of strings into a single string with a specified delimiter. Args: lst (List[...
code_exercise_27k
5,181
Write a Python function to find the maximum element in a given list of numeric values. The function should handle both integer and floating-point numbers. If the input list is empty, the function should raise a `ValueError`. The code should start with: ```python from typing import List, Union def find_max_element(lst:...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_max_element(lst: List[Union[int, float]]) -> Union[int, float]: """ Finds the maximum element in a given list of numeric values. Args: lst (List[Union[int, float]]): A list o...
code_exercise_27k
5,184
Write a Python function to find all the even numbers in a given list and return them in a new list. The function should handle lists of integers and return an empty list if no even numbers are found. The code should start with: ```python from typing import List def find_even_numbers(lst: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_even_numbers(lst: List[int]) -> List[int]: """ Returns a list of all the even numbers in the given list. Args: lst (List[int]): A list of integers. Returns: List[int]: ...
code_exercise_27k
5,186
Write a Python function to generate a set of prime numbers between two given numbers using set comprehension. The function should handle the input validation and ensure that the start number is less than the end number. The code should start with: ```python def generate_prime_numbers(start: int, end: int) -> set: ```
Here is the Python code to solve the given problem in the markdown block: ```python def generate_prime_numbers(start: int, end: int) -> set: """ Generate a set of prime numbers between the given start and end numbers. Args: start (int): The starting number. end (int): The ending number. ...
code_exercise_27k
5,189
Write a Python function to generate a set of all possible subsets of a given list. Each subset should be represented as a `frozenset` to ensure immutability and hashability, which is necessary for storing subsets in a set. The function should be efficient and handle lists of varying lengths. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Set from itertools import combinations def generate_subsets(lst: List[int]) -> Set[frozenset]: """ Generate a set of all possible subsets of a given list. Args: lst (List[int]): The input l...
code_exercise_27k
5,190
Write a Python function to merge two sorted lists into a new sorted list. The function should handle lists of integers and ensure that the input lists are sorted. If either list is not sorted, the function should raise a `ValueError`. The function should start with: ```python from typing import List def merge_sorted_l...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]: """ Merge two sorted lists into a new sorted list. Args: list1 (List[int]): The first sorted list. list2 (Lis...
code_exercise_27k
5,191
Write a Python function to find the intersection of keys and their respective values in a list of dictionaries. The function should return a dictionary where the keys are the common keys found in all dictionaries, and the values are lists containing the corresponding values from each dictionary. If the input list of di...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def find_intersection_of_dicts(dicts: List[Dict[str, Any]]) -> Dict[str, List[Any]]: """ Finds the intersection of keys and their values in a list of dictionaries. Args: dicts (Li...
code_exercise_27k
5,194
Write a Python function to remove all duplicates from a given list while preserving the order of the elements. The function should return a new list with unique elements in the order they first appeared in the original list. The code should start with: ```python from typing import List def remove_duplicates_preserve_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_preserve_order(lst: List[int]) -> List[int]: """ Remove duplicates from a given list while preserving the order of the elements. This function takes a list as input and returns...
code_exercise_27k
5,195
Create a Python function that takes a dictionary of fruits and their colors, and a list of fruit names, and returns a new dictionary containing only the fruits from the list with their corresponding colors. If a fruit in the list is not found in the original dictionary, it should be ignored. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def filter_fruits_by_list(fruits: Dict[str, str], fruit_list: List[str]) -> Dict[str, str]: """ Filters the given dictionary of fruits by a list of fruit names and returns a new dictionary cont...
code_exercise_27k
5,198
Write a Python function to update the "fruits" dictionary by adding a new key-value pair representing a new fruit's information. The function should also handle the case where the fruit already exists in the dictionary by updating its information. The code should start with: ```python def update_fruit_info(fruits: dict...
Here is the Python code to solve the given problem in the markdown block: ```python def update_fruit_info(fruits: dict, fruit_name: str, fruit_info: str) -> dict: """ Updates the 'fruits' dictionary by adding a new key-value pair representing a new fruit's information. If the fruit already exists in the dic...
code_exercise_27k
5,200
Write a Python function to convert a datetime object to a string representation in a specified format. The function should handle different formats and ensure that the input is a valid datetime object. The code should start with: ```python from datetime import datetime from typing import Optional def datetime_to_strin...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime from typing import Optional def datetime_to_string(dt: datetime, format_str: Optional[str] = None) -> str: """ Converts a datetime object to a string representation in the specified format. Ar...
code_exercise_27k
5,202
Write a Python function to remove a specific key-value pair from a given dictionary using the `pop()` method. The function should return the value associated with the removed key if it exists, otherwise it should return `None`. The code should start with: ```python def remove_key_value_pair(dictionary: dict, key) -> an...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_key_value_pair(dictionary: dict, key) -> any: """ Remove a specific key-value pair from the dictionary using the `pop()` method. Args: dictionary (dict): The dictionary from which to remove the key-value ...
code_exercise_27k
5,203
Write a Python function to convert a list of strings into a dictionary where each string in the list becomes a key, and its corresponding value is the index of the string in the list. The function should handle lists of any length, including empty lists. The code should start with: ```python from typing import List, D...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def list_to_dict(lst: List[str]) -> Dict[str, int]: """ Converts a list of strings into a dictionary where each string is a key and its index in the list is the value. Args: lst (List[...
code_exercise_27k
5,204
Write a Python function to generate a set of all possible distinct pairs of integers from two given lists. Each pair should consist of one integer from the first list and one integer from the second list. The function should use set comprehension for efficiency and clarity. The code should start with: ```python from t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Set def generate_pairs(list1: List[int], list2: List[int]) -> Set[tuple]: """ Generate a set of all possible distinct pairs of integers from two given lists. Args: list1 (List[int]): The fi...
code_exercise_27k
5,206
Write a Python function to check if a given key exists in a dictionary and return the corresponding value if the key exists. If the key does not exist, return a default value provided by the user. The function should handle cases where the default value is not provided by returning `None`. The code should start with: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Optional def get_value_or_default(dictionary: dict, key: Any, default: Optional[Any] = None) -> Any: """ Check if a given key exists in a dictionary and return the corresponding value. If the key doe...
code_exercise_27k
5,207
Write a Python function to sort the elements of a list in descending order. The function should not modify the original list but return a new list with the elements sorted in descending order. The code should start with: ```python from typing import List def sort_list_descending(lst: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_list_descending(lst: List[int]) -> List[int]: """ Sorts the elements of a list in descending order without modifying the original list. Args: lst (List[int]): The list to be sorted....
code_exercise_27k
5,208
Write a Python function to generate a set of all possible permutations of a given list. The function should use set comprehension to achieve this. The code should start with: ```python from typing import List, Set, Tuple from itertools import permutations def generate_permutations(lst: List[int]) -> Set[Tuple[int, ......
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Set, Tuple from itertools import permutations def generate_permutations(lst: List[int]) -> Set[Tuple[int, ...]]: """ Generate all possible permutations of a given list using set comprehension. Args...
code_exercise_27k
5,217
Write a Python function to update the value of a specific key in a given dictionary. If the key does not exist in the dictionary, the function should raise a `KeyError`. The function should return the updated dictionary. The code should start with: ```python def update_value(vocabulary: dict, key, new_value) -> dict: ...
Here is the Python code to solve the given problem in the markdown block: ```python def update_value(vocabulary: dict, key, new_value) -> dict: """ Update the value of a specific key in the given dictionary. Args: vocabulary (dict): The dictionary to update. key: The key of the value to upd...
code_exercise_27k
5,220
Write a Python function to check if a given value exists in a nested dictionary structure. The function should be able to handle nested dictionaries of arbitrary depth. If the value is found at any level of the nested dictionary, the function should return `True`. Otherwise, it should return `False`. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Dict def is_value_in_nested_dict(value: Any, nested_dict: Dict[Any, Any]) -> bool: """ Check if a given value exists in a nested dictionary structure. Args: value (Any): The value to search ...
code_exercise_27k
5,225
Write a Python function to find the average of all elements in a given list, handling both integers and floats. The function should return 0 if the list is empty to avoid division by zero. The code should start with: ```python from typing import List def find_average(lst: List[float]) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_average(lst: List[float]) -> float: """ Calculate the average of all elements in a given list of numbers. Args: lst (List[float]): A list of numbers (integers or floats). Retur...