source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
code_exercise_27k
3,704
Write a Python function to convert a dictionary into a list of tuples, where each tuple contains a key-value pair from the dictionary. The function should handle dictionaries with various types of keys and values, including nested dictionaries. The code should start with: ```python from typing import Dict, List, Tuple,...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple, Any def convert_dict_to_list_of_tuples(dictionary: Dict[Any, Any]) -> List[Tuple[Any, Any]]: """ Converts a dictionary into a list of tuples, handling nested dictionaries recursively. ...
code_exercise_27k
3,706
Write a Python function to check if a given set is a subset of another set. The function should return `True` if all elements of the first set are present in the second set, and `False` otherwise. The function should handle sets of any size and type of elements. The code should start with: ```python def is_subset(set1...
Here is the Python code to solve the given problem in the markdown block: ```python def is_subset(set1: set, set2: set) -> bool: """ Check if set1 is a subset of set2. Parameters: set1 (set): The set to be checked for being a subset. set2 (set): The set against which set1 is checked. R...
code_exercise_27k
3,708
Write a Python function to calculate the sum of all values in a given dictionary. The dictionary may contain numeric values (integers or floats). The function should handle dictionaries with non-numeric values by raising a `TypeError`. The code should start with: ```python from typing import Union def calculate_total(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Union def calculate_total(dictionary: dict) -> Union[int, float]: """ Calculate the sum of all numeric values in a given dictionary. Args: dictionary (dict): The dictionary containing numeric val...
code_exercise_27k
3,709
Write a Python function to determine if one set is a proper subset of another set. A set `A` is a proper subset of a set `B` if all elements of `A` are also elements of `B`, but `A` is not equal to `B`. The function should return `True` if `A` is a proper subset of `B`, and `False` otherwise. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python def is_proper_subset(set_a: set, set_b: set) -> bool: """ Determine if one set is a proper subset of another set. Args: set_a (set): The first set to check. set_b (set): The second set to check. Returns...
code_exercise_27k
3,712
Write a Python function to find the symmetric difference between two sets. The symmetric difference of two sets is defined as the set of elements which are in either of the sets but not in their intersection. The function should return a new set containing the symmetric difference. The code should start with: ```pytho...
Here is the Python code to solve the given problem in the markdown block: ```python def symmetric_difference(set1: set, set2: set) -> set: """ Calculate the symmetric difference between two sets. The symmetric difference of two sets is the set of elements which are in either of the sets but not in their in...
code_exercise_27k
3,715
Write a Python function to count the number of dictionaries in a list that contain a specific key. The function should iterate through the list and check each dictionary for the presence of the key. If the key is found in a dictionary, the count should be incremented. The function should return the total count of dicti...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def count_dicts_with_key(lst: List[Dict[str, Any]], key: str) -> int: """ Count the number of dictionaries in a list that contain a specific key. Args: lst (List[Dict[str, Any]]):...
code_exercise_27k
3,716
Write a Python function to determine if a given number is both a prime number and a multiple of 6. The function should return `True` if the number meets both conditions, and `False` otherwise. The code should start with: ```python def is_prime_and_multiple_of_six(number: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime_and_multiple_of_six(number: int) -> bool: """ Determine if a given number is both a prime number and a multiple of 6. Args: number (int): The number to be checked. Returns: bool: True if th...
code_exercise_27k
3,724
Write a Python function to find all key-value pairs in a dictionary where the key starts with a specified prefix. The function should return a new dictionary containing only the key-value pairs that match the prefix. The code should start with: ```python from typing import Dict def find_key_value_pairs_with_prefix(dic...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def find_key_value_pairs_with_prefix(dictionary: Dict[str, any], prefix: str) -> Dict[str, any]: """ Find all key-value pairs in a dictionary where the key starts with a specified prefix. Args: ...
code_exercise_27k
3,728
Write a Python function to filter a dictionary and return a new dictionary containing only the key-value pairs where the values match a specified target value. The function should handle cases where the target value is not found in the dictionary by returning an empty dictionary. 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 Dict, Any def filter_dictionary_by_value(dictionary: Dict[Any, Any], target_value: Any) -> Dict[Any, Any]: """ Filters a dictionary and returns a new dictionary containing only the key-value pairs where t...
code_exercise_27k
3,729
Write a Python function to find the symmetric difference between two sets. The symmetric difference of two sets is defined as the set of elements which are in either of the sets but not in their intersection. The function should take two sets as input and return a new set containing the symmetric difference. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python def symmetric_difference_of_sets(set1: set, set2: set) -> set: """ Find the symmetric difference between two sets. The symmetric difference of two sets is the set of elements which are in either of the sets but not in t...
code_exercise_27k
3,730
Write a Python function to calculate the sum of two numbers using the '+' operator. The function should be able to handle both integer and floating-point inputs. The code should start with: ```python def calculate_sum(a: int | float, b: int | float) -> int | float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_sum(a: int | float, b: int | float) -> int | float: """ Calculates the sum of two numbers using the '+' operator. Args: a (int | float): The first number. b (int | float): The second number. ...
code_exercise_27k
3,731
Write a Python function to find the highest three values in a given dictionary. The function should return a list of these values in descending order. If the dictionary contains fewer than three elements, the function should raise a `ValueError`. The code should start with: ```python from typing import Dict, List def...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def find_highest_three_values(dictionary: Dict[str, int]) -> List[int]: """ Find the highest three values in a dictionary. Args: dictionary (Dict[str, int]): The dictionary to search. ...
code_exercise_27k
3,732
Write a Python function to multiply two numbers without using the `*` operator. The function should support both positive and negative integers, as well as zero. The code should start with: ```python def multiply_without_operator(a: int, b: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def multiply_without_operator(a: int, b: int) -> int: """ Multiply two numbers without using the '*' operator. Args: a (int): The first number. b (int): The second number. Returns: int: The prod...
code_exercise_27k
3,733
Write a Python function to find the union of two sets and return the result as a new set. The union of two sets is a set that contains all the elements from both sets, without any duplicates. The function should handle sets of any size and type of elements. The code should start with: ```python def find_union(set1: set...
Here is the Python code to solve the given problem in the markdown block: ```python def find_union(set1: set, set2: set) -> set: """ Find the union of two sets and return the result as a new set. The union of two sets is a set that contains all the elements from both sets, without any duplicates. ...
code_exercise_27k
3,736
Write a Python function to check if two dictionaries are equal, considering nested dictionaries and lists within the dictionaries. The function should return `True` if the dictionaries are equal, and `False` otherwise. The code should start with: ```python from typing import Any, Dict def deep_dict_equal(dict1: Dict[A...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Dict def deep_dict_equal(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> bool: """ Check if two dictionaries are equal, considering nested dictionaries and lists. Args: dict1 (Dict[Any, Any...
code_exercise_27k
3,739
Write a Python function to determine if two given sets are disjoint. Two sets are considered disjoint if they have no elements in common. The function should efficiently check for common elements and return `True` if the sets are disjoint, and `False` otherwise. The code should start with: ```python def are_disjoint_se...
Here is the Python code to solve the given problem in the markdown block: ```python def are_disjoint_sets(set1: set, set2: set) -> bool: """ Determine if two sets are disjoint. Args: set1 (set): The first set. set2 (set): The second set. Returns: bool: True if the sets are disj...
code_exercise_27k
3,744
Write a Python function to convert a dictionary of lists into a list of dictionaries. Each dictionary in the resulting list should have the same keys as the input dictionary, but the values should be taken from the corresponding positions in the lists. If a list is shorter than others, the corresponding value in the re...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Any def convert_dict_to_list_of_dicts(dictionary: Dict[str, List[Any]]) -> List[Dict[str, Any]]: """ Convert a dictionary of lists into a list of dictionaries. Each dictionary in the resultin...
code_exercise_27k
3,746
Write a Python function to calculate the floor division of two numbers using the '//' operator. The function should handle both integer and floating-point inputs and return the appropriate quotient. The function should also raise a `ZeroDivisionError` if the divisor is zero. The code should start with: ```python def f...
Here is the Python code to solve the given problem in the markdown block: ```python def floor_division(dividend: int | float, divisor: int | float) -> int | float: """ Calculates the floor division of two numbers using the '//' operator. Args: dividend (int | float): The number to be divided. ...
code_exercise_27k
3,747
Write a Python function to determine if a given set is mutable or immutable. The function should return `True` if the set is immutable (i.e., a `frozenset`), and `False` if the set is mutable (i.e., a regular `set`). The function should handle both types of sets and any potential edge cases. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python def is_mutable_set(my_set) -> bool: """ Determine if a given set is mutable or immutable. Args: my_set (set or frozenset): The set that needs to be checked. Returns: bool: True if the set is immutable (...
code_exercise_27k
3,750
Write a Python function to multiply corresponding elements of two dictionaries and return a new dictionary containing the results. If the input dictionaries have different keys, raise a `ValueError`. The function should start with: ```python def multiply_dict_elements(dict1: dict, dict2: dict) -> dict: ```
Here is the Python code to solve the given problem in the markdown block: ```python def multiply_dict_elements(dict1: dict, dict2: dict) -> dict: """ Multiplies corresponding elements of two dictionaries and returns a new dictionary. Args: dict1 (dict): First dictionary. dict2 (dict): Secon...
code_exercise_27k
3,752
Write a Python function to determine if two given numbers are not equal using the '!=' operator. The function should handle numeric inputs and return a boolean value indicating whether the two numbers are not equal. The code should start with: ```python def are_numbers_not_equal(num1: float, num2: float) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def are_numbers_not_equal(num1: float, num2: float) -> bool: """ Determines if two given numbers are not equal using the '!=' operator. Args: num1 (float): The first number to compare. num2 (float): The seco...
code_exercise_27k
3,753
Write a Python function to sort a dictionary by its values in ascending order. If two or more keys have the same value, these keys should then be sorted by their keys in ascending order. The function should return the sorted dictionary. The code should start with: ```python from typing import Dict def sort_dictionary...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dictionary_by_value_and_key(dictionary: Dict[str, int]) -> Dict[str, int]: """ Sorts a dictionary by its values in ascending order. If two or more keys have the same value, these keys are th...
code_exercise_27k
3,754
Write a Python function to update a set with the elements from another set, ensuring that the original set is modified in place and the function returns the updated set. The function should handle cases where the sets may be empty or contain overlapping elements. The code should start with: ```python def update_set_in...
Here is the Python code to solve the given problem in the markdown block: ```python def update_set_in_place(original_set: set, new_set: set) -> set: """ Updates the original set in place by adding elements from the new set. Args: original_set (set): The original set to be updated. new_set (...
code_exercise_27k
3,755
Write a Python function to determine if a given number is a prime number. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The function should return `True` if the number is prime and `False` otherwise. The code should start with: ```python def is_prime(number: in...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(number: int) -> bool: """ Determine if a given number is a prime number. Args: number (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. ...
code_exercise_27k
3,759
Write a Python function to determine if a given number is within a specified range, inclusive of the boundaries. The function should take three parameters: the number to be checked, the lower boundary of the range, and the upper boundary of the range. The function should return `True` if the number is within the range ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_within_range(num: int, lower_bound: int, upper_bound: int) -> bool: """ Determines if a given number is within a specified range, inclusive of the boundaries. Args: num (int): The number to be checked. ...
code_exercise_27k
3,763
Write a Python function to calculate the intersection of multiple sets. The function should take a list of sets as input and return a set containing the elements that are common to all the sets in the list. If the input list is empty, the function should return an empty set. The code should start with: ```python from ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_intersection_of_sets(sets: List[set]) -> set: """ Calculate the intersection of multiple sets. Args: sets (List[set]): A list of sets to calculate the intersection from. Returns...
code_exercise_27k
3,765
Write a Python function to calculate the average value of the values in a given dictionary. The dictionary should contain only numeric values. If the dictionary is empty or contains non-numeric values, the function should raise a `ValueError`. The code should start with: ```python def get_average_value(dictionary: dic...
Here is the Python code to solve the given problem in the markdown block: ```python def get_average_value(dictionary: dict) -> float: """ Calculate the average value of the numeric values in a given dictionary. Args: dictionary (dict): A dictionary with numeric values. Returns: float: ...
code_exercise_27k
3,766
Write a Python function to calculate the area of a rectangle using the `*` operator, ensuring that the function handles non-negative inputs only. The function should raise a `ValueError` if either the length or the width is negative. The code should start with: ```python def calculate_area(length: float, width: float) ...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_area(length: float, width: float) -> float: """ Calculate the area of a rectangle. Args: length (float): The length of the rectangle. Must be non-negative. width (float): The width of the recta...
code_exercise_27k
3,767
Write a Python function to check if a dictionary contains a specific value in any of its keys. The function should return `True` if the value is found in any of the keys, and `False` otherwise. The code should start with: ```python def check_dictionary_value(dictionary: dict, value: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def check_dictionary_value(dictionary: dict, value: str) -> bool: """ Check if a specific value is present in any of the keys in a dictionary. Args: dictionary (dict): The input dictionary to be checked. val...
code_exercise_27k
3,768
Write a Python function to generate the Cartesian product of two 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 a set containing these ordered pairs. The code should start with: `...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set def cartesian_product(set1: Set[int], set2: Set[int]) -> Set[tuple]: """ Generates the Cartesian product of two sets. Args: set1 (Set[int]): The first set. set2 (Set[int]): The second...
code_exercise_27k
3,771
Write a Python function to filter a dictionary based on values. The function should take a dictionary and a value as input and return a new dictionary containing only the key-value pairs whose values match the given value. The code should start with: ```python def filter_dict_by_value(dictionary: dict, value) -> dict: ...
Here is the Python code to solve the given problem in the markdown block: ```python def filter_dict_by_value(dictionary: dict, value) -> dict: """ Filter a dictionary by value. This function takes a dictionary and a value as input and returns a new dictionary containing only the key-value pairs who...
code_exercise_27k
3,772
Write a Python function to find the power set of a given set. The power set of a set is the set of all possible subsets, including the empty set and the set itself. The function should return the power set as a set of sets. The code should start with: ```python from typing import Set def power_set(s: Set[int]) -> Set...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set def power_set(s: Set[int]) -> Set[Set[int]]: """ Returns the power set of a given set. Args: s (Set[int]): The set for which to find the power set. Returns: Set[Set[int]]: The po...
code_exercise_27k
3,773
Write a Python function to merge two dictionaries, concatenating values of common keys. If a key exists in both dictionaries, the values should be concatenated in the order they appear (first from `dict1`, then from `dict2`). If a key exists only in one dictionary, it should be added to the merged dictionary with its v...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def merge_dicts(dict1: Dict[str, str], dict2: Dict[str, str]) -> Dict[str, str]: """ Merge two dictionaries and concatenate values of common keys. Args: dict1 (Dict[str, str]): The first dic...
code_exercise_27k
3,775
Write a Python function to calculate the hypotenuse of a right-angled triangle using the Pythagorean theorem. The function should take two sides of the triangle as input and return the length of the hypotenuse. The function should use the `**`, `+`, and `sqrt()` operators from the `math` module. The code should start ...
Here is the Python code to solve the given problem in the markdown block: ```python import math def calculate_hypotenuse(side1: float, side2: float) -> float: """ Calculates the hypotenuse of a right-angled triangle using the Pythagorean theorem. Args: side1 (float): Length of one of the sides of ...
code_exercise_27k
3,776
Write a Python function to add an element to a nested dictionary using a list of keys that define the path to the element. The function should handle the creation of intermediate dictionaries if they do not exist. The function should return the modified nested dictionary. The code should start with: ```python from typ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Dict, List def add_element_to_nested_dict(nested_dict: Dict[str, Any], keys: List[str], value: Any) -> Dict[str, Any]: """ Add an element to a nested dictionary using a list of keys that define the path ...
code_exercise_27k
3,781
Write a Python function to find the k largest values in a given dictionary. The function should return a list containing the k largest values from the dictionary. If the dictionary has fewer than k values, the function should return all the values in descending order. 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, List def find_k_largest_values(dictionary: Dict[str, int], k: int) -> List[int]: """ Returns the k largest values from the given dictionary. Args: dictionary (Dict[str, int]): A dictionary ...
code_exercise_27k
3,785
Write a Python function to convert a list of dictionaries into a dictionary where each key is a unique identifier extracted from the original dictionaries, and the value is the corresponding dictionary from the list. The unique identifier is specified by a key that is common across all dictionaries in the list. The co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def convert_dict_list_to_dict(dict_list: List[Dict[str, Any]], key: str) -> Dict[Any, Dict[str, Any]]: """ Converts a list of dictionaries into a dictionary, with a unique identifier as the ke...
code_exercise_27k
3,789
Write a Python function to check if a given number is divisible by either 2 or 3 using the '%' and 'or' operators. The function should return `True` if the number is divisible by either 2 or 3, and `False` otherwise. The code should start with: ```python def is_divisible_by_2_or_3(num: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_2_or_3(num: int) -> bool: """ Check if a number is divisible by either 2 or 3. Args: num (int): The number to be checked. Returns: bool: True if the number is divisible by either 2 o...
code_exercise_27k
3,790
Write a Python function to change the position of a particular key in a dictionary. The function should take a dictionary, a key, and a new position as inputs and return the modified dictionary with the key moved to the new position. If the key is not found in the dictionary or the new position is out of range, appropr...
Here is the Python code to solve the given problem in the markdown block: ```python def change_key_position(dictionary: dict, key: str, new_position: int) -> dict: """ Change the position of a particular key in a dictionary. Args: dictionary (dict): The input dictionary. key (str): The key ...
code_exercise_27k
3,792
Write a Python function to convert temperature from Fahrenheit to Celsius using only the `-` and `*` operators. The function should take a single parameter representing the temperature in Fahrenheit and return the temperature in Celsius. The formula for the conversion is: \[ \text{Celsius} = \left( \text{Fahrenheit} - ...
Here is the Python code to solve the given problem in the markdown block: ```python def fahrenheit_to_celsius(fahrenheit: float) -> float: """ Convert temperature from Fahrenheit to Celsius using only the '-' and '*' operators. Parameters: - fahrenheit (float): The temperature in Fahrenheit. Retur...
code_exercise_27k
3,798
Write a Python function to calculate the factorial of a number using an iterative approach and the `*` operator. The function should handle non-negative integers only. 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: """ Calculate the factorial of a number using an iterative approach and the '*' operator. Parameters: n (int): The number for which factorial needs to be calculated. Returns:...
code_exercise_27k
3,801
Write a Python function to determine if a given year is a leap year. The function should use the '%' and 'or' operators to check the conditions for a leap year. The function should return `True` if the year is a leap year and `False` otherwise. The code should start with: ```python def is_leap_year(year: int) -> bool: ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_leap_year(year: int) -> bool: """ Determine if a given year is a leap year. A year is a leap year if: 1. It is divisible by 4. 2. It is not divisible by 100, unless it is also divisible by 400. Args: ...
code_exercise_27k
3,804
Write a Python function to check if a set is a proper superset of another set. A proper superset is a superset that is not equal to the other set. The function should return `True` if the first set is a proper superset of the second set, and `False` otherwise. The function should also handle cases where the inputs are ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_proper_superset(set1, set2): """ Check if a set is a proper superset of another set. Parameters: set1 (set): The first set. set2 (set): The second set. Returns: bool: True if set1 is a pr...
code_exercise_27k
3,806
Write a Python function to flatten a nested list of arbitrary depth and return a flat list. The function should handle lists that contain other lists, which may themselves contain more lists, and so on. The function should start with: ```python from typing import List, Any def flatten_nested_list(nested_list: List[Any...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def flatten_nested_list(nested_list: List[Any]) -> List[Any]: """ Flattens a nested list of arbitrary depth and returns a flat list. Args: nested_list (List[Any]): The nested list to fl...
code_exercise_27k
3,807
Write a Python function to find common items between two dictionaries. The function should return a set of keys that have the same corresponding values in both dictionaries. The code should start with: ```python from typing import Dict, Set def find_common_items(dict1: Dict, dict2: Dict) -> Set: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Set def find_common_items(dict1: Dict, dict2: Dict) -> Set: """ Find common items between two dictionaries. This function returns a set of keys that have the same corresponding values in both dicti...
code_exercise_27k
3,810
Write a Python function to reverse a dictionary, ensuring that if multiple keys in the original dictionary map to the same value, the reversed dictionary will contain a list of those keys as the value for that common value. The function should handle cases where the original dictionary contains non-hashable values by c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any, List def reverse_dict_with_lists(dictionary: Dict[Any, Any]) -> Dict[Any, List[Any]]: """ Reverse the key-value pairs of a dictionary, handling duplicate values and non-hashable values. Args: ...
code_exercise_27k
3,811
Write a Python function to flatten a list of dictionaries and return a flat list of values. The function should handle dictionaries with nested dictionaries and lists, ensuring that all values, including those in nested structures, are included in the flattened list. The code should start with: ```python from typing im...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def flatten_dict_list(dict_list: List[dict]) -> List[Any]: """ Flatten a list of dictionaries and return a flat list of values, including nested dictionaries and lists. Args: dict_list ...
code_exercise_27k
3,813
Write a Python function to flatten a list of lists containing integers and return a flat list. The function should handle nested lists of arbitrary depth. The code should start with: ```python from typing import List def flatten_nested_list(nested_list: 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 flatten_nested_list(nested_list: List[List[int]]) -> List[int]: """ Flatten a list of lists containing integers and return a flat list. Args: nested_list (List[List[int]]): The input l...
code_exercise_27k
3,816
Write a Python function to sort the key-value pairs of a dictionary based on the keys without using any built-in sorting functions. The function should return a list of tuples containing the sorted key-value pairs. The code should start with: ```python from typing import Dict, List, Tuple def sort_dictionary_by_key(di...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def sort_dictionary_by_key(dictionary: Dict[str, int]) -> List[Tuple[str, int]]: """ Sorts the key-value pairs of a dictionary based on the keys without using built-in sorting functions. ...
code_exercise_27k
3,817
Write a Python function to flatten a list of lists containing strings and return a flat list. The function should handle nested lists of arbitrary depth and ensure that only strings are included in the resulting flat list. The code should start with: ```python from typing import List def flatten_list_of_lists(list_of_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def flatten_list_of_lists(list_of_lists: List[List[str]]) -> List[str]: """ Flatten a list of lists containing strings and return a flat list. Args: list_of_lists (List[List[str]]): A list o...
code_exercise_27k
3,818
Write a Python function to convert a decimal number to its binary representation using the '%' and '//' operators. The function should handle both positive and zero decimal numbers. The code should start with: ```python def decimal_to_binary(decimal: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def decimal_to_binary(decimal: int) -> str: """ Convert a decimal number to its binary representation. This function uses the '%' and '//' operators to convert a given decimal number to its binary equivalent. The binary...
code_exercise_27k
3,822
Write a Python function to flatten a nested list of mixed types into a single-level list. The function should handle lists, dictionaries, strings, and other types of elements. If an element is a list, it should be recursively flattened. If an element is a dictionary, it should be added to the flat list as is. If an ele...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def flatten_mixed_list(nested_list: List[Any]) -> List[Any]: """ Flatten a nested list of mixed types into a single-level list. Args: nested_list (List[Any]): The input list that needs ...
code_exercise_27k
3,823
Write a Python function to flatten a deeply nested list of integers and return a flat list. The function should handle lists nested at any level and should only flatten lists of integers. The code should start with: ```python from typing import List def flatten_nested_list(nested_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 flatten_nested_list(nested_list: List[int]) -> List[int]: """ Flatten a deeply nested list of integers and return a flat list. Args: nested_list (List[int]): The nested list to be flatte...
code_exercise_27k
3,824
Write a Python function to check if a given string is a palindrome. The function should ignore case and spaces when determining if the string is a palindrome. The function should use the `==` and `[]` operators to compare the string with its reverse. The code should start with: ```python def is_palindrome(s: str) -> b...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(s: str) -> bool: """ Check if a given string is a palindrome, ignoring case and spaces. Parameters: s (str): The string to check. Returns: bool: True if the string is a palindrome, False other...
code_exercise_27k
3,827
Write a Python function to determine if a given set is a proper subset of itself. A proper subset is a subset that is not equal to the original set. The function should return `True` if the set is a proper subset of itself, and `False` otherwise. The code should start with: ```python def is_proper_subset_of_self(s: set...
Here is the Python code to solve the given problem in the markdown block: ```python def is_proper_subset_of_self(s: set) -> bool: """ Determine if a given set is a proper subset of itself. A proper subset is a subset that is not equal to the original set. Since a set cannot be a proper subset of itself...
code_exercise_27k
3,830
Write a Python function to sort the key-value pairs of a dictionary based on the values in ascending order without using any built-in sorting functions. The function should return a list of tuples containing the key-value pairs sorted by value. The code should start with: ```python from typing import Dict, List, Tuple...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def sort_dict_by_value(dictionary: Dict[str, int]) -> List[Tuple[str, int]]: """ Sorts the key-value pairs of a dictionary based on the values in ascending order without using built-in sorti...
code_exercise_27k
3,832
Write a Python function to flatten a nested list while removing any `None` values. The function should handle lists of arbitrary depth and complexity. The code should start with: ```python from typing import List, Any def flatten_list_with_none_removal(lst: List[Any]) -> List[Any]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def flatten_list_with_none_removal(lst: List[Any]) -> List[Any]: """ Flatten a nested list while removing any `None` values. Args: lst (List[Any]): The input list that needs to be flatt...
code_exercise_27k
3,833
Write a Python function to count the total number of elements in a nested list, where the list can contain other lists at any level of nesting. The function should handle lists with varying levels of nesting and should return the total count of all elements, including those within nested lists. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def count_nested_elements(nested_list: List[Union[int, List]]) -> int: """ Counts the total number of elements in a nested list, including elements within nested lists. Args: nested_l...
code_exercise_27k
3,834
Write a Python function to find the greatest common divisor (GCD) of two numbers using the Euclidean algorithm. The function should use the '%' operator and a 'while' loop to iteratively compute the GCD. The code should start with: ```python def find_gcd(num1: int, num2: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def find_gcd(num1: int, num2: int) -> int: """ Calculate the greatest common divisor (GCD) of two numbers using the Euclidean algorithm. Args: num1 (int): The first number. num2 (int): The second number. ...
code_exercise_27k
3,838
Write a Python function to remove duplicates from a given flattened list while preserving the order of the remaining elements. The function should return a new list with all duplicate elements removed. The code should start with: ```python from typing import List def remove_duplicates_preserve_order(flattened_list: Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_preserve_order(flattened_list: List[int]) -> List[int]: """ Remove duplicates from a given flattened list while preserving the order of the remaining elements. Args: fl...
code_exercise_27k
3,840
Write a Python function to calculate the sum of two variables and return the result. The function should handle both integer and floating-point inputs. The code should start with: ```python def sum_variables(a: int | float, b: int | float) -> int | float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_variables(a: int | float, b: int | float) -> int | float: """ Calculate the sum of two variables. This function takes two variables 'a' and 'b' as input and returns their sum. Both 'a' and 'b' can be either inte...
code_exercise_27k
3,842
Write a Python function to flatten a nested list and remove any empty sublists. The function should handle lists of integers and nested lists of arbitrary depth. The code should start with: ```python from typing import List, Any def flatten_and_remove_empty_lists(nested_list: List[Any]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def flatten_and_remove_empty_lists(nested_list: List[Any]) -> List[int]: """ Flattens a nested list and removes any empty sublists. Args: nested_list (List[Any]): A nested list containi...
code_exercise_27k
3,843
Write a Python function that assigns a new value to a variable based on a condition. Specifically, if the value of `x` is greater than 5, the function should assign the value of 10 to `y`. Otherwise, `y` should retain its original value. The function should then return the updated value of `y`. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python def assign_value_if_condition_met(x: int, y: int) -> int: """ Assigns the value of 10 to 'y' if 'x' is greater than 5. Otherwise, 'y' retains its original value. Parameters: - x (int): The value of 'x' used for comparis...
code_exercise_27k
3,844
Write a Python function to convert a nested dictionary into a flat dictionary. The function should recursively traverse the nested dictionary and flatten it by concatenating the keys using a specified separator. The function should handle dictionaries with multiple levels of nesting and should be able to handle any typ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def flatten_nested_dict(nested_dict: Dict, parent_key: str = '', separator: str = '.') -> Dict: """ Recursively flattens a nested dictionary into a flat dictionary. Args: nested_dict (dict):...
code_exercise_27k
3,849
Write a Python function to calculate the product of two variables `m` and `n` and return the result. The function should handle both integer and floating-point inputs. The code should start with: ```python def calculate_product(m: int | float, n: int | float) -> int | float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_product(m: int | float, n: int | float) -> int | float: """ Calculate the product of two variables and return the result. Args: m (int | float): The first variable. n (int | float): The second ...
code_exercise_27k
3,850
Write a Python function to check if a given set is a subset of another set. The function should take two sets as input and return a boolean indicating whether the first set is a subset of the second set. The code should start with: ```python def is_subset(set1: set, set2: set) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_subset(set1: set, set2: set) -> bool: """ Check if the first set is a subset of the second set. Args: set1 (set): The first set to be checked. set2 (set): The second set to check against. Returns...
code_exercise_27k
3,851
Write a Python function to decrement the value of a given counter by a specified decrement value. The function should handle both positive and negative decrement values. The code should start with: ```python def decrement_counter(counter: int, decrement: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def decrement_counter(counter: int, decrement: int) -> int: """ Decrement the value of 'counter' by the specified 'decrement' value. Args: counter (int): The current value of the counter. decrement (int): Th...
code_exercise_27k
3,852
Write a Python function to create a new dictionary from an existing dictionary by excluding a set of specified keys. The function should handle cases where the original dictionary is empty, the set of keys to exclude is empty, or both. The function should also ensure that the original dictionary is not modified. The c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Set def exclude_keys(dictionary: Dict[str, int], exclude_set: Set[str]) -> Dict[str, int]: """ Create a new dictionary by excluding a set of keys from another dictionary. Args: dictionary (...
code_exercise_27k
3,854
Write a Python function to calculate the remainder of dividing two numbers, ensuring that the function handles the case where the denominator is zero by raising a `ZeroDivisionError`. The function should be able to handle both integer and floating-point inputs. The code should start with: ```python def calculate_remai...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_remainder(numerator: int or float, denominator: int or float) -> int or float: """ Calculates the remainder of dividing two numbers. Args: numerator (int or float): The numerator of the division. ...
code_exercise_27k
3,855
Write a Python function to remove items from a dictionary based on their values. The function should take a dictionary and a value as input and return a new dictionary that excludes all items with the specified value. The original dictionary should remain unchanged. The code should start with: ```python from typing im...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def remove_items_by_value(dictionary: Dict[str, int], value: int) -> Dict[str, int]: """ Remove items from a dictionary based on their values. Args: dictionary (Dict[str, int]): The input di...
code_exercise_27k
3,858
Write a Python function to calculate the integer quotient of two given integers `a` and `b` using the floor division operator `//`. The function should handle cases where `b` is zero by returning `None` and should also handle cases where `a` or `b` are not integers by returning `None`. The function should start with: `...
Here is the Python code to solve the given problem in the markdown block: ```python def integer_quotient(a: int, b: int) -> int: """ Calculates the integer quotient of two integers 'a' and 'b' using the floor division operator. Args: a (int): The dividend. b (int): The divisor. Returns...
code_exercise_27k
3,859
Write a Python function to concatenate two strings `s1` and `s2` and return the result. The function should handle cases where either or both strings are empty. The code should start with: ```python def concatenate_strings(s1: str, s2: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_strings(s1: str, s2: str) -> str: """ Concatenates two strings 's1' and 's2' and returns the result. Args: s1 (str): The first string. s2 (str): The second string. Returns: str: ...
code_exercise_27k
3,861
Write a Python function to flatten a nested list and ensure that all elements in the resulting list are of the same data type. If the input list contains elements of different data types, raise a `TypeError`. The function should handle lists containing integers, floats, and strings. The code should start with: ```pyth...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def flatten_and_check_type(lst: List[Union[List, Union[int, float, str]]]) -> List[Union[int, float, str]]: """ Flatten a nested list and ensure all elements are of the same data type. Args: ...
code_exercise_27k
3,863
Write a Python function to increment the value of a given integer by a specified increment value. The function should take two parameters: the current value of the integer and the increment value. The function should return the updated value of the integer after the increment. The code should start with: ```python def...
Here is the Python code to solve the given problem in the markdown block: ```python def increment_value(current_value: int, increment_by: int) -> int: """ Increments the given integer by the specified increment value. Args: current_value (int): The current value of the integer that needs to be incr...
code_exercise_27k
3,865
Write a Python function to find the symmetric difference between two dictionaries. The symmetric difference should include key-value pairs that are present in only one of the dictionaries, as well as key-value pairs that have different values in both dictionaries. The function should return a dictionary where each key ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def symmetric_difference(dict1: Dict, dict2: Dict) -> Dict: """ Find the symmetric difference between two dictionaries. Args: dict1 (Dict): The first dictionary to compare. dict2 (Di...
code_exercise_27k
3,868
Write a Python function to flatten a list of strings into a single string and remove duplicate characters while preserving the order of their first appearance. The function should handle lists of varying lengths and strings of varying lengths. The code should start with: ```python from typing import List def flatten_a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def flatten_and_remove_duplicates(lst: List[str]) -> str: """ Flattens a list of strings into a single string and removes duplicate characters while preserving the order of their first appearance. A...
code_exercise_27k
3,873
Write a Python function to find the intersection of two sets and return the result as a new set. The function should handle cases where either or both sets are empty. The code should start with: ```python def set_intersection(set1: set, set2: set) -> set: ```
Here is the Python code to solve the given problem in the markdown block: ```python def set_intersection(set1: set, set2: set) -> set: """ Find the intersection of two sets and return the result as a new set. Args: set1 (set): The first set. set2 (set): The second set. Returns: ...
code_exercise_27k
3,875
Write a Python function to find the intersection of two sets, i.e., a new set containing only the elements that are present in both sets. The function should handle sets of any size and type of elements. The code should start with: ```python def intersection_of_sets(set1: set, set2: set) -> set: ```
Here is the Python code to solve the given problem in the markdown block: ```python def intersection_of_sets(set1: set, set2: set) -> set: """ Find the intersection of two sets, i.e., a new set containing only the elements that are present in both sets. Args: set1 (set): The first set. set2...
code_exercise_27k
3,876
Write a Python function to flatten a nested list while preserving the order of elements at each depth level. The function should handle lists with varying depths and ensure that all elements are added to the result list in the order they appear, regardless of their depth. The code should start with: ```python from typ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def flatten_nested_list(lst: List[Any]) -> List[Any]: """ Flatten a nested list while preserving the order of elements at each depth level. Args: lst (List[Any]): The input nested list ...
code_exercise_27k
3,877
Write a Python function to perform a series of arithmetic operations on a given number `total` using the assignment operators. The operations to be performed are: 1. Add 5 to `total`. 2. Subtract 3 from `total`. 3. Multiply `total` by 4. 4. Divide `total` by 2. 5. Modulo `total` by 3. The function should return the fi...
Here is the Python code to solve the given problem in the markdown block: ```python def perform_operations(total: float) -> float: """ Performs a series of arithmetic operations on the given number 'total' using assignment operators. The operations performed are: 1. Add 5 to 'total'. 2. Subtract 3 ...
code_exercise_27k
3,878
Write a Python function to combine two dictionaries such that if a key is present in both dictionaries, the value from the first dictionary is retained, and if a key is present only in the second dictionary, it is added to the combined dictionary. The function should handle dictionaries with any type of values (e.g., i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def combine_dictionaries(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]: """ Combines two dictionaries by retaining values from the first dictionary for common keys. Args: ...
code_exercise_27k
3,880
Write a Python function to remove specific elements from a flattened list. The function should take two arguments: a flattened list and a list of elements to be removed. The function should return a new list with the specified elements removed. The code should start with: ```python from typing import List def remove_e...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_elements(lst: List[int], elements: List[int]) -> List[int]: """ Remove specific elements from a flattened list. Args: lst (List[int]): The flattened list from which elements are t...
code_exercise_27k
3,883
Write a Python function to create a dictionary from a given dictionary where the keys are unique values from the original dictionary, and the values are lists of keys from the original dictionary that correspond to those unique values. The code should start with: ```python from typing import Dict, List def create_uni...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def create_unique_value_dict(input_dict: Dict[str, int]) -> Dict[int, List[str]]: """ Create a dictionary where the keys are unique values from the original dictionary, and the values are lists...
code_exercise_27k
3,884
Write a Python function to determine if a given boolean variable `flag` is `True` or `False` and return a string indicating the result. If `flag` is `True`, return the string "The flag is True". If `flag` is `False`, return the string "The flag is False". The function should handle any boolean input and return the appr...
Here is the Python code to solve the given problem in the markdown block: ```python def check_flag(flag: bool) -> str: """ Determines if the given boolean variable 'flag' is True or False and returns a corresponding string. Args: flag (bool): The boolean variable to check. Returns: str...
code_exercise_27k
3,885
Write a Python function to find the intersection of two sets and return the result as a new set. The function should handle sets of any size and type of elements. The code should start with: ```python def find_intersection(set1: set, set2: set) -> set: ```
Here is the Python code to solve the given problem in the markdown block: ```python def find_intersection(set1: set, set2: set) -> set: """ Find the intersection of two sets and return the result as a new set. Args: set1 (set): The first set. set2 (set): The second set. Returns: ...
code_exercise_27k
3,887
Write a Python function to calculate the final score based on the initial score and a list of multipliers. Each multiplier in the list should be applied sequentially to the score. The function should start with: ```python from typing import List, Union def apply_multipliers(score: Union[int, float], multipliers: List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def apply_multipliers(score: Union[int, float], multipliers: List[Union[int, float]]) -> Union[int, float]: """ Calculate the final score by applying each multiplier in the list sequentially to th...
code_exercise_27k
3,888
Write a Python function to find the elements that are not common in both sets. The function should take two sets as input and return a set containing the elements that are present in either of the sets but not in both. The code should start with: ```python def find_non_common_elements(set1: set, set2: set) -> set: ```
Here is the Python code to solve the given problem in the markdown block: ```python def find_non_common_elements(set1: set, set2: set) -> set: """ Find the elements that are not common in both sets. Args: set1 (set): The first set. set2 (set): The second set. Returns: set: A se...
code_exercise_27k
3,890
Write a Python function to remove an arbitrary element from a given set. The function should handle the case where the element to be removed is not present in the set by raising a `ValueError`. The code should start with: ```python def remove_element_from_set(my_set: set, element: any) -> set: ```
Here is the Python code to solve the given problem in the markdown block: ```python def remove_element_from_set(my_set: set, element: any) -> set: """ Removes an arbitrary element from a given set. Args: my_set (set): The set from which the element needs to be removed. element (any): The el...
code_exercise_27k
3,891
Write a Python function to convert a given string to its uppercase version and return it. Additionally, write a helper function to check if a string is already in uppercase. The main function should use this helper function to determine if the conversion is necessary. If the string is already in uppercase, it should re...
Here is the Python code to solve the given problem in the markdown block: ```python def is_uppercase(text: str) -> bool: """ Helper function to check if a given string is already in uppercase. Args: text (str): The input string to be checked. Returns: bool: True if the string is in upp...
code_exercise_27k
3,892
Write a Python function to flatten a nested list and remove elements that satisfy a given condition. The function should take a nested list and a condition function as input and return a flattened list with the elements that do not satisfy the condition. The code should start with: ```python from typing import List, C...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable def flatten_and_filter(lst: List[List[int]], condition: Callable[[int], bool]) -> List[int]: """ Flattens a nested list and removes elements that satisfy a given condition. Args: l...
code_exercise_27k
3,893
Write a Python function to find the index position of a specific key-value pair in a dictionary of lists. The function should return a tuple containing the index position of the key-value pair. If the key-value pair is not found, the function should return `(-1, -1)`. 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, List, Tuple, Any def find_index_position(dictionary: Dict[Any, List[Any]], key: Any, value: Any) -> Tuple[int, int]: """ Find the index position of a specific key-value pair in a dictionary of lists. ...
code_exercise_27k
3,894
Write a Python function to swap the values of two variables 'a' and 'b' using arithmetic operations. The function should not use any temporary variables or Python's tuple unpacking. The code should start with: ```python def swap_variables_arithmetic(a: int, b: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def swap_variables_arithmetic(a: int, b: int) -> tuple: """ Swaps the values of two integer variables 'a' and 'b' using arithmetic operations. Parameters: a (int): The first variable. b (int): The second variable. ...
code_exercise_27k
3,895
Write a Python function to flatten a list of dictionaries and extract specific keys. The function should iterate through each dictionary in the list and extract the values corresponding to the specified keys. If a dictionary does not contain a specified key, it should be ignored. The function should return a flattened ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def flatten_and_extract(list_of_dicts: List[Dict[str, any]], keys: List[str]) -> List[any]: """ Flattens a list of dictionaries and extracts specific keys. Args: list_of_dicts (List[Di...
code_exercise_27k
3,896
Write a Python function to check if a set is disjoint from multiple sets. The function should take a single set and a list of sets as input and return `True` if the single set is disjoint from all the sets in the list, and `False` otherwise. The function should be efficient and handle edge cases such as empty sets and ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Set def is_disjoint_with_sets(set1: Set[int], sets: List[Set[int]]) -> bool: """ Check if a set is disjoint from multiple sets. Args: set1 (Set[int]): The set to be checked for disjointness...
code_exercise_27k
3,897
Write a Python function to generate a dictionary where the keys are unique words from a given list, and the values are the number of occurrences of each word in the list. The function should handle lists with any number of words, including empty lists. The code should start with: ```python from typing import List, Dict...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def word_frequency(word_list: List[str]) -> Dict[str, int]: """ Generates a dictionary with keys as unique words from a given list, and values as the number of occurrences of each word in the l...
code_exercise_27k
3,898
Write a Python function to compute the bitwise OR operation between two integers and return the result. Additionally, provide a function to compute the bitwise XOR operation between two integers and return the result. The functions should handle any integer inputs and return the correct bitwise operation result. The s...
Here is the Python code to solve the given problem in the markdown block: ```python def bitwise_or(x: int, y: int) -> int: """ Compute the bitwise OR operation between two integers 'x' and 'y'. Parameters: x (int): The first integer operand. y (int): The second integer operand. Returns...
code_exercise_27k
3,900
Write a Python function to find the number of common elements in two sets. The function should take two sets as input and return the count of elements that are present in both sets. The code should start with: ```python def count_common_elements(set1: set, set2: set) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_common_elements(set1: set, set2: set) -> int: """ Returns the number of common elements between two sets. Args: set1 (set): The first set. set2 (set): The second set. Returns: int: The...
code_exercise_27k
3,901
Write a Python function to flatten a list of dictionaries and map values to new keys. The function should take a list of dictionaries and an optional prefix string. The function should return a single dictionary where the keys are the original keys from the dictionaries in the list, prefixed with the given prefix, and ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def flatten_dict_list(dict_list: List[Dict[str, Any]], prefix: str = '') -> Dict[str, List[Any]]: """ Flatten a list of dictionaries and map values to new keys with a given prefix. Args: ...
code_exercise_27k
3,903
Write a Python function to calculate the square root of a given number using the `math` module. The function should handle both positive and negative numbers, returning the square root of the absolute value of the number for negative inputs. Additionally, the function should handle the case where the input is zero. The...
Here is the Python code to solve the given problem in the markdown block: ```python import math def calculate_square_root(x: float) -> float: """ Calculate the square root of a given number. If the input number is negative, the function returns the square root of its absolute value. If the input numbe...
code_exercise_27k
3,907
Write a Python function to perform floor division on a given number by a specified divisor using the assignment operator. The function should take two parameters: the number to be divided and the divisor. The function should return the result of the floor division. The code should start with: ```python def floor_divid...
Here is the Python code to solve the given problem in the markdown block: ```python def floor_divide(number: float, divisor: float) -> float: """ Performs floor division on the given number by the specified divisor using the assignment operator. Args: number (float): The number to be floor divided....