source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
code_exercise_27k
5,929
Write a Python function to determine if two given sets have exactly the same elements, i.e., their symmetric difference is empty. The function should return `True` if the symmetric difference is empty and `False` otherwise. The code should start with: ```python def are_sets_identical(A: set, B: set) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def are_sets_identical(A: set, B: set) -> bool: """ Determine if two sets A and B have exactly the same elements. Args: A (set): The first set. B (set): The second set. Returns: bool: True if th...
code_exercise_27k
5,930
Write a Python function to sort a dictionary based on the number of times a specific substring appears in its values. The function should return a new dictionary with the keys sorted in descending order of the substring occurrences in their corresponding values. 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 Dict def sort_dict_by_substring_occurrences(dictionary: Dict[str, str], substring: str) -> Dict[str, str]: """ Sorts a dictionary based on the number of times a specific substring appears in its values. ...
code_exercise_27k
5,935
Write a Python function to check if all elements in a given set are even numbers. The function should return `True` if all elements are even, and `False` otherwise. The code should start with: ```python def check_all_even(s: set) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def check_all_even(s: set) -> bool: """ Check if all elements in a given set are even numbers. Args: s (set): A set of integers. Returns: bool: True if all elements in the set are even, False otherwise....
code_exercise_27k
5,936
Write a Python function to round each float element in a list to the nearest whole number. The function should handle a list of floats and return a list of integers. The code should start with: ```python from typing import List def round_floats_to_nearest_whole(numbers: List[float]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def round_floats_to_nearest_whole(numbers: List[float]) -> List[int]: """ Rounds each float element in a list to the nearest whole number. Args: numbers (List[float]): A list of floats to be...
code_exercise_27k
5,937
Write a Python function to sort a dictionary based on the number of words in its values. The function should return a new dictionary with the same keys as the original dictionary, but sorted based on the number of words in the values. The code should start with: ```python from typing import Dict def sort_dict_by_num_w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_num_words(dictionary: Dict[str, str]) -> Dict[str, str]: """ Sorts a dictionary based on the number of words in its values. Args: dictionary (Dict[str, str]): The dictionary...
code_exercise_27k
5,939
Write a Python function to count the occurrences of each unique element in a given list of strings. The function should return a dictionary where the keys are the unique elements from the list and the values are the counts of their occurrences. The code should start with: ```python from typing import List, Dict def co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_occurrences(strings: List[str]) -> Dict[str, int]: """ Count the occurrences of each unique element in a list of strings. Args: strings (List[str]): A list of strings. R...
code_exercise_27k
5,940
Write a Python function to sort a dictionary based on the number of consonants in its keys and values. The function should return the sorted dictionary. The code should start with: ```python from typing import Dict def sort_dict_by_consonants(dictionary: Dict[str, str]) -> Dict[str, str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_consonants(dictionary: Dict[str, str]) -> Dict[str, str]: """ Sorts a dictionary based on the number of consonants in its keys and values. Args: dictionary (Dict[str, str]):...
code_exercise_27k
5,942
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]: """ Interleaves two lists by alternating their elements. If one list is longer, the remaining elements of the longer list are append...
code_exercise_27k
5,944
Write a Python function to sort a dictionary of dictionaries based on the number of unique keys in each nested dictionary. The function should return a new dictionary with the nested dictionaries sorted in ascending order of unique keys. The code should start with: ```python from typing import Dict def sort_dict_of_di...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_of_dicts(d: Dict[str, Dict[str, any]]) -> Dict[str, Dict[str, any]]: """ Sorts a dictionary of dictionaries based on the number of unique keys in each nested dictionary. Args: ...
code_exercise_27k
5,945
Write a Python function to find the longest common substring between two lists of integers. The function should use dynamic programming to efficiently compute the longest common substring. The code should start with: ```python from typing import List def longest_common_substring(list1: List[int], list2: List[int]) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_common_substring(list1: List[int], list2: List[int]) -> List[int]: """ Finds the longest common substring between two lists of integers using dynamic programming. Args: list1 (Li...
code_exercise_27k
5,946
Write a Python function to remove all elements from a given list that are divisible by a specified divisor. The function should return a new list containing only the elements that are not divisible by the specified divisor. The code should start with: ```python from typing import List def remove_elements_divisible_by(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_elements_divisible_by(input_list: List[int], divisor: int) -> List[int]: """ Remove all elements from the given list that are divisible by the specified divisor. Args: input_list ...
code_exercise_27k
5,950
Write a Python function to find the longest string in a given list of strings. If there are multiple strings with the same maximum length, return the first one encountered. The function should handle an empty list by returning an empty string. The code should start with: ```python from typing import List def find_lon...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_longest_string(strings: List[str]) -> str: """ Finds the longest string in a list of strings. If there are multiple strings with the same maximum length, returns the first one encountered. ...
code_exercise_27k
5,952
Write a Python function to sort a dictionary based on the number of times a specific character sequence appears in its keys and values. The function should return a new dictionary with the keys sorted in ascending order based on the count of the specified sequence in both the key and its corresponding value. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dictionary_by_sequence(dictionary: Dict[str, str], sequence: str) -> Dict[str, str]: """ Sorts a dictionary based on the number of times a specific character sequence appears in its keys and val...
code_exercise_27k
5,954
Write a Python function to find the maximum length subarray with an equal number of zeros and ones in a given list. The function should return the length of this subarray. The code should start with: ```python from typing import List def find_max_length_subarray(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_length_subarray(arr: List[int]) -> int: """ Finds the maximum length subarray with an equal number of zeros and ones in a given list. Args: arr (List[int]): The input list conta...
code_exercise_27k
5,955
Write a Python function to find the difference between the union and intersection of two sets. The function should take two sets as input and return a new set that contains elements that are in the union of the two sets but not in their intersection. The code should start with: ```python def find_set_difference(set1: s...
Here is the Python code to solve the given problem in the markdown block: ```python def find_set_difference(set1: set, set2: set) -> set: """ Finds the difference between the union and intersection of two sets. Args: set1 (set): The first set. set2 (set): The second set. Returns: ...
code_exercise_27k
5,957
Write a Python function to sort a dictionary of lists based on the number of even numbers in each list. The function should return the sorted dictionary. The code should start with: ```python from typing import Dict, List def sort_dict_of_lists_by_even_count(dictionary: Dict[str, List[int]]) -> Dict[str, List[int]]: `...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def sort_dict_of_lists_by_even_count(dictionary: Dict[str, List[int]]) -> Dict[str, List[int]]: """ Sorts a dictionary of lists based on the number of even numbers in each list. Args: ...
code_exercise_27k
5,958
Write a Python function to check if a given set is a proper subset of multiple sets. A proper subset is defined as a set that contains all elements of the given set but is not equal to it. The function should return `True` if the given set is a proper subset of all the sets in the list, and `False` otherwise. The code...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Set def is_proper_subset(given_set: Set[int], sets: List[Set[int]]) -> bool: """ Check if a given set is a proper subset of multiple sets. Args: given_set (Set[int]): The set to be checked....
code_exercise_27k
5,959
Write a Python function to flatten a nested list into a single list. The nested list can contain any number of sublists at any level of nesting. The function should handle lists of integers and lists containing other lists. The code should start with: ```python from typing import List, Any def flatten_nested_list(nest...
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 into a single list. Args: nested_list (List[Any]): The nested list to be flattened. Returns...
code_exercise_27k
5,960
Write a Python function to find the set of elements that are in either set A or set B, but not in their intersection. The function should take two sets as input and return a set containing the elements that satisfy the condition. The code should start with: ```python def find_elements_in_either(A: set, B: set) -> set: ...
Here is the Python code to solve the given problem in the markdown block: ```python def find_elements_in_either(A: set, B: set) -> set: """ Finds the set of elements that are in either set A or set B, but not in their intersection. Args: A (set): The first set. B (set): The second set. ...
code_exercise_27k
5,961
Write a Python function to sort a given nested list based on the sum of each nested list. The function should return the sorted nested list. The code should start with: ```python from typing import List def sort_nested_list_by_sum(nested_list: List[List[int]]) -> List[List[int]]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_nested_list_by_sum(nested_list: List[List[int]]) -> List[List[int]]: """ Sorts the given nested list based on the sum of each nested list. Args: nested_list (List[List[int]]): A nes...
code_exercise_27k
5,962
Write a Python function to sort a dictionary based on the sum of the squares of the ASCII values of the keys and values. The function should return a new dictionary with the same key-value pairs as the input dictionary, but sorted according to the sum of the squares of the ASCII values of the keys and values. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_ascii_sum(dictionary: Dict[str, str]) -> Dict[str, str]: """ Sort a dictionary based on the sum of the squares of the ASCII values of the keys and values. Args: dictionary (...
code_exercise_27k
5,964
Write a Python function to remove duplicate elements from a given list while preserving the order of the first occurrence of each element. 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(lst: L...
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 duplicate elements from a list while preserving the order of the first occurrence of each element. Args: lst (L...
code_exercise_27k
5,966
Write a Python function to sort a dictionary of tuples based on the absolute difference between the first and second element of each tuple. The function should return the sorted dictionary. The code should start with: ```python from typing import Dict, Tuple def sort_dict_by_abs_diff(dictionary: Dict[str, Tuple[int, i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Tuple def sort_dict_by_abs_diff(dictionary: Dict[str, Tuple[int, int]]) -> Dict[str, Tuple[int, int]]: """ Sorts a dictionary of tuples based on the absolute difference between the first and second elem...
code_exercise_27k
5,968
Write a Python function to check if all strings in a given list start with a specified prefix. If the list is empty, the function should return `True`. The function should be case-sensitive. The code should start with: ```python from typing import List def check_string_prefix(strings: List[str], prefix: str) -> bool:...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def check_string_prefix(strings: List[str], prefix: str) -> bool: """ Check if all strings in the given list start with the specified prefix. Args: strings (List[str]): List of strings to be...
code_exercise_27k
5,969
Write a Python function to check if all elements in a given set are multiples of a specified divisor. The function should return `True` if all elements in the set are multiples of the divisor, and `False` otherwise. The code should start with: ```python def check_multiples(set_of_numbers: set, divisor: int) -> bool: ``...
Here is the Python code to solve the given problem in the markdown block: ```python def check_multiples(set_of_numbers: set, divisor: int) -> bool: """ Check if all elements in a set are multiples of a given divisor. Args: set_of_numbers (set): A set of integers to be checked. divisor (int)...
code_exercise_27k
5,970
Write a Python function to merge two sorted lists into a single 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 single sorted list. Args: list1 (List[int]): The first sorted list. list2 (...
code_exercise_27k
5,971
Write a Python function to sort a dictionary based on the number of times a specific element appears in its values. The dictionary values are lists of elements. The function should return a new dictionary with keys sorted in descending order based on the count of the specified element in their corresponding values. Th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Any def sort_dict_by_element_count(dictionary: Dict[Any, List[Any]], element: Any) -> Dict[Any, int]: """ Sorts a dictionary based on the number of times a specific element appears in its values. ...
code_exercise_27k
5,975
Write a Python function to sort a list of integers in descending order using the merge sort algorithm. The function should be efficient and 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 sort_list_descending(input_list: List[in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_list_descending(input_list: List[int]) -> List[int]: """ Sorts a list of integers in descending order using the merge sort algorithm. Args: input_list (List[int]): The list of integ...
code_exercise_27k
5,976
Write a Python function to multiply each element in a given list of floats by a specified factor. The function should return a new list containing the elements multiplied by the factor. The code should start with: ```python from typing import List def multiply_elements(input_list: List[float], factor: float) -> List[f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def multiply_elements(input_list: List[float], factor: float) -> List[float]: """ Multiply each element in the input_list by the specified factor. Args: input_list (List[float]): A list of f...
code_exercise_27k
5,977
Write a Python function to sort a dictionary based on the number of digits in its keys and values. The function should return the sorted dictionary. The sorting should be done first by the number of digits in the keys, and if two keys have the same number of digits, then by the number of digits in the values. The code...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_digits(dictionary: Dict[int, int]) -> Dict[int, int]: """ Sorts a dictionary based on the number of digits in its keys and values. Args: dictionary (Dict[int, int]): The dic...
code_exercise_27k
5,978
Write a Python function to reverse the order of elements in a given list. The function should handle lists of any data type, including nested lists. The code should start with: ```python from typing import List, Any def reverse_list(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 reverse_list(lst: List[Any]) -> List[Any]: """ Reverses the order of elements in a given list, including nested lists. Args: lst (List[Any]): The list to be reversed. Returns: ...
code_exercise_27k
5,979
Write a Python function to find the complement of a given set with respect to another set. The complement of set1 with respect to set2 is defined as the set of elements that are in set2 but not in set1. The function should handle any type of hashable elements in the sets. The code should start with: ```python def find...
Here is the Python code to solve the given problem in the markdown block: ```python def find_complement(set1: set, set2: set) -> set: """ Finds the complement of set1 with respect to set2. The complement of set1 with respect to set2 is the set of elements that are in set2 but not in set1. Args: ...
code_exercise_27k
5,984
Write a Python function to sort a dictionary based on the number of uppercase letters in both its keys and values. The function should return a new dictionary with the keys sorted in descending order of the total number of uppercase letters in the key and its corresponding value. If two keys have the same number of upp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def count_uppercase_letters(s: str) -> int: """ Counts the number of uppercase letters in a given string. Args: s (str): The string to count uppercase letters in. Returns: int: ...
code_exercise_27k
5,985
Write a Python function to count the occurrences of a given number in a list. The function should take a list of integers and a target number as input and return the number of times the target number appears in the list. The code should start with: ```python from typing import List def count_occurrences(lst: List[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_occurrences(lst: List[int], number: int) -> int: """ Count the number of times a given number appears in a list. Args: lst (List[int]): The input list of integers. number (...
code_exercise_27k
5,986
Write a Python function to filter out elements from a given list that are not divisible by a specified divisor. The function should return a new list containing only the elements that are divisible by the specified divisor. The code should start with: ```python from typing import List def filter_elements_by_divisor(nu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_elements_by_divisor(numbers: List[int], divisor: int) -> List[int]: """ Filters out elements from the given list that are not divisible by the specified divisor. Args: numbers (Li...
code_exercise_27k
5,988
Write a Python function to check if a given list of integers 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 of integers is sorted in non-decreasing order. Args: lst (List[int]): A list of integers to be checked. Returns...
code_exercise_27k
5,990
Write a Python function to sort a dictionary of dictionaries based on the number of nested dictionaries in each nested dictionary. The function should return a new dictionary with the nested dictionaries sorted based on the count of nested dictionaries. The code should start with: ```python from typing import Dict def...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_nested_dicts(dictionary: Dict[str, Dict[str, any]]) -> Dict[str, Dict[str, any]]: """ Sorts a dictionary of dictionaries based on the number of nested dictionaries. Args: di...
code_exercise_27k
5,991
Write a Python function to calculate the sum of all elements in a given list of numeric values. The function should handle lists containing integers and floating-point numbers. The function should also handle edge cases such as an empty list and lists with mixed numeric types. 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, Union def sum_of_list_elements(lst: List[Union[int, float]]) -> Union[int, float]: """ Calculate the sum of all elements in a given list of numeric values. Args: lst (List[Union[int, float]...
code_exercise_27k
5,993
Write a Python function to check if all elements in a given set are odd numbers. The function should return `True` if all elements are odd, and `False` otherwise. The code should start with: ```python def check_all_odd(s: set) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def check_all_odd(s: set) -> bool: """ Check if all elements in a given set are odd numbers. Args: s (set): The set of numbers to be checked. Returns: bool: True if all elements in the set are odd numbe...
code_exercise_27k
5,994
Write a Python function to sort a dictionary of strings based on the number of vowels in each string. The function should return a new dictionary with the same keys but sorted by the number of vowels in the corresponding values. The code should start with: ```python from typing import Dict def sort_dict_by_vowels(dict...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_vowels(dictionary: Dict[str, str]) -> Dict[str, str]: """ Sorts a dictionary of strings based on the number of vowels in each string. Args: dictionary (Dict[str, str]): The ...
code_exercise_27k
5,995
Write a Python function to find the maximum number in a given list of numbers. If the list is empty, raise a `ValueError` with the message "Input list cannot be empty." The function should be efficient and handle various types of numeric inputs, including integers and floats. 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, Union def find_max_number(numbers: List[Union[int, float]]) -> Union[int, float]: """ Find the maximum number in a list of numbers. Args: numbers (List[Union[int, float]]): A list of number...
code_exercise_27k
5,997
Write a Python function to find the set of elements that are common to all three given sets. The function should handle the case where any of the inputs is not a set by raising a `TypeError`. The code should start with: ```python from typing import Set def common_elements(A: Set, B: Set, C: Set) -> Set: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set def common_elements(A: Set, B: Set, C: Set) -> Set: """ Find the set of elements that are common to all three sets A, B, and C. Args: A (Set): The first set. B (Set): The second set. ...
code_exercise_27k
5,999
Write a Python function to replace all occurrences of a specific number with a new number in a given list. The function should handle the case where the old number is not found in the list by raising a `ValueError`. The code should start with: ```python from typing import List def replace_number_in_list(lst: List[int]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def replace_number_in_list(lst: List[int], old_num: int, new_num: int) -> List[int]: """ Replace all occurrences of a specific number with a new number in a given list. Args: lst (List[int])...
code_exercise_27k
6,002
Write a Python function to sort a dictionary based on the number of digits in the product of its keys and values. The function should return a list of tuples representing the sorted dictionary. The code should start with: ```python from typing import Dict, List, Tuple def sort_dict_by_product_digits(dictionary: Dict[i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def get_num_digits(n: int) -> int: """Function to calculate the number of digits in a number. Args: n (int): The number to calculate the number of digits for. Returns: ...
code_exercise_27k
6,003
Write a Python function to sort a nested list based on the sum of the squares of each nested list. Each element of the nested list is itself a list of integers. The function should return the sorted nested list. The code should start with: ```python from typing import List def sort_nested_list_by_sum_of_squares(neste...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_nested_list_by_sum_of_squares(nested_list: List[List[int]]) -> List[List[int]]: """ Sorts a nested list based on the sum of the squares of each nested list. Args: nested_list (List[...
code_exercise_27k
6,004
Write a Python function to merge two lists such that the resulting list contains all elements from both lists in ascending order. The function should handle lists of integers and ensure that the merged list does not contain any duplicates. The code should start with: ```python from typing import List def merge_sorted_...
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]: """ Merges two lists of integers into a single sorted list without duplicates. Args: list1 (List[int]): The first lis...
code_exercise_27k
6,005
Write a Python function to remove all elements from a given list that are smaller than the previous element. The function should return the modified list. The code should start with: ```python from typing import List def remove_smaller_elements(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_smaller_elements(lst: List[int]) -> List[int]: """ Remove all elements from the list that are smaller than the previous element. Args: lst (List[int]): The input list of integers....
code_exercise_27k
6,008
Write a Python function to sort a dictionary based on the number of lowercase letters in its keys and values. The function should return a new dictionary with the same key-value pairs but sorted according to the specified criteria. The code should start with: ```python def sort_dictionary_by_lowercase_count(dictionary:...
Here is the Python code to solve the given problem in the markdown block: ```python def sort_dictionary_by_lowercase_count(dictionary: dict) -> dict: """ Sorts a dictionary based on the number of lowercase letters in its keys and values. Args: dictionary (dict): The input dictionary to be sorted. ...
code_exercise_27k
6,010
Write a Python function to count the number of occurrences of a specified number in a given list. The function should be able to handle any integer as the target number, not just the number 5. The code should start with: ```python from typing import List def count_occurrences(lst: List[int], target: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_occurrences(lst: List[int], target: int) -> int: """ Counts the number of occurrences of a specified number in a list. Args: lst (List[int]): The input list of integers. ta...
code_exercise_27k
6,011
Write a Python function to sort a dictionary of lists of tuples based on the sum of the second element of each tuple in each list. The function should return a new dictionary with the lists sorted in ascending order based on the sum of the second elements of the tuples. The code should start with: ```python from typin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def sort_dict_of_lists(dictionary: Dict[str, List[Tuple[int, int]]]) -> Dict[str, List[Tuple[int, int]]]: """ Sorts a dictionary of lists of tuples based on the sum of the second element of ...
code_exercise_27k
6,013
Write a Python function to find the index of the third occurrence of a specific element in a given list of integers. If the element does not occur at least three times, return -1. The function should handle cases where the element is not an integer by raising a `ValueError`. 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 find_third_occurrence(lst: List[int], element: int) -> int: """ Find the index of the third occurrence of a specific element in a list of integers. Args: lst (List[int]): The list of int...
code_exercise_27k
6,014
Write a Python function to sort a dictionary based on the number of times a specific word appears in its keys. The function should return the sorted dictionary with keys ordered by the frequency of the specific word in descending order. If two keys have the same frequency, their original order should be preserved. The...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_word_frequency(dictionary: Dict[str, int], word: str) -> Dict[str, int]: """ Sorts a dictionary based on the number of times a specific word appears in its keys. Args: dicti...
code_exercise_27k
6,015
Write a Python function to filter out all the odd numbers from a given list of integers and return a new list containing only the even numbers. The function should handle lists of any length, including empty lists. The code should start with: ```python from typing import List def filter_even_numbers(numbers: List[int]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_even_numbers(numbers: List[int]) -> List[int]: """ Filters out all the odd numbers from the given list and returns a new list containing only the even numbers. Args: numbers (List...
code_exercise_27k
6,016
Write a Python function to calculate the sum of all positive elements in a given list of floats. The function should handle input validation to ensure that the input is a list of floats. If the input is not a list or contains elements that are not floats, the function should raise appropriate exceptions. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_positive_sum(float_list: List[float]) -> float: """ Calculate the sum of all positive elements in a given list of floats. Args: float_list (List[float]): A list of floats. ...
code_exercise_27k
6,018
Write a Python function to multiply each element of a given list by a specified factor. The function should handle both positive and negative integers, as well as zero. The code should start with: ```python from typing import List def multiply_elements_by_factor(lst: List[int], factor: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def multiply_elements_by_factor(lst: List[int], factor: int) -> List[int]: """ Multiply each element of a given list by a specified factor. Args: lst (List[int]): The list of integers to be ...
code_exercise_27k
6,019
Write a Python function to sort a dictionary based on the number of words ending with a specific letter in its values. The dictionary's values are lists of strings. The function should return the sorted dictionary. The code should start with: ```python from typing import Dict, List def sort_dict_by_ending_letter(dict...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def sort_dict_by_ending_letter(dictionary: Dict[str, List[str]], letter: str) -> Dict[str, List[str]]: """ Sorts a dictionary based on the number of words ending with a specific letter in its value...
code_exercise_27k
6,020
Write a Python function to capitalize the first letter of each word in a given list of strings. The function should return a new list containing the capitalized words. The code should start with: ```python from typing import List def capitalize_first_letter_of_each_word(words: List[str]) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def capitalize_first_letter_of_each_word(words: List[str]) -> List[str]: """ Capitalizes the first letter of each word in a given list of strings. Args: words (List[str]): A list of strings ...
code_exercise_27k
6,021
Write a Python function to merge two lists and return a new list that contains all elements from both lists, but with duplicates removed. The order of elements in the resulting list should be maintained according to their first appearance in the input lists. The code should start with: ```python from typing import Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_lists_unique(list1: List[int], list2: List[int]) -> List[int]: """ Merges two lists and returns a new list containing all unique elements from both lists, maintaining the order of their fir...
code_exercise_27k
6,023
Write a Python function to sort a dictionary based on the sum of the fourth powers of the ASCII values of the keys and values. The function should return a new sorted dictionary. The code should start with: ```python from typing import Dict def sort_dict_by_ascii_power(dictionary: Dict[str, str]) -> Dict[str, str]: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_ascii_power(dictionary: Dict[str, str]) -> Dict[str, str]: """ Sorts a dictionary based on the sum of the fourth powers of the ASCII values of the keys and values. Args: dic...
code_exercise_27k
6,024
Write a Python function to remove duplicate elements from a given list while preserving the original order of the 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 duplicate elements from a list while preserving the original order. Args: lst (List[int]): The list from which d...
code_exercise_27k
6,027
Write a Python function to sort a dictionary based on the number of occurrences of a specific character in its keys and values. The function should return the sorted dictionary. The code should start with: ```python from typing import Dict def sort_dict_by_char_occurrences(dictionary: Dict[str, any], char: str) -> Dic...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_char_occurrences(dictionary: Dict[str, any], char: str) -> Dict[str, any]: """ Sorts a dictionary based on the number of occurrences of a specific character in its keys and values. ...
code_exercise_27k
6,030
Write a Python function to sort a dictionary of dictionaries based on the number of keys in each nested dictionary. The function should return a new dictionary with the same keys and values, but sorted in ascending order based on the number of keys in each nested dictionary. 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 Dict def sort_dict_of_dicts(dictionary: Dict[str, Dict[str, any]]) -> Dict[str, Dict[str, any]]: """ Sorts a dictionary of dictionaries based on the number of keys in each nested dictionary. Args: ...
code_exercise_27k
6,032
Write a Python function to sort a dictionary of strings based on the number of consonants in each string. The function should return the sorted dictionary. The code should start with: ```python from typing import Dict def sort_dict_by_consonants(dictionary: Dict[str, str]) -> Dict[str, str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_consonants(dictionary: Dict[str, str]) -> Dict[str, str]: """ Sorts a dictionary of strings based on the number of consonants in each string. Args: dictionary (Dict[str, str...
code_exercise_27k
6,034
Write a Python function to find all prime numbers in a given list of integers. The function should return a list of all prime numbers found in the input list. If no prime numbers are found, the function should return an empty list. The code should start with: ```python from typing import List def find_primes(numbers:...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def is_prime(n: int) -> bool: """ Check if a number is prime or not. Parameters: n (int): The number to check for primality. Returns: bool: True if the number is prime, Fals...
code_exercise_27k
6,035
Write a Python function to generate a list of random numbers and sort them in descending order. The function should take an integer `length` as input, which specifies the number of random numbers to generate. The function should return the sorted list. The code should start with: ```python import random from typing im...
Here is the Python code to solve the given problem in the markdown block: ```python import random from typing import List def generate_sorted_random_list(length: int) -> List[float]: """ Generate a list of random numbers and sort them in descending order. Args: length (int): The number of random n...
code_exercise_27k
6,037
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 elements and the divisor. The function should return the updated list after removing the elements that are divisible by the divisor. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_elements_divisible_by(lst: List[int], divisor: int) -> List[int]: """ Removes all elements from the list that are divisible by the specified divisor. Args: lst (List[int]): The li...
code_exercise_27k
6,038
Write a Python function to check if all elements in a given list are divisible by a specific number. The function should return `True` if all elements are divisible by the divisor, and `False` otherwise. The code should start with: ```python from typing import List def check_all_divisible(numbers: List[int], divisor: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def check_all_divisible(numbers: List[int], divisor: int) -> bool: """ Check if all elements in a list are divisible by a specific number. Args: numbers: A list of integers. divisor:...
code_exercise_27k
6,041
Write a Python function to generate a list of the squares of the numbers within a given range, both inclusive. The function should handle the case where the start value is greater than the end value by raising a `ValueError`. The code should start with: ```python from typing import List def generate_squared_list(start...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_squared_list(start: int, end: int) -> List[int]: """ Generate a list of the squares of the numbers within the given range, both inclusive. Args: start (int): The starting value ...
code_exercise_27k
6,043
Write a Python function to check if all elements in a given set are alphabetical characters. The function should return `True` if all elements are alphabetical characters, and `False` otherwise. The function should handle sets of varying sizes and types of elements. The code should start with: ```python def are_all_el...
Here is the Python code to solve the given problem in the markdown block: ```python def are_all_elements_alphabetic(s: set) -> bool: """ Check if all elements in a given set are alphabetical characters. Args: s (set): The set to check. Returns: bool: True if all elements are alphabetic...
code_exercise_27k
6,047
Write a Python function to sort a dictionary based on the number of special characters in its keys and values. The function should return a new dictionary with the same key-value pairs but sorted in ascending order of the total number of special characters in the key and the value. Special characters are defined as any...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict import string def count_special_chars(s: str) -> int: """Count the number of special characters in a string. Args: s (str): The string to count the special characters from. Returns: ...
code_exercise_27k
6,053
Write a Python function to calculate the product of all numbers in a given list. The function should handle empty lists and non-numeric values by raising appropriate exceptions. The code should start with: ```python from typing import List def calculate_product(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_product(numbers: List[int]) -> int: """ Calculates the product of all numbers in the given list. Args: numbers (List[int]): A list of integers. Returns: int: The p...
code_exercise_27k
6,054
Write a Python function to split a list of integers into two separate lists, one containing positive elements and the other containing negative elements, while ignoring zero values. The function should return a tuple with the two lists. The code should start with: ```python from typing import List, Tuple def split_lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def split_list_ignore_zero(numbers: List[int]) -> Tuple[List[int], List[int]]: """ Split a list of integers into two separate lists, one containing positive elements and the other containing negat...
code_exercise_27k
6,057
Write a Python function to replace all negative elements in a list of floats with their absolute values. The function should handle lists of any length, including empty lists. The code should start with: ```python from typing import List def replace_negative_with_absolute(lst: List[float]) -> List[float]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def replace_negative_with_absolute(lst: List[float]) -> List[float]: """ Replace all negative elements in a list of floats with their absolute values. Args: lst (List[float]): The input list...
code_exercise_27k
6,058
Write a Python function to flatten a nested list into a single list. The function should handle lists nested at any level and should not use any external libraries. The code should start with: ```python from typing import List, Any def flatten_nested_list(nested_list: 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_nested_list(nested_list: List[Any]) -> List[Any]: """ Recursively flatten a nested list into a single list. Args: nested_list (List[Any]): The nested list to flatten. R...
code_exercise_27k
6,060
Write a Python function to remove all vowels from a list of strings. The function should return a new list where each string has had its vowels removed. The vowels to be removed include both uppercase and lowercase vowels. The code should start with: ```python from typing import List def remove_vowels_from_list(strin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_vowels_from_list(strings: List[str]) -> List[str]: """ Removes all vowels from each string in the given list of strings. Args: strings (List[str]): A list of strings from which vo...
code_exercise_27k
6,064
Write a Python function to rearrange the elements of a given list in a random order. The function should return a new list with the elements shuffled, without modifying the original list. The code should start with: ```python from typing import List import random def shuffle_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 import random def shuffle_list(input_list: List[int]) -> List[int]: """ Rearrange the elements of a given list in a random order. Args: input_list (List[int]): The list of elements to be rea...
code_exercise_27k
6,067
Write a Python function to sort a dictionary based on the number of occurrences of a specific digit in its keys and values. The function should return a new dictionary with the same key-value pairs but sorted in ascending order based on the count of the specified digit in both keys and values. If two keys have the same...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_digit_occurrences(data: Dict[int, int], digit: int) -> Dict[int, int]: """ Sorts a dictionary based on the number of occurrences of a specific digit in its keys and values. Args: ...
code_exercise_27k
6,069
Write a Python function to find the median element of a list of integers. The function should handle both odd and even lengths of the list. If the list has an odd number of elements, the median is the middle element. If the list has an even number of elements, the median is the average of the two middle elements. The f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_median(numbers: List[int]) -> Union[int, float]: """ Find the median element of a list of integers. Parameters: numbers (List[int]): A list of integers. Returns: Union[i...
code_exercise_27k
6,070
Write a Python function to sort a dictionary of dictionaries based on the sum of all the values in each nested dictionary. The function should return the sorted dictionary of dictionaries. The code should start with: ```python from typing import Dict def sort_dict_of_dicts(dictionary: Dict[str, Dict[str, int]]) -> Dic...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_of_dicts(dictionary: Dict[str, Dict[str, int]]) -> Dict[str, Dict[str, int]]: """ Sort a dictionary of dictionaries based on the sum of all the values in each nested dictionary. Args: ...
code_exercise_27k
6,073
Write a Python function to remove all elements from a list that are not unique. An element is considered unique if it appears exactly once in the list. The function should return a new list containing only the unique elements. The original list should not be modified. 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 List def remove_non_unique_elements(lst: List[int]) -> List[int]: """ Remove all elements that are not unique in the list. Parameters: lst (List[int]): The input list of integers. Returns: L...
code_exercise_27k
6,074
Write a Python function to sort a dictionary of strings based on the number of uppercase letters in each string. The function should return a new dictionary with the strings sorted in ascending order based on the number of uppercase letters. The code should start with: ```python from typing import Dict def sort_dict_b...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_uppercase(dictionary: Dict[str, str]) -> Dict[str, str]: """ Sorts a dictionary of strings based on the number of uppercase letters in each string. Args: dictionary (Dict[st...
code_exercise_27k
6,076
Write a Python function to insert an element at a specific position in a given list. The function should handle the insertion efficiently and return the modified list. The function should also raise an `IndexError` if the specified position is out of range. 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, Any def insert_element_at_position(lst: List[Any], element: Any, position: int) -> List[Any]: """ Inserts an element at a specific position in a list. Args: lst (List[Any]): The original li...
code_exercise_27k
6,077
Write a Python function to remove all duplicate adjacent elements from a given list. The function should return a new list with the duplicate adjacent elements removed. The code should start with: ```python from typing import List def remove_adjacent_duplicates(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_adjacent_duplicates(lst: List[int]) -> List[int]: """ Remove duplicate adjacent elements from a given list. Args: lst (List[int]): The input list from which to remove adjacent dup...
code_exercise_27k
6,078
Write a Python function to sort a dictionary based on the number of words with less than three letters in its values. The function should return a new dictionary with the same keys and values as the original, but sorted according to the specified criterion. 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, Any def sort_dict_by_short_words(dictionary: Dict[Any, str]) -> Dict[Any, str]: """ Sorts a dictionary based on the number of words with less than three letters in its values. Args: diction...
code_exercise_27k
6,084
Write a Python function to count the number of words in a given string and return a list of these words with any leading or trailing punctuation marks removed. The function should handle various punctuation marks and multiple spaces between words. The code should start with: ```python from typing import List def coun...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_words_and_clean(string: str) -> List[str]: """ Counts the number of words in a string and returns a list of these words with any leading or trailing punctuation marks removed. Args: ...
code_exercise_27k
6,085
Write a Python function to sort a list of strings based on the length of the strings in ascending order. If two strings have the same length, they should remain in the order they were originally in the list. The function should be efficient and handle various edge cases, such as an empty list or a list with strings of ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_list_by_string_length(lst: List[str]) -> List[str]: """ Sorts a list of strings based on the length of the strings in ascending order. If two strings have the same length, they remain in the...
code_exercise_27k
6,086
Write a Python function to sort a dictionary based on the number of spaces in both its keys and values. The function should return the sorted dictionary. The code should start with: ```python from typing import Dict def sort_dict_by_space_count(dictionary: Dict[str, any]) -> Dict[str, any]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_space_count(dictionary: Dict[str, any]) -> Dict[str, any]: """ Sorts a dictionary based on the number of spaces in both its keys and values. Args: dictionary (Dict[str, any]...
code_exercise_27k
6,088
Write a Python function to find the element that appears the most number of times in a given list. If there is a tie, return the element that appears first. The function should handle an empty list by returning `None`. The code should start with: ```python from typing import List, Optional def find_most_frequent_elem...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_most_frequent_element(lst: List[int]) -> Optional[int]: """ Finds the element that appears the most number of times in a given list. If there is a tie, returns the element that app...
code_exercise_27k
6,092
Write a Python function to calculate the cumulative sum of the elements in a given list. The cumulative sum is a sequence of partial sums of a given list. For example, the cumulative sum of the list `[1, 2, 3, 4, 5]` is `[1, 3, 6, 10, 15]`. The function should handle empty lists by returning an empty list. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def cumulative_sum(lst: List[int]) -> List[int]: """ Calculate the cumulative sum of the elements in a list. Args: lst (List[int]): The input list of integers. Returns: List[int...
code_exercise_27k
6,094
Write a Python function to sort a dictionary based on the number of times a specific word appears in its values. The dictionary values are strings, and the function should return a new dictionary sorted in descending order based on the word count. The code should start with: ```python from typing import Dict def sort...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_word_count(dictionary: Dict[str, str], word: str) -> Dict[str, str]: """ Sorts a dictionary based on the number of times a specific word appears in its values. Args: diction...
code_exercise_27k
6,095
Write a Python function to convert a list of strings into a single string with a specified delimiter. The function should take two parameters: a list of strings and a delimiter string. The function should return a single string formed by concatenating all the strings in the list, with each string separated by the speci...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def list_to_string_with_delimiter(lst: List[str], delimiter: str) -> str: """ Convert a list of strings into a single string with a specified delimiter. Args: lst (List[str]): The list of st...
code_exercise_27k
6,097
Write a Python function to remove all elements from a given list that occur more than once. The function should return a new list containing only the elements that appear exactly once in the original list. The code should start with: ```python from typing import List def remove_elements_with_duplicates(lst: List[int])...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_elements_with_duplicates(lst: List[int]) -> List[int]: """ Remove all elements from a list that occur more than once. Args: lst (List[int]): The input list from which to remove du...
code_exercise_27k
6,100
Write a Python function to find the union of the intersection of two sets with another set. Specifically, given three sets `A`, `B`, and `C`, the function should return the union of `(A intersection B)` and `(B intersection C)`. The code should start with: ```python def find_union_of_intersections(A: set, B: set, C: s...
Here is the Python code to solve the given problem in the markdown block: ```python def find_union_of_intersections(A: set, B: set, C: set) -> set: """ Find the union of (A intersection B) and (B intersection C). Args: A (set): The first set. B (set): The second set. C (set): The th...
code_exercise_27k
6,101
Write a Python function to sort a dictionary based on the sum of the sixth powers of the ASCII values of the keys and values. The function should return the sorted dictionary. The code should start with: ```python from typing import Dict def sort_dict_by_ascii_power(dictionary: Dict[str, str]) -> Dict[str, str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_ascii_power(dictionary: Dict[str, str]) -> Dict[str, str]: """ Sorts a dictionary based on the sum of the sixth powers of the ASCII values of the keys and values. Args: dict...
code_exercise_27k
6,102
Write a Python function to generate a list of prime numbers up to a given number `n` using the Sieve of Eratosthenes algorithm. The Sieve of Eratosthenes is an efficient algorithm to find all primes up to a specified integer. The function should start with: ```python from typing import List def sieve_of_eratosthenes(n...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sieve_of_eratosthenes(n: int) -> List[int]: """ Generate a list of prime numbers up to a given number using the Sieve of Eratosthenes algorithm. Args: n (int): The upper limit until whic...
code_exercise_27k
6,104
Write a Python function to find the maximum and minimum elements in multiple sets without using built-in functions like `max()` and `min()`. The function should handle a list of sets and return a tuple containing the maximum and minimum elements. The function should raise appropriate exceptions if the input is empty or...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Set, Tuple def find_max_min_elements(sets: List[Set[int]]) -> Tuple[int, int]: """ Find the maximum and minimum elements in multiple sets. Args: sets (List[Set[int]]): A list of sets contai...
code_exercise_27k
6,106
Write a Python function to sort a dictionary based on the number of occurrences of a specific letter case (either upper or lower) in its keys and values. The function should return the sorted dictionary with the key-value pairs ordered by the total count of the specified letter case in descending order. If two key-valu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_letter_case(d: Dict[str, str], letter: str) -> Dict[str, str]: """ Sorts a dictionary based on the number of occurrences of a specific letter case in its keys and values. Args: ...
code_exercise_27k
6,107
Write a Python function to find the element that occurs the least number of times in a given list of strings. If there are multiple elements with the same minimum occurrence count, return any one of them. The function should raise a `ValueError` if the input list is empty. The code should start with: ```python from ty...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_least_occurrences(strings: List[str]) -> str: """ Find the element that occurs the least number of times in a list of strings. Args: strings (List[str]): A list of strings. Ret...
code_exercise_27k
6,109
Write a Python function to sort a dictionary of dictionaries based on the maximum value in each nested dictionary. The function should return a new dictionary with the same keys and values, but sorted in descending order based on the maximum value in each nested dictionary. The code should start with: ```python from t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def sort_dict_of_dicts(dictionary: Dict[Any, Dict[Any, Any]]) -> Dict[Any, Dict[Any, Any]]: """ Sorts a dictionary of dictionaries based on the maximum value in each nested dictionary. Args: ...
code_exercise_27k
6,115
Write a Python function to find the position of the first occurrence of a number in a given list. If the number is not found in the list, the function should return -1. The function should be efficient and handle edge cases such as an empty list or a list with duplicate elements. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_first_occurrence(lst: List[Union[int, float, str]], number: Union[int, float, str]) -> int: """ Find the position of the first occurrence of a number in the list. Args: lst (...