source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 3,908 | Write a Python function to clone or copy a set. The function should create a new set that is a copy of the original set, ensuring that changes to the original set do not affect the cloned set. The code should start with:
```python
def clone_set(original_set: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def clone_set(original_set: set) -> set:
"""
Clones or copies a set.
Parameters:
original_set (set): The original set to be cloned.
Returns:
set: A clone or copy of the original set.
Example:
>> origin... |
code_exercise_27k | 3,909 | Write a Python function to assign a value based on a given condition. If the condition is `True`, the function should return `1`; otherwise, it should return `0`. The function should handle various types of conditions, including boolean values, comparisons, and logical operations.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
def assign_value(condition) -> int:
"""
Assign the value of 1 if the provided condition is True, otherwise assign 0.
Args:
condition: Any value or expression that can be evaluated to a boolean.
Returns:
... |
code_exercise_27k | 3,911 | Write a Python function to merge two dictionaries and create a dictionary of dictionaries. The function should take two dictionaries as input and return a new dictionary where each key is a combination of keys from both input dictionaries. If a key exists in both dictionaries, the value should be a dictionary containin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_dictionaries(dict1: Dict[str, int], dict2: Dict[str, int]) -> Dict[str, Dict[str, int]]:
"""
Merge two dictionaries into a dictionary of dictionaries.
Args:
dict1 (Dict[str, int]):... |
code_exercise_27k | 3,912 | Write a Python function to find the maximum common element among multiple sets using bitwise operations. The function should handle the following:
1. Accept a list of sets as input.
2. Use bitwise operations to find the common elements among all sets.
3. Return the maximum common element.
4. Raise a `ValueError` if the... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Set
def find_max_common_element(sets: List[Set[int]]) -> int:
"""
Finds the maximum common element among multiple sets using bitwise operations.
Args:
sets: A list of sets containing intege... |
code_exercise_27k | 3,913 | Write a Python function to determine the value of 'x' based on the given conditions. If 'x' is less than 10, assign the value of 'y' to 'x'. Otherwise, return 'x' unchanged. The function should handle both integer and floating-point inputs.
The code should start with:
```python
def assign_y_to_x(x: int | float, y: int... | Here is the Python code to solve the given problem in the markdown block:
```python
def assign_y_to_x(x: int | float, y: int | float) -> int | float:
"""
Assigns the value of 'y' to 'x' if 'x' is less than 10.
Parameters:
x (int | float): The value to be assigned.
y (int | float): The value... |
code_exercise_27k | 3,918 | Write a Python function to create a dictionary where the keys are unique elements from a given list, and the values are lists of indices where each key occurs in the original list. The function should handle lists with any type of elements, including duplicates.
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, Dict, Any
def create_index_dict(lst: List[Any]) -> Dict[Any, List[int]]:
"""
Create a dictionary with keys as unique elements from a given list
and values as a list of indices where the key occurs i... |
code_exercise_27k | 3,919 | Write a Python function to perform a bitwise OR operation on two integers and return the result. Additionally, create a function to perform a bitwise AND operation on two integers and return the result. Both functions should be well-documented with docstrings and type annotations.
The starter code should be:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def bitwise_or(x: int, y: int) -> int:
"""
Performs a bitwise OR operation on two integers 'x' and 'y'.
Args:
x (int): The first integer.
y (int): The second integer.
Returns:
... |
code_exercise_27k | 3,921 | Write a Python function to calculate the difference between the maximum and minimum elements of 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 calculate_difference(s: set) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_difference(s: set) -> int:
"""
Calculate the difference between the maximum and minimum elements of a set.
Args:
s (set): The input set of elements.
Returns:
int: The difference between th... |
code_exercise_27k | 3,922 | Write a Python function to reverse a given string and return the reversed string. The function should handle strings of varying lengths, including empty strings. The code should start with:
```python
def reverse_string(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_string(text: str) -> str:
"""
Reverse a given string.
Args:
- text (str): The input text to be reversed.
Returns:
- str: The reversed text.
Example:
>>> reverse_string("Hello World")
... |
code_exercise_27k | 3,924 | Write a Python function to calculate the cube of a given number using the assignment operator. The function should take an integer as input and return the cube of that integer. The code should start with:
```python
def calculate_cube(number: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_cube(number: int) -> int:
"""
Calculate the cube of a given number using the assignment operator.
Parameters:
number (int): The number whose cube needs to be calculated.
Returns:
int: The cube of ... |
code_exercise_27k | 3,928 | Write a Python function to check if a given dictionary is a subset of another dictionary. The function should return `True` if all key-value pairs in the first dictionary (subset) exist in the second dictionary (superset) with the same values, and `False` otherwise. The code should start with:
```python
from typing imp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def is_subset_of_dict(subset_dict: Dict, superset_dict: Dict) -> bool:
"""
Check if a dictionary is a subset of another dictionary.
Args:
subset_dict (Dict): The dictionary to be checked if ... |
code_exercise_27k | 3,930 | Write a Python function to flatten a nested list and count the occurrence of each element in the flattened list. The function should handle lists containing integers, strings, and other lists. The code should start with:
```python
from typing import List, Any, Dict
def flatten_and_count_elements(lst: List[Any]) -> Dic... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any, Dict
def flatten_and_count_elements(lst: List[Any]) -> Dict[Any, int]:
"""
Flatten a nested list and count the occurrence of each element.
Args:
lst (List[Any]): The input list to be f... |
code_exercise_27k | 3,931 | Write a Python function to count the occurrences of each word in a given string and return a dictionary with words as keys and their occurrences as values. The function should handle case-insensitive comparisons and ignore punctuation. The code should start with:
```python
from typing import Dict
import string
def cou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import string
def count_word_occurrences(input_string: str) -> Dict[str, int]:
"""
Counts the occurrences of each word in a given string and returns a dictionary
with words as keys and their occurren... |
code_exercise_27k | 3,932 | Write a Python function to calculate the absolute value of a given number and return it. The function should handle both integers and floating-point numbers. The code should start with:
```python
def calculate_absolute_value(x: int | float) -> int | float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_absolute_value(x: int | float) -> int | float:
"""
Calculate the absolute value of a given number.
Args:
x (int | float): The input number, which can be either an integer or a floating-point number.
... |
code_exercise_27k | 3,935 | Write a Python function to calculate the integer part of the division of a given number by 2 using the floor division operator. The function should handle both integer and floating-point inputs and return the integer part of the division result.
The code should start with:
```python
def floor_division_by_two(number: i... | Here is the Python code to solve the given problem in the markdown block:
```python
def floor_division_by_two(number: int | float) -> int:
"""
Calculate the integer part of the division of a given number by 2 using the floor division operator.
Args:
number (int | float): The number to be divided by... |
code_exercise_27k | 3,936 | Write a Python function to create a dictionary where the keys are unique elements from a given list, and the values are lists of indices where each key occurs in the original list. The function should handle lists with duplicate elements and ensure that each unique element maps to a list of its occurrence indices.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_index_dictionary(lst: List[str]) -> Dict[str, List[int]]:
"""
Create a dictionary with unique elements from a given list as keys,
and values as a list of indices where the key occurs... |
code_exercise_27k | 3,937 | Write a Python function to find the longest common subsequence (LCS) between two given strings. The function should return the length of the LCS.
The code should start with:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
"""
Calculate the length of the longest common subsequence (LCS) between two strings.
Args:
str1 (str): The first string.
str2 (str): The second s... |
code_exercise_27k | 3,938 | Write a Python function to determine if one set is a proper subset of the other. A set `A` is a proper subset of set `B` if all elements of `A` are in `B`, but `A` is not equal to `B`. The function should take two sets as input and return a boolean indicating whether the first set is a proper subset of the second 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:
"""
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,939 | Write a Python function to merge two lists alternatively, ensuring that elements from both lists are included in the merged list in an alternating fashion. If one list is longer than the other, the remaining elements of the longer list should be appended to the end of the merged list.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_alternately(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge the elements of two lists alternatively.
Args:
list1 (List[int]): The first list.
list2 (List[int]):... |
code_exercise_27k | 3,940 | Write a Python function that assigns the value of `x` to `y` if `x` is not equal to `y`. The function should return `None` if `x` is equal to `y`, otherwise it should return the updated value of `y`. The function should handle different types of inputs, including integers, floats, strings, and lists. The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
def assign_if_not_equal(x, y):
"""
Assigns the value of 'x' to 'y' if 'x' is not equal to 'y'.
Args:
x: The value to assign to 'y' if 'x' is not equal to 'y'.
y: The value that will be updated if 'x' is not ... |
code_exercise_27k | 3,941 | Write a Python function to find the k smallest elements in a given set efficiently. The function should return a list of the k smallest elements in ascending order. If k is greater than the size of the set, the function should return all elements in the set in ascending order.
The code should start with:
```python
fro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set, List
def find_k_smallest_elements(some_set: Set[int], k: int) -> List[int]:
"""
Find the k smallest elements in a given set and return them in ascending order.
Args:
some_set (Set[int]): The... |
code_exercise_27k | 3,943 | Write a Python function to merge two sorted lists into a new sorted list. The function should efficiently combine the elements from both lists while maintaining the sorted order. The code should start with:
```python
from typing import List
def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two sorted lists into a new sorted list.
Args:
list1 (List[int]): The first sorted list.
list2 (Lis... |
code_exercise_27k | 3,948 | Write a Python function to merge two lists while removing duplicates. The function should take two lists as input and return a new list that contains all unique elements from both lists, maintaining the order of elements as they appear in the input lists. 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 merge_lists_without_duplicates(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two lists while removing duplicates and maintaining the order of elements.
Args:
list1 (List[in... |
code_exercise_27k | 3,950 | Write a Python function to extract the last n characters from a given string. If n is greater than the length of the string, return the entire string. The function should handle cases where n is zero or negative by returning an empty string.
The code should start with:
```python
def get_last_n_chars(text: str, n: int)... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_last_n_chars(text: str, n: int) -> str:
"""
Returns the last n characters from the given string.
Args:
text (str): The string from which to extract the last n characters.
n (int): The number of chara... |
code_exercise_27k | 3,952 | Write a Python function to find the smallest and largest elements in a given set of numbers. The function should return a tuple containing the smallest and largest elements. If the set is empty, the function should raise a `ValueError` with the message "The set is empty."
The code should start with:
```python
def find... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_smallest_and_largest(numbers: set) -> tuple:
"""
Find the smallest and largest elements in a given set of numbers.
Args:
numbers (set): The set of numbers.
Returns:
tuple: A tuple containing th... |
code_exercise_27k | 3,954 | Write a Python function to merge two lists, keeping only the common elements, while preserving the order of elements as they appear in the first list. The function should handle lists of any type of elements, including integers, strings, and other objects. The code should start with:
```python
from typing import List,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def merge_common_elements_preserving_order(list1: List[Any], list2: List[Any]) -> List[Any]:
"""
Merge two lists, keeping only the common elements and preserving the order of elements as they appear... |
code_exercise_27k | 3,956 | Write a Python function to calculate the factorial of a given non-negative integer `n` using a loop and the assignment operator. The function should handle the case where `n` is 0 by returning 1, as the factorial of 0 is defined to be 1. The function should raise a `ValueError` if `n` is a negative number.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_factorial(n: int) -> int:
"""
Calculates the factorial of a given non-negative integer.
Args:
n (int): The number for which to calculate the factorial.
Returns:
int: The factorial of 'n'.
... |
code_exercise_27k | 3,958 | Write a Python function to perform a series of value assignments and return the final values of the variables. The function should take a single input `x`, assign its value to `y`, then assign the value of `y` to `z`, and finally return the values of `y` and `z`. The code should start with:
```python
def assign_and_ret... | Here is the Python code to solve the given problem in the markdown block:
```python
def assign_and_return_values(x):
"""
Assigns the value of 'x' to 'y', then assigns the value of 'y' to 'z', and returns the values of 'y' and 'z'.
Args:
x: The value to be assigned to 'y' and 'z'.
Returns:
... |
code_exercise_27k | 3,959 | Write a Python function to merge two lists while preserving the order of elements and ensuring that only unique elements are included in the result. The function should start with:
```python
from typing import List
def merge_ordered_unique_lists(list1: List[int], list2: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_ordered_unique_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two lists while preserving the order of elements and ensuring that only unique elements are included.
Args:... |
code_exercise_27k | 3,960 | Write a Python function to create a copy of a set and remove an element from the copy. The function should return the modified copy of the set. The original set should remain unchanged.
The code should start with:
```python
def copy_set_and_remove_element(original_set: set, element) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def copy_set_and_remove_element(original_set: set, element) -> set:
"""
Create a copy of a set and remove an element from the copy.
Parameters:
original_set (set): The original set to be copied.
element: The element... |
code_exercise_27k | 3,962 | Write a Python function to merge two lists, keeping only the elements that occur more than once across both lists. The function should return a list of these elements. The code should start with:
```python
from typing import List
def merge_lists_with_duplicates(list1: List[int], list2: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_lists_with_duplicates(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two lists, keeping only the elements that occur more than once across both lists.
Args:
list1 (Lis... |
code_exercise_27k | 3,964 | Write a Python function to perform a bitwise right shift operation on a given integer `x` by a specified number of positions `n`. The function should return the result of the bitwise right shift operation. The code should start with:
```python
def bitwise_right_shift(x: int, n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_right_shift(x: int, n: int) -> int:
"""
Perform a bitwise right shift operation on the given integer 'x' by 'n' positions.
Args:
x (int): The integer on which the bitwise right shift operation will be pe... |
code_exercise_27k | 3,967 | Write a Python function to merge two sorted lists into a single sorted list without using the built-in `sorted()` function. The function should efficiently merge the two lists by iterating through them and combining their elements in ascending order.
The code should start with:
```python
from typing import List
def m... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two sorted lists into a single sorted list.
This function takes two sorted lists as input and merges them into a ne... |
code_exercise_27k | 3,969 | Write a Python function to merge two lists into a single list, removing the last element of each list. The function should handle cases where the input lists are empty or have only one element. The code should start with:
```python
from typing import List
def merge_lists_remove_last(list1: List[int], list2: List[int])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_lists_remove_last(list1: List[int], list2: List[int]) -> List[int]:
"""
Merges two lists into a single list, removing the last element of each list.
Args:
list1 (List[int]): The fi... |
code_exercise_27k | 3,971 | Write a Python function to create a frozen set from an existing set and return the frozen set. Additionally, write a function to check if a given set is a subset of another set. The code should start with:
```python
def create_frozen_set(s: set) -> frozenset:
"""
Create a frozen set from an existing set.
P... | Here is the Python code to solve the given problem in the markdown block:
```python
def create_frozen_set(s: set) -> frozenset:
"""
Create a frozen set from an existing set.
Parameters:
s (set): The original set.
Returns:
frozenset: The frozen set created from the original set.
"""
ret... |
code_exercise_27k | 3,972 | Write a Python function to merge two lists into a single list, arranging elements alternatively. If one list is longer than the other, the remaining elements of the longer list should be appended to the end of the merged list. The function should start with:
```python
from typing import List
def merge_alternatively(li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_alternatively(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two lists into a single list, arranging elements alternatively.
Args:
list1 (List[int]): The first list.
... |
code_exercise_27k | 3,973 | Write a Python function to perform the modulus operation on a given integer `x` with another integer `y` using the assignment operator. The function should handle the case where the divisor `y` is zero by raising a `ZeroDivisionError` with a custom error message. The function should return the remainder of the division... | Here is the Python code to solve the given problem in the markdown block:
```python
def modulus_operation(x: int, y: int) -> int:
"""
Perform the modulus operation on x with y using the assignment operator.
Args:
x (int): The dividend.
y (int): The divisor.
Returns:
int: The re... |
code_exercise_27k | 3,974 | Write a Python function to merge two lists and return a new list containing only the elements that occur at least three times across both lists. The function should be efficient and handle any type of elements, including duplicates.
The code should start with:
```python
from typing import List, Any
from collections im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
from collections import Counter
def merge_lists_with_min_occurrences(lst1: List[Any], lst2: List[Any], min_occurrences: int = 3) -> List[Any]:
"""
Merge two lists and return a new list containing on... |
code_exercise_27k | 3,977 | Write a Python function to perform a boolean OR operation between two variables `a` and `b` and assign the result to a third variable `result`. The function should return the value of `result`.
The code should start with:
```python
def boolean_or_operation(a: bool, b: bool) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def boolean_or_operation(a: bool, b: bool) -> bool:
"""
Performs a boolean OR operation between two variables.
Args:
a (bool): The first variable.
b (bool): The second variable.
Returns:
bool: T... |
code_exercise_27k | 3,978 | Write a Python function to remove and return an arbitrary key-value pair from a given dictionary. If the dictionary is empty, the function should return `(None, None)`. The function should be efficient and handle edge cases appropriately.
The code should start with:
```python
def remove_arbitrary_key_value(dictionary:... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_arbitrary_key_value(dictionary: dict) -> tuple:
"""
Removes and returns an arbitrary key-value pair from a dictionary.
Args:
dictionary (dict): The dictionary from which to remove and return a key-value p... |
code_exercise_27k | 3,979 | Write a Python function to calculate the sum of all elements in multiple sets. The function should handle a list of sets containing integer elements and return the total sum of all elements in these sets. The function should also validate the input to ensure it is a list of sets and that each set contains only integer ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Set
def calculate_sum_of_sets(sets: List[Set[int]]) -> int:
"""
Calculate the sum of all elements in multiple sets.
Args:
sets (List[Set[int]]): A list of sets containing integer elements.
... |
code_exercise_27k | 3,981 | Write a Python function to merge two sorted lists into a new sorted list without using the built-in `sort` function. The function should efficiently combine the elements from both lists while maintaining the sorted order. The code should start with:
```python
from typing import List
def merge_sorted_lists(list1: List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two sorted lists into a new sorted list without using the built-in sort function.
Args:
list1 (List[int]): ... |
code_exercise_27k | 3,982 | Write a Python function to validate if all keys in a given dictionary have corresponding non-None values. The function should return `True` if all keys have non-None values, and `False` otherwise. The code should start with:
```python
def validate_dictionary(dictionary: dict) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def validate_dictionary(dictionary: dict) -> bool:
"""
Validate if all keys in the given dictionary have corresponding non-None values.
Args:
dictionary (dict): The dictionary to validate.
Returns:
bool... |
code_exercise_27k | 3,990 | Write a Python function to perform the modulus operation on a given integer `a` with a specified divisor `b` using the assignment operator `%=`. The function should return the modified value of `a` after the operation.
The code should start with:
```python
def modulus_assignment(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def modulus_assignment(a: int, b: int) -> int:
"""
Perform the modulus operation on the given integer 'a' with the specified divisor 'b' using the assignment operator '%='.
Args:
a (int): The integer to be operated ... |
code_exercise_27k | 3,992 | Write a Python function to convert a dictionary into a list of tuples, where each tuple represents a key-value pair from the dictionary. The function should handle dictionaries with various types of keys and values, including nested dictionaries. The code should start with:
```python
from typing import Dict, List, Tupl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple, Any
def dict_to_list_of_tuples(dictionary: Dict[Any, Any]) -> List[Tuple[Any, Any]]:
"""
Convert a dictionary into a list of tuples, where each tuple represents a key-value pair from the di... |
code_exercise_27k | 3,993 | Write a Python function to check if a given set is a subset of any other set in a list of sets. The function should return `True` if the given set is a subset of any set in the list, and `False` otherwise. The function should handle cases where the list of sets is empty or contains only one set.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Set
def is_subset_of_any(subset: Set[int], sets: List[Set[int]]) -> bool:
"""
Check if a given set is a subset of any other set in a list of sets.
Args:
subset (Set[int]): The set that we w... |
code_exercise_27k | 3,994 | Write a Python function to sort a dictionary by its values in descending order. The function should return a new dictionary with the keys sorted based on their corresponding values in descending order. The original dictionary should remain unchanged.
The code should start with:
```python
from typing import Dict
def s... | 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 by its values in descending order.
Args:
dictionary (Dict[str, int]): The dictionary to be ... |
code_exercise_27k | 3,997 | Write a Python function to sort a dictionary by its values in ascending order. If two or more keys have the same value, their order should be preserved based on their original order in the dictionary. The function should return a new dictionary with the sorted keys and values.
The code should start with:
```python
fro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_values(dictionary: Dict[str, int]) -> Dict[str, int]:
"""
Sort a dictionary by its values in ascending order. If two or more keys have the same value,
their order should be preserved... |
code_exercise_27k | 3,999 | Write a Python function to merge two lists into a new list, where each element is the sum of the corresponding elements in the original lists. If the input lists have different lengths, the function should handle this by filling the shorter list with zeros until it matches the length of the longer list. The function sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_lists_with_padding(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two lists by calculating the sum of corresponding elements. If the lists have different lengths,
pad the short... |
code_exercise_27k | 4,003 | Write a Python function to perform a bitwise left shift operation on a given integer `x` by a specified number of positions `n`. The function should return the result of this operation. The code should start with:
```python
def bitwise_left_shift(x: int, n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_left_shift(x: int, n: int) -> int:
"""
Performs a bitwise left shift of the given integer 'x' by 'n' positions and returns the result.
Args:
x (int): The input integer to be left shifted.
n (int)... |
code_exercise_27k | 4,006 | Write a Python function to find the minimum element in a set without using built-in functions or sorting algorithms. The function should iterate through the set and keep track of the smallest element found. The code should start with:
```python
def find_minimum_element(my_set: set) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_minimum_element(my_set: set) -> int:
"""
Find the minimum element in a set without using built-in functions or sorting algorithms.
Args:
my_set (set): A set of elements.
Returns:
int: The minim... |
code_exercise_27k | 4,007 | Write a Python function to merge two lists into a single list, with each element repeated 'n' times. The function should handle lists of any type of elements and ensure that the elements from both lists are merged in the order they appear. The function should also raise a `ValueError` if 'n' is less than or equal to 0.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def merge_lists_with_repetition(list1: List[Any], list2: List[Any], n: int) -> List[Any]:
"""
Merge two lists into a single list, with each element repeated 'n' times.
Args:
list1 (List... |
code_exercise_27k | 4,009 | Write a Python function to check if one set is a proper subset of another set. A proper subset is a subset that is not equal to 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(se... | 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 one set is a proper subset of another set.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
bool: True if se... |
code_exercise_27k | 4,011 | Write a Python function to merge two lists, removing the elements that are common to both lists. The function should return a new list that contains all unique elements from both lists, excluding the common elements. The code should start with:
```python
from typing import List
def merge_lists_without_common(list1: Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_lists_without_common(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two lists, removing the elements that are common to both lists.
Args:
list1 (List[int]): The first ... |
code_exercise_27k | 4,012 | Write a Python function to calculate the sum of the first `n` natural numbers using the formula for the sum of an arithmetic series. The function should return the sum directly without using a loop. The code should start with:
```python
def calculate_sum_arithmetic(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_sum_arithmetic(n: int) -> int:
"""
Calculates the sum of the first 'n' natural numbers using the arithmetic series formula.
Args:
n (int): The upper limit for the range of numbers to be summed (inclusi... |
code_exercise_27k | 4,014 | Write a Python function to merge two lists into a single list, arranging elements alternatively in ascending and descending order. The function should start with:
```python
from typing import List
def merge_alternating_order(lst1: List[int], lst2: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_alternating_order(lst1: List[int], lst2: List[int]) -> List[int]:
"""
Merge two lists into a single list, arranging elements alternatively in ascending and descending order.
Args:
... |
code_exercise_27k | 4,016 | Write a Python function to update the value of `x` with the value of `y` if `x` is greater than or equal to a specified threshold `t`. The function should handle both integer and floating-point numbers. The code should start with:
```python
def update_value_if_threshold(x: float, y: float, t: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def update_value_if_threshold(x: float, y: float, t: float) -> float:
"""
Updates the value of 'x' with the value of 'y' if 'x' is greater than or equal to the specified threshold 't'.
Args:
x (float): The value to ... |
code_exercise_27k | 4,017 | Write a Python function to create a set of unique words from a given string, where words are defined as sequences of characters separated by whitespace. The function should handle multiple spaces and leading/trailing spaces gracefully.
The code should start with:
```python
from typing import Set
def string_to_word_se... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def string_to_word_set(input_string: str) -> Set[str]:
"""
Create a set of unique words from a given string.
Args:
input_string (str): The input string from which the set of unique words need... |
code_exercise_27k | 4,018 | Write a Python function to merge two lists into a single list by alternating elements from both lists while maintaining the order. If the lengths of the input lists are not equal, the function should raise a `ValueError`. The code should start with:
```python
from typing import List
def merge_lists(list1: List, list2:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_lists(list1: List, list2: List) -> List:
"""
Merge two lists into a single list by alternating elements from both lists while maintaining the order.
Args:
list1 (List): The first l... |
code_exercise_27k | 4,025 | Write a Python function to compare two dictionaries for equality, considering nested dictionaries and lists within the dictionaries. The function should return `True` if the dictionaries are equal, and `False` otherwise. The code should start with:
```python
from typing import Any, Dict
def deep_dict_compare(dict1: Di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, Dict
def deep_dict_compare(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> bool:
"""
Compare two dictionaries for equality, including nested dictionaries and lists.
Args:
dict1 (Dict[Any, A... |
code_exercise_27k | 4,028 | Write a Python function to calculate the average of a list of numbers. The function should take a list of integers or floats as input and return the average as a float. The code should start with:
```python
from typing import List
def calculate_average(numbers: List[float]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_average(numbers: List[float]) -> float:
"""
Calculate the average of a list of numbers.
Args:
numbers (List[float]): A list of numbers (integers or floats) for which to calcula... |
code_exercise_27k | 4,029 | Write a Python function to retrieve the first key-value pair from a given dictionary. If the dictionary is empty, raise a `ValueError`. The function should be efficient and handle any type of dictionary.
The code should start with:
```python
def get_first_key_value(dictionary: dict) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_first_key_value(dictionary: dict) -> tuple:
"""
Retrieves the first key-value pair from a given dictionary.
Args:
dictionary (dict): The input dictionary from which to retrieve the first key-value pair.
... |
code_exercise_27k | 4,030 | Write a Python function to generate all possible combinations of elements from two sets. Each combination should be a tuple where the first element is from the first set and the second element is from the second set. The function should return a set containing all these combinations.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_combinations(set1: set, set2: set) -> set:
"""
Generate all possible combinations of elements from two sets.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
se... |
code_exercise_27k | 4,031 | Write a Python function to perform a series of value assignments and return the final value. The function should first assign the value of the input parameter `z` to a variable `y`, then assign the value of `y` to a variable `x`, and finally return the value of `x`. The function should handle any type of input value.
... | Here is the Python code to solve the given problem in the markdown block:
```python
def assign_values(z):
"""
Assigns the value of 'z' to 'y', and then assigns the value of 'y' to 'x'.
Parameters:
z (any type): The value to assign to 'y'.
Returns:
x (any type): The value assigned to 'x'.
"... |
code_exercise_27k | 4,034 | Write a Python function to find the largest common element among multiple sets using the `reduce` function from the `functools` module. The function should return the largest common element if there is one, otherwise it should return `None`. The code should start with:
```python
from functools import reduce
from typing... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import reduce
from typing import List, Set, Optional
def find_largest_common_element(sets: List[Set[int]]) -> Optional[int]:
"""
Finds the largest common element among multiple sets.
Args:
sets (List... |
code_exercise_27k | 4,036 | Write a Python function to merge two lists into a new list, where each element is the product of the corresponding elements in the original lists. The function should raise a `ValueError` if the input lists are not of the same length.
The code should start with:
```python
from typing import List
def merge_lists(list1... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two lists into a new list, where each element is the product of the corresponding elements in the original lists.
Args:
... |
code_exercise_27k | 4,037 | Write a Python function to find the second-smallest value in a given dictionary. The dictionary contains numeric values. If the dictionary is empty or contains only one unique value, the function should return `None`. The function should also raise a `TypeError` if any of the dictionary values are not numeric.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Union
def find_second_smallest_value(dictionary: Dict[str, Union[int, float]]) -> Union[int, float, None]:
"""
Find the second-smallest value in a dictionary.
Args:
dictionary (dict): A dic... |
code_exercise_27k | 4,038 | Write a Python function to perform a bitwise right shift of a given integer by a specified number of positions. The function should handle both positive and negative integers and return the result of the bitwise right shift operation. The code should start with:
```python
def bitwise_right_shift(x: int, shift: int) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_right_shift(x: int, shift: int) -> int:
"""
Perform a bitwise right shift of the given integer by the specified number of positions.
Args:
x (int): The integer to be shifted.
shift (int): The num... |
code_exercise_27k | 4,040 | Write a Python function to convert a given string to its lowercase version using a built-in method. The function should handle any string input and return the lowercase version of the input string. The code should start with:
```python
def convert_to_lowercase(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_lowercase(text: str) -> str:
"""
Converts a given text string to its lowercase version using the built-in method lower().
Parameters:
text (str): The input text string.
Returns:
str: The lowercas... |
code_exercise_27k | 4,042 | Write a Python function to merge two lists into a single list, arranging elements in a zigzag pattern. The zigzag pattern means that elements from the first list and the second list are interleaved, starting with the first element of the first list, followed by the first element of the second list, and so on. If one li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_lists_zigzag(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two lists into a single list, arranging elements in a zigzag pattern.
Args:
list1 (List[int]): The first li... |
code_exercise_27k | 4,048 | Write a Python function to update the value of a variable `x` with the value of another variable `y` only if `x` is not equal to a specified value `z`. The function should return the updated value of `x`. The code should start with:
```python
def update_x_if_not_z(x, y, z):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def update_x_if_not_z(x, y, z):
"""
Updates the value of `x` with the value of `y` only if `x` is not equal to `z`.
Args:
x (any): The variable to be updated.
y (any): The value to assign to `x` if `x` is no... |
code_exercise_27k | 4,054 | Write a Python function to calculate the square root of the absolute value of a given number. The function should handle both positive and negative inputs and return the result as a floating-point number. The code should start with:
```python
import math
def calculate_sqrt_abs(x: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_sqrt_abs(x: float) -> float:
"""
Calculate the square root of the absolute value of a given number.
Parameters:
----------
x : float
The number for which the square root of the abs... |
code_exercise_27k | 4,055 | Write a Python function to perform integer division on a given integer `a` with a specified divisor `b`. The function should return the result of the integer division. The code should start with:
```python
def integer_division(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def integer_division(a: int, b: int) -> int:
"""
Performs integer division on the given integer 'a' with the specified divisor 'b'.
Args:
a (int): The number to be divided.
b (int): The divisor.
Returns... |
code_exercise_27k | 4,059 | Write a Python function to rotate the values of three variables `x`, `y`, and `z` in a cyclic manner. Specifically, the value of `y` should be assigned to `x`, the value of `z` should be assigned to `y`, and the value of `x` should be assigned to `z`. The function should return a tuple containing the new values of `x`,... | Here is the Python code to solve the given problem in the markdown block:
```python
def rotate_variables(x, y, z):
"""
Rotates the values of three variables `x`, `y`, and `z` in a cyclic manner.
Args:
x (any type): The first variable.
y (any type): The second variable.
z (any type):... |
code_exercise_27k | 4,060 | Write a Python function to find the second largest element in a given set of integers. If the set has fewer than two elements, the function should return `None`. The function should be efficient and handle edge cases appropriately.
The code should start with:
```python
def find_second_largest_element(input_set: set) -... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_second_largest_element(input_set: set) -> int:
"""
Finds the second largest element in a given set of integers.
Args:
input_set (set): The set of integers from which to find the second largest element.
... |
code_exercise_27k | 4,064 | Write a Python function to perform a bitwise left shift operation on a given integer by a specified number of positions. The function should return the result of the shift operation. The code should start with:
```python
def bitwise_left_shift(x: int, shift_positions: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_left_shift(x: int, shift_positions: int) -> int:
"""
Perform a bitwise left shift of a variable 'x' by 'shift_positions'.
Args:
x (int): The integer to be shifted.
shift_positions (int): The numb... |
code_exercise_27k | 4,065 | Write a Python function to merge two dictionaries with nested values. If a key exists in both dictionaries, the function should recursively merge the nested dictionaries. If a key exists in only one dictionary, it should be added directly to the merged dictionary. The function should handle nested dictionaries at any d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_nested_dicts(dict1: Dict, dict2: Dict) -> Dict:
"""
Merge two dictionaries with nested values. If a key exists in both dictionaries,
the function recursively merges the nested dictionaries.... |
code_exercise_27k | 4,067 | Write a Python function to convert a given string to uppercase using a built-in method. The function should take a string as input and return the uppercase version of the string. The code should start with:
```python
def convert_to_uppercase(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_uppercase(text: str) -> str:
"""
Converts the input 'text' to uppercase using the built-in upper() method.
Args:
text (str): The input string to be converted to uppercase.
Returns:
str: T... |
code_exercise_27k | 4,068 | Write a Python function to perform a bitwise AND operation on a given integer `a` with a specified integer `b`. The function should return the result of the bitwise AND operation. The code should start with:
```python
def bitwise_and(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_and(a: int, b: int) -> int:
"""
Performs a bitwise AND operation on the given integers 'a' and 'b'.
Args:
a (int): The first integer to perform the operation on.
b (int): The second integer to pe... |
code_exercise_27k | 4,070 | Write a Python function to find the common elements between two lists, ensuring that the common elements are returned in the order they appear in the first list. The function should handle lists of any data type, including mixed types. The code should start with:
```python
from typing import List, Any
def find_common_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def find_common_elements(list1: List[Any], list2: List[Any]) -> List[Any]:
"""
Find the common elements between two lists and return them in the order they appear in the first list.
Args:
... |
code_exercise_27k | 4,073 | Write a Python function to update the value of `x` based on the following conditions:
1. If `x` is less than or equal to 10, assign the value of `y` to `x`.
2. If `x` is greater than 10, increment `x` by the value of `y`.
The function should return the updated value of `x`.
The code should start with:
```python
def u... | Here is the Python code to solve the given problem in the markdown block:
```python
def update_value(x: int, y: int) -> int:
"""
Updates the value of `x` based on the following conditions:
1. If `x` is less than or equal to 10, assign the value of `y` to `x`.
2. If `x` is greater than 10, increment `x` ... |
code_exercise_27k | 4,079 | Write a Python function to create a dictionary from a list of tuples. Each tuple in the list contains exactly two elements: the first element will be used as the key and the second element will be used as the value in the resulting dictionary. The function should handle cases where the list of tuples may contain duplic... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def create_dict_from_tuples(tuples_list: List[Tuple[any, any]]) -> Dict[any, any]:
"""
Creates a dictionary from a list of tuples.
Args:
tuples_list (List[Tuple[any, any]]): The... |
code_exercise_27k | 4,080 | Write a Python function to find the index of the first common element between two sets. If there is no common element, the function should return -1. The function should be efficient and should handle sets of varying sizes.
The code should start with:
```python
def find_intersection_index(set1: set, set2: set) -> int:... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_intersection_index(set1: set, set2: set) -> int:
"""
Finds the index of the first common element between two sets.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
... |
code_exercise_27k | 4,081 | Write a Python function to calculate the boolean XOR operation between two variables `a` and `b` and return the result. The function should handle any combination of boolean inputs and return the correct boolean result based on the XOR logic. The code should start with:
```python
def boolean_xor(a: bool, b: bool) -> bo... | Here is the Python code to solve the given problem in the markdown block:
```python
def boolean_xor(a: bool, b: bool) -> bool:
"""
Calculate the boolean XOR operation between two variables 'a' and 'b'.
Parameters:
a (bool): The first boolean input.
b (bool): The second boolean input.
Returns:
... |
code_exercise_27k | 4,082 | Write a Python function to find the intersection of all the lists in a given list of lists. The function should return a list containing the common elements present in all the inner lists. The code should start with:
```python
from typing import List
def find_intersection_of_lists(list_of_lists: List[List[int]]) -> Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_intersection_of_lists(list_of_lists: List[List[int]]) -> List[int]:
"""
Find the intersection of all the lists in the given list of lists.
Args:
list_of_lists (List[List[int]]): A l... |
code_exercise_27k | 4,086 | Write a Python function to extract a substring from a given string `text` starting from a specified index `start` and ending at a specified index `end`. The function should handle cases where `start` or `end` are out of bounds by adjusting them to the nearest valid index. The function should also handle cases where `te... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_substring(text: str, start: int, end: int) -> str:
"""
Extracts a substring from a given string 'text' starting from index 'start' and ending at index 'end'.
Args:
text (str): The original text from which th... |
code_exercise_27k | 4,089 | Write a Python function to perform exponentiation on a given variable `a` with a specified exponent `b` using the assignment operator. The function should return the result of the exponentiation. The code should start with:
```python
def exponentiate_variable(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def exponentiate_variable(a: int, b: int) -> int:
"""
Perform exponentiation on the input variable 'a' with the specified exponent 'b'.
Args:
a (int): The base number to be exponentiated.
b (int): The expone... |
code_exercise_27k | 4,092 | Write a Python function to find the key with the highest value in a given dictionary. The function should handle dictionaries with any hashable keys and comparable values. The code should start with:
```python
from typing import Any, Dict
def find_key_with_highest_value(dictionary: Dict[Any, Any]) -> Any:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, Dict
def find_key_with_highest_value(dictionary: Dict[Any, Any]) -> Any:
"""
Finds the key with the highest value in a given dictionary.
Args:
dictionary (Dict[Any, Any]): The dictionary to ... |
code_exercise_27k | 4,093 | Write a Python function to find the intersection of two sorted lists. The function should return a new list containing the common elements between the two lists, without duplicates. The function should raise a `ValueError` if either of the input lists is not sorted.
The code should start with:
```python
from typing im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_intersection(list1: List[int], list2: List[int]) -> List[int]:
"""
Find the intersection of two sorted lists.
Args:
list1 (List[int]): The first sorted list.
list2 (List[int... |
code_exercise_27k | 4,097 | Write a Python function to find the intersection of three sorted lists. The function should return a new list containing the common elements found in all three lists. The code should start with:
```python
from typing import List
def find_intersection_of_three_lists(list1: List[int], list2: List[int], list3: List[int])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_intersection_of_three_lists(list1: List[int], list2: List[int], list3: List[int]) -> List[int]:
"""
Finds the intersection of three sorted lists.
Args:
list1 (List[int]): The first ... |
code_exercise_27k | 4,098 | Write a Python function to perform a bitwise right shift operation on a given integer `x` by a specified number of positions `n`. The function should return the result of the bitwise right shift operation. The code should start with:
```python
def bitwise_right_shift(x: int, n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_right_shift(x: int, n: int) -> int:
"""
Shifts the bits of the given integer 'x' to the right by 'n' positions and returns the result.
Args:
x (int): The integer whose bits need to be shifted.
n ... |
code_exercise_27k | 4,100 | Write a Python function to extract a substring from a given string `text` based on the specified start and end indices. The function should handle both positive and negative indices, and ensure that the indices are within the bounds of the string. If the indices are out of bounds, the function should return an empty st... | Here is the Python code to solve the given problem in the markdown block:
```python
def extract_substring(text: str, start: int, end: int) -> str:
"""
Extracts a substring from the given string 'text' based on the specified start and end indices.
Args:
text (str): The original string from which the... |
code_exercise_27k | 4,102 | Write a Python function to find the common elements between two lists without using the intersection function. The function should be efficient and handle duplicate elements correctly. The code should start with:
```python
from typing import List
def find_common_elements(list1: List[int], list2: List[int]) -> List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import Counter
def find_common_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Find the common elements between two lists, preserving the count of duplicates.
Args:
... |
code_exercise_27k | 4,104 | Write a Python function to calculate the square root of a given number using the assignment operator and handle the case where the input number is negative by raising a `ValueError`. The function should start with:
```python
import math
def calculate_square_root(x: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_square_root(x: float) -> float:
"""
Calculate the square root of a given number.
Args:
x (float): The number to calculate the square root of.
Returns:
float: The square root o... |
code_exercise_27k | 4,108 | Write a Python function to find the intersection of two lists while preserving the order of elements in the first list. The function should return a new list containing elements that are present in both input lists, with the order of elements in the result list matching the order of their first appearance in the first ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def intersection_preserve_order(list1: List[int], list2: List[int]) -> List[int]:
"""
Find the intersection of two lists while preserving the order of elements in the first list.
Args:
list1... |
code_exercise_27k | 4,109 | Write a Python function to remove all even numbers from a given set of integers. The function should return a new set containing only the odd numbers from the original set. The code should start with:
```python
def remove_even_numbers(numbers: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_even_numbers(numbers: set) -> set:
"""
Removes all even numbers from the given set of integers.
Args:
numbers (set): A set of integers from which to remove even numbers.
Returns:
set: A new s... |
code_exercise_27k | 4,113 | Write a Python function to find the intersection of two sets, which are provided as lists of integers. The function should return the intersection as a list of integers, sorted in ascending order. The code should start with:
```python
from typing import List
def find_intersection_of_lists(list1: List[int], list2: List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_intersection_of_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Finds the intersection of two lists of integers and returns the result as a sorted list.
Args:
list1 (Lis... |
code_exercise_27k | 4,114 | Write a Python function to find the intersection of two lists without using built-in functions like `set.intersection` or `list.intersection`. The function should return a new list containing the common elements from both lists, ensuring that each common element appears only once in the result.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_intersection(list1: List[int], list2: List[int]) -> List[int]:
"""
Finds the intersection of two lists without using built-in functions.
Args:
list1 (List[int]): The first list.
... |
code_exercise_27k | 4,117 | Write a Python function to find the intersection of two lists using the set data structure. The function should return a list of common elements, sorted in ascending order. The code should start with:
```python
from typing import List
def find_intersection_sorted(list1: List[int], list2: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_intersection_sorted(list1: List[int], list2: List[int]) -> List[int]:
"""
Finds the intersection of two lists using set data structure and returns the result sorted in ascending order.
Args... |
code_exercise_27k | 4,119 | Write a Python function to create a new set with the elements found in either set A or set B, but not in both. The function should use set operations to achieve this. The code should start with:
```python
def symmetric_difference_custom(set_a: set, set_b: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def symmetric_difference_custom(set_a: set, set_b: set) -> set:
"""
Creates a new set with the elements found in either set A or set B, but not in both.
Args:
set_a (set): The first set.
set_b (set): The sec... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.