source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 3,481 | Write a Python function to move all zeros to the end of a given list while maintaining the relative order of the non-zero elements. The function should not use any additional data structures except for a constant amount of extra space. The code should start with:
```python
from typing import List
def move_zeros(lst: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def move_zeros(lst: List[int]) -> List[int]:
"""
Moves all zeros to the end of the given list while maintaining the relative order of non-zero elements.
Args:
lst (List[int]): The input list... |
code_exercise_27k | 3,483 | Write a Python function to determine if one set is a proper subset of another set. A proper subset is defined as a set that contains all elements of 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 ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_proper_subset(set1: set, set2: set) -> bool:
"""
Determine if set1 is a proper subset of set2.
Args:
set1 (set): The first set to check.
set2 (set): The second set to check against.
Returns:
... |
code_exercise_27k | 3,485 | Write a Python function to merge two dictionaries into a single dictionary. If both dictionaries have the same key, the value from the second dictionary should overwrite the value from the first dictionary. The function should handle any type of dictionary keys and values.
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 Dict, Any
def merge_dictionaries(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Merge two dictionaries into a single dictionary. If both dictionaries have the same key,
the value fro... |
code_exercise_27k | 3,487 | Write a Python function to rename elements in a list by adding a prefix to each element. The function should return a new list with the renamed elements. The original list should remain unchanged.
The code should start with:
```python
from typing import List
def rename_list_elements_with_prefix(input_list: List[str],... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def rename_list_elements_with_prefix(input_list: List[str], prefix: str) -> List[str]:
"""
Rename elements in a list by adding a prefix to each element.
Args:
input_list (List[str]): The inp... |
code_exercise_27k | 3,488 | Write a Python function to find the longest word in a given list of words. If there are multiple words with the same maximum length, the function should return the first occurrence of such a word. The function should handle an empty list by returning an empty string.
The code should start with:
```python
from typing i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_longest_word(words: List[str]) -> str:
"""
Finds the longest word in a given list of words.
Args:
words (List[str]): A list of words.
Returns:
str: The longest word in ... |
code_exercise_27k | 3,489 | Write a Python function to check if a given string contains only uppercase letters. The function should return `True` if all characters in the string are uppercase letters, and `False` otherwise. The function should also raise a `TypeError` if the input is not a string.
The code should start with:
```python
def is_all... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_all_uppercase(s: str) -> bool:
"""
Checks if a string contains only uppercase letters.
Args:
s (str): The string to check.
Returns:
bool: True if the string contains only uppercase letters, False... |
code_exercise_27k | 3,490 | Write a Python function to find the maximum value in a given set of integers. If the set is empty, the function should return `None`. The function should be efficient and handle edge cases appropriately.
The code should start with:
```python
def find_max_value(my_set: set) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_max_value(my_set: set) -> int:
"""
Find the maximum value in a given set of integers.
Args:
my_set (set): The set of integers in which to find the maximum value.
Returns:
int: The maximum value... |
code_exercise_27k | 3,491 | Write a Python function to remove a specific key-value pair from a dictionary. If the key is not present in the dictionary, the function should return the original dictionary without any modifications. The function should not raise any exceptions.
The code should start with:
```python
from typing import Dict, Any
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def remove_key_value_pair(dic: Dict[Any, Any], key: Any) -> Dict[Any, Any]:
"""
Remove a specific key-value pair from a dictionary. If the key is not present,
return the original dictionary with... |
code_exercise_27k | 3,492 | Write a Python function to check if a given string contains only lowercase letters. The function should return `True` if all characters in the string are lowercase letters, and `False` otherwise. The function should handle strings of any length, including empty strings.
The code should start with:
```python
def contai... | Here is the Python code to solve the given problem in the markdown block:
```python
def contains_only_lowercase(string: str) -> bool:
"""
Check if a string contains only lowercase letters.
Args:
string (str): The input string to be checked.
Returns:
bool: True if the string contains on... |
code_exercise_27k | 3,495 | Write a Python function to replace the value associated with a specific key in a dictionary. If the key does not exist in the dictionary, the function should raise a `KeyError`. The function should return the modified dictionary.
The code should start with:
```python
def replace_value(dictionary: dict, key, new_value)... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_value(dictionary: dict, key, new_value) -> dict:
"""
Replace the value associated with a specific key in a dictionary.
Args:
dictionary (dict): The dictionary in which to replace the value.
key: ... |
code_exercise_27k | 3,497 | Write a Python function to count the number of key-value pairs in a given dictionary. The function should return the count as an integer. The code should start with:
```python
def count_dict_pairs(dictionary: dict) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def count_dict_pairs(dictionary: dict) -> int:
"""
Counts the number of key-value pairs in a given dictionary.
Args:
dictionary (dict): The dictionary whose key-value pairs need to be counted.
Returns:
... |
code_exercise_27k | 3,501 | Write a Python function to merge two dictionaries, ensuring that if both dictionaries have the same key, the value from the second dictionary should overwrite the value from the first dictionary. The function should handle cases where the input dictionaries are empty or contain nested dictionaries. The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def merge_dicts(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Merges two dictionaries into a single dictionary. If both dictionaries have the same key,
the value from the ... |
code_exercise_27k | 3,502 | Write a Python function to find the largest sum of two distinct numbers in a given list of integers. The function should ensure that the two numbers chosen are distinct and that their sum is the largest possible among all pairs of distinct numbers in the list.
The code should start with:
```python
from typing import L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_largest_sum_of_two_distinct_numbers(numbers: List[int]) -> int:
"""
Find the largest sum of two distinct numbers in a given list of integers.
Args:
numbers (List[int]): A list of in... |
code_exercise_27k | 3,504 | Write a Python function to determine if a given year is a leap year and a multiple of 400. A leap year is defined as a year that is divisible by 4, but not by 100 unless it is also divisible by 400. The function should return `True` if the year is both a leap year and a multiple of 400, and `False` otherwise.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_leap_year_and_multiple_of_400(year: int) -> bool:
"""
Determine if a given year is a leap year and a multiple of 400.
Args:
year (int): The year to be checked.
Returns:
bool: True if the year is ... |
code_exercise_27k | 3,505 | Write a Python function to update the values of multiple keys in a dictionary. The function should take two dictionaries as input: the first dictionary is the one to be updated, and the second dictionary contains the keys and their updated values. The function should return the updated dictionary. The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def update_dict_values(dictionary: Dict[str, int], updates: Dict[str, int]) -> Dict[str, int]:
"""
Update the values of multiple keys in a dictionary.
Args:
dictionary (Dict[str, int]): The ... |
code_exercise_27k | 3,510 | Write a Python function to calculate the sum of all elements in a given set. The function should handle sets containing integers, floats, and a mix of both. The function should also raise a `TypeError` if the input is not a set.
The code should start with:
```python
def sum_of_set_elements(s: set) -> int | float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_set_elements(s: set) -> int | float:
"""
Calculates the sum of all elements in a given set.
Args:
s (set): The set whose elements are to be summed.
Returns:
int or float: The sum of all eleme... |
code_exercise_27k | 3,515 | Write a Python function to calculate the average of all numeric elements in a given set. The function should handle cases where the set is empty or does not contain any numeric elements by raising appropriate exceptions. The code should start with:
```python
def calculate_average(elements: set) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_average(elements: set) -> float:
"""
Calculates the average of all numeric elements in a given set.
Args:
elements (set): A set containing numeric elements.
Returns:
float: The average of ... |
code_exercise_27k | 3,518 | Write a Python function to find the second smallest element in a given set of numbers. If the set is empty or contains less than two elements, the function should return `None`. The function should also raise a `TypeError` if the provided argument is not a set.
The code should start with:
```python
def get_second_smal... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_second_smallest_number(s: set) -> int or None:
"""
Returns the second smallest element in a set of numbers.
Args:
s (set): A set of numbers.
Returns:
int or None: The second smallest number in t... |
code_exercise_27k | 3,521 | Write a Python function to remove all key-value pairs from a given dictionary and return the modified dictionary. The function should handle dictionaries with various types of keys and values. The code should start with:
```python
def remove_all_key_value_pairs(d: dict) -> dict:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_all_key_value_pairs(d: dict) -> dict:
"""
Remove all key-value pairs from the given dictionary and return the modified dictionary.
Args:
d (dict): The dictionary from which to remove all key-value pairs.
... |
code_exercise_27k | 3,523 | Write a Python function to find the kth smallest element in a given list of integers using the Quickselect algorithm. The function should be efficient and handle edge cases such as an empty list or an invalid k value.
The code should start with:
```python
from typing import List, Optional
def find_kth_smallest(arr: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def partition(arr: List[int], low: int, high: int) -> int:
"""
Partition the array using the last element as the pivot.
Args:
arr (List[int]): The list of integers to partition.
... |
code_exercise_27k | 3,528 | Write a Python function to find the difference between consecutive elements in a list. The function should return a list of differences. If the input list is empty, the function should raise a `ValueError`.
The code should start with:
```python
from typing import List
def find_differences(lst: List[int]) -> List[int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_differences(lst: List[int]) -> List[int]:
"""
Find the difference between consecutive elements in a list.
Args:
lst (List[int]): A list of numeric elements.
Returns:
Li... |
code_exercise_27k | 3,529 | Write a Python function to determine if two dictionaries have at least one common key. The function should return `True` if there is at least one key that exists in both dictionaries, and `False` otherwise. The code should start with:
```python
def have_common_key(dict1: dict, dict2: dict) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def have_common_key(dict1: dict, dict2: dict) -> bool:
"""
Determine if two dictionaries have at least one common key.
Args:
dict1 (dict): The first dictionary.
dict2 (dict): The second dictionary.
Retu... |
code_exercise_27k | 3,532 | Write a Python function to check if a given string contains only alphanumeric characters. An alphanumeric character is defined as either a letter (a-z, A-Z) or a digit (0-9). The function should return `True` if the string contains only alphanumeric characters, and `False` otherwise. The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_alphanumeric(string: str) -> bool:
"""
Check if a string contains only alphanumeric characters.
Args:
string (str): The string to be checked.
Returns:
bool: True if the string contains only alpha... |
code_exercise_27k | 3,533 | Write a Python function to find the largest common subset of multiple sets. The function should take a list of sets as input and return a set containing the largest common subset of the input sets. If no sets are provided, the function should return an empty set.
The code should start with:
```python
from typing impor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Set
def find_largest_common_subset(sets: List[Set[int]]) -> Set[int]:
"""
Finds the largest common subset of multiple sets.
Args:
sets (List[Set[int]]): A list of sets containing integers.
... |
code_exercise_27k | 3,537 | Write a Python function to compute the Cartesian product of two sets. The Cartesian product of two sets \( A \) and \( B \) is the set of all ordered pairs \( (a, b) \) where \( a \) is in \( A \) and \( b \) is in \( B \). The function should return a set containing these ordered pairs.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def cartesian_product(set1: Set[int], set2: Set[int]) -> Set[tuple]:
"""
Compute the Cartesian product of two sets.
The Cartesian product of two sets A and B is the set of all ordered pairs (a, b)
... |
code_exercise_27k | 3,538 | Write a Python function to sort a dictionary based on its values in ascending order. The function should return a new dictionary with the same keys but sorted values. The code should start with:
```python
from typing import Dict
def sort_dict_by_values(dictionary: Dict[str, int]) -> Dict[str, int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_values(dictionary: Dict[str, int]) -> Dict[str, int]:
"""
Sorts a dictionary based on its values in ascending order.
Args:
dictionary (Dict[str, int]): The dictionary to be ... |
code_exercise_27k | 3,539 | Write a Python function to determine if a given number is a multiple of 2, 3, or 7, but not a multiple of any combination of these numbers (i.e., not a multiple of 6, 14, or 21). The function should return `True` if the number meets the condition, and `False` otherwise.
The code should start with:
```python
def is_mul... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_multiple_of_2_3_or_7_but_not_combination(num: int) -> bool:
"""
Determines if a number is a multiple of 2, 3, or 7, but not a multiple of any combination of these numbers.
Args:
num (int): The number to be ch... |
code_exercise_27k | 3,540 | Write a Python function to find the square roots of all the elements in a given list of non-negative numbers. The function should handle the following:
1. Ensure the input is a list.
2. Ensure all elements in the list are non-negative.
3. Return a new list containing the square roots of the elements in the input list.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def find_square_roots(numbers: List[float]) -> List[float]:
"""
Calculates the square roots of all the elements in a list of non-negative numbers.
Args:
numbers (List[float]): A ... |
code_exercise_27k | 3,544 | Write a Python function to calculate the cube of all elements in a given list. The function should return a new list containing the cube of each element from the input list. The function should handle both integer and floating-point numbers. The code should start with:
```python
from typing import List
def calculate_c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_cubes(numbers: List[float]) -> List[float]:
"""
Calculate the cube of all elements in the given list.
Args:
numbers (List[float]): A list of integer or floating-point numbers.
... |
code_exercise_27k | 3,547 | Write a Python function to create a dictionary of words and their frequencies from a given text. The function should handle punctuation and case sensitivity by converting the text to lowercase and removing all non-alphanumeric characters except spaces. The function should return a dictionary where the keys are words an... | Here is the Python code to solve the given problem in the markdown block:
```python
def create_word_frequency(text: str) -> dict:
"""
Creates a dictionary of words and their frequencies from a given text.
Args:
text (str): The input text.
Returns:
dict: A dictionary containing words as... |
code_exercise_27k | 3,553 | Write a Python function to calculate the factorial of a given number using a list. The function should handle non-negative integers only. If the input number is negative, the function should raise a `ValueError`. The function should start with:
```python
def factorial_with_list(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def factorial_with_list(n: int) -> int:
"""
Calculate the factorial of a given non-negative integer using a list.
Args:
n (int): The non-negative integer for which the factorial needs to be calculated.
Returns:... |
code_exercise_27k | 3,555 | Write a Python function to check if a string contains only whitespace characters. The function should return `True` if the string contains only whitespace characters, and `False` otherwise. The code should start with:
```python
def is_only_whitespace(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_only_whitespace(s: str) -> bool:
"""
Check if a string contains only whitespace characters.
Args:
s (str): The input string to check.
Returns:
bool: True if the string contains only whitespace ch... |
code_exercise_27k | 3,556 | Write a Python function to generate all possible combinations of elements from two given sets. Each combination should be a tuple containing one element from each set. The function should return a set of these tuples.
The code should start with:
```python
from typing import Set, Any
def generate_combinations(set1: Se... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set, Any
from itertools import product
def generate_combinations(set1: Set[Any], set2: Set[Any]) -> Set[Any]:
"""
Generates a set with all possible combinations of elements from two given sets.
Args:
... |
code_exercise_27k | 3,561 | Write a Python function to check if one dictionary is a subset of another dictionary. A dictionary `dict1` is considered a subset of `dict2` if every key in `dict1` exists in `dict2` and the corresponding values are equal.
The code should start with:
```python
def is_subset(dict1: dict, dict2: dict) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_subset(dict1: dict, dict2: dict) -> bool:
"""
Check if dict1 is a subset of dict2.
Args:
dict1 (dict): The dictionary to check if it is a subset.
dict2 (dict): The dictionary to check if it contains d... |
code_exercise_27k | 3,562 | Write a Python function to find the sum of all prime numbers in a given list of integers. The function should include a helper function to check if a number is prime. The code should start with:
```python
from typing import List
def sum_of_primes(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
if n <... |
code_exercise_27k | 3,565 | Write a Python function to find the difference between the maximum and minimum numbers in a given list of integers. The function should handle lists of any length, including empty lists, and return the difference as an integer. If the list is empty, the function should raise 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 List
def find_difference(numbers: List[int]) -> int:
"""
Finds the difference between the maximum and minimum numbers in a list.
Args:
numbers (List[int]): A list of integers.
Returns:
... |
code_exercise_27k | 3,568 | Write a Python function to count the number of even and odd numbers in a given list of integers. The function should return a tuple containing the count of even numbers followed by the count of odd numbers. The code should start with:
```python
from typing import List, Tuple
def count_even_odd(numbers: List[int]) -> T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def count_even_odd(numbers: List[int]) -> Tuple[int, int]:
"""
Counts the number of even and odd numbers in a given list of integers.
Args:
numbers (List[int]): A list of integers.
... |
code_exercise_27k | 3,569 | Write a Python function to determine if two sets have the same sum of squared differences. The function should compare the sum of squared differences of each set with itself. The code should start with:
```python
from typing import Set
def have_same_sum_of_squared_differences(set1: Set[float], set2: Set[float]) -> boo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def have_same_sum_of_squared_differences(set1: Set[float], set2: Set[float]) -> bool:
"""
Determines if two sets have the same sum of squared differences.
The sum of squared differences for a set wit... |
code_exercise_27k | 3,572 | Write a Python function to count the occurrences of each element in a given list without using any built-in functions or libraries. The function should return a dictionary where the keys are the elements of the list and the values are the counts of their occurrences.
The code should start with:
```python
from typing i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_occurrences(lst: List[int]) -> Dict[int, int]:
"""
Count the occurrence of each element in a list without using any built-in functions.
Args:
lst (List[int]): The input list ... |
code_exercise_27k | 3,576 | Write a Python function to find the number of elements that are common in two lists without using any built-in functions. The function should be efficient and avoid unnecessary computations. The code should start with:
```python
from typing import List
def find_common_elements(list1: List[int], list2: List[int]) -> in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_common_elements(list1: List[int], list2: List[int]) -> int:
"""
Finds the number of elements that are common in two lists without using any built-in functions.
Args:
list1 (List[int... |
code_exercise_27k | 3,577 | Write a Python function to merge two dictionaries into a single dictionary. If both dictionaries have the same key, the value from the second dictionary should overwrite the value from the first dictionary. The function should start with:
```python
def merge_dictionaries(dict1: dict, dict2: dict) -> dict:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def merge_dictionaries(dict1: dict, dict2: dict) -> dict:
"""
Merge two dictionaries into a single dictionary. If both dictionaries have the same key,
the value from the second dictionary will overwrite the value from the fi... |
code_exercise_27k | 3,578 | Write a Python function to concatenate two dictionaries into a new dictionary, ensuring that if there are any overlapping keys, the values from the second dictionary overwrite the values from the first dictionary. The function should handle dictionaries with any types of values, including nested dictionaries.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def concatenate_dicts(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Concatenates two dictionaries into a new dictionary. If there are overlapping keys,
the values from the... |
code_exercise_27k | 3,579 | Write a Python function to convert a list of strings into a single string without using any built-in functions like `join`. The function should concatenate all the characters from each string in the list into a single string. The code should start with:
```python
from typing import List
def list_to_string(lst: List[st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def list_to_string(lst: List[str]) -> str:
"""
Convert a list of strings into a single string without using any built-in functions.
Args:
lst (List[str]): The list of strings to be converted... |
code_exercise_27k | 3,582 | Write a Python function to check if a given key exists in a dictionary and return the corresponding value if the key exists, otherwise return a default value. The function should handle cases where the dictionary is empty or the key is not found.
The code should start with:
```python
from typing import Any, Dict, Opti... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, Dict, Optional
def get_value_or_default(dictionary: Dict[Any, Any], key: Any, default: Optional[Any] = None) -> Optional[Any]:
"""
Checks if a given key exists in a dictionary and returns the correspondi... |
code_exercise_27k | 3,585 | Write a Python function to find the longest common prefix of a list of strings without using any built-in functions. The function should iterate over each character of the first string and compare it with the corresponding character in the other strings. If a mismatch is found, the function should return the prefix up ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_common_prefix(str_list: List[str]) -> str:
"""
Find the longest common prefix of a list of strings.
Args:
str_list (List[str]): A list of strings to find the longest common prefi... |
code_exercise_27k | 3,586 | Write a Python function to determine if one set is a strict superset of another set. A set `set1` is considered a strict superset of `set2` if `set1` contains all elements of `set2` and `set1` is not equal to `set2`.
The code should start with:
```python
def is_strict_superset(set1: set, set2: set) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_strict_superset(set1: set, set2: set) -> bool:
"""
Determine if set1 is a strict superset of set2.
Args:
set1 (set): The first set to be checked.
set2 (set): The second set to be checked.
Returns... |
code_exercise_27k | 3,587 | Write a Python function to remove a specified key from a given dictionary. If the key does not exist in the dictionary, the function should return the dictionary unchanged. The function should handle both the presence and absence of the key appropriately.
The code should start with:
```python
def remove_key(dictionary... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_key(dictionary: dict, key) -> dict:
"""
Remove a specific key from a dictionary. If the key does not exist, the dictionary remains unchanged.
Args:
dictionary (dict): The dictionary from which the key nee... |
code_exercise_27k | 3,588 | Write a Python function to find the element with the most occurrences in a given list without using any built-in functions like `max`, `sorted`, or `collections.Counter`. The function should handle empty lists by raising a `ValueError`.
The code should start with:
```python
from typing import List, Any
def find_most_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def find_most_occurrences(lst: List[Any]) -> Any:
"""
Find the element with the most occurrences in a given list without using built-in functions.
Args:
lst (List[Any]): The input list ... |
code_exercise_27k | 3,590 | Write a Python function to sort a dictionary by its keys in descending order. The function should return a new dictionary with the keys sorted in descending order. The original dictionary should remain unchanged.
The code should start with:
```python
from typing import Dict
def sort_dict_by_key_descending(dictionary:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_key_descending(dictionary: Dict[str, int]) -> Dict[str, int]:
"""
Sorts a dictionary by its keys in descending order and returns a new dictionary.
Args:
dictionary (Dict[str... |
code_exercise_27k | 3,592 | Write a Python function to find the second-largest element in a given list without using any built-in functions. The function should handle lists with at least two elements and ensure that the list contains only numerical values. If the list has fewer than two elements or contains non-numerical values, the function sho... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_second_largest(list_nums):
"""
Finds the second-largest element in a given list.
Args:
list_nums (list): The list with numerical elements.
Returns:
int: The second-largest element in the list.
Rai... |
code_exercise_27k | 3,595 | Write a Python function to find the maximum and minimum values in a dictionary. The function should return a tuple containing the maximum value and the minimum value. If the dictionary is empty, the function should raise a `ValueError`.
The code should start with:
```python
def find_max_min_values(dictionary: dict) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_max_min_values(dictionary: dict) -> tuple:
"""
Find the maximum and minimum values in a given dictionary.
Args:
dictionary (dict): A dictionary containing key-value pairs.
Returns:
tuple: A tup... |
code_exercise_27k | 3,596 | Write a Python function to check if a given string starts with an uppercase letter and ends with a digit. The function should return `True` if both conditions are met, and `False` otherwise. The code should start with:
```python
def check_string_format(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def check_string_format(string: str) -> bool:
"""
Check if a string starts with an uppercase letter and ends with a digit.
Args:
string (str): The string to be checked.
Returns:
bool: True if the string... |
code_exercise_27k | 3,597 | Write a Python function to check if a given set is a subset of another set. The function should return `True` if all elements of the first set are present in the second set, and `False` otherwise. The function should handle any type of elements that can be stored in a set, including numbers, strings, and other hashable... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_subset(set1: set, set2: set) -> bool:
"""
Check if set1 is a subset of set2.
Args:
set1 (set): The first set to check.
set2 (set): The second set to check against.
Returns:
bool: True if ... |
code_exercise_27k | 3,598 | Write a Python function to find all the prime numbers within a given range using list comprehension. The function should take two integers, `start` and `end`, as input and return a list of all prime numbers within this range (inclusive). The function should be efficient and use list comprehension for the prime number g... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_prime_numbers(start: int, end: int) -> List[int]:
"""
Finds all the prime numbers within a given range using list comprehension.
Args:
start (int): The starting number of the range.... |
code_exercise_27k | 3,599 | Write a Python function to check if a given string contains only letters and digits. The function should return `True` if the string contains only letters and digits, and `False` otherwise. The code should start with:
```python
def is_alphanumeric(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_alphanumeric(s: str) -> bool:
"""
Check if a given string contains only letters and digits.
Args:
s (str): The input string to be checked.
Returns:
bool: True if the string contains only letters ... |
code_exercise_27k | 3,601 | Write a Python function to get the first and last element of a list without using any built-in functions. The function should handle edge cases such as an empty list and return `None` in such cases. The code should start with:
```python
def get_first_and_last_element(lst):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_first_and_last_element(lst):
"""
Get the first and last element of a list without using any built-in functions.
Args:
lst (list): The input list from which to get the first and last element.
... |
code_exercise_27k | 3,603 | Write a Python function to iterate over a dictionary and modify its values based on a given transformation function. The transformation function should be applied to each value in the dictionary. The function should return the modified dictionary.
The code should start with:
```python
from typing import Dict, Callable... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Callable
def modify_dict_values(dictionary: Dict, transformation: Callable) -> Dict:
"""
Iterate over a dictionary and modify its values using a given transformation function.
Args:
diction... |
code_exercise_27k | 3,604 | Write a Python function to calculate the average of even and odd numbers separately in a given list of integers. The function should return a tuple containing the average of even numbers and the average of odd numbers. If there are no even or odd numbers in the list, the corresponding average should be 0. The function ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def calculate_average_even_odd(numbers: List[int]) -> Tuple[float, float]:
"""
Calculate the average of even and odd numbers separately in a list.
Args:
numbers (List[int]): A list of... |
code_exercise_27k | 3,607 | Write a Python function to merge two dictionaries into a new dictionary. If there are any common keys in the two dictionaries, the values from the second dictionary should overwrite the values from the first dictionary. The function should be efficient and handle any type of dictionary values, including nested dictiona... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def merge_dictionaries(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Merge two dictionaries into a new dictionary.
This function takes two dictionaries, dict1 and dict2, ... |
code_exercise_27k | 3,608 | Write a Python function to determine if a given list is a supersequence of another list. A list `superseq` is considered a supersequence of another list `subseq` if every element of `subseq` appears in `superseq` in the same order, but not necessarily consecutively.
The function should start with:
```python
from typin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_supersequence(superseq: List[int], subseq: List[int]) -> bool:
"""
Determine if a list `superseq` is a supersequence of another list `subseq`.
Args:
superseq (List[int]): The potentia... |
code_exercise_27k | 3,610 | Write a Python function to find the symmetric difference between two sets, which is defined as the set of elements that are in either of the sets but not in their intersection. The function should return the symmetric difference as a new set. The code should start with:
```python
def symmetric_difference(set1: set, set... | Here is the Python code to solve the given problem in the markdown block:
```python
def symmetric_difference(set1: set, set2: set) -> set:
"""
Find the symmetric difference between two sets.
The symmetric difference is defined as the set of elements that are in either
of the sets but not in their inter... |
code_exercise_27k | 3,611 | Write a Python function to check if a given string contains only printable ASCII characters. Printable ASCII characters are those with ASCII values between 32 and 126 inclusive. The function should return `True` if the string contains only printable ASCII characters, 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_printable_ascii(string: str) -> bool:
"""
Check if a given string contains only printable ASCII characters.
Printable ASCII characters are those with ASCII values between 32 and 126 inclusive.
Args:
stri... |
code_exercise_27k | 3,612 | Write a Python function to remove duplicate values from a given dictionary. The function should return a new dictionary that contains only the first occurrence of each value. The original dictionary should not be modified. The code should start with:
```python
from typing import Dict
def remove_duplicates_from_dict(di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def remove_duplicates_from_dict(dictionary: Dict[str, int]) -> Dict[str, int]:
"""
Remove duplicate values from a given dictionary and return a new dictionary with unique values.
Args:
dicti... |
code_exercise_27k | 3,613 | Write a Python function to check if two sets are disjoint (i.e., they have no common elements). The function should return `True` if the sets are disjoint and `False` otherwise. The code should start with:
```python
def are_disjoint(set1: set, set2: set) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def are_disjoint(set1: set, set2: set) -> bool:
"""
Check if two sets are disjoint (i.e., they have no common elements).
Args:
set1 (set): The first set to check.
set2 (set): The second set to check.
Re... |
code_exercise_27k | 3,615 | Write a Python function to determine if two given lists are permutations of each other. A permutation of a list is another list that contains the same elements, but possibly in a different order. The function should return `True` if the two lists are permutations of each other, and `False` otherwise. The function shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def are_lists_permutations(list1: List[int], list2: List[int]) -> bool:
"""
Determine if two lists are permutations of each other.
Args:
list1 (List[int]): The first list to check.
l... |
code_exercise_27k | 3,616 | Write a Python function to remove the common elements from two sets and return a set containing only the unique elements from both sets. The function should start with:
```python
def remove_common_elements(set1: set, set2: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_common_elements(set1: set, set2: set) -> set:
"""
Remove common elements present in both sets and return the unique elements.
Args:
set1 (set): First set.
set2 (set): Second set.
Returns:
... |
code_exercise_27k | 3,619 | Write a Python function to find the elements that are in either of the two sets but not in both. The function should return a new set containing these elements. The code should start with:
```python
def symmetric_difference(set1: set, set2: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def symmetric_difference(set1: set, set2: set) -> set:
"""
Return the symmetric difference between two sets.
The symmetric difference of two sets, set1 and set2, is the set of elements that are in either set1 or set2, but n... |
code_exercise_27k | 3,623 | Write a Python function to find the elements that are common in three sets. The function should take three sets as input and return a set containing the common elements in all three sets. The code should start with:
```python
def find_common_elements(set1: set, set2: set, set3: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_common_elements(set1: set, set2: set, set3: set) -> set:
"""
Find the elements that are common in three sets.
Args:
set1 (set): The first set.
set2 (set): The second set.
set3 (set): The thi... |
code_exercise_27k | 3,625 | Write a Python function to multiply all values in a given dictionary. The dictionary contains key-value pairs where the values are integers or floats. The function should return the product of all values in the dictionary. If the dictionary is empty, the function should return 1.
The code should start with:
```python
... | Here is the Python code to solve the given problem in the markdown block:
```python
def multiply_dict_values(dictionary: dict) -> int | float:
"""
Multiplies all values in a given dictionary.
Args:
dictionary (dict): A dictionary whose values need to be multiplied.
Returns:
int or floa... |
code_exercise_27k | 3,626 | Write a Python function to check if two sets are equal, i.e., they contain the same elements, regardless of the order of elements. The function should return `True` if the sets are equal and `False` otherwise. The code should start with:
```python
def are_sets_equal(set1: set, set2: set) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def are_sets_equal(set1: set, set2: set) -> bool:
"""
Check if two sets are equal.
This function takes two sets as input and checks if they contain the same elements.
If both sets are equal, it returns True; otherwise, ... |
code_exercise_27k | 3,627 | Write a Python function to find the index of the first occurrence of a subsequence in a given list. The function should return the starting index of the subsequence if it exists in the main sequence, otherwise it should return -1. The function should handle lists of any type of elements, including integers, strings, an... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def find_subsequence_index(seq: List[Any], subseq: List[Any]) -> int:
"""
Find the index of the first occurrence of a subsequence in a list.
Args:
seq (List[Any]): The main sequence to ... |
code_exercise_27k | 3,629 | Write a Python function to find the length of a dictionary, which is defined as the number of key-value pairs it contains. The function should handle dictionaries with various types of keys and values. The code should start with:
```python
def get_dict_length(dictionary: dict) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def get_dict_length(dictionary: dict) -> int:
"""
Calculate the length of a dictionary, which is the number of key-value pairs it contains.
Args:
dictionary (dict): The input dictionary whose length is to be calcu... |
code_exercise_27k | 3,630 | Write a Python function to determine if one set is a proper subset of another set. A proper subset is a subset that does not equal the original set. 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... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_proper_subset(set1: set, set2: set) -> bool:
"""
Determine if set1 is a proper subset of set2.
A proper subset is a subset that does not equal the original set.
Args:
set1 (set): The first set to check.
... |
code_exercise_27k | 3,633 | Write a Python function to combine two dictionaries by adding values for common keys. If a key exists in only one dictionary, it should be included in the result with its value unchanged. The function should handle dictionaries with integer values.
The code should start with:
```python
from typing import Dict
def com... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def combine_dictionaries(dict1: Dict[str, int], dict2: Dict[str, int]) -> Dict[str, int]:
"""
Combines two dictionaries by adding values for common keys.
Args:
dict1 (Dict[str, int]): The fi... |
code_exercise_27k | 3,634 | Write a Python function to check if a given set is a superset of another set. A set `set1` is considered a superset of `set2` if every element in `set2` is also in `set1`. The function should return `True` if `set1` is a superset of `set2`, and `False` otherwise. The code should start with:
```python
def is_superset(se... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_superset(set1: set, set2: set) -> bool:
"""
Check if set1 is a superset of set2.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
bool: True if set1 is a superset of ... |
code_exercise_27k | 3,644 | Write a Python function to find the common elements between two sets and return them as a new set. The function should handle cases where one or both sets are empty. The code should start with:
```python
def find_common_elements(set1: set, set2: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_common_elements(set1: set, set2: set) -> set:
"""
Find and return a new set containing the elements that are common between two sets.
Args:
set1 (set): The first set.
set2 (set): The second set.
... |
code_exercise_27k | 3,645 | Write a Python function to group elements of a dictionary into sub-dictionaries based on a specified group size. The function should return a list of dictionaries, where each dictionary contains a specified number of key-value pairs from the original dictionary. If the number of elements in the dictionary is not perfec... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def group_dictionary_elements(dictionary: Dict[str, int], group_size: int) -> List[Dict[str, int]]:
"""
Groups elements of a dictionary into sub-dictionaries based on a specified group size.
A... |
code_exercise_27k | 3,647 | Write a Python function to remove duplicates from a given list and return the modified list in the same order as they appear. The function should handle lists of integers, strings, and mixed types. The code should start with:
```python
from typing import List, Union
def remove_duplicates_from_list(lst: List[Union[int,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def remove_duplicates_from_list(lst: List[Union[int, str]]) -> List[Union[int, str]]:
"""
Removes duplicates from a list while maintaining the order of the first occurrence of each element.
A... |
code_exercise_27k | 3,648 | Write a Python function to find the number of sublists of a given list that have a specified length. The function should handle cases where the specified length is greater than the length of the list, and it should return the correct count of sublists.
The code should start with:
```python
from typing import List
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_sublists_of_length(lst: List[int], sublist_len: int) -> int:
"""
Counts the number of sublists of a given length in a list.
Args:
lst (List[int]): The input list from which to coun... |
code_exercise_27k | 3,649 | Write a Python function to create a dictionary where the keys are elements from a given list and the values are the cubes of the corresponding keys. The function should handle lists of integers and floats. The code should start with:
```python
from typing import List, Dict, Union
def cube_dict(keys_list: List[Union[in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Union
def cube_dict(keys_list: List[Union[int, float]]) -> Dict[Union[int, float], Union[int, float]]:
"""
Create a dictionary with keys from a list and values as their cubed values.
Args:
... |
code_exercise_27k | 3,651 | Write a Python function to find the unique elements from two sets, i.e., elements that are present in only one of the two sets. The function should return a new set containing these unique elements. The code should start with:
```python
def get_unique_elements(set1: set, set2: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_unique_elements(set1: set, set2: set) -> set:
"""
Returns a new set containing only the unique elements from both input sets.
Args:
set1 (set): The first input set.
set2 (set): The second input set.
... |
code_exercise_27k | 3,654 | Write a Python function to filter out and return a set containing only the even numbers from a given set of integers. The function should handle an empty set and sets with both even and odd numbers. The code should start with:
```python
def get_even_numbers(input_set: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_even_numbers(input_set: set) -> set:
"""
Returns a set that contains only the even numbers from the input_set.
Args:
input_set (set): A set of integers from which to filter even numbers.
Returns:
... |
code_exercise_27k | 3,657 | Write a Python function to check if a given string contains only digits and uppercase letters. The function should return `True` if the string meets the criteria, and `False` otherwise. The code should start with:
```python
def contains_only_digits_and_uppercase_letters(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def contains_only_digits_and_uppercase_letters(s: str) -> bool:
"""
Check if a string contains only digits and uppercase letters.
Args:
s (str): The string to be checked.
Returns:
bool: True if the stri... |
code_exercise_27k | 3,660 | Write a Python function to filter out prime numbers from a given set of integers. The function should return a new set containing only the prime numbers from the original set. The code should start with:
```python
def get_prime_numbers(numbers: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_prime_numbers(numbers: set) -> set:
"""
Returns a set containing only the prime numbers from the given set of integers.
Args:
numbers (set): A set of integers.
Returns:
set: A set containing the... |
code_exercise_27k | 3,661 | Write a Python function to check if a given number is divisible by exactly three out of the numbers 3, 4, 5, and 7. The function should return `True` if the number is divisible by exactly three of these numbers, and `False` otherwise.
The code should start with:
```python
def is_divisible_by_three_of_four(num: int) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_divisible_by_three_of_four(num: int) -> bool:
"""
Check if a number is divisible by exactly three out of the numbers 3, 4, 5, and 7.
Args:
num (int): The number to check for divisibility.
Returns:
... |
code_exercise_27k | 3,662 | Write a Python function to access nested dictionary keys. The function should take a nested dictionary and a list of keys representing the path to the value. It should return the value corresponding to the given keys. If any of the keys in the path does not exist in the dictionary, the function should raise a `KeyError... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_nested_value(data: dict, keys: list) -> any:
"""
Accesses nested dictionary keys.
Parameters:
- data (dict): The nested dictionary to be accessed.
- keys (list): The list of keys representing the path to the... |
code_exercise_27k | 3,664 | Write a Python function to compute the set difference between two sets, i.e., return a new set that contains only the elements that are present in the first set but not in the second set. The function should handle any type of hashable elements in the sets.
The code should start with:
```python
def set_difference(set1... | Here is the Python code to solve the given problem in the markdown block:
```python
def set_difference(set1: set, set2: set) -> set:
"""
Computes the set difference between two sets, returning a new set that contains only the elements present in set1 but not in set2.
Args:
set1 (set): The first set... |
code_exercise_27k | 3,669 | Write a Python function to count the frequency of values 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 how many times each unique value appears.
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 count_value_frequency(dictionary: Dict[str, str]) -> Dict[str, int]:
"""
Count the frequency of values in a given dictionary.
Args:
dictionary (Dict[str, str]): A dictionary where keys a... |
code_exercise_27k | 3,671 | Write a Python function to filter a set of strings and return a new set that contains only the strings starting with a vowel. The function should handle both uppercase and lowercase vowels. The code should start with:
```python
def filter_strings_starting_with_vowel(strings: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def filter_strings_starting_with_vowel(strings: set) -> set:
"""
Filter a set of strings and return a new set that contains only the strings starting with a vowel.
Args:
strings (set): The set of strings to filter.
... |
code_exercise_27k | 3,672 | Write a Python function to count the number of sublists of a given list that contain only prime numbers. A sublist is defined as any contiguous segment of the list. The function should take a list of integers as input and return the count of such sublists.
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
import math
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
""... |
code_exercise_27k | 3,678 | Write a Python function to find and return all unique values from a given dictionary. The dictionary may contain duplicate values, and the function should return a list of these unique values in the order they first appear.
The code should start with:
```python
from typing import Dict, List
def get_unique_values(dict... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def get_unique_values(dictionary: Dict[str, int]) -> List[int]:
"""
Returns a list of unique values from the given dictionary.
Args:
dictionary (Dict[str, int]): A dictionary where key... |
code_exercise_27k | 3,680 | Write a Python function to sort a dictionary by its values in descending order. If two values are the same, sort by keys in ascending order. The function should return a list of tuples representing key-value pairs, sorted according to the specified criteria.
The code should start with:
```python
from typing import Dic... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def sort_dict_by_value_desc(d: Dict[str, int]) -> List[Tuple[str, int]]:
"""
Sorts a dictionary by its values in descending order. If two values are the same,
sort by keys in ascending ... |
code_exercise_27k | 3,683 | Write a Python function to determine if a given number is both a perfect square and divisible by 15. The function should return `True` if the number meets both conditions, and `False` otherwise. The code should start with:
```python
import math
def is_perfect_square_and_divisible_by_15(num: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def is_perfect_square_and_divisible_by_15(num: int) -> bool:
"""
Determine if a given number is both a perfect square and divisible by 15.
Args:
num (int): The number to be checked.
Returns:
... |
code_exercise_27k | 3,684 | Write a Python function to get the top three values from a given dictionary. The function should return a list containing the top three values in descending order. If the dictionary contains fewer than three values, the function should return a list of all values in descending order.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def get_top_three_values(dictionary: Dict[str, int]) -> List[int]:
"""
Retrieves the top three values from a given dictionary.
Args:
dictionary (Dict[str, int]): The dictionary from wh... |
code_exercise_27k | 3,686 | Write a Python function to split a given list into sublists where each sublist contains consecutive increasing elements. The function should handle lists of integers and return a list of sublists, where each sublist contains elements that are consecutive in value.
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 split_into_consecutive_sublists(lst: List[int]) -> List[List[int]]:
"""
Split a list into sublists where each sublist contains consecutive increasing elements.
Args:
lst (List[int]): The... |
code_exercise_27k | 3,687 | Write a Python function to find the elements that are present in either of two sets, but not in both. The function should return a new set containing these exclusive elements. The code should start with:
```python
def exclusive_elements(set1: set, set2: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def exclusive_elements(set1: set, set2: set) -> set:
"""
Returns a new set containing elements that are present in either set1 or set2, but not in both.
Args:
set1 (set): The first set.
set2 (set): The secon... |
code_exercise_27k | 3,693 | Write a Python function to find the differences between two dictionaries. The function should return a dictionary that contains the differences between the two input dictionaries. The differences should be represented as follows:
- If a key is present in the first dictionary but not in the second, the value should be a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any, Tuple
def find_dictionary_differences(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Tuple[Any, Any]]:
"""
Find the differences between two dictionaries.
Args:
dict1 (Dict[... |
code_exercise_27k | 3,698 | Write a Python function to find and replace keys within a dictionary. The function should take a dictionary, an old key, and a new key as inputs. If the old key exists in the dictionary, it should be replaced with the new key. If the old key does not exist, the function should raise a `KeyError`. The function should re... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_and_replace_keys(dictionary: dict, old_key, new_key) -> dict:
"""
Find and replace keys within a dictionary.
Args:
dictionary (dict): The dictionary to be modified.
old_key: The existing key to be r... |
code_exercise_27k | 3,701 | Write a Python function to remove duplicate elements from a given list and return a new list with unique elements while maintaining the order of their first appearance. The function should start with:
```python
from typing import List
def remove_duplicates_keep_order(input_list: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_keep_order(input_list: List[int]) -> List[int]:
"""
Removes duplicate elements from a list while maintaining the order of their first appearance.
Args:
input_list (List... |
code_exercise_27k | 3,702 | Write a Python function to create a dictionary from two lists, where the keys are taken from the first list and the values are taken from the second list. If the lengths of the two lists are not equal, the function should handle this by only creating key-value pairs for the elements that have corresponding pairs in bot... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_dictionary(keys: List[str], values: List[str]) -> Dict[str, str]:
"""
Create a dictionary from two lists, using keys from one and values from another.
Args:
keys (List[str])... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.