source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 5,226 | Write a Python function to convert a decimal number to its Roman numeral representation. The function should handle decimal numbers from 1 to 3999. The code should start with:
```python
def decimal_to_roman(num: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def decimal_to_roman(num: int) -> str:
"""
Convert a decimal number to its Roman numeral representation.
Args:
num (int): The decimal number to convert, ranging from 1 to 3999.
Returns:
str: The Roman n... |
code_exercise_27k | 5,230 | Write a Python function to find the word with the highest frequency from a given dictionary of words and their frequencies. If there are multiple words with the same highest frequency, return the first one encountered. The function should handle an empty dictionary by raising a `ValueError`.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def get_most_frequent_word(word_freq: Dict[str, int]) -> str:
"""
Get the word with the highest frequency from a dictionary of word frequencies.
Args:
word_freq (Dict[str, int]): A dictionar... |
code_exercise_27k | 5,231 | Write a Python function to remove the nth element from the end of a given list. The function should handle cases where `n` is out of range by returning the original list unchanged. The function should not raise any exceptions.
The code should start with:
```python
from typing import List
def remove_nth_from_end(lst: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_nth_from_end(lst: List[int], n: int) -> List[int]:
"""
Remove the nth element from the end of a given list.
Args:
lst (List[int]): The input list.
n (int): The position of... |
code_exercise_27k | 5,232 | Write a Python function to combine two dictionaries (`dict1` and `dict2`) into a new dictionary. If both dictionaries have the same key, the value from `dict2` should overwrite the value from `dict1`. The function should handle dictionaries with any types of keys and values. 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 combine_dictionaries(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Combines two dictionaries into a new dictionary. If both dictionaries have the same key,
the value f... |
code_exercise_27k | 5,234 | Write a Python function to count the number of elements in a list that are greater than a specified value. The function should be efficient and handle various types of numeric data. The code should start with:
```python
from typing import List, Union
def count_elements_greater_than(lst: List[Union[int, float]], value:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def count_elements_greater_than(lst: List[Union[int, float]], value: Union[int, float]) -> int:
"""
Count the number of elements in a list that are greater than a specified value.
Args:
... |
code_exercise_27k | 5,235 | Write a Python function to calculate the total expenses for a given category from a dictionary of expenses. The dictionary contains categories as keys and lists of expenses as values. The function should sum all the expenses in the list corresponding to the given category and return the total.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Union
def calculate_category_expenses(expenses: Dict[str, List[float]], category: str) -> float:
"""
Calculates the total expenses for a given category from a dictionary of expenses.
Paramete... |
code_exercise_27k | 5,236 | Write a Python function to check if two lists are identical, 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 identical.
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, Any
def are_lists_identical(list1: List[Any], list2: List[Any]) -> bool:
"""
Check if two lists are identical, including nested lists.
Parameters:
list1 (List[Any]): The first list to compare.
... |
code_exercise_27k | 5,237 | Write a Python function to convert a list of integers to their corresponding words representation. The function should handle numbers from 0 to 999, including negative numbers. The words should be formatted as follows:
- Numbers from 0 to 19 should be represented directly by their word equivalents.
- Numbers from 20 to... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_to_words(numbers: List[int]) -> List[str]:
"""
Convert a list of integers to their corresponding words representation.
Args:
numbers (List[int]): A list of integers to be convert... |
code_exercise_27k | 5,238 | Write a Python function to calculate the total price of all the products in a given list of dictionaries. Each dictionary represents a product and contains a 'price' key with a numeric value. The function should handle input validation and raise appropriate exceptions if the input is not a list, if any dictionary does ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Union
def calculate_total_price(products: List[Dict[str, Union[str, int, float]]]) -> float:
"""
Calculate the total price of all the products in the given list of dictionaries.
Args:
... |
code_exercise_27k | 5,240 | Write a Python function to find the maximum and minimum value in a given set. The function should return a tuple containing the maximum and minimum values. If the set is empty, the function should return `(None, None)`. The function should also raise a `ValueError` if the input is not a set.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_max_min(s: set) -> tuple:
"""
Finds the maximum and minimum value in a set.
Args:
s (set): The set in which to find the maximum and minimum value.
Returns:
tuple: A tuple containing the maximum... |
code_exercise_27k | 5,241 | Write a Python function to find the index of the first occurrence of a given element in a list. If the element is not found, the function should return -1. The function should handle lists of any type, including nested lists. The code should start with:
```python
from typing import List, Any
def find_first_occurrence(... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def find_first_occurrence(lst: List[Any], element: Any) -> int:
"""
Find the index of the first occurrence of a given element in a list.
Args:
lst (List[Any]): The list to search.
... |
code_exercise_27k | 5,242 | Write a Python function to find the country with the largest GDP from a given dictionary. The dictionary contains countries as keys and their respective GDP values as values. The function should return the country with the largest GDP. If the dictionary is empty, the function should raise a `ValueError`.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def get_country_with_largest_gdp(country_gdp: Dict[str, int]) -> str:
"""
Get the country with the largest GDP from the given dictionary.
Args:
country_gdp (Dict[str, int]): A dictionary con... |
code_exercise_27k | 5,243 | 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(lst: List[int], divisor: int) -> List[int]:
"""
Remove all elements from a list that are divisible by a specified divisor.
Args:
lst (List[int]): The list of... |
code_exercise_27k | 5,245 | Write a Python function to find the last occurrence of a given element in a list. The function should return the index of the last occurrence of the element, or -1 if the element is not found in the list. The code should start with:
```python
from typing import List, Any
def find_last_occurrence(lst: List[Any], elemen... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def find_last_occurrence(lst: List[Any], element: Any) -> int:
"""
Find the last occurrence of a given element in a list.
Args:
lst (List[Any]): The list to search for the element.
... |
code_exercise_27k | 5,246 | Write a Python function to filter and return a list of products from a given dictionary of sales data, where the sales amount for each product is greater than a specified threshold. The function should handle cases where the sales dictionary is empty or the threshold is set to zero.
The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Union
def get_products_with_sales_greater_than(sales: Dict[str, Union[int, float]], amount: Union[int, float]) -> List[str]:
"""
Returns a list of products with sales greater than a given amount.
... |
code_exercise_27k | 5,247 | Write a Python function to find the smallest and largest elements in a given list of numbers. The function should handle lists of integers and floating-point numbers. The function should raise a `ValueError` if the input list is empty. The code should start with:
```python
from typing import List, Tuple
def find_small... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_smallest_largest(numbers: List[float]) -> Tuple[float, float]:
"""
Find the smallest and largest elements in a given list of numbers.
Args:
numbers (List[float]): A list of n... |
code_exercise_27k | 5,252 | Write a Python function to find the sum of all even numbers in a given list of integers. The function should iterate through the list, check if each number is even, and if so, add it to a running total. The function should return the total sum of all even numbers.
The code should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_even_numbers(numbers: List[int]) -> int:
"""
Calculates the sum of all even numbers in a given list of integers.
Args:
numbers (List[int]): A list of integers.
Returns:
... |
code_exercise_27k | 5,255 | Write a Python function to find the word(s) with the longest length from a given dictionary where keys are words and values are their respective lengths. If there are multiple words with the same longest length, the function should return all of them. The function should handle an empty dictionary by raising a `ValueEr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def find_longest_words(word_length: Dict[str, int]) -> List[str]:
"""
Find the word(s) with the longest length from a given dictionary where keys are words and values are their respective lengths.
... |
code_exercise_27k | 5,258 | Write a Python function to calculate the difference between consecutive elements in a given list. The function should return a new list containing these differences. If the input list has fewer than two elements, the function should return an empty list.
The code should start with:
```python
from typing import List
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_differences(numbers: List[int]) -> List[int]:
"""
Calculate the difference between consecutive elements in a list.
Args:
numbers (List[int]): A list of integers.
Returns:
... |
code_exercise_27k | 5,260 | Write a Python function to convert a nested list into a flat list. The function should handle lists nested at any level. 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]:
"""
Converts a nested list into a flat list.
Args:
nested_list (List[Any]): The nested list to be flattened.
Returns:
... |
code_exercise_27k | 5,262 | Write a Python function to check if a list is sorted in non-descending order. The function should return `True` if the list is sorted in non-descending order, and `False` otherwise. The function should handle lists of integers and floats.
The code should start with:
```python
from typing import List, Union
def is_sor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def is_sorted_non_descending(lst: List[Union[int, float]]) -> bool:
"""
Checks if a list is sorted in non-descending order.
Args:
lst (List[Union[int, float]]): The list to be checked... |
code_exercise_27k | 5,263 | Write a Python function to extract a specific attribute's values from a dictionary of team statistics. The dictionary contains team names as keys and dictionaries of attributes as values. The function should return a list of all the teams' attribute values for the given attribute.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def get_attribute_values(team_stats: Dict[str, Dict[str, int]], attribute: str) -> List[int]:
"""
Retrieve a list of all teams' attribute values from the given dictionary.
Args:
team_s... |
code_exercise_27k | 5,264 | Write a Python function to find the intersection of two lists and return the result as a set. The intersection should contain only unique elements that are present in both lists. The function should handle lists of any length, including empty lists.
The code should start with:
```python
from typing import List, Set
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Set
def find_intersection(list1: List[int], list2: List[int]) -> Set[int]:
"""
Finds the intersection of two lists and returns the result as a set.
Args:
list1 (List[int]): The first list t... |
code_exercise_27k | 5,266 | Write a Python function to find the maximum sum of sublists in a given list. The function should handle lists containing both positive and negative integers. The function should return the maximum sum of any contiguous sublist within the given list. The code should start with:
```python
from typing import List
def max... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_sublist_sum(lst: List[int]) -> int:
"""
Finds the maximum sum of contiguous sublists in a given list.
Args:
lst (List[int]): The input list containing integers.
Returns:
... |
code_exercise_27k | 5,268 | Write a Python function to calculate the product of all elements in a given list. The function should handle both integer and floating-point numbers. If the list is empty, the function should raise a `ValueError`. The code should start with:
```python
from typing import List, Union
def calculate_product(numbers: List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def calculate_product(numbers: List[Union[int, float]]) -> Union[int, float]:
"""
Calculates the product of all elements in a given list.
Args:
numbers (List[Union[int, float]]): A li... |
code_exercise_27k | 5,272 | Write a Python function to find the length of the longest increasing subsequence (LIS) in a given list of integers. The function should return the length of the LIS, which is the longest sequence of numbers in the list such that each number is strictly greater than the previous number.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_increasing_subsequence_length(nums: List[int]) -> int:
"""
Finds the length of the longest increasing subsequence in a given list of integers.
Args:
nums (List[int]): The list of... |
code_exercise_27k | 5,278 | Write a Python function to convert a list of strings containing numbers into a matrix. Each string in the list represents a row of the matrix, and the numbers within each string are separated by spaces. The function should handle both integer and floating-point numbers. If any string contains invalid characters that ca... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def string_list_to_matrix(string_list: List[str]) -> List[List[float]]:
"""
Converts a list of strings containing numbers to a matrix.
Args:
string_list (List[str]): A list of strings where ... |
code_exercise_27k | 5,280 | Write a Python function to convert a given 2D matrix into a list of strings, where each string represents a row of the matrix. Each element in the row should be separated by a space. The function should handle matrices of varying sizes and ensure that the output list contains the correct number of strings.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def matrix_to_string_list(matrix: List[List[int]]) -> List[str]:
"""
Convert a given 2D matrix into a list of strings, where each string represents a row of the matrix.
Args:
matrix (List[Li... |
code_exercise_27k | 5,281 | Write a Python function to check if a given set is a subset of another set. The function should return `True` if the first set is a subset of the second set, and `False` otherwise. The function should handle sets of any size, including empty sets.
The code should start with:
```python
def is_subset(set1: set, set2: se... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_subset(set1: set, set2: set) -> bool:
"""
Check if the first set is a subset of the second set.
Args:
set1 (set): The set to check if it is a subset.
set2 (set): The set to check against.
Returns... |
code_exercise_27k | 5,287 | Write a Python function to update a dictionary with new key-value pairs representing additional country information. The function should handle the case where the country already exists in the dictionary by updating its capital city. The function should also handle the case where the input dictionary is empty.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def update_countries(countries: Dict[str, str], country_name: str, capital: str) -> Dict[str, str]:
"""
Update the 'countries' dictionary with new or updated country information.
Args:
count... |
code_exercise_27k | 5,288 | Write a Python function to generate all possible subsets of a given set. The function should return a set containing all possible subsets of the input set, including the empty set and the input set itself. The code should start with:
```python
from typing import Set
def generate_all_subsets(input_set: Set[int]) -> Set... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def generate_all_subsets(input_set: Set[int]) -> Set[frozenset]:
"""
Generate all possible subsets of a given set.
Args:
input_set (Set[int]): The input set for which to generate subsets.
... |
code_exercise_27k | 5,291 | Write a Python function to remove a specific key-value pair from a given dictionary using the `pop()` method. The function should handle cases where the key does not exist in the dictionary by returning `None` instead of raising an error. Additionally, the function should raise a `TypeError` if the input is not a dicti... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_key_value_pair(dictionary: dict, key) -> object:
"""
Removes a specific key-value pair from the given dictionary using the pop() method.
Args:
dictionary (dict): The dictionary from which the key-value pa... |
code_exercise_27k | 5,293 | Write a Python function to check if a given key exists in a nested dictionary. The function should be able to handle nested dictionaries of arbitrary depth. If the key exists at any level of the nested dictionary, the function should return `True`. Otherwise, it should return `False`.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_key_in_nested_dict(dictionary: dict, key) -> bool:
"""
Check if a given key exists in a nested dictionary of arbitrary depth.
Args:
dictionary (dict): The nested dictionary to search through.
key: ... |
code_exercise_27k | 5,294 | Write a Python function to find the number with the maximum occurrences in a given list. If multiple numbers have the same maximum occurrences, return the smallest number. The function should raise a `ValueError` if the input list is empty.
The code should start with:
```python
from typing import List
def find_max_oc... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_max_occurrences(numbers: List[int]) -> int:
"""
Find the number with the maximum occurrences in a given list.
If multiple numbers have the same maximum occurrences, return the smallest numbe... |
code_exercise_27k | 5,295 | Write a Python function to create a set with all the distinct characters from a given string, excluding any whitespace characters. The function should handle strings with various characters, including special characters and numbers. The code should start with:
```python
def create_distinct_set_without_whitespace(string... | Here is the Python code to solve the given problem in the markdown block:
```python
def create_distinct_set_without_whitespace(string: str) -> set:
"""
Create a set containing all the distinct characters from a given string, excluding any whitespace characters.
Args:
string (str): The input string ... |
code_exercise_27k | 5,301 | Write a Python function to determine the relationship between two sets, specifically whether one set is a proper subset or superset of the other, or if neither relationship holds. The function should return a string indicating the relationship.
The code should start with:
```python
def check_set_relationship(set1: set... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_set_relationship(set1: set, set2: set) -> str:
"""
Determine the relationship between two sets, specifically whether one set is a proper subset or superset of the other, or if neither relationship holds.
Args:
... |
code_exercise_27k | 5,305 | Write a Python function to truncate a list to the first n elements. The function should handle cases where n is greater than the length of the list, and it should raise a `ValueError` if n is negative. The code should start with:
```python
from typing import List
def truncate_list(lst: List, n: int) -> List:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def truncate_list(lst: List, n: int) -> List:
"""
Truncates the given list to the first n elements.
Args:
lst (List): The list to be truncated.
n (int): The number of elements to kee... |
code_exercise_27k | 5,306 | Write a Python function to check if a given value exists in a dictionary. The function should return `True` if the value is found in any of the dictionary's values, and `False` otherwise. The function should also raise a `TypeError` if the input is not a dictionary.
The code should start with:
```python
def check_valu... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_value_in_dict(dictionary, value):
"""
Check if a given value exists in the dictionary.
Args:
- dictionary (dict): The dictionary to be checked.
- value: The value to search for in the dictionary.
Retu... |
code_exercise_27k | 5,309 | Write a Python function to find the mode(s) of elements in a given list. The mode is the element(s) that appear most frequently in the list. If there are multiple elements with the same highest frequency, return all of them. If the list is empty or there is no mode, return an empty list. The function should handle list... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_mode(lst: List[Union[int, float, str]]) -> List[Union[int, float, str]]:
"""
Finds the mode(s) of elements in a given list.
The mode is the element(s) that appear most frequently in ... |
code_exercise_27k | 5,314 | Write a Python function to find the index of the smallest element in a given list. If there are multiple smallest elements, return the index of the first occurrence. The function should handle empty lists by raising a `ValueError`.
The code should start with:
```python
from typing import List
def find_smallest_index(... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_smallest_index(lst: List[int]) -> int:
"""
Find the index of the smallest element in a given list.
Args:
lst (List[int]): A list of integers.
Returns:
int: The index of... |
code_exercise_27k | 5,316 | Write a Python function to find the number of characters in the longest word in a given list of strings. The function should return the length of the longest word. The code should start with:
```python
from typing import List
def find_longest_word_length(word_list: List[str]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_longest_word_length(word_list: List[str]) -> int:
"""
Find the number of characters in the longest word in a given list of strings.
Args:
word_list (List[str]): A list of strings wh... |
code_exercise_27k | 5,317 | Write a Python function to find the largest sequence of consecutive integers in a given list of numbers. The function should return the largest sequence as a list of integers. If there are multiple sequences of the same maximum length, return the first one encountered.
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 find_largest_consecutive_sequence(numbers: List[int]) -> List[int]:
"""
Find the largest sequence of consecutive integers in a given list of numbers.
Args:
numbers (List[int]): A list of... |
code_exercise_27k | 5,318 | Write a Python function to find the largest number in a given list that is divisible by 3. If the list is empty or contains no numbers divisible by 3, the function should return `None`. The function should not raise any exceptions.
The code should start with:
```python
from typing import List, Optional
def find_large... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_largest_divisible_by_three(numbers: List[int]) -> Optional[int]:
"""
Find the largest number in a given list that is divisible by 3.
Args:
numbers (List[int]): A list of i... |
code_exercise_27k | 5,319 | Write a Python function to convert a given string to Morse code. The function should handle both uppercase and lowercase letters and ignore any characters that are not in the Morse code mapping. The Morse code representation should be separated by spaces between each character.
The code should start with:
```python
de... | Here is the Python code to solve the given problem in the markdown block:
```python
def string_to_morse_code(s: str) -> str:
"""
Converts a string to Morse code.
Args:
s (str): The string to convert to Morse code.
Returns:
str: The Morse code representation of the input string, with ea... |
code_exercise_27k | 5,327 | Write a Python function to check if a given key is present in a dictionary and return the corresponding value if the key exists. If the key does not exist, return a default value provided by the user. The function should handle cases where the dictionary is not of type `dict` by raising a `TypeError`.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_value_or_default(dictionary, key, default_value):
"""
Check if a given key is present in the dictionary and return the corresponding value.
If the key is not present, return a default value provided by the user.
... |
code_exercise_27k | 5,328 | Write a Python function to calculate the number of elements in the power set of a given set. The power set of a set is the set of all possible subsets, including the empty set and the set itself. The function should take a set as input and return an integer representing the number of elements in the power set.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
def power_set_size(s: set) -> int:
"""
Calculate the number of elements in the power set of a given set.
The power set of a set is the set of all possible subsets, including the empty set and the set itself.
Args:
... |
code_exercise_27k | 5,330 | Write a Python function to check if a list of characters is balanced. A list is considered balanced if it contains an equal number of opening and closing brackets, and each opening bracket has a corresponding closing bracket in the correct order. The function should return `True` if the list is balanced, and `False` ot... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_balanced_list(lst: List[str]) -> bool:
"""
Check if a list of characters is balanced.
A list is considered balanced if it contains an equal number of opening and closing brackets,
and eac... |
code_exercise_27k | 5,335 | Write a Python function to retrieve all the keys from a given dictionary. The function should handle the case where the input is not a dictionary by raising a `TypeError`. The code should start with:
```python
from typing import List
def get_all_keys(dictionary: dict) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_all_keys(dictionary: dict) -> List[str]:
"""
Retrieve all the keys from a given dictionary.
Args:
dictionary (dict): The input dictionary from which to retrieve the keys.
Return... |
code_exercise_27k | 5,336 | Write a Python function to find the longest common prefix of two lists. The function should compare the elements of the two lists and return the longest prefix that is common to both lists. The lists can contain any type of elements, but the comparison should be based on equality.
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, Any
def find_longest_common_prefix(list1: List[Any], list2: List[Any]) -> List[Any]:
"""
Find the longest common prefix of two lists.
Args:
list1 (List[Any]): The first list.
list2 ... |
code_exercise_27k | 5,339 | Write a Python function to calculate the square root of each element in a given list. The function should handle non-negative integers and floats. If any element in the list is negative, the function should raise a `ValueError`. If the input is not a list, the function should raise a `TypeError`.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def calculate_square_root(lst: List[float]) -> List[float]:
"""
Calculates the square root of each element in a given list.
Args:
lst (List[float]): The list of non-negative numb... |
code_exercise_27k | 5,340 | Write a Python function to generate all unique permutations of a given string and return them as a list of strings. The function should handle strings with duplicate characters by ensuring that each permutation is unique. The code should start with:
```python
from typing import List
def unique_permutations(input_strin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from itertools import permutations
def unique_permutations(input_string: str) -> List[str]:
"""
Generate all unique permutations of a given string and return them as a list of strings.
Args:
... |
code_exercise_27k | 5,342 | Write a Python function to create a deep copy of a dictionary. A deep copy means that the new dictionary will have its own copy of all the elements, including nested dictionaries, lists, and other objects. The function should handle dictionaries with various data types, including nested structures.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, Dict
import copy
def deep_copy_dict(source_dict: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Creates a deep copy of the given dictionary.
Args:
source_dict (Dict[Any, Any]): The dictionary to be ... |
code_exercise_27k | 5,345 | Write a Python function to retrieve all values from a given dictionary, ensuring that the input is a dictionary and handling cases where the dictionary might be empty. The function should return a list containing all the values from the dictionary. The code should start with:
```python
from typing import List, Dict
de... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def get_all_values(dictionary: Dict) -> List:
"""
Retrieve all values from a given dictionary.
Args:
dictionary (Dict): The input dictionary from which to retrieve the values.
Ret... |
code_exercise_27k | 5,346 | Write a Python function to generate all possible subsets of a given string. Each subset should be a unique combination of characters from the string, including the empty subset. The function should return a list of these subsets.
The code should start with:
```python
from typing import List
def generate_subsets(strin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_subsets(string: str) -> List[str]:
"""
Generate all possible subsets of a given string.
Args:
string (str): The input string from which to generate subsets.
Returns:
... |
code_exercise_27k | 5,350 | Write a Python function to convert a list of subsets into a string representation. Each subset is represented as a list of elements, and the final string should format each subset enclosed in curly braces `{}` and separated by a comma. The function should handle subsets containing integers, strings, or a mix of both.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def subsets_to_string(subsets: List[List[object]]) -> str:
"""
Convert a list of subsets to a string representation.
Args:
subsets (List[List[object]]): A list of subsets, where each subset ... |
code_exercise_27k | 5,351 | Write a Python function to create and return an empty set. Additionally, write a function to check if a given object is an instance of a set. The code should start with:
```python
def create_empty_set() -> set:
def is_set(obj) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def create_empty_set() -> set:
"""
Creates and returns an empty set.
Returns:
set: An empty set.
"""
return set()
def is_set(obj) -> bool:
"""
Checks if the given object is an instance of a set.
... |
code_exercise_27k | 5,353 | Write a Python function to find the sum of all elements in a list that are divisible by a given divisor. The function should take two parameters: a list of integers and an integer divisor. The function should return the sum of all elements in the list that are divisible by the divisor.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_divisible_by(numbers: List[int], divisor: int) -> int:
"""
Calculates the sum of all elements in a list that are divisible by a given divisor.
Args:
numbers (List[int]): A list of in... |
code_exercise_27k | 5,354 | Write a Python function to check if two dictionaries have the same key-value pairs, considering nested dictionaries as values. The function should recursively compare the dictionaries, including all nested structures.
The code should start with:
```python
from typing import Any, Dict
def are_dicts_equal(dict1: Dict[A... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, Dict
def are_dicts_equal(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> bool:
"""
Recursively checks if two dictionaries have the same key-value pairs, including nested dictionaries.
Args:
... |
code_exercise_27k | 5,356 | Write a Python function to find the intersection of two sets and return the result as a new set. The function should handle cases where one or both sets are empty. The code should start with:
```python
def find_intersection(set1: set, set2: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_intersection(set1: set, set2: set) -> set:
"""
Finds the intersection of two sets and returns the result as a new set.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
... |
code_exercise_27k | 5,361 | Write a Python function to shift all zeroes to the end of a given list while maintaining the relative order of the non-zero elements. The function should be efficient and should not use any additional data structures except for a constant amount of extra space.
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 shift_zeroes_to_end(lst: List[int]) -> List[int]:
"""
Shifts all zeroes to the end of the given list while maintaining the relative order of non-zero elements.
Args:
lst (List[int]): The... |
code_exercise_27k | 5,366 | Write a Python function to count the number of occurrences of each value in a given dictionary. The function should return a new dictionary where the keys are the unique values from the input dictionary, and the values are the counts of each respective value.
The code should start with:
```python
from typing import Di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_value_occurrences(dictionary: Dict[str, int]) -> Dict[int, int]:
"""
Count the number of occurrences of each value in a given dictionary.
Args:
dictionary (Dict[str, int]): The dic... |
code_exercise_27k | 5,367 | Write a Python function to find the frequency of each element in a given list and return the result as a dictionary. The keys of the dictionary should be the elements of the list, and the values should be their respective frequencies. The code should start with:
```python
from typing import List, Dict
def element_freq... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def element_frequency(lst: List[int]) -> Dict[int, int]:
"""
Calculate the frequency of each element in a given list.
Args:
lst (List[int]): The list of integers for which to calculate... |
code_exercise_27k | 5,369 | Write a Python function to find the key associated with the maximum value in a given dictionary. If the dictionary is empty, return `None`. The function should start with:
```python
def find_key_with_max_value(dictionary: dict) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_key_with_max_value(dictionary: dict) -> str:
"""
Finds the key associated with the maximum value in a dictionary.
Args:
dictionary (dict): The dictionary to find the key with the maximum value from.
Re... |
code_exercise_27k | 5,372 | Write a Python function to check if a given string is a valid parenthesis sequence. The function should return `True` if the sequence is valid and `False` otherwise. A valid parenthesis sequence is defined as a sequence where every opening parenthesis `'('` has a corresponding closing parenthesis `')'` and they are pro... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_parenthesis_sequence(sequence: str) -> bool:
"""
Checks if a given string is a valid parenthesis sequence.
Parameters:
sequence (str): A string of characters representing the parenthesis sequence.
Retu... |
code_exercise_27k | 5,373 | Write a Python function to find the union of two sets, ensuring that the function handles cases where the input sets are empty or contain duplicate elements. The function should return a new set containing all unique elements from both sets.
The code should start with:
```python
def union_of_sets(set1: set, set2: set)... | Here is the Python code to solve the given problem in the markdown block:
```python
def union_of_sets(set1: set, set2: set) -> set:
"""
Returns the union of two sets.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
set: The union set containing unique elem... |
code_exercise_27k | 5,375 | Write a Python function to split a given list of integers into two sublists: one containing all the positive numbers (including zero) and one containing all the negative numbers. The function should return a tuple where the first element is the list of negative numbers and the second element is the list of positive num... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def split_list_into_positive_and_negative(numbers: List[int]) -> Tuple[List[int], List[int]]:
"""
Splits a given list of integers into two sublists: one with positive numbers (including zero) and ... |
code_exercise_27k | 5,379 | Write a Python function to check if one set is a proper subset of another. A proper subset is a subset that is not equal to the superset. The function should return `True` if the first set is a proper subset of the second set, and `False` otherwise.
The code should start with:
```python
def is_proper_subset(set1: set,... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_proper_subset(set1: set, set2: set) -> bool:
"""
Check if set1 is a proper subset of set2.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
bool: True if set1 is a pr... |
code_exercise_27k | 5,380 | Write a Python function to calculate the sum of all numeric values in a given dictionary. The function should handle dictionaries with integer and float values. The function should raise a `TypeError` if the input is not a dictionary and a `ValueError` if any value in the dictionary is not numeric.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_dictionary_sum(dictionary: dict) -> float:
"""
Calculate the sum of all numeric values in a given dictionary.
Args:
dictionary (dict): The input dictionary containing numeric values.
Returns:
fl... |
code_exercise_27k | 5,381 | Write a Python function to find the maximum difference between two adjacent elements in a given list. The function should return the maximum difference, and it should raise a `ValueError` if the list is empty or contains less than two elements.
The code should start with:
```python
from typing import List
def max_adj... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_adjacent_difference(lst: List[int]) -> int:
"""
Find the maximum difference between two adjacent elements in a given list.
Args:
lst (List[int]): A list of integers.
Returns:
... |
code_exercise_27k | 5,383 | Write a Python function to find the maximum element in a given set. If the set is empty, the function should raise a `ValueError`. The function should iterate through the set to find the maximum element, ensuring that the solution is efficient and handles edge cases appropriately.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_maximum_element(s: set) -> int:
"""
Find the maximum element in a given set.
Args:
s (set): The set from which to find the maximum element.
Returns:
int: The maximum element in the set.
Ra... |
code_exercise_27k | 5,385 | Write a Python function to find the minimum element in a given set. The function should handle the case where the set is empty by raising a `ValueError`. The code should start with:
```python
def find_minimum_element(input_set: set) -> object:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_minimum_element(input_set: set) -> object:
"""
Find the minimum element in a given set.
Args:
input_set (set): The input set from which to find the minimum element.
Returns:
object: The minimum... |
code_exercise_27k | 5,387 | Write a Python function to remove duplicate characters from a given string and create a list of unique characters. The function should maintain the order of characters as they appear in the input string. The code should start with:
```python
from typing import List
def remove_duplicates(string: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates(string: str) -> List[str]:
"""
Remove duplicate characters from a given string and create a list of unique characters.
Args:
string (str): The input string from which d... |
code_exercise_27k | 5,389 | Write a Python function to sort a dictionary based on its values in descending order. If two or more values are the same, the keys should be sorted in ascending order. The function should return a new dictionary with the sorted key-value pairs.
The code should start with:
```python
from typing import Dict
def sort_di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_values_desc(dictionary: Dict[str, int]) -> Dict[str, int]:
"""
Sorts a dictionary based on its values in descending order. If two or more values are the same,
the keys are sorted in... |
code_exercise_27k | 5,391 | Write a Python function to sort a dictionary based on its keys in ascending order. The function should return a new dictionary with the original dictionary's key-value pairs sorted by keys. The code should start with:
```python
from typing import Dict
def sort_dict_by_keys(dict_to_sort: Dict[str, int]) -> Dict[str, in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_keys(dict_to_sort: Dict[str, int]) -> Dict[str, int]:
"""
Sorts a dictionary based on its keys in ascending order.
Args:
dict_to_sort (Dict[str, int]): The dictionary to be ... |
code_exercise_27k | 5,392 | Write a Python function to find the smallest number that is a multiple of all elements in a given list of positive integers. The function should efficiently compute this value using the least common multiple (LCM) of the numbers. The code should start with:
```python
from typing import List
from math import gcd
def fi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from math import gcd
def find_smallest_multiple(numbers: List[int]) -> int:
"""
Find the smallest number that is a multiple of all elements in a given list of positive integers.
Args:
number... |
code_exercise_27k | 5,393 | Write a Python function to find the second smallest value in a given dictionary. The dictionary contains key-value pairs where the values are integers. The function should handle cases where the dictionary has fewer than 2 distinct values by raising a `ValueError`.
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, Any
def find_second_smallest_value(dictionary: Dict[Any, int]) -> int:
"""
Find the second smallest value in a dictionary.
Args:
dictionary (Dict[Any, int]): The dictionary to search for th... |
code_exercise_27k | 5,395 | Write a Python function to check if two strings are anagrams. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. The function should ignore case and any whitespace in the strings. The code should start with:
```python
def are_anagrams(str1: str, str2: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(str1: str, str2: str) -> bool:
"""
Checks if two strings are anagrams.
An anagram is a word or phrase formed by rearranging the letters of another word or phrase.
This function ignores case and any whit... |
code_exercise_27k | 5,398 | Write a Python function to remove all elements from a given list that are less than a specified value. The function should return the modified list. The code should start with:
```python
from typing import List
def remove_elements_less_than(lst: List[int], value: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_elements_less_than(lst: List[int], value: int) -> List[int]:
"""
Removes all elements from a list that are less than a specified value.
Args:
lst (List[int]): The input list of in... |
code_exercise_27k | 5,399 | Write a Python function to find the second largest key in a given dictionary. If the dictionary has fewer than two keys, the function should return `None`. The function should handle dictionaries with integer keys only.
The code should start with:
```python
def get_second_largest_key(dictionary: dict) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_second_largest_key(dictionary: dict) -> int:
"""
Find the second largest key in a dictionary with integer keys.
Args:
dictionary (dict): The dictionary to find the second largest key from.
Returns:
... |
code_exercise_27k | 5,401 | Write a Python function to count the number of occurrences of a specific character in a given string. The function should be case-sensitive, meaning 'A' and 'a' are considered different characters. The code should start with:
```python
def count_character_occurrences(string: str, char: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_character_occurrences(string: str, char: str) -> int:
"""
Counts the number of occurrences of a specific character in a given string.
Args:
string (str): The input string in which to search for occurrences... |
code_exercise_27k | 5,402 | Write a Python function to create a set of unique characters from a given string, while preserving the order of their first occurrence in the string. The function should start with:
```python
from typing import Set
def create_ordered_unique_char_set(string: str) -> Set[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import Set
def create_ordered_unique_char_set(string: str) -> Set[str]:
"""
Create a set of unique characters from a string, preserving the order of their first occurrence.
Args:
string (str): The inp... |
code_exercise_27k | 5,407 | Write a Python function to remove duplicates from a given set and return the result as a new set. The function should ensure that the original set remains unchanged. The code should start with:
```python
def remove_duplicates(set_data: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_duplicates(set_data: set) -> set:
"""
Remove duplicates from a given set and return the result as a new set.
Args:
set_data (set): The original set containing elements.
Returns:
set: The set ... |
code_exercise_27k | 5,408 | Write a Python function to find the largest number in a given list that is a multiple of 3. If no such number exists, the function should return `None`. The function should be efficient and handle various edge cases, such as an empty list or a list with no multiples of 3.
The code should start with:
```python
from typ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_largest_multiple_of_three(numbers: List[int]) -> Optional[int]:
"""
Find the largest number in the given list that is a multiple of 3.
Args:
numbers (List[int]): A lis... |
code_exercise_27k | 5,409 | Write a Python function to remove common elements from two sets and store the result in a new set. The function should return a tuple containing two sets: the first set with elements that are unique to the first set, and the second set with elements that are unique to the second set. The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_common_elements(set1: set, set2: set) -> tuple:
"""
Removes common elements from two sets and stores the result in two new sets.
Parameters:
- set1 (set): The first set.
- set2 (set): The second set.
... |
code_exercise_27k | 5,411 | Write a Python function to find the length of the longest word in a given list of words. The function should be efficient and handle various edge cases, such as an empty list or a list with words of the same length. The code should start with:
```python
from typing import List
def find_longest_word_length(word_list: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_longest_word_length(word_list: List[str]) -> int:
"""
Find the length of the longest word in a given list of words.
Args:
word_list (List[str]): A list of words (strings) to check.
... |
code_exercise_27k | 5,415 | Write a Python function to filter out key-value pairs from a dictionary where the value is greater than a given number. The function should return a new dictionary containing only the key-value pairs where the value is greater than the specified number. 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 filter_dict_values(dictionary: Dict[str, Union[int, float]], number: Union[int, float]) -> Dict[str, Union[int, float]]:
"""
Filter out key-value pairs from a dictionary where the value is gre... |
code_exercise_27k | 5,416 | Write a Python function to check if one set is a proper subset of another. A proper subset is defined as a set that is entirely contained within another set but is not equal to it. The function should return `True` if the first set is a proper subset of the second set, and `False` otherwise. The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_proper_subset(set1: set, set2: set) -> bool:
"""
Check if set1 is a proper subset of set2.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
bool: True if set1 is a pr... |
code_exercise_27k | 5,418 | Write a Python function to find the length of the longest string value in a given dictionary. The function should handle dictionaries with mixed data types, including non-string values, and should return the length of the longest string found. If the dictionary is empty, the function should raise a `ValueError`.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_longest_string_length(dictionary: dict) -> int:
"""
Find the length of the longest string value in a dictionary.
Args:
dictionary (dict): The input dictionary containing key-value pairs.
Returns:
... |
code_exercise_27k | 5,420 | Write a Python function to remove the intersection of two sets from one of the sets. The function should take two sets as input and return the first set with all elements that are common with the second set removed. The function should handle cases where the input is not a set by raising a `TypeError`.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_intersection(set1: set, set2: set) -> set:
"""
Remove the intersection of two sets from set1.
Args:
set1 (set): The first set from which to remove the intersection.
set2 (set): The second set whos... |
code_exercise_27k | 5,422 | Write a Python function to reverse a given string without using any built-in functions or string slicing. The function should iterate through the string and construct the reversed string manually.
The code should start with:
```python
def reverse_string(string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(string: str) -> str:
"""
Reverses a given string without using any built-in functions or string slicing.
Args:
string (str): The input string to be reversed.
Returns:
str: The reverse... |
code_exercise_27k | 5,423 | Write a Python function to map each key in a dictionary to its square value. The function should take a dictionary as input and return a new dictionary where each key from the input dictionary is mapped to the square of its corresponding value. The code should start with:
```python
from typing import Dict
def square_d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def square_dictionary_values(input_dict: Dict[str, int]) -> Dict[str, int]:
"""
Maps each key in a dictionary to its square value.
Args:
input_dict (Dict[str, int]): A dictionary containing ... |
code_exercise_27k | 5,424 | Write a Python function to generate all possible combinations of elements from two sets. Each combination should be a tuple consisting of one element from the first set and one element from the second set. The function should return a set of these combinations.
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 Set
def get_all_combinations(set1: Set[int], set2: Set[str]) -> Set[tuple]:
"""
Generates all possible combinations of elements from two sets.
Args:
set1 (Set[int]): The first set of integers.
... |
code_exercise_27k | 5,426 | Write a Python function to filter out key-value pairs from a dictionary where the key contains a specific substring. The function should return a new dictionary containing only the key-value pairs where the key contains the specified substring. The code should start with:
```python
from typing import Dict
def filter_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_substring(dictionary: Dict[str, any], substring: str) -> Dict[str, any]:
"""
Filters out key-value pairs from a dictionary where the key contains a specific substring.
Args:
... |
code_exercise_27k | 5,430 | Write a Python function to convert all string values in a dictionary to lowercase. The function should iterate through the dictionary, check if each value is a string, and if so, convert it to lowercase. Non-string values should remain unchanged. The function should return a new dictionary with the updated values.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_dict_values_to_lowercase(dictionary: dict) -> dict:
"""
Converts all string values in a dictionary to lowercase.
Args:
dictionary (dict): The dictionary whose string values need to be converted.
Ret... |
code_exercise_27k | 5,431 | Write a Python function to check if a given string is a valid palindrome, considering only alphanumeric characters and ignoring cases, spaces, and punctuation. The function should return `True` if the string is a palindrome and `False` otherwise. The code should start with:
```python
def is_valid_palindrome(s: str) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_palindrome(s: str) -> bool:
"""
Check if a given string is a valid palindrome, considering only alphanumeric characters and ignoring cases, spaces, and punctuation.
Args:
s (str): The string to check fo... |
code_exercise_27k | 5,434 | Write a Python function to filter out duplicate string values from a given dictionary. The function should return a new dictionary that contains only the first occurrence of each string value from the original dictionary. The code should start with:
```python
from typing import Dict
def filter_duplicate_values(diction... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def filter_duplicate_values(dictionary: Dict[str, str]) -> Dict[str, str]:
"""
Filter out duplicate string values from a given dictionary.
Args:
dictionary (Dict[str, str]): The dictionary t... |
code_exercise_27k | 5,435 | Write a Python function to split a given list of integers into two sublists: one containing all the even numbers and the other containing all the odd numbers. The function should return a tuple with the two sublists. The code should start with:
```python
from typing import List, Tuple
def split_list_into_even_odd(numb... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def split_list_into_even_odd(numbers: List[int]) -> Tuple[List[int], List[int]]:
"""
Splits a given list of integers into two sublists: one containing all even numbers and the other containing all... |
code_exercise_27k | 5,438 | Write a Python function to filter out key-value pairs from a dictionary where the value is an empty string. The function should return a new dictionary containing only the key-value pairs where the value is not an empty string. The code should start with:
```python
from typing import Dict
def filter_non_empty_values(d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def filter_non_empty_values(dictionary: Dict[str, str]) -> Dict[str, str]:
"""
Filter out key-value pairs from a dictionary where the value is an empty string.
Args:
dictionary (Dict[str, st... |
code_exercise_27k | 5,440 | Write a Python function to check if a given set is a superset of multiple sets. The function should take a main set and a list of subsets as input and return `True` if the main set is a superset of all the subsets, and `False` otherwise. The code should start with:
```python
from typing import List, Set
def is_superse... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Set
def is_superset_of_all(main_set: Set[int], subsets: List[Set[int]]) -> bool:
"""
Check if a given set is a superset of multiple sets.
Args:
main_set (Set[int]): The main set to check if... |
code_exercise_27k | 5,442 | Write a Python function to generate all possible subsets from a given set. The function should handle both lists and sets as input and return a list of all possible subsets, including the empty set and the original set itself. The code should start with:
```python
from typing import List, Union
def generate_subsets(se... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def generate_subsets(set_list: Union[List, set]) -> List[List]:
"""
Generate all possible subsets from a given set.
Args:
set_list (Union[List, set]): The input set, which can be a li... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.