source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 2,935 | Write a Python function to remove elements from a set that are not present at the beginning of a string. The function should return the modified set containing only the elements that start the string. The code should start with:
```python
def remove_elements_not_at_beginning(my_set: set, my_string: str) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_elements_not_at_beginning(my_set: set, my_string: str) -> set:
"""
Remove elements from a set that are not present at the beginning of a string.
Args:
my_set (set): The set of elements to be modified.
... |
code_exercise_27k | 2,936 | Write a Python function to remove the first occurrence of a specified element from a given tuple. If the element is not found in the tuple, the function should return the original tuple. The function should be efficient and handle edge cases such as an empty tuple or a tuple with no occurrences of the specified element... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def remove_first_occurrence(tuple_data: Tuple, element) -> Tuple:
"""
Remove the first occurrence of a specified element from a given tuple.
Args:
tuple_data (Tuple): The input tuple from w... |
code_exercise_27k | 2,937 | Write a Python function to find the kth largest element in a given list of integers using the quickselect algorithm. The function should handle the case where `k` is out of bounds by raising a `ValueError`. The code should start with:
```python
from typing import List
def find_kth_largest(nums: List[int], k: int) -> i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_kth_largest(nums: List[int], k: int) -> int:
"""
Finds the kth largest element in a list using the quickselect algorithm.
Args:
nums (List[int]): A list of integers.
k (int)... |
code_exercise_27k | 2,938 | Write a Python function to delete multiple elements from a given tuple. The function should take two parameters: the original tuple and a tuple containing the elements to be deleted. The function should return a new tuple with the specified elements removed. The code should start with:
```python
from typing import Tupl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def delete_elements_from_tuple(t: Tuple, elements: Tuple) -> Tuple:
"""
Deletes specified elements from a given tuple.
Args:
t (Tuple): The original tuple from which elements are to be dele... |
code_exercise_27k | 2,942 | Write a Python function to delete all elements from a given tuple and return a new tuple with no elements. The function should handle tuples of any size, including empty tuples. The code should start with:
```python
def delete_tuple_elements(tup: tuple) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def delete_tuple_elements(tup: tuple) -> tuple:
"""
Delete all elements from a given tuple and return a new empty tuple.
Args:
tup (tuple): The input tuple from which all elements are to be deleted.
Returns:
... |
code_exercise_27k | 2,943 | Write a Python function to remove elements from a given set that are not present at the end of a specified string. The function should return the updated set containing only the elements that are found at the end of the string.
The code should start with:
```python
def remove_elements_from_set_not_at_end(s: str, my_se... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_elements_from_set_not_at_end(s: str, my_set: set) -> set:
"""
Remove elements from a set that are not present at the end of a string.
Args:
s (str): The input string.
my_set (set): The set of elem... |
code_exercise_27k | 2,945 | Write a Python function to remove all occurrences of a specified element from a given tuple. The function should return a new tuple with the specified element removed. The original tuple should remain unchanged.
The code should start with:
```python
from typing import Tuple
def remove_elements_from_tuple(tuple_value:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def remove_elements_from_tuple(tuple_value: Tuple, element_to_remove) -> Tuple:
"""
Removes all occurrences of a specified element from a given tuple.
Args:
tuple_value (Tuple): The input t... |
code_exercise_27k | 2,946 | Write a Python function to perform multiplication of two binary numbers using only bitwise operations. The function should take two integers as input, where each integer represents a binary number. The function should return the result of the multiplication as an integer. The function should not use any arithmetic oper... | Here is the Python code to solve the given problem in the markdown block:
```python
def multiply_binary_numbers(a: int, b: int) -> int:
"""
Multiplies two binary numbers using only bitwise operations.
Args:
a (int): The first binary number.
b (int): The second binary number.
Returns:
... |
code_exercise_27k | 2,947 | Write a Python function to remove elements from a given set that are vowels in a specified string. The function should return a new set with the vowels removed. The code should start with:
```python
def remove_vowels_from_set(input_set: set, string: str) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_vowels_from_set(input_set: set, string: str) -> set:
"""
Removes vowels from the input set based on the characters present in the provided string.
Args:
input_set (set): The set from which vowels need to ... |
code_exercise_27k | 2,949 | Write a Python function to delete even-indexed elements from a given tuple. The function should return a new tuple containing only the elements at odd indices. The original tuple should not be modified.
The code should start with:
```python
from typing import Tuple
def delete_even_indexed_elements(tup: Tuple[int]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def delete_even_indexed_elements(tup: Tuple[int]) -> Tuple[int]:
"""
Deletes even-indexed elements from the given tuple and returns a new tuple with only odd-indexed elements.
Args:
tup (Tu... |
code_exercise_27k | 2,950 | Write a Python function to calculate the sum of two binary numbers using bitwise operations only. The function should take two binary strings as input and return the sum as a binary string. The function should handle binary numbers of different lengths by padding the shorter one with leading zeros. The function should ... | Here is the Python code to solve the given problem in the markdown block:
```python
def add_binary_numbers(a: str, b: str) -> str:
"""
Calculate the sum of two binary numbers using bitwise operations only.
Args:
a (str): The first binary number.
b (str): The second binary number.
Retur... |
code_exercise_27k | 2,952 | Write a Python function to remove duplicate elements from a given list while preserving the order of the first occurrence of each element. The function should return a new list with the duplicates removed. The code should start with:
```python
from typing import List
def remove_duplicates_preserve_order(lst: List) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_preserve_order(lst: List) -> List:
"""
Remove duplicate elements from a list while preserving the order of the first occurrence of each element.
Args:
lst (List): The i... |
code_exercise_27k | 2,954 | Write a Python function to remove elements from multiple positions in a tuple. The function should take a tuple and a list of positions as input and return a new tuple with the elements at the specified positions removed. The function should handle cases where the positions are out of range by raising an `IndexError`.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def remove_elements_from_tuple(data: Tuple, positions: List[int]) -> Tuple:
"""
Remove elements from multiple positions in a tuple.
Args:
data (Tuple): The original tuple.
pos... |
code_exercise_27k | 2,955 | Write a Python function to remove duplicate elements from a given list while preserving their frequency. The function should return a new list where each element is a tuple containing the original element and its frequency in the input list.
The code should start with:
```python
from typing import List, Tuple
def rem... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def remove_duplicates_with_frequency(input_list: List[int]) -> List[Tuple[int, int]]:
"""
Removes duplicate elements from a list while preserving their frequency.
Args:
input_list (Li... |
code_exercise_27k | 2,956 | Write a Python function to remove elements from a given list that are common with another list while preserving the order of the remaining elements. The function should return a new list containing only the elements from the first list that are not present in the second list.
The code should start with:
```python
from... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_common_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Remove elements from list1 that are common with list2 and preserve the order.
Args:
list1 (List[int]): The fi... |
code_exercise_27k | 2,964 | Write a Python function to delete every nth element from a given tuple. The function should return a new tuple with the specified elements removed. The code should start with:
```python
from typing import Tuple
def delete_nth_elements(tup: Tuple, n: int) -> Tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def delete_nth_elements(tup: Tuple, n: int) -> Tuple:
"""
Deletes every nth element from a given tuple.
Args:
tup (Tuple): The input tuple from which to delete elements.
n (int): Th... |
code_exercise_27k | 2,965 | Write a Python function to remove all elements from a given list that are divisible by a specified divisor. The function should return a new list containing only the elements that are not divisible by the specified divisor. The code should start with:
```python
from typing import List
def remove_divisible_elements(lst... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_divisible_elements(lst: List[int], divisor: int) -> List[int]:
"""
Remove all elements from a list that are divisible by a specified divisor.
Args:
lst (List[int]): The list of in... |
code_exercise_27k | 2,966 | Write a Python function to determine if a given character is a vowel, consonant, or neither. The function should handle both uppercase and lowercase characters and return 'vowel' if the character is a vowel, 'consonant' if the character is a consonant, and 'invalid' if the character is neither. The function should also... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_character_type(character: str) -> str:
"""
Determines if a given character is a vowel, consonant, or neither.
Args:
character (str): The character to be checked. If the input string has more than one chara... |
code_exercise_27k | 2,967 | Write a Python function to remove elements from a set that are uppercase characters in a given string. The function should modify the set in place and return the modified set. The code should start with:
```python
def remove_uppercase_from_set(word_set: set, input_string: str) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_uppercase_from_set(word_set: set, input_string: str) -> set:
"""
Removes uppercase characters from a set based on an input string.
Args:
word_set (set): The set to modify.
input_string (str): The ... |
code_exercise_27k | 2,972 | Write a Python function to remove all occurrences of a specified element from a given tuple without using the `del` statement. The function should return the modified tuple. The code should start with:
```python
from typing import Tuple
def remove_element_from_tuple(tup: Tuple, element) -> Tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def remove_element_from_tuple(tup: Tuple, element) -> Tuple:
"""
Remove all occurrences of a specified element from a given tuple and return the modified tuple.
Args:
tup (Tuple): The input... |
code_exercise_27k | 2,974 | Write a Python function to remove elements from a set that are not present in a specified substring of a given string. The function should take a set of characters, a string, and the start and end indices of the substring as inputs. It should return a new set containing only the elements that are present in the specifi... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_elements_not_in_substring(my_set: set, my_string: str, start: int, end: int) -> set:
"""
Remove elements from a set that are not present in a specified substring of a given string.
Args:
my_set (set): The... |
code_exercise_27k | 2,980 | Write a Python function to generate all possible combinations of a given list of characters. Each combination should be a tuple containing one or more characters from the list. The function should return a list of all such combinations.
The code should start with:
```python
from typing import List, Tuple
import iterto... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import itertools
def generate_combinations(characters: List[str]) -> List[Tuple[str]]:
"""
Generate all possible combinations of a list of characters.
Args:
characters (List[str]): Li... |
code_exercise_27k | 2,987 | Write a Python function to determine if a given number is a prime number. The function should return `True` if the number is prime and `False` otherwise. The function should be efficient and handle edge cases such as numbers less than 2.
The code should start with:
```python
def is_prime(number: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(number: int) -> bool:
"""
Determine if the given number is a prime number.
Args:
number (int): The number to be checked.
Returns:
bool: True if the number is prime, False otherwise.
"""... |
code_exercise_27k | 2,988 | Write a Python function to remove elements from a set that have repeating characters in a string. The function should iterate through each string in the set, check if the string contains any repeating characters, and if so, remove it from the set. The function should return the modified set.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_repeating_chars(my_set: set) -> set:
"""
Removes elements from a set that have repeating characters in a string.
Args:
my_set (set): A set containing strings.
Returns:
set: The modified set w... |
code_exercise_27k | 2,989 | Write a Python function to group elements in a list by their occurrence. The function should return a dictionary where the keys represent the unique elements in the list and the values represent the number of times each element occurs in the list. The code should start with:
```python
from typing import List, Dict
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def group_by_occurrence(lst: List[int]) -> Dict[int, int]:
"""
Group elements in a list by their occurrence.
Args:
lst (List[int]): The list of integers to be grouped.
Returns:
... |
code_exercise_27k | 2,990 | Write a Python function to delete elements from a tuple that satisfy a given condition. The function should take a tuple and a condition function as input and return a new tuple with the elements that do not satisfy the condition. The code should start with:
```python
def delete_from_tuple(t: tuple, condition) -> tuple... | Here is the Python code to solve the given problem in the markdown block:
```python
def delete_from_tuple(t: tuple, condition) -> tuple:
"""
Deletes elements from a tuple that satisfy a given condition.
Args:
t (tuple): The original tuple from which elements are to be deleted.
condition (fu... |
code_exercise_27k | 2,991 | Write a Python function to find the greatest common divisor (GCD) of two non-negative integers using the Euclidean algorithm. The function should raise a `ValueError` if either of the input numbers is negative. The code should start with:
```python
def gcd(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def gcd(a: int, b: int) -> int:
"""
Calculate the greatest common divisor (GCD) of two non-negative integers using the Euclidean algorithm.
Args:
a (int): The first non-negative integer.
b (int): The second ... |
code_exercise_27k | 2,992 | Write a Python function to remove duplicate characters from a list of strings while preserving the order of the first occurrence of each character. The function should return a list of strings where each string contains only unique characters from the original string, in the order they first appeared.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_preserve_order(strings: List[str]) -> List[str]:
"""
Remove duplicate characters from a list of strings while preserving the order of the first occurrence of each character.
Ar... |
code_exercise_27k | 2,995 | Write a Python function to determine the type of a triangle based on the lengths of its sides. The function should classify the triangle as 'Equilateral', 'Isosceles', or 'Scalene'. Additionally, the function should raise a `ValueError` if the given side lengths do not form a valid triangle.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
def triangle_type(a: float, b: float, c: float) -> str:
"""
Determine the type of a triangle based on the lengths of its sides.
Parameters:
a (float): The length of the first side of the triangle.
b (float): The len... |
code_exercise_27k | 2,996 | Write a Python function to remove the first `n` elements from a given list. If `n` is greater than the length of the list, the function should return an empty list. The function should not raise any exceptions.
The code should start with:
```python
from typing import List
def remove_first_n_elements(lst: List[int], n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_first_n_elements(lst: List[int], n: int) -> List[int]:
"""
Remove the first n elements from the given list.
Args:
lst (List[int]): The input list from which elements are to be rem... |
code_exercise_27k | 2,998 | Write a Python function to remove adjacent duplicate elements from a given tuple. The function should return a new tuple with all adjacent duplicate elements removed. The original tuple should not be modified.
The code should start with:
```python
from typing import Tuple
def remove_adjacent_duplicates(tpl: Tuple) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def remove_adjacent_duplicates(tpl: Tuple) -> Tuple:
"""
Removes adjacent duplicate elements from a given tuple and returns a new tuple.
Args:
tpl (Tuple): The input tuple from which adjace... |
code_exercise_27k | 2,999 | Write a Python function to remove elements at even indices from a given list. The function should return a new list containing only the elements at odd indices. The original list should not be modified.
The code should start with:
```python
from typing import List
def remove_even_index(lst: List) -> List:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_even_index(lst: List) -> List:
"""
Remove elements at even indices from a given list and return a new list with only the elements at odd indices.
Args:
lst (List): The input list ... |
code_exercise_27k | 3,001 | Write a Python function to check if a given list of integers is a palindrome. A list is considered a palindrome if it reads the same forwards and backwards. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def is_palindrome_list(lst: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_palindrome_list(lst: List[int]) -> bool:
"""
Check if a list of integers is a palindrome.
A list is considered a palindrome if it reads the same forwards and backwards.
Args:
lst... |
code_exercise_27k | 3,004 | Write a Python function to remove specified elements from a given tuple without using any built-in functions. The function should iterate through the original tuple and construct a new tuple that excludes the specified elements. The code should start with:
```python
from typing import Tuple
def remove_elements_from_tu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def remove_elements_from_tuple(tup: Tuple, elements: Tuple) -> Tuple:
"""
Removes specified elements from a given tuple without using built-in functions.
Args:
tup (Tuple): The original tup... |
code_exercise_27k | 3,005 | Write a Python function to delete all elements from a given tuple except the first and last element. The function should return a new tuple containing only the first and last elements of the input tuple. The code should start with:
```python
def delete_elements_from_tuple(t: tuple) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def delete_elements_from_tuple(t: tuple) -> tuple:
"""
Delete all elements from a tuple except the first and last element.
Args:
t (tuple): The tuple from which elements need to be deleted.
Returns:
tup... |
code_exercise_27k | 3,007 | Write a Python function to find the largest subarray with non-negative elements in a given list of integers. The function should return the largest subarray containing only non-negative integers. If there are multiple subarrays with the same maximum length, return the first one encountered.
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_largest_subarray_non_negative(nums: List[int]) -> List[int]:
"""
Find the largest subarray with non-negative elements in a list.
Args:
nums (List[int]): The input list of integers.
... |
code_exercise_27k | 3,009 | Write a Python function to remove elements from a tuple that are divisible by a given integer `k`. The function should return a new tuple containing only the elements that are not divisible by `k`. The code should start with:
```python
from typing import Tuple
def remove_elements_divisible_by_k(tup: Tuple[int], k: int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def remove_elements_divisible_by_k(tup: Tuple[int], k: int) -> Tuple[int]:
"""
Remove elements from a tuple that are divisible by a given integer `k`.
Args:
tup (Tuple[int]): The input tupl... |
code_exercise_27k | 3,010 | Write a Python function to remove elements from a set that have a specific number of special characters in a string. Special characters are defined as any character that is not alphanumeric (i.e., not a letter or a digit). The function should return a new set with the elements that do not meet the specified number of s... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_elements_with_special_chars(my_set: set, num_special_chars: int) -> set:
"""
Removes elements from a set that have a specific number of special characters in a string.
Args:
my_set (set): The set of eleme... |
code_exercise_27k | 3,012 | Write a Python function to determine if a given number is a perfect square. The function should use a binary search approach to efficiently check if the number is a perfect square. The function should handle edge cases such as negative numbers and small numbers (0 and 1). The code should start with:
```python
def is_pe... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_perfect_square(number: int) -> bool:
"""
Determine if a given number is a perfect square using a binary search approach.
Args:
number (int): The number to check.
Returns:
bool: True if the number... |
code_exercise_27k | 3,014 | Write a Python function to find the largest sum of a contiguous subarray within a given list of integers. The function should return the maximum sum of any subarray found. The code should start with:
```python
from typing import List
def max_subarray_sum(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_subarray_sum(arr: List[int]) -> int:
"""
Find the largest sum of a contiguous subarray within a given list of integers.
Args:
arr (List[int]): List of integers.
Returns:
... |
code_exercise_27k | 3,015 | Write a Python function to remove elements from a set of strings that contain both uppercase and lowercase characters. The function should return a new set containing only the strings that do not have both uppercase and lowercase characters.
The code should start with:
```python
def remove_elements_with_mixed_case(str... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_elements_with_mixed_case(string_set: set) -> set:
"""
Remove elements from a set if they contain both uppercase and lowercase characters.
Args:
string_set (set): A set of strings to process.
Returns:... |
code_exercise_27k | 3,018 | Write a Python function to calculate the sum of the digits of a given number. The function should handle both positive and negative integers. If the number is negative, the function should ignore the negative sign and calculate the sum of the digits.
The code should start with:
```python
def sum_of_digits(number: int)... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_digits(number: int) -> int:
"""
Calculates the sum of digits in a given number, ignoring the negative sign if present.
Args:
number (int): The number whose digits need to be summed.
Returns:
... |
code_exercise_27k | 3,022 | Write a Python function to check if a given string has matching pairs of delimiters (e.g., parentheses, brackets, or braces). The function should return `True` if all delimiters are properly matched and `False` otherwise. The code should start with:
```python
def has_matching_delimiters(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def has_matching_delimiters(string: str) -> bool:
"""
Check if a given string has matching pairs of delimiters.
Args:
string (str): The string to check.
Returns:
bool: True if all delimiters are properl... |
code_exercise_27k | 3,025 | Write a Python function to concatenate two lists without using built-in functions like `extend` or `+`. The function should iterate through each list and append its elements to a new list. The code should start with:
```python
from typing import List
def concatenate_lists(list1: List[int], list2: List[int]) -> List[in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def concatenate_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Concatenates two lists without using built-in functions.
Args:
list1 (List[int]): The first list to concatenate.
... |
code_exercise_27k | 3,027 | Write a Python function to count the number of open and close delimiters in a given string. The delimiters to be considered are parentheses `()`, square brackets `[]`, and curly braces `{}`. The function should return a tuple containing the counts of open and close delimiters respectively.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_delimiters(string: str) -> tuple:
"""
Counts the number of open and close delimiters in a given string.
Args:
string (str): The input string to count the delimiters in.
Returns:
tuple: A tuple... |
code_exercise_27k | 3,029 | Write a Python function to sort three integers in ascending order without using conditional statements or loops. The function should take three integers as input and return a tuple containing the integers sorted in ascending order. The code should start with:
```python
def sort_three_integers(a: int, b: int, c: int) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def sort_three_integers(a: int, b: int, c: int) -> Tuple[int, int, int]:
"""
Sorts three integers in ascending order without using conditional statements or loops.
Args:
a (int): The first ... |
code_exercise_27k | 3,030 | Write a Python function to remove all specified delimiters from a given string. The delimiters to be removed are defined in a list. The function should return the modified string with all delimiters removed.
The code should start with:
```python
from typing import List
def remove_delimiters(string: str, delimiters: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_delimiters(string: str, delimiters: List[str]) -> str:
"""
Removes all specified delimiters from a given string.
Args:
string (str): The input string containing delimiters.
... |
code_exercise_27k | 3,037 | Write a Python function to find the largest number that can be formed by concatenating the elements of a given list of integers. The function should return the largest number as an integer. The code should start with:
```python
from typing import List
def find_largest_number(nums: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_largest_number(nums: List[int]) -> int:
"""
Find the largest number that can be formed by concatenating the elements of a list of integers.
Args:
nums (List[int]): A list of integer... |
code_exercise_27k | 3,039 | Write a Python function to find the symmetric difference between two sets. The symmetric difference between two sets is defined as the set of elements which are in either of the sets but not in both. The function should take two sets as input and return a new set containing the symmetric difference.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
def symmetric_difference(set1: set, set2: set) -> set:
"""
Computes the symmetric difference between two sets.
The symmetric difference is the set of elements which are in either of the sets
but not in both.
Args:
... |
code_exercise_27k | 3,043 | Write a Python function to find the symmetric difference between two sets and store the result in a new set. The symmetric difference between two sets is defined as the set of elements which are in either of the sets but not in both.
The code should start with:
```python
def symmetric_difference(set1: set, set2: 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.
Given two sets, this function returns a new set that contains the elements
that are in either `set1` or `set2` b... |
code_exercise_27k | 3,044 | Write a Python function to calculate the percentage of marks obtained by a student, considering the possibility of negative marks and total marks. The function should handle edge cases such as zero total marks and negative values appropriately. The code should start with:
```python
def calculate_percentage(total_marks:... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_percentage(total_marks: float, obtained_marks: float) -> float:
"""
Calculates the percentage of marks obtained by a student.
Args:
total_marks (float): Total marks for the examination. Must be positiv... |
code_exercise_27k | 3,047 | Write a Python function to determine if the delimiters in a given mathematical expression are balanced. The function should check for the following delimiters: parentheses `()`, square brackets `[]`, and curly braces `{}`. The function should return `True` if all delimiters are properly matched and nested, and `False` ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_balanced_expression(expression: str) -> bool:
"""
Check if the delimiters in the given mathematical expression are balanced.
Args:
expression (str): The mathematical expression to check.
Returns:
... |
code_exercise_27k | 3,048 | Write a Python function to determine if a given number is a power of 2 using bitwise operations. The function should return `True` if the number is a power of 2 and `False` otherwise. The code should start with:
```python
def is_power_of_two_bitwise(n: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_power_of_two_bitwise(n: int) -> bool:
"""
Determines if a given number is a power of 2 using bitwise operations.
Args:
n (int): The number to be checked.
Returns:
bool: True if the number is a po... |
code_exercise_27k | 3,049 | Write a Python function to find the elements that are present in the first set `S1`, but not in the second set `S2`. The function should return a new set containing these elements. The code should start with:
```python
def find_elements_in_s1_not_in_s2(S1: set, S2: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_elements_in_s1_not_in_s2(S1: set, S2: set) -> set:
"""
Finds the elements that are present in S1, but not in S2.
Args:
S1 (set): The first set.
S2 (set): The second set.
Returns:
set: A... |
code_exercise_27k | 3,053 | Write a Python function to calculate the symmetric difference between two sets and return the result. The symmetric difference of two sets is defined as the set of elements which are in either of the sets but not in their intersection. The code should start with:
```python
def symmetric_difference(set1: set, set2: set)... | Here is the Python code to solve the given problem in the markdown block:
```python
def symmetric_difference(set1: set, set2: set) -> set:
"""
Calculate the symmetric difference between two sets and return the result.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns... |
code_exercise_27k | 3,054 | Write a Python function to compute the symmetric difference between two sets. The symmetric difference of two sets is the set of elements which are in either of the sets, but not in their intersection. The function should handle any type of set input and return the symmetric difference as a set.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
def symmetric_difference(set1: set, set2: set) -> set:
"""
Compute the symmetric difference between two sets.
The symmetric difference of two sets is the set of elements which are in either of the sets,
but not in their... |
code_exercise_27k | 3,055 | Write a Python function to replace all occurrences of a specific delimiter with a different delimiter in a given string. The function should handle multiple occurrences of the delimiter and should not modify the original string. The code should start with:
```python
def replace_delimiter(string: str, old_delimiter: str... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_delimiter(string: str, old_delimiter: str, new_delimiter: str) -> str:
"""
Replaces all occurrences of a specific delimiter with a different delimiter in a given string.
Args:
string (str): The input str... |
code_exercise_27k | 3,056 | 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, with the same frequency, but possibly in a different order. The function should return `True` if the two lists are permutations of each other, and `False` othe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def are_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 compare.
list2... |
code_exercise_27k | 3,057 | Write a Python function to find the largest among four numbers using nested if statements. The function should take four numbers as input and return the largest number. The code should start with:
```python
def find_largest(num1: int, num2: int, num3: int, num4: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_largest(num1: int, num2: int, num3: int, num4: int) -> int:
"""
Find the largest among four numbers using nested if statements.
Args:
num1 (int): The first number to compare.
num2 (int): The second ... |
code_exercise_27k | 3,058 | Write a Python function to split a given string into substrings using a specific delimiter, while also handling cases where the delimiter might not be present in the string. The function should return a list of substrings, and if the delimiter is not found, it should return the original string as a single-element list.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def split_string_with_delimiter(string: str, delimiter: str) -> List[str]:
"""
Splits a given string into substrings using a specific delimiter.
If the delimiter is not found in the string, returns t... |
code_exercise_27k | 3,060 | Write a Python function to find the smallest among four numbers using nested if statements. The function should take four numbers as input and return the smallest number. The code should start with:
```python
def find_smallest(a: int, b: int, c: int, d: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_smallest(a: int, b: int, c: int, d: int) -> int:
"""
Find the smallest among four numbers using nested if statements.
Args:
a (int): The first number to compare.
b (int): The second number to compar... |
code_exercise_27k | 3,063 | Write a Python function to find the elements that are not common between two sets and return them in a new set. The function should efficiently compute the result using set operations.
The code should start with:
```python
def find_non_common_elements(set1: set, set2: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_non_common_elements(set1: set, set2: set) -> set:
"""
Finds the elements that are not common between two sets and returns them in a new set.
Args:
set1 (set): The first set.
set2 (set): The second s... |
code_exercise_27k | 3,064 | Write a Python function to determine if a given number is both a prime number and a palindrome. The function should return `True` if the number meets both criteria, and `False` otherwise. The code should start with:
```python
def is_prime_palindrome(n: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime_palindrome(n: int) -> bool:
"""
Determine if a given number is both a prime number and a palindrome.
Args:
n (int): The number to check.
Returns:
bool: True if the number is both a prime an... |
code_exercise_27k | 3,071 | Write a Python function to check if a given string has balanced delimiters, ignoring any nested delimiters. The function should ensure that each opening delimiter has a corresponding closing delimiter in the correct order. The function should handle the following delimiters: parentheses `()`, square brackets `[]`, and ... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_delimiters_balanced(string: str) -> bool:
"""
Check if a given string has balanced delimiters, ignoring any nested delimiters.
Args:
string (str): The input string containing delimiters.
Returns:
... |
code_exercise_27k | 3,073 | Write a Python function to remove the last occurrence of a specific delimiter from a given string. The function should handle cases where the delimiter is not present in the string and should return the original string in such cases. The function should also handle cases where the delimiter is an empty string.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_last_occurrence(text: str, delimiter: str) -> str:
"""
Remove the last occurrence of a specific delimiter from the given string.
Args:
text (str): The input string from which to remove the delimiter.
... |
code_exercise_27k | 3,081 | Write a Python function to count the number of nested delimiters in a given string. The function should take three parameters: the input string, the opening delimiter, and the closing delimiter. The function should return the number of nested pairs of delimiters found in the string. A nested pair is defined as a pair o... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_nested_delimiters(string: str, opening_delimiter: str, closing_delimiter: str) -> int:
"""
Counts the number of nested delimiters in a given string.
Args:
string (str): The input string to search for neste... |
code_exercise_27k | 3,086 | Write a Python function to check if a list contains three consecutive duplicates. The function should return `True` if there are three consecutive elements in the list that are the same, and `False` otherwise. The code should start with:
```python
from typing import List
def has_three_consecutive_duplicates(lst: List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def has_three_consecutive_duplicates(lst: List[int]) -> bool:
"""
Check if a list contains three consecutive duplicates.
Args:
lst (List[int]): The list to be checked.
Returns:
... |
code_exercise_27k | 3,089 | Write a Python function to find the set difference between two sets using a different approach than the built-in set difference method. The function should iterate through the elements of the first set and add them to a new set if they are not present in the second set. The code should start with:
```python
def custom_... | Here is the Python code to solve the given problem in the markdown block:
```python
def custom_set_difference(set1: set, set2: set) -> set:
"""
Find the set difference between two sets using a custom approach.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
... |
code_exercise_27k | 3,090 | Write a Python function to check if a given string is a valid URL or not. The function should use a regular expression to validate the URL. The URL should be considered valid if it starts with `http://` or `https://`, followed by a domain name, an optional port number, and an optional path, query string, or fragment. T... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_url(url: str) -> bool:
"""
Check if a given string is a valid URL.
Parameters:
url (str): The string to be checked.
Returns:
bool: True if the string is a valid URL, False otherw... |
code_exercise_27k | 3,091 | Write a Python function to find the smallest missing positive integer in a given list of integers. The function should return `None` if there are no positive integers in the list. The code should start with:
```python
from typing import List, Optional
def find_smallest_missing_positive(numbers: List[int]) -> Optional[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_smallest_missing_positive(numbers: List[int]) -> Optional[int]:
"""
Finds the smallest missing positive integer in a given list of integers.
Args:
numbers (List[int]): A l... |
code_exercise_27k | 3,092 | Write a Python function to find the intersection of two sets. The function should take two sets as input and return a new set that contains only the elements that are present in both sets. The code should start with:
```python
def intersection(set1: set, set2: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def intersection(set1: set, set2: set) -> set:
"""
Returns the intersection of two sets.
Parameters:
set1 (set): The first set.
set2 (set): The second set.
Returns:
set: The intersection of the two sets.
... |
code_exercise_27k | 3,093 | Write a Python function to find the largest number in a list that is smaller than a given target value. If no number in the list satisfies the condition, the function should return `None`. The code should start with:
```python
from typing import List, Union
def find_largest_smaller_number(lst: List[Union[int, float]],... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_largest_smaller_number(lst: List[Union[int, float]], target: Union[int, float]) -> Union[int, float, None]:
"""
Find the largest number in a list that is smaller than a given target value... |
code_exercise_27k | 3,094 | Write a Python function to calculate the sum of the squares of the first n natural numbers. The function should handle input validation to ensure that n is a positive integer. If n is not a positive integer, the function should raise a `ValueError`.
The code should start with:
```python
def sum_of_squares(n: int) -> i... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_squares(n: int) -> int:
"""
Calculates the sum of the squares of the first n natural numbers.
Args:
n (int): The number of natural numbers to consider.
Returns:
int: The sum of the squares of... |
code_exercise_27k | 3,101 | Write a Python function to check if a given string is a valid IPv4 address. An IPv4 address consists of four decimal numbers separated by dots, where each number is between 0 and 255 inclusive. The function should return `True` if the address is valid and `False` otherwise.
The code should start with:
```python
def is... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_ipv4(address: str) -> bool:
"""
Check if a given string is a valid IPv4 address.
An IPv4 address consists of four decimal numbers separated by dots,
where each number is between 0 and 255 inclusive.
Ar... |
code_exercise_27k | 3,102 | Write a Python function to convert a list of integers into their corresponding Roman numerals. Each integer in the list should be converted individually using the `int_to_roman` function provided. The function should handle lists of varying lengths and ensure that the conversion is accurate for all integers within the ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def int_to_roman(num: int) -> str:
"""
Converts an integer into a Roman numeral.
Parameters:
- num (int): The integer to be converted.
Returns:
- roman_numeral (str): The Roman numeral ... |
code_exercise_27k | 3,105 | 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 sets of any size, including empty sets.
The code should start with:
```python
def is_subset(set... | 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,108 | Write a Python function to remove duplicates from a given list and return the result as a new list. The function should maintain the order of elements as they appear in the input list. The code should start with:
```python
from typing import List
def remove_duplicates_from_list(input_list: List[int]) -> List[int]:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_from_list(input_list: List[int]) -> List[int]:
"""
Removes duplicates from a list while maintaining the order of elements.
Args:
input_list (List[int]): The original li... |
code_exercise_27k | 3,109 | Write a Python function to calculate the sum of digits of a given number using recursion. The function should handle both positive and negative integers. If the input number is negative, the function should return the sum of digits of the absolute value of the number.
The code should start with:
```python
def sum_of_d... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_digits(n: int) -> int:
"""
Calculates the sum of digits of a given number using recursion.
Args:
n (int): The input number.
Returns:
int: The sum of digits of the input number.
Example:
... |
code_exercise_27k | 3,112 | Write a Python function to merge multiple sets into a single set. The function should accept a variable number of sets as arguments and return a new set that contains all the unique elements from the input sets. The function should handle any number of input sets, including zero sets.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set, Union
def merge_sets(*sets: Union[Set[int], Set[str], Set[float]]) -> Set[Union[int, str, float]]:
"""
Merge multiple sets into a single set containing all unique elements.
Args:
*sets: A va... |
code_exercise_27k | 3,114 | Write a Python function to find the symmetric difference between two sets. The symmetric difference between two sets is defined as the set of elements which are in either of the sets but not in both. The function should return a new set containing the symmetric difference.
The code should start with:
```python
def sym... | 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 between two sets is the set of elements which are in either of the sets but not in both.
... |
code_exercise_27k | 3,116 | Write a Python function to find the maximum number of non-overlapping subarrays with a sum of zero in a given list. The function should return the count of such subarrays. The code should start with:
```python
from typing import List
def max_zero_sum_subarrays(nums: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_zero_sum_subarrays(nums: List[int]) -> int:
"""
Find the maximum number of non-overlapping subarrays with a sum of zero in a given list.
Args:
nums: List of integers.
Returns:
... |
code_exercise_27k | 3,119 | Write a Python function to count the number of digits in a given number. The function should handle both positive and negative integers, as well as the special case of zero. The code should start with:
```python
def count_digits(number: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_digits(number: int) -> int:
"""
Counts the number of digits in a given integer.
Args:
number (int): The integer for which to count the digits.
Returns:
int: The number of digits in the given i... |
code_exercise_27k | 3,121 | Write a Python function to find the maximum sum of non-adjacent elements in a given list of integers. The function should return the maximum sum that can be obtained by selecting elements such that no two selected elements are adjacent in the list.
The code should start with:
```python
from typing import List
def max... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_sum_non_adjacent(nums: List[int]) -> int:
"""
Find the maximum sum of non-adjacent elements in a list.
Args:
nums (List[int]): A list of integers.
Returns:
int: The maxi... |
code_exercise_27k | 3,125 | Write a Python function to find the length of a set and return the length as an integer. The function should handle sets of various sizes, including empty sets. The code should start with:
```python
def calculate_set_length(my_set: set) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_set_length(my_set: set) -> int:
"""
Calculate the length of a given set.
Args:
my_set (set): The set for which the length needs to be calculated.
Returns:
int: The length of the set.
"... |
code_exercise_27k | 3,127 | Write a Python function to find the maximum length of an increasing subsequence in a given list of integers. An increasing subsequence is a sequence of numbers where each number is strictly greater than the previous number. The function should return the length of the longest such subsequence.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_increasing_subsequence_length(nums: List[int]) -> int:
"""
Finds the maximum length of an increasing subsequence in a list.
Args:
nums (List[int]): A list of integers.
Returns:
... |
code_exercise_27k | 3,129 | Write a Python function to calculate the symmetric difference of two sets. The symmetric difference of two sets is the set of elements which are in either of the sets but not in both. The function should handle sets of any size and type of elements. The code should start with:
```python
def symmetric_difference(set1: s... | Here is the Python code to solve the given problem in the markdown block:
```python
def symmetric_difference(set1: set, set2: set) -> set:
"""
Calculates the symmetric difference of two sets.
The symmetric difference of two sets is the set of elements which are in either of the sets but not in both.
A... |
code_exercise_27k | 3,131 | Write a Python function to find the longest common prefix among a list of strings. The function should return the longest prefix that is common to all strings in the list. If there is no common prefix, the function should return an empty string.
The code should start with:
```python
from typing import List
def longes... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_common_prefix(strings: List[str]) -> str:
"""
Find the longest common prefix among a list of strings.
Args:
strings (List[str]): A list of strings to find the longest common pref... |
code_exercise_27k | 3,132 | Write a Python function to determine if a given number is a perfect power of another number. A number is considered a perfect power if there exist integers `a` and `b` such that `a^b = n` where `a > 1` and `b > 1`. The function should return `True` if the number is a perfect power, and `False` otherwise.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_perfect_power(n: int) -> bool:
"""
Determine if a given number is a perfect power of another number.
A number `n` is a perfect power if there exist integers `a` and `b` such that `a^b = n`
where `a > 1` and `b > ... |
code_exercise_27k | 3,133 | Write a Python function to find the k largest elements from a given dataset efficiently. The dataset is a list of integers. The function should return a list of the k largest elements in descending order.
The code should start with:
```python
from typing import List
def get_k_largest_elements(dataset: List[int], k: i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import heapq
def get_k_largest_elements(dataset: List[int], k: int) -> List[int]:
"""
Returns the k largest elements from the given dataset in descending order.
Args:
dataset (list): The dat... |
code_exercise_27k | 3,134 | Write a Python function to find the k smallest elements in a given set of integers. 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 of the set in ascending order. The function should handle sets of any siz... | 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(s: Set[int], k: int) -> List[int]:
"""
Returns the k smallest elements from the given set of integers in ascending order.
Args:
s (Set[int]): The set of int... |
code_exercise_27k | 3,136 | Write a Python function to determine if a given string is an anagram of any element in a list of strings. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should be case-insensitive and should ignore any n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def is_anagram_of_any(string: str, lst: List[str]) -> bool:
"""
Determines if a given string is an anagram of any element in a list of strings.
Args:
string (str): The string to ch... |
code_exercise_27k | 3,138 | Write a Python function to find the common elements between two lists. The function should return a list containing the common elements, sorted in ascending order. 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
def find_common_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Find the common elements between two lists and return them sorted in ascending order.
Args:
list1 (List[int]): ... |
code_exercise_27k | 3,139 | Write a Python function to determine if a list of intervals is non-overlapping. Each interval is represented as a tuple of two numbers: (start, end). The function should return `True` if the intervals are non-overlapping, and `False` otherwise. The function should also handle invalid intervals by raising a `ValueError`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def is_non_overlapping(intervals: List[Tuple[int, int]]) -> bool:
"""
Check if a list of intervals is non-overlapping.
Args:
intervals (List[Tuple[int, int]]): A list of intervals, wh... |
code_exercise_27k | 3,142 | Write a Python function to create a deep copy of a dictionary. A deep copy means that the new dictionary will have its own copy of all the elements, including nested dictionaries, lists, and other mutable objects. The function should handle dictionaries with arbitrary levels of nesting.
The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, Dict
def deep_copy_dict(original: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Create a deep copy of a dictionary, including all nested dictionaries, lists, and other mutable objects.
Args:
origin... |
code_exercise_27k | 3,143 | Write a Python function to find the maximum profit achievable by buying and selling stocks from a given list of stock prices over a period of time. The function should return the maximum profit that can be achieved by buying at the lowest price and selling at the highest price after the buying point. The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_profit(prices: List[float]) -> float:
"""
Finds the maximum profit achievable by buying and selling stocks.
Args:
prices (List[float]): A list of stock prices over a period of time.
... |
code_exercise_27k | 3,146 | Write a Python function to update elements in a set based on a given list of elements. The function should add elements to the set if they are not already present and remove elements if they are present in the set. The function should handle both positive and negative integers in the list, where positive integers indic... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Set
def update_set_elements(s: Set[int], elements: List[int]) -> Set[int]:
"""
Update elements in a set based on a given list of elements.
This function takes a set `s` and a list of elements `elem... |
code_exercise_27k | 3,157 | Write a Python function to count the number of unique elements in a list. The function should take a list of integers as input and return the count of unique elements in the list. The code should start with:
```python
from typing import List
def count_unique_elements(lst: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def count_unique_elements(lst: List[int]) -> int:
"""
Count the number of unique elements in a list.
Args:
lst (List[int]): The list of integers for which to count unique elements.
Re... |
code_exercise_27k | 3,160 | Write a Python function to check if a set is a superset of another set. The function should return `True` if the first set is a superset of the second set, and `False` otherwise. The function should handle any type of sets, including empty sets and sets with different types of elements.
The code should start with:
```... | 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,162 | Write a Python function to check if a given string has an equal number of open and close delimiters, and if each open delimiter has a corresponding close delimiter in the correct order. The delimiters to be considered are `()`, `[]`, and `{}`. The function should return `True` if the string is balanced, and `False` oth... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_balanced_delimiters(string: str) -> bool:
"""
Check if a given string has an equal number of open and close delimiters,
and if each open delimiter has a corresponding close delimiter in the correct order.
Args:
... |
code_exercise_27k | 3,163 | Write a Python function to find the maximum and minimum values from two sets. The function should handle the case where either set is empty by raising a `ValueError`. The function should return a tuple containing the maximum and minimum values from the combined set of both input sets.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_max_min(set1: set, set2: set) -> tuple:
"""
Find the maximum and minimum values from two sets.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
tuple: A tuple conta... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.