source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 2,647 | Write a Python function named `is_unique_words` that takes a string called `sentence` as a parameter. The function should return `True` if all words in the sentence are unique (no duplicates), and `False` otherwise. The function should handle case-insensitive comparison and ignore punctuation.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
import string
def is_unique_words(sentence: str) -> bool:
"""
Check if all words in a sentence are unique, ignoring case and punctuation.
Args:
sentence (str): The sentence to check.
Returns:
bool: Tru... |
code_exercise_27k | 2,649 | Write a Python function named `is_substring` that takes two parameters: two strings called `str1` and `str2`. The function should return `True` if `str1` is a substring of `str2` (i.e., `str1` appears consecutively within `str2`), and `False` otherwise. The function should be efficient and handle edge cases such as emp... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_substring(str1: str, str2: str) -> bool:
"""
Check if str1 is a substring of str2.
Parameters:
str1 (str): The first string to check if it is a substring.
str2 (str): The second string to check against.
... |
code_exercise_27k | 2,651 | Write a Python function named `is_rotation` that takes two parameters: two strings called `str1` and `str2`. The function should return `True` if `str1` is a rotation of `str2` (i.e., `str1` can be obtained by rotating `str2` by any number of positions), and `False` otherwise. The function should handle cases where the... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_rotation(str1: str, str2: str) -> bool:
"""
Check if str1 is a rotation of str2.
Parameters:
str1 (str): The first string.
str2 (str): The second string.
Returns:
bool: True if str1 is a rotation of ... |
code_exercise_27k | 2,653 | Write a Python function named `is_anagram_strict_case_insensitive` that takes two parameters: two strings called `str1` and `str2`. The function should return `True` if `str1` is a strict anagram of `str2` (contains the same characters with the same frequencies), ignoring case, and `False` otherwise. The function shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_anagram_strict_case_insensitive(str1: str, str2: str) -> bool:
"""
Check if str1 is a strict anagram of str2, ignoring case.
Parameters:
str1 (str): The first string.
str2 (str): The second string.
Retur... |
code_exercise_27k | 2,656 | Write a Python function named `find_missing_chars_str_case_insensitive` that takes two parameters: two strings called `str1` and `str2`. The function should return a new string containing the characters that are present in `str1` but not in `str2`, ignoring case. The function should handle both uppercase and lowercase ... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_missing_chars_str_case_insensitive(str1: str, str2: str) -> str:
"""
Find the characters that are present in str1 but not in str2, ignoring case.
Args:
str1 (str): The first string.
str2 (str): The ... |
code_exercise_27k | 2,659 | Write a Python function named `is_subsequence_str_case_insensitive` that takes two parameters: two strings called `str1` and `str2`. The function should return `True` if `str1` is a subsequence of `str2` (all characters in `str1` appear in `str2` in the same order), ignoring case, and `False` otherwise. The function sh... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_subsequence_str_case_insensitive(str1: str, str2: str) -> bool:
"""
Check if str1 is a subsequence of str2, ignoring case.
Parameters:
str1 (str): The first string to check if it is a subsequence.
str2 (str):... |
code_exercise_27k | 2,660 | Write a Python function named `find_unique_elements_str` that takes a string called `word` as a parameter. The function should return a new string containing the unique characters from the original word, in the order they first appear, ignoring case.
The code should start with:
```python
def find_unique_elements_str(w... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_unique_elements_str(word: str) -> str:
"""
Find the unique characters in a word, in the order they first appear, ignoring case.
Parameters:
word (str): The word to find unique characters in.
Returns:
s... |
code_exercise_27k | 2,661 | Write a Python function named `is_consecutive_str_case_insensitive` that takes a string called `word` as a parameter. The function should return `True` if the characters in the word are consecutive letters (in ascending or descending order), ignoring case, and `False` otherwise. The function should handle both uppercas... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_consecutive_str_case_insensitive(word: str) -> bool:
"""
Check if the characters in a word are consecutive letters, ignoring case.
Parameters:
word (str): The word to check.
Returns:
bool: True if the ch... |
code_exercise_27k | 2,663 | Write a Python function named `is_unique_words_str` that takes a string called `sentence` as a parameter. The function should return `True` if all words in the sentence are unique (no duplicates), ignoring case, and `False` otherwise. The function should handle sentences with multiple spaces and punctuation marks, trea... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_unique_words_str(sentence: str) -> bool:
"""
Check if all words in a sentence are unique, ignoring case.
Parameters:
sentence (str): The sentence to check.
Returns:
bool: True if all words in the sentenc... |
code_exercise_27k | 2,667 | Write a Python function named `find_unique_elements_str_case_insensitive` that takes a string called `word` as a parameter. The function should return a new string containing the unique characters from the original word, in the order they first appear, ignoring case.
The code should start with:
```python
def find_uniq... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_unique_elements_str_case_insensitive(word: str) -> str:
"""
Find the unique characters in a word, in the order they first appear, ignoring case.
Parameters:
word (str): The word to find unique characters in.
... |
code_exercise_27k | 2,675 | Write a Python function named `factorial_overflow` that calculates the factorial of a given integer `n`. If the factorial exceeds the maximum value that can be represented by an integer, the function should return the string "Overflow occurred". The function should start with:
```python
import sys
def factorial_overfl... | Here is the Python code to solve the given problem in the markdown block:
```python
import sys
def factorial_overflow(n: int) -> int or str:
"""
Calculate the factorial of a given integer n. If the factorial exceeds the maximum value
that can be represented by an integer, return the string "Overflow occurr... |
code_exercise_27k | 2,705 | Write a Python function named `binary_count_ones` that takes a binary string as input. The function should count the number of '1's in the binary string and return the count as an integer. The function should handle binary strings of any length, including empty strings.
The code should start with:
```python
def binary... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_count_ones(binary_string: str) -> int:
"""
Counts the number of '1's in a given binary string.
Args:
binary_string (str): The binary string to count '1's in.
Returns:
int: The number of '1's ... |
code_exercise_27k | 2,706 | Write a Python function named `binary_count_zeros` that takes a binary string as input. The function should count the number of zeros in the binary number and return the count as an integer. The function should handle binary strings of any length, including empty strings.
The code should start with:
```python
def bina... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_count_zeros(binary_string: str) -> int:
"""
Counts the number of zeros in a given binary string.
Args:
binary_string (str): The binary string to count zeros in.
Returns:
int: The number of ze... |
code_exercise_27k | 2,713 | Write a Python function to determine if a given integer is a prime number. The function should return `True` if the number is prime and `False` otherwise. The function should handle edge cases such as negative numbers, 0, and 1, which are not prime numbers. The function should also be efficient by checking divisibility... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def is_prime(n: int) -> bool:
"""
Determines if a given integer is a prime number.
Args:
n (int): The integer to check for primality.
Returns:
bool: True if the number is prime, False other... |
code_exercise_27k | 2,714 | Write a Python function to calculate the factorial of a given non-negative integer `n`. The factorial of a number `n` (denoted as `n!`) is the product of all positive integers less than or equal to `n`. The function should handle edge cases such as `n = 0` and `n = 1` correctly.
The code should start with:
```python
d... | Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int:
"""
Calculate the factorial of a given non-negative integer n.
The factorial of n (denoted as n!) is the product of all positive integers
less than or equal to n. By definition, 0! is 1.
... |
code_exercise_27k | 2,716 | Write a Python function named `sum_digits` that takes a non-negative integer `n` as input. The function should calculate the sum of the digits in the number and return the result as an integer. The function should handle any non-negative integer input, including zero.
The code should start with:
```python
def sum_digi... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_digits(n: int) -> int:
"""
Calculate the sum of the digits of a non-negative integer.
Args:
n (int): The non-negative integer whose digits are to be summed.
Returns:
int: The sum of the digits o... |
code_exercise_27k | 2,718 | Write a Python function to count the number of vowels in a given string. The function should be case-insensitive and should return the count as an integer. The code should start with:
```python
def count_vowels(s: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_vowels(s: str) -> int:
"""
Counts the number of vowels (a, e, i, o, u) in a given string.
Args:
s (str): The input string in which to count the vowels.
Returns:
int: The number of vowels found... |
code_exercise_27k | 2,720 | Write a Python function to determine if a given string is a pangram. A pangram is a sentence that contains every letter of the alphabet at least once. The function should ignore case sensitivity and non-alphabetic characters. The code should start with:
```python
import string
def is_pangram(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import string
def is_pangram(s: str) -> bool:
"""
Determine if the given string is a pangram.
A pangram is a sentence that contains every letter of the alphabet at least once.
This function ignores case sensitivity and... |
code_exercise_27k | 2,721 | Write a Python function named `capitalize_words` that takes a string input `s`. The function should capitalize the first letter of each word in the string and return the modified string. The function should handle multiple spaces between words and leading/trailing spaces correctly.
The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
def capitalize_words(s: str) -> str:
"""
Capitalizes the first letter of each word in the given string and returns the modified string.
Args:
s (str): The input string to be processed.
Returns:
str: The... |
code_exercise_27k | 2,726 | Write a Python function to reverse the order of elements in a given list without using the built-in `reverse()` method or slicing. The function should modify the list in place and return the reversed list. The code should start with:
```python
from typing import List
def reverse_list(lst: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_list(lst: List[int]) -> List[int]:
"""
Reverses the order of elements in the given list in place and returns the reversed list.
Args:
lst (List[int]): The list of integers to be ... |
code_exercise_27k | 2,727 | Write a Python function to perform a binary search on a sorted list to find the index of a target value. If the target value is not found in the list, the function should return -1. The function should be efficient and handle edge cases such as an empty list or a target value that is not present in the list.
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(lst: List[int], target: int) -> int:
"""
Perform a binary search on a sorted list to find the index of a target value.
Args:
lst (List[int]): A sorted list of integers.
... |
code_exercise_27k | 2,728 | Write a Python function named `increment_by_n` that takes two integers as input: `num` and `n`. The function should return the value of `num` incremented by `n`. The function should handle cases where `n` is negative, effectively performing a decrement operation. The code should start with:
```python
def increment_by_n... | Here is the Python code to solve the given problem in the markdown block:
```python
def increment_by_n(num: int, n: int) -> int:
"""
Increments the given integer `num` by the integer `n`.
Args:
num (int): The integer to be incremented.
n (int): The integer by which `num` should be increment... |
code_exercise_27k | 2,729 | Create a Python function named `increment` that takes an integer as input and returns the input value incremented by 1. The function should handle both positive and negative integers, as well as zero. The code should start with:
```python
def increment(num: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def increment(num: int) -> int:
"""
Function to increment an integer by 1.
Parameters:
num (int): The input integer.
Returns:
int: The input integer incremented by 1.
"""
return num + 1
```
|
code_exercise_27k | 2,730 | Write a Python function to find the absolute value of a given number. The function should handle both integers and floating-point numbers. The code should start with:
```python
def absolute_value(value: int | float) -> int | float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def absolute_value(value: int | float) -> int | float:
"""
Calculate the absolute value of a given number.
Args:
value (int | float): The number for which to calculate the absolute value.
Returns:
int |... |
code_exercise_27k | 2,733 | Write a Python function to determine if a given tuple is monotonic. A tuple is considered monotonic if its elements are either strictly increasing or strictly decreasing. The function should return `True` if the tuple is monotonic and `False` otherwise.
The code should start with:
```python
from typing import Tuple
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def is_monotonic(tup: Tuple[int]) -> bool:
"""
Determine if a given tuple is monotonic (either strictly increasing or strictly decreasing).
Args:
tup (Tuple[int]): The input tuple to be che... |
code_exercise_27k | 2,736 | Write a Python function to sort a tuple of strings in alphabetical order and return a new tuple with the sorted strings. The function should handle any tuple of strings, including an empty tuple. The code should start with:
```python
from typing import Tuple
def sort_tuple_strings(strings: Tuple[str]) -> Tuple[str]:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def sort_tuple_strings(strings: Tuple[str]) -> Tuple[str]:
"""
Sorts the strings in the given tuple in alphabetical order and returns a new sorted tuple.
Args:
strings (Tuple[str]): The tup... |
code_exercise_27k | 2,739 | Write a Python function to remove elements from a set that are multiples of a given number. The function should take a set of integers and an integer as input and return a new set with all elements that are multiples of the given number removed. The code should start with:
```python
def remove_multiples(s: set, num: in... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_multiples(s: set, num: int) -> set:
"""
Remove elements from a set that are multiples of a given number.
Args:
s (set): The set of integers from which to remove multiples.
num (int): The number wh... |
code_exercise_27k | 2,740 | Write a Python function to convert a given number to its positive counterpart. The function should handle both integers and floating-point numbers. The code should start with:
```python
def convert_to_positive(number: int | float) -> int | float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_positive(number: int | float) -> int | float:
"""
Convert a given number to its positive counterpart.
Args:
number (int | float): The input number to be converted.
Returns:
int | float: T... |
code_exercise_27k | 2,744 | Write a Python function to calculate the reciprocal of a given non-zero number. The function should handle the case where the input number is zero by raising a `ValueError`. The code should start with:
```python
def calculate_reciprocal(num: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_reciprocal(num: float) -> float:
"""
Calculates the reciprocal of a given non-zero number.
Args:
num (float): The non-zero number for which the reciprocal will be calculated.
Returns:
floa... |
code_exercise_27k | 2,748 | Write a Python function to increment a given number by a specified increment value. The function should handle both positive and negative increment values. The code should start with:
```python
def increment_number_by_value(number: int, increment: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def increment_number_by_value(number: int, increment: int) -> int:
"""
Increments a given number by a specified increment value.
Args:
number (int): The number to be incremented.
increment (int): The value b... |
code_exercise_27k | 2,752 | Write a Python function to decrement a given number by a specified decrement value. The function should handle both positive and negative decrement values. If the decrement value is zero, the function should return the original number. The code should start with:
```python
def decrement_number_by(number: int, decrement... | Here is the Python code to solve the given problem in the markdown block:
```python
def decrement_number_by(number: int, decrement_value: int) -> int:
"""
Decrement a given number by a specified decrement value.
Args:
number (int): The number to be decremented.
decrement_value (int): The va... |
code_exercise_27k | 2,753 | Write a Python function to extract elements at even indices from a given tuple and return a new tuple containing only those elements. The function should handle tuples of any length, including empty tuples. The code should start with:
```python
def extract_even_index_elements(input_tuple: tuple) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def extract_even_index_elements(input_tuple: tuple) -> tuple:
"""
Extracts elements at even indices from the given tuple and returns a new tuple containing only those elements.
Args:
input_tuple (tuple): The input t... |
code_exercise_27k | 2,756 | Write a Python function to remove elements from a set that start with a specific character. The function should return the modified set. The code should start with:
```python
def remove_elements_starting_with_character(s: set, character: str) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_elements_starting_with_character(s: set, character: str) -> set:
"""
Remove elements from a set that start with a specific character.
Args:
s (set): The input set containing string elements.
chara... |
code_exercise_27k | 2,758 | Write a Python function to count the number of non-empty elements in a tuple of strings. The function should iterate through the tuple and count only those strings that are not empty. The code should start with:
```python
from typing import Tuple
def count_non_empty_elements(strings: Tuple[str]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def count_non_empty_elements(strings: Tuple[str]) -> int:
"""
Count the number of non-empty elements in a tuple of strings.
Args:
strings (Tuple[str]): A tuple of strings.
Returns:
... |
code_exercise_27k | 2,762 | Write a Python function to perform element-wise division of two tuples. The function should return a new tuple containing the result of the division. The function should raise a `ValueError` if the lengths of the two tuples are different and a `ZeroDivisionError` if any element in the second tuple is zero.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
def element_wise_division(tuple1: tuple, tuple2: tuple) -> tuple:
"""
Perform element-wise division of two tuples.
Args:
tuple1 (tuple): The first tuple.
tuple2 (tuple): The second tuple.
Returns:
... |
code_exercise_27k | 2,766 | Write a Python function to swap the first and last elements of a given tuple. The function should handle tuples of any length, including those with a single element. The function should return a new tuple with the first and last elements swapped, while preserving the order of the other elements. The function should rai... | Here is the Python code to solve the given problem in the markdown block:
```python
def swap_first_last(tup: tuple) -> tuple:
"""
Swap the first and last elements of a given tuple.
Args:
tup (tuple): The input tuple.
Returns:
tuple: A new tuple with the first and last elements swapped.... |
code_exercise_27k | 2,776 | Write a Python function to find the sum of all numeric elements in a given tuple of mixed data types. The function should be able to handle integers and floating-point numbers, and ignore any non-numeric elements. The code should start with:
```python
from typing import Tuple, Union
def sum_numeric_elements(t: Tuple[U... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Union
def sum_numeric_elements(t: Tuple[Union[int, float, str], ...]) -> Union[int, float]:
"""
Calculate the sum of all numeric elements in a given tuple of mixed data types.
Args:
t (Tup... |
code_exercise_27k | 2,779 | Write a Python function to calculate the common logarithm (base 10) of a given number. The function should handle both positive and negative numbers, returning `None` for negative numbers since the common logarithm is not defined for negative values. The function should also handle the special case where the input numb... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_common_logarithm(number: float) -> float:
"""
Calculate the common logarithm (base 10) of a given number.
Args:
number (float): The number for which the common logarithm is to be calculate... |
code_exercise_27k | 2,780 | Write a Python function to remove duplicate elements from a given tuple and return a new tuple with unique elements. The function should maintain the order of elements as they appear in the input tuple. The code should start with:
```python
from typing import Tuple
def remove_duplicates_with_order(input_tuple: Tuple) ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def remove_duplicates_with_order(input_tuple: Tuple) -> Tuple:
"""
Removes duplicate elements from a tuple while maintaining the order of elements.
Args:
input_tuple (Tuple): The input tupl... |
code_exercise_27k | 2,781 | Write a Python function to calculate the binary logarithm (base 2 logarithm) of a given number. The function should handle non-positive numbers by raising a `ValueError`. The code should start with:
```python
import math
def binary_logarithm(number: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def binary_logarithm(number: float) -> float:
"""
Calculates the binary logarithm (base 2 logarithm) of a given number.
Args:
number (float): The number for which the binary logarithm will be calculated... |
code_exercise_27k | 2,782 | Write a Python function to remove elements from a set based on their indices within a specified range. The function should handle edge cases such as negative indices and non-set inputs. The code should start with:
```python
def remove_elements_from_set(s: set, start: int, end: int) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_elements_from_set(s: set, start: int, end: int) -> set:
"""
Removes elements from a set with indices in a specific range.
Args:
s (set): The set from which elements will be removed.
start (int): T... |
code_exercise_27k | 2,785 | Write a Python function to find the common elements and their frequencies between two tuples. The function should return a dictionary where the keys are the common elements and the values are their frequencies in the first tuple. The code should start with:
```python
from typing import Tuple, Dict
def find_common_elem... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict
def find_common_elements_with_frequencies(tuple1: Tuple[int], tuple2: Tuple[int]) -> Dict[int, int]:
"""
Finds the common elements and their frequencies between two tuples.
Args:
tupl... |
code_exercise_27k | 2,786 | Write a Python function to remove elements from a given set that are present in another set. The function should return a new set containing the elements of the first set that are not present in the second set. The code should start with:
```python
def remove_elements_from_set(set1: set, set2: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_elements_from_set(set1: set, set2: set) -> set:
"""
Removes elements from set1 that are present in set2 and returns a new set.
Args:
set1 (set): The original set from which elements are to be removed.
... |
code_exercise_27k | 2,789 | Write a Python function to create a new tuple with elements separated by a specific delimiter from a given tuple. The function should handle tuples of any length, including empty tuples. The code should start with:
```python
def separate_elements(tuple_value: tuple, delimiter: str) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def separate_elements(tuple_value: tuple, delimiter: str) -> tuple:
"""
Creates a new tuple with elements separated by a specific delimiter from a given tuple.
Args:
tuple_value (tuple): The tuple to separate the el... |
code_exercise_27k | 2,796 | Write a Python function to create a new tuple where each element from the input tuple is repeated a specified number of times. The function should handle tuples of any type and ensure that the repeated elements maintain their original order. The code should start with:
```python
from typing import Tuple, Any
def repea... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Any
def repeat_tuple_elements(input_tuple: Tuple[Any, ...], times: int) -> Tuple[Any, ...]:
"""
Creates a new tuple where each element from the input tuple is repeated a specified number of times.
... |
code_exercise_27k | 2,797 | Write a Python function to remove all occurrences of a specified value from a given set. The function should return the updated set after removing the elements equal to the specified value. The code should start with:
```python
def remove_values_from_set(my_set: set, value) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_values_from_set(my_set: set, value) -> set:
"""
Remove all occurrences of a specified value from a given set.
Args:
my_set (set): The set from which the elements should be removed.
value: The valu... |
code_exercise_27k | 2,799 | Write a Python function to remove elements from a set that are not equal to a specific value. The function should return a new set containing only the elements that are equal to the specified value. The code should start with:
```python
def filter_set_by_value(s: set, value) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def filter_set_by_value(s: set, value) -> set:
"""
Remove elements from a set that are not equal to a specific value.
Args:
s (set): The original set.
value: The value which the elements will be compared aga... |
code_exercise_27k | 2,804 | Write a Python function to calculate the conjugate of a given complex number. The function should take a complex number as input and return its conjugate. The code should start with:
```python
def calculate_conjugate(complex_num: complex) -> complex:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_conjugate(complex_num: complex) -> complex:
"""
Calculate the conjugate of a given complex number.
Args:
complex_num (complex): The complex number for which the conjugate needs to be calculated.
R... |
code_exercise_27k | 2,805 | Write a Python function to combine adjacent elements of a given tuple into sub-tuples. The function should ensure that the input tuple has an even number of elements. If the input tuple has an odd number of elements, the function should raise a `ValueError`. The function should start with:
```python
def combine_adjacen... | Here is the Python code to solve the given problem in the markdown block:
```python
def combine_adjacent_elements(input_tuple: tuple) -> tuple:
"""
Combines adjacent elements of a given tuple into sub-tuples.
Args:
input_tuple (tuple): The input tuple to be processed.
Returns:
tuple: A... |
code_exercise_27k | 2,807 | Write a Python function to remove elements from a given set that are less than a specific value. The function should return a new set containing only the elements that are greater than or equal to the specified value. The function should handle the case where the input is not a set by raising a `TypeError`.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_elements_less_than(some_set: set, value: int) -> set:
"""
Remove elements from a set that are less than a specific value.
Args:
some_set (set): The set from which to remove elements.
value (int): ... |
code_exercise_27k | 2,808 | Write a Python function to simplify a given complex number by calculating its magnitude and argument (phase angle), and then reconstructing the complex number using these values. The function should return the simplified complex number in the form of a tuple containing the real and imaginary parts, rounded to two decim... | Here is the Python code to solve the given problem in the markdown block:
```python
import cmath
def simplify_complex_number(complex_num: complex) -> tuple:
"""
Simplifies a given complex number by calculating its magnitude and argument,
and then reconstructing the complex number using these values.
A... |
code_exercise_27k | 2,818 | Write a Python function to determine if a given tuple of integers is strictly increasing. A tuple is considered strictly increasing if each element is greater than the element before it. The function should return `True` if the tuple is strictly increasing and `False` otherwise.
The code should start with:
```python
f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def is_strictly_increasing(t: Tuple[int]) -> bool:
"""
Determine if a given tuple of integers is strictly increasing.
Args:
t (Tuple[int]): The input tuple of integers.
Returns:
... |
code_exercise_27k | 2,822 | Write a Python function to compute the cumulative sums of elements in a given tuple and return a new tuple with these cumulative sums. The function should handle tuples of integers and floats. The code should start with:
```python
from typing import Tuple
def cumulative_sums_tuple(input_tuple: Tuple[int, ...]) -> Tupl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def cumulative_sums_tuple(input_tuple: Tuple[int, ...]) -> Tuple[int, ...]:
"""
Compute the cumulative sums of elements in a given tuple and return a new tuple with these cumulative sums.
Args:
... |
code_exercise_27k | 2,827 | Write a Python function to check if a given tuple is a subset of another tuple. The function should return `True` if all elements of the test tuple are present in the sorted tuple, and `False` otherwise. The function should handle tuples of any length and any type of elements, including duplicates.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_subset_of_tuple(sorted_tuple: tuple, test_tuple: tuple) -> bool:
"""
Check if a given tuple is a subset of another tuple.
Args:
sorted_tuple (tuple): A tuple that is assumed to be sorted.
test_tuple (... |
code_exercise_27k | 2,831 | Write a Python function to calculate the Cartesian product of two given tuples. The Cartesian product of two sets \( A \) and \( B \) is the set of all ordered pairs \( (a, b) \) where \( a \) is in \( A \) and \( b \) is in \( B \). The function should return a list of tuples representing the Cartesian product. The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, List
def cartesian_product(tuple_1: Tuple, tuple_2: Tuple) -> List[Tuple]:
"""
Calculates the Cartesian product of two given tuples.
Args:
tuple_1 (Tuple): The first input tuple.
t... |
code_exercise_27k | 2,832 | Write a Python function to remove elements from a set that are present in one set but not in the other. Specifically, the function should remove elements from `set1` that are not present in `set2`. The function should return the modified `set1`.
The code should start with:
```python
def remove_elements(set1: set, set2... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_elements(set1: set, set2: set) -> set:
"""
Remove elements from set1 that are not present in set2.
Args:
- set1 (set): A set of elements.
- set2 (set): Another set of elements.
Returns:
- set: Th... |
code_exercise_27k | 2,834 | Write a Python function to convert a decimal number to its binary representation. The function should handle both positive and zero decimal numbers. The binary representation should be returned as a string. The code should start with:
```python
def decimal_to_binary(decimal: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def decimal_to_binary(decimal: int) -> str:
"""
Convert a decimal number to its binary representation.
Args:
decimal (int): The decimal number to be converted. Must be a non-negative integer.
Returns:
s... |
code_exercise_27k | 2,836 | Write a Python function to check if a given tuple is strictly decreasing. A tuple is considered strictly decreasing if each element is strictly greater than the element that follows it. The function should return `True` if the tuple is strictly decreasing and `False` otherwise.
The code should start with:
```python
de... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_strictly_decreasing(t: tuple) -> bool:
"""
Check if a tuple is strictly decreasing.
A tuple is strictly decreasing if each element is strictly greater than the element that follows it.
Args:
t (tuple): T... |
code_exercise_27k | 2,837 | Write a Python function to count the number of set bits (1s) in a given binary number. The function should efficiently count the set bits using bitwise operations. The code should start with:
```python
def count_set_bits(binary_number: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_set_bits(binary_number: int) -> int:
"""
Count the number of set bits (1s) in a given binary number.
Args:
binary_number (int): The binary number to count the set bits in.
Returns:
int: The nu... |
code_exercise_27k | 2,841 | 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:
"""
Determine 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 pow... |
code_exercise_27k | 2,842 | Write a Python function to filter elements from a given list that can form a specific word with character transpositions. A character transposition means that the characters in the word can be rearranged to form the target word. The function should return a new list containing only those elements from the input list th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_words_with_transpositions(word: str, lst: List[str]) -> List[str]:
"""
Filters elements from a list that can form a specific word with character transpositions.
Args:
word (str): ... |
code_exercise_27k | 2,844 | Write a Python function to check if a given tuple is a superset of another tuple. The function should return `True` if the target tuple contains all elements of the sorted tuple, and `False` otherwise. The function should handle tuples of any length and any type of elements.
The code should start with:
```python
def i... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_superset(sorted_tuple: tuple, target_tuple: tuple) -> bool:
"""
Check if a target tuple is a superset of a sorted tuple.
Args:
sorted_tuple (tuple): The sorted tuple to be checked against.
target_tupl... |
code_exercise_27k | 2,848 | Write a Python function to count the number of leading zeros in a given binary number string. The function should return the count of leading zeros as an integer. The code should start with:
```python
def count_leading_zeros(binary_number: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_leading_zeros(binary_number: str) -> int:
"""
Count the number of leading zeros in a given binary number string.
Args:
binary_number (str): A binary number string.
Returns:
int: The number of ... |
code_exercise_27k | 2,851 | Write a Python function to remove elements from a given set that satisfy a specific condition. The condition is defined by a function that takes an element as input and returns a boolean indicating whether the element satisfies the condition or not. The function should return the modified set after removing the element... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_elements_from_set(some_set: set, condition) -> set:
"""
Remove elements from a set that satisfy a specific condition.
Args:
some_set (set): The set from which elements need to be removed.
conditio... |
code_exercise_27k | 2,854 | Write a Python function to filter elements from a set based on a given condition. The function should remove elements from the set that do not satisfy the specified condition. The condition is provided as a function that takes an element as input and returns `True` if the element satisfies the condition, and `False` ot... | Here is the Python code to solve the given problem in the markdown block:
```python
def filter_set_elements(set_elements: set, condition) -> set:
"""
Filters elements from a set based on a given condition.
Args:
set_elements (set): The set of elements to filter.
condition (function): The co... |
code_exercise_27k | 2,862 | Write a Python function to remove elements from a given set based on a provided lambda function. The function should return a new set containing only the elements that do not satisfy the condition defined by the lambda function. The code should start with:
```python
def remove_elements(set_: set, func: callable) -> set... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_elements(set_: set, func: callable) -> set:
"""
Remove elements from a set based on a given lambda function.
Args:
set_ (set): The set from which elements will be removed.
func (callable): The lam... |
code_exercise_27k | 2,863 | Write a Python function to calculate the sum of all elements in a list, ensuring that the input is a list of numeric values (integers or floats). The function should raise a `TypeError` if the input is not a list or if any element in the list is not numeric.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def sum_of_list_elements(lst: List[Union[int, float]]) -> Union[int, float]:
"""
Calculate the sum of all elements in a list.
Parameters:
lst (List[Union[int, float]]): A list of integer ... |
code_exercise_27k | 2,864 | Write a Python function to rotate a tuple to the left by a specified number of positions. The function should handle cases where the number of positions to rotate is greater than the length of the tuple by taking the modulo of the positions with the length of the tuple. The function should not raise any exceptions.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
def rotate_tuple_left(tup: tuple, positions: int) -> tuple:
"""
Rotate a tuple to the left by a specified number of positions.
Args:
tup (tuple): The tuple to be rotated.
positions (int): The number of posit... |
code_exercise_27k | 2,866 | Write a Python function to remove duplicate elements from a list while preserving their order. The function should take a list as input and return a new list with all duplicate elements removed, maintaining the order of the first occurrence of each element.
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
def remove_duplicates_preserve_order(some_list: List[int]) -> List[int]:
"""
Remove duplicate elements from a list while preserving their order.
Args:
some_list (List[int]): The list to remo... |
code_exercise_27k | 2,867 | Write a Python function to calculate the average of all elements in a given list of numbers. If the list is empty, the function should raise a `ValueError` with the message "List is empty." The function 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 all elements in a list of numbers.
Args:
numbers (List[float]): A list of numbers.
Returns:
fl... |
code_exercise_27k | 2,869 | Write a Python function to multiply two given integers using only bitwise operators. The function should handle both positive and negative integers. The code should start with:
```python
def multiply_bitwise(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def multiply_bitwise(x: int, y: int) -> int:
"""
Multiplies two integers using only bitwise operators.
Args:
x (int): The first integer.
y (int): The second integer.
Returns:
int: The product of... |
code_exercise_27k | 2,871 | Write a Python function to find the maximum element in a list of integers. If the list is empty, raise a `ValueError` with the message "The list is empty." The function should start with:
```python
from typing import List
def find_max_element(lst: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_max_element(lst: List[int]) -> int:
"""
Find the maximum element in a list of integers.
Args:
lst (List[int]): A list of integers from which to find the maximum element.
Return... |
code_exercise_27k | 2,872 | Write a Python function to divide two integers using bitwise operators only. The function should handle both positive and negative integers and return the quotient of the division. The function should raise a `ZeroDivisionError` if the divisor is zero.
The code should start with:
```python
def bitwise_divide(dividend:... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_divide(dividend: int, divisor: int) -> int:
"""
Divides two integers using bitwise operators only.
Parameters:
- dividend (int): The integer to be divided.
- divisor (int): The integer that divides the d... |
code_exercise_27k | 2,873 | Write a Python function to compute the element-wise sum of two tuples and return the result as a new tuple. The function should handle tuples of the same length and ensure that neither tuple is empty. If the input tuples do not meet these criteria, the function should raise a `ValueError`.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def tuple_sum(tuple1: tuple, tuple2: tuple) -> tuple:
"""
Computes the element-wise sum of two tuples and returns the result as a new tuple.
Args:
tuple1 (tuple): The first input tuple.
tuple2 (tuple): The s... |
code_exercise_27k | 2,875 | Write a Python function to find the maximum element in a list. The function should handle lists of integers and floats. If the list is empty, the function should raise a `ValueError`. The code should start with:
```python
from typing import List, Union
def find_max_element(lst: List[Union[int, float]]) -> Union[int, f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_max_element(lst: List[Union[int, float]]) -> Union[int, float]:
"""
Finds the maximum element in a list of integers and floats.
Args:
lst (List[Union[int, float]]): The input... |
code_exercise_27k | 2,876 | Write a Python function to find the maximum power of 2 that divides a given integer. The function should return the highest exponent `k` such that `2^k` divides the integer exactly. The code should start with:
```python
def max_power_of_two(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def max_power_of_two(n: int) -> int:
"""
Finds the maximum power of 2 that divides a given integer.
Args:
n (int): The integer for which we want to find the maximum power of 2 that divides it.
Returns:
... |
code_exercise_27k | 2,877 | Write a Python function to find the two smallest elements in a given tuple efficiently. The function should handle tuples of any comparable type and return a tuple containing the two smallest elements. If the input tuple has fewer than two elements, the function should raise a `ValueError`.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def find_two_smallest_elements(tup: Tuple) -> Tuple:
"""
Finds the two smallest elements in a given tuple efficiently.
Args:
tup (Tuple): A tuple containing elements of any comparable type.... |
code_exercise_27k | 2,881 | Write a Python function to remove duplicates from a given list while preserving the order of the elements. The function should return a new list with all duplicate elements removed. The code should start with:
```python
from typing import List
def remove_duplicates_preserve_order(lst: List) -> 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:
"""
Removes duplicates from a list while preserving the order of the elements.
Args:
lst (list): The input list with possible duplica... |
code_exercise_27k | 2,882 | Write a Python function to determine if a given number is a palindrome in its binary representation. The function should return `True` if the binary representation of the number reads the same forwards and backwards, and `False` otherwise. The code should start with:
```python
def is_binary_palindrome(num: int) -> bool... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_binary_palindrome(num: int) -> bool:
"""
Check if a given number is a palindrome in its binary representation.
Args:
num (int): The number to check.
Returns:
bool: True if the binary representati... |
code_exercise_27k | 2,883 | Write a Python function to multiply corresponding elements of two tuples and return a new tuple with the results. The function should raise a `ValueError` if the input tuples have different lengths. The code should start with:
```python
from typing import Tuple
def multiply_tuples(tuple1: Tuple[int], tuple2: Tuple[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def multiply_tuples(tuple1: Tuple[int], tuple2: Tuple[int]) -> Tuple[int]:
"""
Multiplies corresponding elements of two tuples and returns a new tuple.
Args:
tuple1 (Tuple[int]): The first ... |
code_exercise_27k | 2,886 | Write a Python function to find the kth smallest element in a given tuple of integers. The function should handle cases where k is out of bounds by returning `None`. The code should start with:
```python
from typing import Tuple, Optional
def find_kth_smallest_element(elements: Tuple[int], k: int) -> Optional[int]:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Optional
def find_kth_smallest_element(elements: Tuple[int], k: int) -> Optional[int]:
"""
Finds the kth smallest element in a tuple of integers.
Args:
elements (Tuple[int]): The tuple of ... |
code_exercise_27k | 2,888 | Write a Python function to remove words from a given set that have a specific length. The function should return a new set containing only the words that do not match the specified length. The code should start with:
```python
from typing import Set
def remove_words_by_length(word_set: Set[str], length: int) -> Set[st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def remove_words_by_length(word_set: Set[str], length: int) -> Set[str]:
"""
Remove words from a set that have a specific length.
Args:
word_set (Set[str]): A set of words.
length (in... |
code_exercise_27k | 2,893 | Write a Python function to remove all odd numbers from a given list of integers. The function should return a new list containing only the even numbers from the original list. The code should start with:
```python
from typing import List
def remove_odd_numbers(lst: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_odd_numbers(lst: List[int]) -> List[int]:
"""
Removes all odd numbers from a given list of integers.
Args:
lst (List[int]): The input list of integers.
Returns:
List[... |
code_exercise_27k | 2,896 | Write a Python function to sort a list of numbers in descending order. The function should return a new list containing the numbers in descending order without modifying the original list. The code should start with:
```python
from typing import List
def sort_list_descending(numbers: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_list_descending(numbers: List[int]) -> List[int]:
"""
Sorts a given list of numbers in descending order.
Args:
numbers (List[int]): A list of numbers to be sorted.
Returns:
... |
code_exercise_27k | 2,897 | Write a Python function to find the longest consecutive sequence of set bits (1s) in a given binary number. The function should return both the length of the longest sequence and the starting index of this sequence in the binary representation of the number.
The code should start with:
```python
def find_longest_conse... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_longest_consecutive_sequence(binary_number: int) -> tuple[int, int]:
"""
Finds the longest consecutive sequence of set bits in a given binary number.
Args:
binary_number (int): The binary number.
Retur... |
code_exercise_27k | 2,900 | Write a Python function to sort a list of integers in descending order using the merge sort algorithm. The function should be efficient and maintain the stability of the sort. The code should start with:
```python
from typing import List
def merge_sort_descending(lst: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def merge_sort_descending(lst: List[int]) -> List[int]:
"""
Sorts a list of integers in descending order using the merge sort algorithm.
Args:
lst (List[int]): The list of integers to be s... |
code_exercise_27k | 2,901 | Write a Python function to remove duplicate tuples from a given set of tuples. A tuple is considered a duplicate if it contains the same elements as another tuple, regardless of the order of elements. The function should return a new set containing only unique tuples.
The code should start with:
```python
from typing ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set, Tuple
def remove_duplicates_from_set(s: Set[Tuple[int, ...]]) -> Set[Tuple[int, ...]]:
"""
Remove duplicate tuples from a given set of tuples.
A tuple is considered a duplicate if it contains the sa... |
code_exercise_27k | 2,903 | Write a Python function to reverse a given list in-place. The function should modify the original list and not return a new list. The code should start with:
```python
from typing import List
def reverse_list_in_place(lst: List[int]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def reverse_list_in_place(lst: List[int]) -> None:
"""
Reverse the given list in-place.
This function modifies the original list by reversing the order of its elements.
Args:
lst (Lis... |
code_exercise_27k | 2,904 | Write a Python function to calculate the bitwise OR of all numbers from 1 to n. The function should handle the case where n is a non-positive integer by raising a `ValueError`. The code should start with:
```python
def bitwise_or_of_numbers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_or_of_numbers(n: int) -> int:
"""
Calculate the bitwise OR of all numbers from 1 to n.
Args:
n (int): The upper limit of the range of numbers.
Returns:
int: The bitwise OR result.
Raise... |
code_exercise_27k | 2,908 | Write a Python function to remove elements from a set that are common in both the set and a list. The function should return the updated set with the common elements removed. The code should start with:
```python
def remove_common_elements(original_set: set, common_list: list) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_common_elements(original_set: set, common_list: list) -> set:
"""
Remove elements from a set that are common in both the set and a list.
Args:
original_set (set): The original set from which elements need... |
code_exercise_27k | 2,909 | Write a Python function to generate all possible subsets of a given set using bitwise operators. The function should return a list of lists, where each inner list represents a subset of the original set. The code should start with:
```python
from typing import List
def generate_subsets(s: List[int]) -> List[List[int]]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_subsets(s: List[int]) -> List[List[int]]:
"""
Generate all possible subsets of a given set using bitwise operators.
Args:
s (List[int]): A list representing the set for which su... |
code_exercise_27k | 2,910 | Write a Python function to flatten a list of lists into a single list. The function should handle nested lists of arbitrary depth. The code should start with:
```python
from typing import List, Any
def flatten_list(list_of_lists: List[Any]) -> List[Any]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def flatten_list(list_of_lists: List[Any]) -> List[Any]:
"""
Flatten a list of lists into a single list, handling nested lists of arbitrary depth.
Args:
list_of_lists (List[Any]): The l... |
code_exercise_27k | 2,911 | Write a Python function to combine two tuples into a new tuple with elements from both tuples in an alternating order. If one tuple is longer than the other, the remaining elements of the longer tuple should be appended to the end of the resulting tuple.
The code should start with:
```python
def alternate_tuples(tuple... | Here is the Python code to solve the given problem in the markdown block:
```python
def alternate_tuples(tuple1: tuple, tuple2: tuple) -> tuple:
"""
Combines two tuples and returns a new tuple with elements from both tuples in alternate order.
Args:
tuple1 (tuple): The first input tuple.
... |
code_exercise_27k | 2,912 | Write a Python function to remove all odd numbers from a given list of integers. The function should return a new list containing only the even numbers from the input list. The code should start with:
```python
from typing import List
def remove_odd_numbers(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_odd_numbers(input_list: List[int]) -> List[int]:
"""
Removes all odd numbers from the given list and returns a new list containing only the even numbers.
Args:
input_list (List[in... |
code_exercise_27k | 2,915 | Write a Python function to delete the second element from a given tuple. If the tuple has fewer than two elements, the function should return the tuple unchanged. The function should handle tuples of any length and type of elements. The code should start with:
```python
from typing import Tuple, Any
def delete_second_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Any
def delete_second_element(t: Tuple[Any, ...]) -> Tuple[Any, ...]:
"""
Deletes the second element from a given tuple.
Args:
t (Tuple[Any, ...]): The input tuple from which the second el... |
code_exercise_27k | 2,916 | Write a Python function to remove duplicate elements from a given tuple while preserving the order of the first occurrence of each element. The function should return a new tuple with the duplicates removed.
The code should start with:
```python
from typing import Tuple
def remove_duplicates_from_tuple(tuple_to_proce... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def remove_duplicates_from_tuple(tuple_to_process: Tuple) -> Tuple:
"""
Removes duplicate elements from a tuple while preserving the order of the first occurrence of each element.
Args:
tup... |
code_exercise_27k | 2,920 | Write a Python function to check if all elements in a given list of numbers are positive. The function should return `True` if all elements are positive, and `False` otherwise. The code should start with:
```python
from typing import List
def are_all_positive(numbers: List[int]) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def are_all_positive(numbers: List[int]) -> bool:
"""
Check if all elements in a list of numbers are positive.
Args:
numbers (List[int]): A list of integers to be checked.
Returns:
... |
code_exercise_27k | 2,925 | Write a Python function to merge two tuples and remove any repeated elements. The function should return a new tuple containing all unique elements from both input tuples, maintaining the order of elements as they appear in the input tuples.
The code should start with:
```python
from typing import Tuple
def merge_tup... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def merge_tuples_unique(tuple1: Tuple, tuple2: Tuple) -> Tuple:
"""
Merges two tuples and removes any repeated elements, maintaining the order of elements.
Args:
tuple1 (Tuple): The first t... |
code_exercise_27k | 2,929 | Write a Python function to delete all occurrences of a specific element from a given tuple. The function should return a new tuple with the specified element removed. The code should start with:
```python
def delete_element_from_tuple(input_tuple: tuple, element) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def delete_element_from_tuple(input_tuple: tuple, element) -> tuple:
"""
Deletes all occurrences of a specific element from a given tuple.
Args:
input_tuple (tuple): The input tuple from which the element needs to b... |
code_exercise_27k | 2,931 | Write a Python function to find the kth smallest element in a given list of integers efficiently. The function should handle edge cases such as an empty list or an invalid k value. The code should start with:
```python
from typing import List
def find_kth_smallest(arr: List[int], k: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_kth_smallest(arr: List[int], k: int) -> int:
"""
Finds the kth smallest element in a list using the Quickselect algorithm.
Args:
arr (List[int]): The list of integers from which to ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.