source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
code_exercise_27k
5,444
Write a Python function to count the number of elements in a given list that are divisible by both 2 and 3. The function should take a list of integers as input and return the count of such elements. The code should start with: ```python from typing import List def count_divisible_by_2_and_3(lst: List[int]) -> int: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_divisible_by_2_and_3(lst: List[int]) -> int: """ Counts the number of elements in a list that are divisible by both 2 and 3. Args: lst (List[int]): A list of integers. Returns...
code_exercise_27k
5,448
Write a Python function to determine if a given list of three numbers can form a valid triangle based on the triangle inequality theorem. The triangle inequality theorem states that for any triangle, the sum of the lengths of any two sides must be greater than the length of the remaining side. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_valid_triangle(sides: List[float]) -> bool: """ Determines if a given list of three numbers can form a valid triangle. The function checks if the sum of the lengths of any two sides is greate...
code_exercise_27k
5,452
Write a Python function to convert a list of sets to a list of frozen sets. Each set in the input list should be converted to a frozen set and returned in the same order within a new list. The function should handle an empty list and ensure that the input list is not modified. The code should start with: ```python fro...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Set def convert_sets_to_frozen_sets(input_list: List[Set[int]]) -> List[frozenset]: """ Convert a list of sets to a list of frozen sets. Args: input_list (List[Set[int]]): A list of sets to...
code_exercise_27k
5,455
Write a Python function to generate a new dictionary where each key is mapped to the ASCII representation of its corresponding value. The value can be either a string or an integer. If the value is a string, the ASCII representation should be a list of ASCII values of each character in the string. If the value is an in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Union def generate_ascii_mapping(dictionary: Dict[str, Union[str, int]]) -> Dict[str, List[int]]: """ Generates a mapping of each key with its corresponding value's ASCII representation. Args...
code_exercise_27k
5,457
Write a Python function to filter out key-value pairs from a dictionary where the key is a vowel. The function should return a new dictionary containing only the key-value pairs where the key is a vowel (both uppercase and lowercase). The code should start with: ```python def filter_vowel_keys(dictionary: dict) -> dic...
Here is the Python code to solve the given problem in the markdown block: ```python def filter_vowel_keys(dictionary: dict) -> dict: """ Filters out key-value pairs from a dictionary where the key is a vowel. Args: dictionary (dict): The dictionary to be filtered. Returns: dict: The fi...
code_exercise_27k
5,462
Write a Python function to find the sum of all even values in a given dictionary. The dictionary contains key-value pairs where the values are integers. The function should return the sum of all even integers in the dictionary. The code should start with: ```python def sum_even_values(dictionary: dict) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_even_values(dictionary: dict) -> int: """ Calculate the sum of all even values in a given dictionary. Args: dictionary (dict): A dictionary containing key-value pairs where values are integers. Returns:...
code_exercise_27k
5,463
Write a Python function to find the number of distinct subsets of a given set. The function should take an iterable (like a list or a set) as input and return the number of distinct subsets. The code should start with: ```python from typing import Iterable def count_distinct_subsets(set_elements: Iterable) -> int: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Iterable def count_distinct_subsets(set_elements: Iterable) -> int: """ Calculate the number of distinct subsets of a given set. Args: set_elements (Iterable): The set elements for which the subs...
code_exercise_27k
5,468
Write a Python function to count the number of elements in a list that are divisible by both 3 and 5. The function should take a list of integers as input and return the count of such elements. The code should start with: ```python from typing import List def count_divisible_by_3_and_5(lst: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_divisible_by_3_and_5(lst: List[int]) -> int: """ Count the number of elements in a list that are divisible by both 3 and 5. Args: lst (List[int]): The list of integers to check. ...
code_exercise_27k
5,474
Write a Python function to filter out key-value pairs from a dictionary where the key starts with a specific character. The function should return a new dictionary containing only the key-value pairs that match the criteria. The code should start with: ```python from typing import Dict def filter_dict_by_key_start(d: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def filter_dict_by_key_start(d: Dict[str, any], start_char: str) -> Dict[str, any]: """ Filter out key-value pairs from a dictionary where the key starts with a specific character. Args: d (...
code_exercise_27k
5,480
Write a Python function to generate the set of all possible ordered pairs from two given sets. Each ordered pair should consist of one element from the first set and one element from the second set. The function should handle cases where either or both sets are empty. 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 Set def generate_ordered_pairs(set1: Set, set2: Set) -> Set: """ Generate the set of all possible ordered pairs from two sets. Args: set1 (Set): The first set. set2 (Set): The second set....
code_exercise_27k
5,481
Write a Python function to count the number of elements in a list that are divisible by a specified number. The function should handle lists of integers and return the count of elements that are exactly divisible by the given divisor. The code should start with: ```python from typing import List def count_divisible_el...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_divisible_elements(lst: List[int], divisor: int) -> int: """ Count the number of elements in a list that are divisible by a specified number. Args: lst (List[int]): The list of int...
code_exercise_27k
5,483
Write a Python function to calculate the sum of all elements in a list of lists, where each sublist contains integers. The function should handle nested lists of any depth, meaning it should sum elements in lists that may contain other lists. The code should start with: ```python from typing import List def sum_of_ne...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def sum_of_nested_lists(lst: List[Union[int, List]]) -> int: """ Calculates the sum of all elements in a list of lists, including nested lists. Args: lst (List[Union[int, List]]): A l...
code_exercise_27k
5,486
Write a Python function to map each key in a dictionary to its corresponding value's square root. The function should handle only non-negative values and raise appropriate exceptions for invalid inputs. The code should start with: ```python from typing import Dict from math import sqrt def square_root_mapping(diction...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict from math import sqrt def square_root_mapping(dictionary: Dict[int, float]) -> Dict[int, float]: """ Maps each key in a dictionary to its corresponding value's square root. Args: dictionary ...
code_exercise_27k
5,491
Write a Python function to convert a list of integers to a queue object using the `collections.deque` class. The function should ensure that the input is a list and that all elements in the list are integers. If the input is not a list or contains non-integer elements, the function should raise a `TypeError`. The code...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import deque from typing import List def list_to_queue(lst: List[int]) -> deque: """ Convert a list of integers to a queue object. Args: lst (List[int]): A list of integers. Returns: d...
code_exercise_27k
5,493
Write a Python function to find the key with the maximum value in a given dictionary and return a tuple containing the key and its corresponding value. If there are multiple keys with the same maximum value, return the first one encountered. The function should raise a `ValueError` if the input dictionary is empty. Th...
Here is the Python code to solve the given problem in the markdown block: ```python def find_max_key_value(dictionary: dict) -> tuple: """ Find the key with the maximum value in the input dictionary and return a tuple containing the key and its corresponding value. Args: dictionary (dict): The dict...
code_exercise_27k
5,494
Write a Python function to convert a queue object to a list of integers. The function should ensure that the input queue contains only integers and raise a `TypeError` if any other type of element is found. The function should start with: ```python from queue import Queue from typing import List def queue_to_list(queu...
Here is the Python code to solve the given problem in the markdown block: ```python from queue import Queue from typing import List def queue_to_list(queue: Queue) -> List[int]: """ Converts a queue object to a list of integers. Parameters: queue (Queue): The queue object to be converted. Returns...
code_exercise_27k
5,495
Write a Python function to check if a given string is a valid parentheses sequence, allowing for nested sequences. The string can contain parentheses `()`, square brackets `[]`, and curly braces `{}`. The function should return `True` if the sequence is valid and `False` otherwise. A valid sequence means that every ope...
Here is the Python code to solve the given problem in the markdown block: ```python def is_valid_parentheses(sequence: str) -> bool: """ Check if a given string is a valid parentheses sequence, allowing for nested sequences. Parameters: sequence (str): The string to be checked. Returns: bool: ...
code_exercise_27k
5,496
Write a Python function to find the maximum number of points that lie on the same line in a 2D plane. Given a list of points, the function should return the maximum number of points that can be collinear. The code should start with: ```python from typing import List def max_points_on_a_line(points: List[List[int]]) -...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import defaultdict def max_points_on_a_line(points: List[List[int]]) -> int: """ Find the maximum number of points that lie on the same line in a 2D plane. Args: points: A l...
code_exercise_27k
5,497
Write a Python function to filter out key-value pairs from a dictionary where the value is a list. The function should return a new dictionary containing only the key-value pairs where the value is a list. The code should start with: ```python from typing import Dict, Any def filter_dictionary_by_list_values(dictionar...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def filter_dictionary_by_list_values(dictionary: Dict[Any, Any]) -> Dict[Any, Any]: """ Filters out key-value pairs from a dictionary where the value is a list. Args: dictionary (Dict[A...
code_exercise_27k
5,499
Write a Python function to convert an infix arithmetic expression to a postfix arithmetic expression. The function should handle basic arithmetic operations (`+`, `-`, `*`, `/`, `^`) and parentheses. The input expression is a string with no spaces between characters. The function should return the postfix expression as...
Here is the Python code to solve the given problem in the markdown block: ```python def infix_to_postfix(expression: str) -> str: """ Convert an infix arithmetic expression to a postfix arithmetic expression. Args: expression (str): The infix arithmetic expression with no spaces between characters....
code_exercise_27k
5,500
Write a Python function to map each key in a dictionary to its corresponding value's factorial. The function should handle only non-negative integers as values. If any value is negative or not an integer, the function should raise a `ValueError`. The code should start with: ```python from typing import Dict from math ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict from math import factorial def map_to_factorial(input_dict: Dict[str, int]) -> Dict[str, int]: """ Maps each key in a dictionary to its corresponding value's factorial. Args: input_dict (Dic...
code_exercise_27k
5,503
Write a Python function to filter out key-value pairs from a dictionary where the value is a negative number. The function should return a new dictionary containing only the key-value pairs from the input dictionary where the value is a non-negative number. The code should start with: ```python from typing import Dict ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def filter_non_negative_values(dictionary: Dict[str, int]) -> Dict[str, int]: """ Filter out key-value pairs from a dictionary where the value is a negative number. Args: dictionary (Dict[st...
code_exercise_27k
5,504
Write a Python function to count the number of times a specified element appears in a given list. The function should be efficient and handle various types of elements, including integers, strings, and other data types. The code should start with: ```python from typing import List, Any def count_element_occurrences(ls...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def count_element_occurrences(lst: List[Any], element: Any) -> int: """ Count the number of times a specified element appears in a given list. Args: lst (List[Any]): The list to search ...
code_exercise_27k
5,510
Write a Python function to filter out key-value pairs from a dictionary where the value is a dictionary. The function should return a new dictionary containing only the key-value pairs where the value is not a dictionary. The code should start with: ```python from typing import Dict def filter_non_dict_values(dictiona...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def filter_non_dict_values(dictionary: Dict) -> Dict: """ Filter out key-value pairs from a dictionary where the value is a dictionary. Args: dictionary (dict): The dictionary to be filtered...
code_exercise_27k
5,512
Write a Python function to map each key in a dictionary to its corresponding value's absolute value. The function should handle both positive and negative values, ensuring that all values in the resulting dictionary are non-negative. The code should start with: ```python def map_dict_to_abs(d: dict) -> dict: ```
Here is the Python code to solve the given problem in the markdown block: ```python def map_dict_to_abs(d: dict) -> dict: """ Map each key in a dictionary to its corresponding value's absolute value. Args: d (dict): Input dictionary where values can be integers or floats. Returns: dict...
code_exercise_27k
5,513
Write a Python function to check if a given string is a valid parentheses sequence, allowing for different types of brackets. The function should return `True` if the sequence is valid and `False` otherwise. A valid sequence is defined as follows: - An empty sequence is considered valid. - A sequence with matching open...
Here is the Python code to solve the given problem in the markdown block: ```python def is_valid_parentheses(sequence: str) -> bool: """ Check if a given string is a valid parentheses sequence. Args: sequence (str): A string representing a parentheses sequence. Returns: bool: True if t...
code_exercise_27k
5,514
Write a Python function to filter out key-value pairs from a dictionary where the value is an odd number. The function should return a new dictionary containing only the key-value pairs where the value is an even number. The code should start with: ```python from typing import Dict def filter_even_numbers(dictionary: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def filter_even_numbers(dictionary: Dict[str, int]) -> Dict[str, int]: """ Filter out key-value pairs from a dictionary where the value is an odd number. Args: dictionary (Dict[str, int]): T...
code_exercise_27k
5,515
Write a Python function to convert a float to a boolean value based on the following rules: - If the float number is zero or negative, return `False`. - If the float number is positive, return `True`. The code should start with: ```python def float_to_boolean(float_num: float) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def float_to_boolean(float_num: float) -> bool: """ Converts a float to a boolean value based on the following rules: - If the float number is zero or negative, return `False`. - If the float number is positive, return `...
code_exercise_27k
5,518
Write a Python function to find the key-value pairs from a dictionary where the value is within a specific range. The function should return a new dictionary containing only the key-value pairs that fall within the specified range. The code should start with: ```python from typing import Dict, Union def get_pairs_in_r...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Union def get_pairs_in_range(dictionary: Dict[str, Union[int, float]], minimum: Union[int, float], maximum: Union[int, float]) -> Dict[str, Union[int, float]]: """ Find key-value pairs from a dictionary...
code_exercise_27k
5,520
Write a Python function to find the maximum sum of a non-empty subset from a given set of integers, such that no two elements in the subset are adjacent. The function should handle edge cases where the input list is empty or contains only one element. The code should start with: ```python from typing import List def ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_sum_non_adjacent(nums: List[int]) -> int: """ Finds the maximum sum of a non-empty subset from a set of integers, such that no two elements are adjacent. Args: nums (List[int]): ...
code_exercise_27k
5,521
Write a Python function to map each key in a dictionary to its corresponding value's cube. The function should take a dictionary as input and return a new dictionary where each key is mapped to the cube of its corresponding value. The code should start with: ```python from typing import Dict def map_values_to_cube(dic...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def map_values_to_cube(dictionary: Dict[str, int]) -> Dict[str, int]: """ Map each key in a dictionary to its corresponding value's cube. Args: dictionary (Dict[str, int]): A dictionary with...
code_exercise_27k
5,522
Write a Python function to find the longest common prefix among a list of strings. The function should return the longest prefix that is common to all strings in the list. If there is no common prefix, the function should return an empty string. The code should start with: ```python from typing import List def longes...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_common_prefix(strings: List[str]) -> str: """ Finds the longest common prefix for a list of strings. Args: strings (List[str]): A list of strings to find the common prefix for. ...
code_exercise_27k
5,524
Write a Python function to filter out key-value pairs from a dictionary where the value is a float number. The function should return a new dictionary containing only the key-value pairs where the value is a float. The code should start with: ```python from typing import Dict def filter_float_values(dictionary: Dict[s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def filter_float_values(dictionary: Dict[str, float]) -> Dict[str, float]: """ Filter out key-value pairs from a dictionary where the value is a float number. Args: dictionary (Dict[str, flo...
code_exercise_27k
5,525
Write a Python function to find the minimum number of steps required to make all elements in a given set of integers equal, where a step is defined as incrementing or decrementing any number by 1. The function should start with: ```python def min_steps_to_equalize(nums: set) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def min_steps_to_equalize(nums: set) -> int: """ Finds the minimum number of steps required to make all elements in the given set equal. Parameters: nums (set): The set of integers to be equalized. Returns:...
code_exercise_27k
5,528
Write a Python function to convert a list of integers to a list of strings. The function should handle lists of varying lengths, including empty lists. The code should start with: ```python from typing import List def convert_integers_to_strings(int_list: List[int]) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_integers_to_strings(int_list: List[int]) -> List[str]: """ Convert a list of integers to a list of strings. Args: int_list (List[int]): A list of integers to be converted. R...
code_exercise_27k
5,529
Write a Python function to merge overlapping intervals from a given list of intervals. Each interval is represented as a tuple of start and end points. The function should return a list of merged intervals. The code should start with: ```python from typing import List, Tuple def merge_intervals(intervals: List[Tuple[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def merge_intervals(intervals: List[Tuple[int, int]]) -> List[Tuple[int, int]]: """ Merge overlapping intervals and return the merged intervals. Args: intervals (List[Tuple[int, int]]...
code_exercise_27k
5,531
Write a Python function to convert a list of strings to a list of integers, ensuring that only valid integers are converted and invalid strings are ignored. The function should return a new list containing only the successfully converted integers. The code should start with: ```python from typing import List def conv...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_strings_to_integers(string_list: List[str]) -> List[int]: """ Converts a list of strings to a list of integers, ignoring invalid strings. Args: string_list (List[str]): A list of...
code_exercise_27k
5,533
Write a Python function to find the maximum and minimum values from a given list of numeric values. The function should handle empty lists by raising a `ValueError`. The code should start with: ```python from typing import List, Tuple def get_max_min(lst: List[int]) -> Tuple[int, int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def get_max_min(lst: List[int]) -> Tuple[int, int]: """ Returns the maximum and minimum values from a list of numeric values. Args: lst (List[int]): A list of numeric values. Ret...
code_exercise_27k
5,534
Write a Python function to convert a list of floats to a list of integers. The function should handle the following: 1. Ensure the input is a list. 2. Convert each float in the list to an integer. 3. Return a new list with the converted integers. 4. Raise a `TypeError` if the input is not a list. 5. Raise a `ValueError...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_list_of_floats_to_integers(float_list: List[float]) -> List[int]: """ Converts a list of floats to a list of integers. Parameters: float_list (List[float]): A list of floating-point ...
code_exercise_27k
5,535
Write a Python function to find the minimum number of intervals that need to be removed to make all remaining intervals non-overlapping. Each interval is represented as a list of two integers, where the first integer is the start point and the second integer is the end point. The function should return the minimum numb...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def erase_overlap_intervals(intervals: List[List[int]]) -> int: """ Find the minimum number of intervals to remove to make all remaining intervals non-overlapping. Args: intervals (List[List...
code_exercise_27k
5,536
Write a Python function to check if a given value is present in a list and return the index of the first occurrence of the value if it is present. If the value is not present, return -1. The function should handle lists of any type, including nested lists. The code should start with: ```python from typing import Any, ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, List, Union def find_value_index(value: Any, lst: Union[List[Any], List[List[Any]]]) -> int: """ Find the index of the first occurrence of a given value in a list. If the value is not found, return -...
code_exercise_27k
5,541
Write a Python function to count the number of occurrences of a specific element in a given list. The function should be efficient and handle various types of elements, including integers, strings, and other data types. The code should start with: ```python from typing import List, Any def count_occurrences(lst: List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def count_occurrences(lst: List[Any], element: Any) -> int: """ Count the number of occurrences of a specific element in a list. Args: lst (List[Any]): The list to search for occurrence...
code_exercise_27k
5,542
Write a Python function to convert a list of booleans to a list of integers. The function should ensure that the input is a list and that all elements in the list are boolean values. If these conditions are not met, the function should raise a `TypeError`. The function should return a new list containing integers corre...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_bool_to_int(bool_list: List[bool]) -> List[int]: """ Convert a list of booleans to a list of integers. Args: bool_list (List[bool]): A list of boolean values. Returns: ...
code_exercise_27k
5,543
Write a Python function to convert a list of integers to a list of booleans. Each integer in the input list should be converted to a boolean value where `True` represents a non-zero integer and `False` represents a zero integer. The function should handle the input validation to ensure that the input is a list. If the ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_integers_to_booleans(integer_list: List[int]) -> List[bool]: """ Converts a list of integers to a list of booleans. Parameters: integer_list (List[int]): A list of integers. Ret...
code_exercise_27k
5,544
Write a Python function to remove all duplicate elements from a given list while preserving the order of the elements. The function should return a new list with all unique elements. The code should start with: ```python from typing import List def remove_duplicates_preserve_order(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 remove_duplicates_preserve_order(lst: List[int]) -> List[int]: """ Removes all duplicate elements from the given list while preserving the order of the elements. Args: lst (List[int]): T...
code_exercise_27k
5,548
Write a Python function to sort a list of integers in ascending order using the merge sort algorithm. The merge sort algorithm is a divide-and-conquer algorithm that recursively divides the list into halves until each sublist contains a single element, then merges the sublists back together in sorted order. The functio...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(lst: List[int]) -> List[int]: """ Sorts a list of integers in ascending order using the merge sort algorithm. Args: lst (List[int]): The list of integers to be sorted. Re...
code_exercise_27k
5,549
Write a Python function to check whether two dictionaries have the same set of keys. The function should return `True` if both dictionaries have exactly the same keys, and `False` otherwise. The code should start with: ```python def have_same_keys(dict1: dict, dict2: dict) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def have_same_keys(dict1: dict, dict2: dict) -> bool: """ Check whether two dictionaries have the same set of keys. Args: dict1 (dict): The first dictionary. dict2 (dict): The second dictionary. Returns...
code_exercise_27k
5,550
Write a Python function to convert a list of booleans to a list of floats. Each boolean value `True` should be converted to `1.0`, and each boolean value `False` should be converted to `0.0`. The function should handle lists of any length, including empty lists. 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 def convert_bools_to_floats(bool_list: List[bool]) -> List[float]: """ Converts a list of booleans to a corresponding list of floats. Args: bool_list (List[bool]): A list containing boolean ...
code_exercise_27k
5,553
Write a Python function to reverse a given list in-place without using any additional data structures or built-in functions that directly reverse the list. The function should modify the original list and return it. The code should start with: ```python from typing import List def reverse_list_in_place(lst: List) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_list_in_place(lst: List) -> List: """ Reverses a given list in-place. This function modifies the original list by swapping elements from the beginning and the end, moving towards the...
code_exercise_27k
5,554
Write a Python function to convert the keys of a dictionary into a list, ensuring that the order of keys in the list matches the order in which they were inserted into the dictionary. The function should handle dictionaries with various types of keys, including but not limited to strings, integers, and tuples. The code...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import OrderedDict from typing import List, Any def dict_keys_to_list(dictionary: OrderedDict) -> List[Any]: """ Convert the keys of an OrderedDict into a list, preserving the insertion order. Args: ...
code_exercise_27k
5,555
Write a Python function to filter out key-value pairs from a dictionary where the key is a prime number and the value's square is even. The function should return a new dictionary containing the filtered key-value pairs. The code should start with: ```python from typing import Dict def filter_prime_even_square(diction...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict import math def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise...
code_exercise_27k
5,557
Write a Python function to extract the even elements from a given list and return a new list containing only those even elements. The function should handle lists of integers and return an empty list if no even elements are found. The function should also raise a `TypeError` if the input is not a list. The code should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def extract_even_elements(input_list: List[int]) -> List[int]: """ Extracts the even elements from the given input_list and returns a new list. Args: input_list (List[int]): The list from wh...
code_exercise_27k
5,559
Write a Python function to calculate the sum of all elements in a list, but with a twist: the function should also handle nested lists, i.e., lists that contain other lists as elements. The function should recursively sum all elements, including those in nested lists. 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 Union, List def recursive_sum(lst: Union[List[Union[int, float]], List[Union[int, float, List]]]) -> Union[int, float]: """ Calculates the sum of all elements in a list, including elements in nested lists. ...
code_exercise_27k
5,561
Write a Python function to filter out key-value pairs from a given dictionary where both the key and value are prime numbers. The function should return a new dictionary containing only the prime key-value pairs. The code should start with: ```python from typing import Dict def filter_prime_pairs(dictionary: Dict[int,...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if n <...
code_exercise_27k
5,562
Write a Python function to remove the first occurrence of a specific element from a given list. If the element is not present in the list, the function should return the original list unchanged. The function should handle lists of any type of elements, including integers, strings, and other objects. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def remove_first_occurrence(lst: List[Any], element: Any) -> List[Any]: """ Remove the first occurrence of a specific element from a list. Args: lst (List[Any]): The input list from whi...
code_exercise_27k
5,563
Write a Python function to generate all possible strings formed by concatenating one string from each of two given sets in alternate order. The function should handle sets of different sizes and ensure that all possible combinations are generated. The code should start with: ```python from typing import Set def genera...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set def generate_combinations(set1: Set[str], set2: Set[str]) -> Set[str]: """ Generate all possible strings formed by concatenating one string from each set in alternate order. Args: set1 (Set[s...
code_exercise_27k
5,565
Write a Python function to create a new list by multiplying each element of an existing list by a given factor. The function should handle both positive and negative factors, as well as the case where the factor is zero. The code should start with: ```python from typing import List def multiply_list_elements(input_lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def multiply_list_elements(input_list: List[int], factor: int) -> List[int]: """ Create a new list by multiplying each element of the input_list by the given factor. Args: input_list (List[i...
code_exercise_27k
5,566
Write a Python function to create a new dictionary from a given dictionary where all the values are unique. If there are duplicate values, only the first occurrence of each value should be retained in the new dictionary. The function should start with: ```python from typing import Dict def create_unique_dict(dictionar...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def create_unique_dict(dictionary: Dict[str, int]) -> Dict[str, int]: """ Create a new dictionary from a given dictionary where all the values are unique. Args: dictionary (Dict[str, int]): ...
code_exercise_27k
5,571
Write a Python function to convert a string of characters to a list of their corresponding ASCII values. The function should handle strings of any length, including an empty string. The code should start with: ```python from typing import List def string_to_ascii_list(s: str) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def string_to_ascii_list(s: str) -> List[int]: """ Convert a string of characters to a list of their corresponding ASCII values. Args: s (str): The string to convert. Returns: L...
code_exercise_27k
5,572
Write a Python function to find the second largest element in a given list of integers. If the list has fewer than two elements, the function should return `None`. The function should handle duplicate values and should not modify the original list. The code should start with: ```python from typing import List, Optiona...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_second_largest(numbers: List[int]) -> Optional[int]: """ Find the second largest element in a list of integers. Args: numbers (List[int]): The list of integers from which ...
code_exercise_27k
5,574
Write a Python function to convert an ASCII value to its corresponding character. The function should validate the input to ensure it is a valid ASCII value (between 0 and 127 inclusive). If the input is not valid, the function should raise a `ValueError`. The code should start with: ```python def ascii_to_char(ascii_...
Here is the Python code to solve the given problem in the markdown block: ```python def ascii_to_char(ascii_val: int) -> str: """ Converts an ASCII value to its corresponding character. Args: ascii_val (int): The ASCII value to be converted. Returns: str: The corresponding character. ...
code_exercise_27k
5,576
Write a Python function to split a list into two equal halves. If the length of the list is odd, the function should raise a `ValueError`. The function should return a tuple containing the two halves. The code should start with: ```python from typing import List, Tuple def split_list_into_halves(lst: List) -> Tuple[L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def split_list_into_halves(lst: List) -> Tuple[List, List]: """ Split a list into two equal halves. Args: lst (List): The list to be split. Returns: Tuple[List, List]: A ...
code_exercise_27k
5,578
Write a Python function to convert a given string to lowercase, while also handling special cases such as strings with non-alphabetic characters and empty strings. The function should return the converted string in lowercase. The code should start with: ```python def convert_to_lowercase(string: str) -> str: ```
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 the string with all alphabetic characters converted to lowercase. Non-alphabetic c...
code_exercise_27k
5,582
Write a Python function to check if a list is sorted in non-decreasing order. The function should return `True` if the list is sorted and `False` otherwise. The code should start with: ```python from typing import List def is_sorted_non_decreasing(lst: List[int]) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_sorted_non_decreasing(lst: List[int]) -> bool: """ Check if a list is sorted in non-decreasing order. Args: lst (List[int]): The input list of integers. Returns: bool: Tr...
code_exercise_27k
5,585
Write a Python function to find the set of all possible strings formed by concatenating all possible pairs of strings from two different sets of strings. Each pair should consist of one string from each set. The function should handle sets of strings and return a set of concatenated strings. 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 concatenate_pairs_from_sets(set1: Set[str], set2: Set[str]) -> Set[str]: """ Find the set of all possible strings formed by concatenating all possible pairs of strings from two different sets. Ar...
code_exercise_27k
5,588
Write a Python function to find the set of all possible strings formed by concatenating one string from each of two given sets of strings in any order. The function should return a set containing all unique concatenated strings. The code should start with: ```python from typing import Set def concatenate_sets(set1: S...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set from itertools import product def concatenate_sets(set1: Set[str], set2: Set[str]) -> Set[str]: """ Return the set of all possible strings formed by concatenating one string from each set in any order. ...
code_exercise_27k
5,589
Write a Python function to merge two dictionaries into one, where the values of common keys are concatenated as a single string with a specified delimiter. The function should also handle cases where the values are not strings by converting them to strings before concatenation. The code should start with: ```python fro...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def merge_dictionaries_with_delimiter(dict1: Dict[Any, Any], dict2: Dict[Any, Any], delimiter: str = ' ') -> Dict[Any, Any]: """ Merge two dictionaries into one, concatenating the values of common k...
code_exercise_27k
5,591
Write a Python function to create a new list by appending the cubes of each element of an existing list. The function should be efficient and handle both positive and negative integers. The code should start with: ```python from typing import List def cube_list(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 cube_list(input_list: List[int]) -> List[int]: """ Creates a new list by appending the cubes of each element of the input list. Args: input_list (List[int]): The list of integers whose c...
code_exercise_27k
5,594
Write a Python function to check if two lists are equal, considering that the lists may contain nested lists or other complex data structures. The function should perform a deep comparison, meaning it should check that all elements at all levels of nesting are equal. The code should start with: ```python from typing i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def are_lists_equal_deep(list1: List[Any], list2: List[Any]) -> bool: """ Check if two lists are deeply equal, meaning all elements at all levels of nesting are equal. Args: list1 (List...
code_exercise_27k
5,597
Write a Python function to convert a given string to kebab case. Kebab case is a style of writing where all spaces and punctuation marks are replaced with a hyphen ("-"), and all letters are converted to lowercase. The function should handle multiple consecutive spaces and punctuation marks by replacing them with a sin...
Here is the Python code to solve the given problem in the markdown block: ```python def to_kebab_case(string: str) -> str: """ Converts a given string to kebab case. Kebab case is a style of writing where all spaces and punctuation marks are replaced with a hyphen ("-"), and all letters are converted ...
code_exercise_27k
5,598
Write a Python function to count the number of even elements in a given list of integers. The function should return the count of even numbers in the list. The code should start with: ```python from typing import List def count_even_elements(lst: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_even_elements(lst: List[int]) -> int: """ Counts the number of even elements in a given list of integers. Args: lst (List[int]): A list of integers. Returns: int: The ...
code_exercise_27k
5,599
Write a Python function to convert a string from kebab case to title case. Kebab case is a string format where words are separated by hyphens (`-`), and all characters are in lowercase. Title case is a string format where each word starts with an uppercase letter and the rest of the letters are in lowercase, with words...
Here is the Python code to solve the given problem in the markdown block: ```python def kebab_to_title(kebab_str: str) -> str: """ Convert a string from kebab case to title case. Args: kebab_str (str): The kebab case string to convert. Returns: str: The title case string. Example:...
code_exercise_27k
5,600
Write a Python function to compute the intersection of two dictionaries based on their key-value pairs. The function should return a new dictionary containing only the key-value pairs that exist in both input dictionaries with the same values. The code should start with: ```python def compute_dict_intersection(dict1: ...
Here is the Python code to solve the given problem in the markdown block: ```python def compute_dict_intersection(dict1: dict, dict2: dict) -> dict: """ Compute the intersection of two dictionaries based on their key-value pairs. Args: dict1 (dict): The first dictionary. dict2 (dict): The s...
code_exercise_27k
5,601
Write a Python function to find the maximum sum that can be obtained by selecting a subset of non-adjacent elements from a given list of integers. The function should handle edge cases such as an empty list or a list with a single element. The code should start with: ```python from typing import List def max_non_adjac...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_non_adjacent_sum(nums: List[int]) -> int: """ Finds the maximum sum that can be obtained by selecting a subset of non-adjacent elements from the given list. Args: nums (List[int]): A...
code_exercise_27k
5,603
Write a Python function to merge two sorted lists into a new sorted list. The function should efficiently combine the elements from both lists while maintaining the sorted order. The code should start with: ```python from typing import List def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]: ```
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,609
Write a Python function to convert a string containing digits into a list of consecutive integers. The function should ignore any non-digit characters in the input string. The code should start with: ```python from typing import List def convert_string_to_list_of_digits(string: str) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_string_to_list_of_digits(string: str) -> List[int]: """ Converts a string containing digits into a list of consecutive integers. Args: string (str): The string containing dig...
code_exercise_27k
5,611
Write a Python function to convert a list of consecutive digits as integers to a string. The function should handle lists of varying lengths and ensure that the output is a single string where each digit is concatenated in the order they appear in the list. The code should start with: ```python from typing import List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_digits_to_string(digits: List[int]) -> str: """ Convert a list of consecutive digits as integers to a string. Args: digits (List[int]): A list of consecutive digits as integers. ...
code_exercise_27k
5,612
Write a Python function to combine two dictionaries into one, where the values of common keys are summed up. The function should handle dictionaries with integer values and return the combined dictionary. The code should start with: ```python from typing import Dict def combine_dicts(dict1: Dict[str, int], dict2: Dict...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def combine_dicts(dict1: Dict[str, int], dict2: Dict[str, int]) -> Dict[str, int]: """ Combine two dictionaries into one, summing up the values of common keys. Args: dict1 (Dict[str, int]): ...
code_exercise_27k
5,613
Write a Python function to count the occurrences of each element in a given list and return the result as a dictionary. The dictionary should have elements as keys and their respective counts as values. The function should handle lists containing any hashable elements, such as integers, strings, or tuples. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def count_element_occurrences(lst: List[Any]) -> Dict[Any, int]: """ Count the occurrences of each element in a given list and return the result as a dictionary. Args: lst (List[A...
code_exercise_27k
5,614
Write a Python function to convert a string of comma-separated integers into a list of integers. The function should handle strings with both positive and negative integers, as well as strings that contain spaces around the commas. The function should also handle empty strings by returning an empty list. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def string_to_list_of_integers(string: str) -> List[int]: """ Convert a string of comma-separated integers into a list of integers. Args: string (str): The input string containing comma-sepa...
code_exercise_27k
5,617
Write a Python function to convert a list of integers to a string with commas, ensuring that the function handles various edge cases such as an empty list, a list with a single element, and a list with negative numbers. The function should also handle lists with non-integer elements by converting them to strings as wel...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_list_to_string(lst: List[int]) -> str: """ Convert a list of integers to a string with commas. Args: lst (List[int]): The list of integers to convert. Returns: str: ...
code_exercise_27k
5,619
Write a Python function to convert a string representation of a binary number to its integer equivalent. The function should handle binary strings of any length and ensure that the input string contains only valid binary characters ('0' and '1'). If the input string contains any non-binary characters, the function shou...
Here is the Python code to solve the given problem in the markdown block: ```python def binary_to_integer(binary_string: str) -> int: """ Convert a string representation of a binary number to an integer. Args: binary_string (str): The binary number as a string. Returns: int: The intege...
code_exercise_27k
5,621
Write a Python function to merge two dictionaries by taking the maximum value for each key. If a key exists in only one dictionary, it should be included in the result with its value from that dictionary. The function should handle dictionaries with integer values. The code should start with: ```python from typing imp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def merge_dicts_max_values(dict1: Dict[str, int], dict2: Dict[str, int]) -> Dict[str, int]: """ Merge two dictionaries by taking the maximum value for each key. Args: dict1 (Dict[str, int]):...
code_exercise_27k
5,622
Write a Python function to convert a non-negative integer to its binary representation as a string. The function should handle the conversion efficiently and return the binary string in the correct order. The code should start with: ```python def int_to_binary_string(num: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def int_to_binary_string(num: int) -> str: """ Convert a non-negative integer to its binary representation as a string. Args: num (int): The non-negative integer to be converted. Returns: str: The binar...
code_exercise_27k
5,624
Write a Python function to calculate the average of all elements in a given list of numbers. The function should handle the case where the list is empty by raising a `ValueError`. The code should start with: ```python from typing import List def calculate_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 calculate_average(lst: List[float]) -> float: """ Calculates the average of all elements in a list. Args: lst (List[float]): The list of numbers. Returns: float: The average...
code_exercise_27k
5,625
Write a Python function to filter out key-value pairs from a dictionary where the key is an anagram of the value. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should handle case insensitivity and retur...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def filter_anagrams(dictionary: Dict[str, str]) -> Dict[str, str]: """ Filters out key-value pairs from a dictionary where the key is an anagram of the value. Args: dictionary (Dict[str, str...
code_exercise_27k
5,630
Write a Python function to convert an integer to its string representation in a given base (between 2 and 36). The function should handle bases from binary (base 2) to alphanumeric (base 36). The code should start with: ```python def int_to_base(num: int, base: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def int_to_base(num: int, base: int) -> str: """ Converts a non-negative integer to its string representation in a given base (between 2 and 36). Args: num (int): The non-negative integer to be converted. ba...
code_exercise_27k
5,632
Write a Python function to remove all duplicates from a given list while preserving the original order of elements. The function should return a new list with the duplicates removed. The code should start with: ```python from typing import List def remove_duplicates_preserve_order(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 remove_duplicates_preserve_order(lst: List[int]) -> List[int]: """ Remove duplicates from a list while preserving the original order of elements. Args: lst (List[int]): The list from whi...
code_exercise_27k
5,636
Write a Python function to find the nth largest element from a given list of integers. The function should handle cases where `n` is out of range by returning `None`. The function should be efficient and avoid unnecessary computations. The code should start with: ```python from typing import List, Optional def nth_la...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def nth_largest_element(lst: List[int], n: int) -> Optional[int]: """ Find the nth largest element from a given list of integers. Args: lst (List[int]): The list of integers from w...
code_exercise_27k
5,637
Write a Python function to convert a given integer to its string representation in a specified base (between 2 and 36). The function should handle both positive and negative integers. The base should be a positive integer between 2 and 36, inclusive. The digits in the string representation should be in the range '0'-'9...
Here is the Python code to solve the given problem in the markdown block: ```python def int_to_base_string(number: int, base: int) -> str: """ Converts an integer to its string representation in a specified base (between 2 and 36). Args: number (int): The integer to be converted. base (int)...
code_exercise_27k
5,641
Write a Python function to merge two lists by interleaving their elements. If one list is longer than the other, the remaining elements of the longer list should be appended to the end of the merged list. The function should start with: ```python from typing import List def interleave_lists(list1: List[int], list2: Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def interleave_lists(list1: List[int], list2: List[int]) -> List[int]: """ Merges two lists by interleaving their elements. If one list is longer than the other, the remaining elements of the longer ...
code_exercise_27k
5,642
Write a Python function to filter out key-value pairs from a dictionary where the key and value contain the same set of characters, but in different order. The function should return a new dictionary containing only the filtered key-value pairs. The code should start with: ```python from typing import Dict def filter...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def filter_dictionary(dictionary: Dict[str, str]) -> Dict[str, str]: """ Filters out key-value pairs from a dictionary where the key and value contain the same set of characters, but in different order. ...
code_exercise_27k
5,645
Write a Python function to remove all elements from a given list that are divisible by a specified divisor. The function should take two parameters: the list of integers and the divisor. The function should return the modified list with all elements that are divisible by the divisor removed. 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 remove_elements_divisible_by(lst: List[int], divisor: int) -> List[int]: """ Removes all elements from a list that are divisible by the specified divisor. Args: lst (List[int]): The list...
code_exercise_27k
5,646
Write a Python function to convert a string representation of an octal number to its binary equivalent. The function should handle the conversion by first converting the octal number to its decimal form and then converting the decimal number to its binary form. The binary representation should not include the '0b' pref...
Here is the Python code to solve the given problem in the markdown block: ```python def octal_to_binary(octal: str) -> str: """ Convert a string representation of an octal number to its binary equivalent. Args: octal (str): A string representation of an octal number. Returns: str: The ...
code_exercise_27k
5,647
Write a Python function to merge two given dictionaries into a new dictionary, ensuring that if both dictionaries have the same key, the value from the second dictionary should overwrite the value from the first dictionary. The function should start with: ```python from typing import Dict def merge_dictionaries(dict1:...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def merge_dictionaries(dict1: Dict, dict2: Dict) -> Dict: """ Merge two dictionaries into a new dictionary. If both dictionaries have the same key, the value from the second dictionary will overwrite...
code_exercise_27k
5,649
Write a Python function to find the first non-repeating element in a given list. The function should return the first element that appears only once in the list. If no such element exists, the function should return `None`. The code should start with: ```python from typing import List, Optional def find_first_non_rep...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_first_non_repeating_element(lst: List[int]) -> Optional[int]: """ Find the first non-repeating element in a list. Args: lst (List[int]): The input list of integers. R...
code_exercise_27k
5,651
Write a Python function to filter out key-value pairs from a dictionary where the key and value are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should return a new dictionary c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def filter_anagrams(dictionary: Dict[str, str]) -> Dict[str, str]: """ Filter out key-value pairs from a dictionary where the key and value are anagrams of each other. Args: dictionary (Dict...
code_exercise_27k
5,653
Write a Python function to convert a hexadecimal number to a string representation of a binary number. The function should handle both uppercase and lowercase letters in the hexadecimal input and return the binary representation without the '0b' prefix. The function should raise a `ValueError` if the input is not a val...
Here is the Python code to solve the given problem in the markdown block: ```python def hex_to_binary(hex_num: str) -> str: """ Convert a hexadecimal number to a string representation of a binary number. Args: hex_num (str): The hexadecimal number to be converted. It can contain both uppercase and ...
code_exercise_27k
5,654
Write a Python function to find the kth smallest element in a given list of integers. The function should handle the case where `k` is out of the valid range (1 to the length of the list) by raising a `ValueError`. The function should be efficient and should not modify the original list. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def kth_smallest_element(lst: List[int], k: int) -> Union[int, float]: """ Returns the kth smallest element in a list. Args: lst (List[int]): The input list of integers. k (in...
code_exercise_27k
5,655
Write a Python function to create a new dictionary from a given dictionary where the keys contain a specific substring and the values are multiplied by a given number. The function should handle both integer and floating-point values for the multiplier. The code should start with: ```python from typing import Dict, Uni...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Union def create_filtered_dict(dictionary: Dict[str, Union[int, float]], substring: str, multiplier: Union[int, float]) -> Dict[str, Union[int, float]]: """ Create a new dictionary by selecting keys fro...