source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 95,961 | Write a Python function to determine all prime numbers up to a given integer `n` using the Sieve of Eratosthenes algorithm. The function should return a list of all prime numbers less than or equal to `n`.
The code should start with:
```python
from typing import List
def sieve_of_eratosthenes(n: int) -> List[int]:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sieve_of_eratosthenes(n: int) -> List[int]:
"""
Find all prime numbers up to a given integer n using the Sieve of Eratosthenes algorithm.
Args:
n (int): The upper limit up to which to fi... |
magic_evol_110k | 95,966 | Write a Python function to add two N x M dimensional matrices with specific integer elements. The function should handle matrices of any size and ensure that the addition is performed correctly. The code should start with:
```python
from typing import List
def add_matrices(matrix1: List[List[int]], matrix2: List[List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def add_matrices(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[List[int]]:
"""
Adds two N x M dimensional matrices.
Args:
matrix1 (List[List[int]]): The first matrix.
m... |
magic_evol_110k | 95,973 | Write a Python function to convert a given 32-bit binary string to its hexadecimal representation. The function should handle both positive and negative binary numbers (represented in 2's complement) correctly. Additionally, the function should validate the input to ensure it is a valid 32-bit binary number and raise a... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_hex(binary_str: str) -> str:
"""
Converts a given 32-bit binary string to its hexadecimal representation.
Handles both positive and negative binary numbers (represented in 2's complement).
Args:
bi... |
magic_evol_110k | 95,999 | Write a Python function to find the number that occurs only once in a list where all other numbers occur exactly twice. The function should efficiently determine the unique number using bitwise operations.
The code should start with:
```python
from typing import List
def find_unique_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_unique_number(nums: List[int]) -> int:
"""
Find the number that occurs only once in a list where all other numbers occur exactly twice.
Args:
nums (List[int]): A list of integers wh... |
magic_evol_110k | 96,003 | Write a Python function to find the common elements between two lists of integers. The function should return a list of these common elements in ascending order. The code should start with:
```python
from typing import List
def get_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 get_common_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Find the common elements between two lists of integers and return them in ascending order.
Args:
list1 (List[int... |
magic_evol_110k | 96,015 | Write a Python function to determine if a given integer is an Armstrong number. An Armstrong number (also known as a narcissistic number) is an integer such that the sum of its own digits each raised to the power of the number of digits is equal to the number itself. For example, 153 is an Armstrong number because 1^3 ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_armstrong(n: int) -> bool:
"""
Determines if a given integer is an Armstrong number.
An Armstrong number is an integer such that the sum of its own digits each raised to the power of the number of digits is equal to ... |
magic_evol_110k | 96,016 | Write a Python function to calculate the absolute difference between two complex numbers. The function should return the magnitude of the difference between the two complex numbers. The code should start with:
```python
def complex_difference(num1: complex, num2: complex) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def complex_difference(num1: complex, num2: complex) -> float:
"""
Calculate the absolute difference between two complex numbers.
Args:
num1 (complex): The first complex number.
num2 (complex): The second co... |
magic_evol_110k | 96,030 | Write a Python function to determine whether a specified substring exists within a given string, count the frequency of its occurrences, and provide the starting indices of each occurrence. The function should be implemented without using any built-in string functions like `find`, `count`, or `index`.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_substring(main_string: str, sub_string: str) -> dict:
"""
Determines whether a specified substring exists within a given string, counts its occurrences,
and provides the starting indices of each occurrence.
Arg... |
magic_evol_110k | 96,040 | Write a Python function to calculate the continuous compound interest based on a given initial principal amount, an annual interest rate, and the duration in years. The function should use the mathematical formula for continuous compound interest, which is given by:
\[ A = P \times e^{r \times t} \]
where:
- \( A \) ... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def continuous_compound_interest(P: float, r: float, t: float) -> float:
"""
Calculate the amount after continuous compound interest.
Args:
P (float): The initial principal amount.
r (float): Th... |
magic_evol_110k | 96,042 | Write a Python function to calculate the area of a triangle given the length of one side and the corresponding height. The function should validate the input parameters and handle errors using exception handling methods. The code should start with:
```python
def triangle_area(a: float, h: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def triangle_area(a: float, h: float) -> float:
"""
Calculate the area of a triangle given the length of one side and the corresponding height.
Args:
a (float): The length of one side of the triangle.
h (flo... |
magic_evol_110k | 96,046 | Write a Python function to determine the maximum value in a list of integers using two different algorithms. The first algorithm initializes the maximum value to -1 and updates it if a larger value is found. The second algorithm initializes the maximum value to the first element of the list and updates it if a larger v... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_max_values(lst: List[int]) -> Tuple[int, int]:
"""
Find the maximum value in a list of integers using two different algorithms.
Algorithm I initializes the maximum value to -1 and up... |
magic_evol_110k | 96,061 | Write a Python function to generate the first ten Twin Prime pairs. Twin Primes are pairs of prime numbers that have a difference of 2 between them. The function should return a list of tuples, where each tuple contains a pair of Twin Primes.
The code should start with:
```python
from typing import List, Tuple
def ge... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def is_prime(num: int) -> bool:
"""
Check if a given number is prime.
Args:
num (int): The number to check for primality.
Returns:
bool: True if the number is prime, Fals... |
magic_evol_110k | 96,081 | Write a Python function to calculate the Lowest Common Multiple (LCM) of two integers `x` and `y` efficiently, considering the constraints where `1 <= x, y <= 10^9`. The function should leverage an optimized algorithm to handle large inputs within the given bounds.
The code should start with:
```python
from math impor... | Here is the Python code to solve the given problem in the markdown block:
```python
from math import gcd
def lcm(x: int, y: int) -> int:
"""
Calculate the Lowest Common Multiple (LCM) of two integers x and y efficiently.
Args:
x (int): The first integer, where 1 <= x <= 10^9.
y (int): The ... |
magic_evol_110k | 96,083 | Write a Python function to remove duplicate elements from a given list of integers while preserving the order of the first occurrence of each element. 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(arr: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates(arr: List[int]) -> List[int]:
"""
Removes duplicate elements from the given list of integers while preserving the order of the first occurrence of each element.
Args:
a... |
magic_evol_110k | 96,093 | Write a Python function to perform a bi-directional shift on a list of floating-point numbers by a specified number of places. The function should return two lists: one that is left-shifted and one that is right-shifted by the given number of places. The code should start with:
```python
from typing import List
def bi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bidirectional_shift(lst: List[float], k: int) -> (List[float], List[float]):
"""
Perform a bi-directional shift on a list of floating-point numbers by a specified number of places.
Args:
... |
magic_evol_110k | 96,105 | Write a Python function to determine if it is possible to merge two dictionaries such that the values of common keys are combined into a list. If a key exists in only one dictionary, it should be included in the merged dictionary with its original value. The function should handle cases where the values are either list... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any, List, Union
def merge_dicts(dict1: Dict[str, Union[Any, List[Any]]], dict2: Dict[str, Union[Any, List[Any]]]) -> Dict[str, List[Any]]:
"""
Merges two dictionaries such that the values of common key... |
magic_evol_110k | 96,127 | Write a Python function to extract and return the data associated with the entity labeled as 'second' from a given dictionary. The dictionary contains nested dictionaries, where each nested dictionary represents an entity with attributes such as 'name', 'age', and 'city'. The function should handle cases where the 'sec... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Optional
def get_second_entity(data: Dict[str, Dict[str, str]]) -> Optional[Dict[str, str]]:
"""
Extracts and returns the data associated with the entity labeled as 'second' from a given dictionary.
... |
magic_evol_110k | 96,146 | Write a Python function to determine if two given strings are isomorphic. Two strings are isomorphic if there is a one-to-one mapping between every character in the first string to every character in the second string. The function should return `True` if the strings are isomorphic and `False` otherwise.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_isomorphic(string1: str, string2: str) -> bool:
"""
Determines if two strings are isomorphic.
Two strings are isomorphic if there is a one-to-one mapping between every character in the first string
to every char... |
magic_evol_110k | 96,167 | Write a Python function to reverse a binary string and perform a bit-wise NOT operation on each bit. The function should take a single string `a` made up only of '1's and '0's, reverse the string, and then invert each bit (i.e., '0' becomes '1' and '1' becomes '0'). The function should return the resulting string.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
def not_reverse_binary(a: str) -> str:
"""
Reverses a binary string and performs a bit-wise NOT operation on each bit.
Args:
a (str): A binary string consisting only of '0's and '1's.
Returns:
str: The ... |
magic_evol_110k | 96,169 | Write a Python function to determine if a set of audio criteria are met based on the given `volume` and `pitch` values. The criteria are:
1. The `volume` must exceed 10.
2. The `pitch` must be greater than or equal to 800 Hz.
The function should return a boolean value indicating whether both criteria are met.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_audio_criteria(volume: int, pitch: int) -> bool:
"""
Determines if the given audio criteria are met based on the volume and pitch values.
Args:
volume (int): The volume level of the audio.
pitch (i... |
magic_evol_110k | 96,173 | Write a Python function to create a dictionary comprehension that squares the values of a given dictionary with string keys and integer values ranging from 1 to n, where n is the total number of keys. The input dictionary is in the form `{"A": 1, "B": 2, "C": 3, "D": 4, ..., "N": n}`. Additionally, identify and correct... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def square_dictionary_values(input_dict: Dict[str, int]) -> Dict[str, int]:
"""
Create a dictionary comprehension that squares the values of a given dictionary.
Args:
input_dict (Dict[str, i... |
magic_evol_110k | 96,179 | Write a Python function to count the frequency of each distinct element in a given list of numeric values and return the result as a dictionary. The dictionary should map each distinct element to its frequency in the list. The code should start with:
```python
from typing import List, Dict
def count_frequency(numbers:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_frequency(numbers: List[int]) -> Dict[int, int]:
"""
Counts the frequency of each distinct element in a given list of numeric values.
Args:
numbers (List[int]): The list of n... |
magic_evol_110k | 96,185 | Write a Python function to calculate the total number of items in different scenarios where items are either added together or subtracted based on the given conditions. The function should handle four scenarios:
1. Adding the number of students on 8 buses, each carrying 64 students.
2. Adding the number of pens and pen... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_total_items(scenario: int, num1: int, num2: int) -> int:
"""
Calculate the total number of items based on the given scenario.
Args:
scenario (int): The scenario number (1 to 4).
num1 (int): The... |
magic_evol_110k | 96,192 | Write a Python function to remove duplicate elements from a list while preserving the original order of the remaining elements. The function should take a list of integers as input and return a new list with all duplicate elements removed.
The code should start with:
```python
from typing import List
def remove_dupli... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates(numbers: List[int]) -> List[int]:
"""
Removes duplicate elements from a list while preserving the original order.
Args:
numbers (List[int]): The list of integers from w... |
magic_evol_110k | 96,223 | Write a Python function to construct an array based on the given sequence of numbers. The function should take a list of integers as input and return a new list that contains these integers in the specified order. The function should also handle cases where the input list is empty or contains fewer elements than the sp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def construct_array(sequence: List[int]) -> List[int]:
"""
Constructs an array based on the specified sequence [13, 29, 37, 42] from the given list of integers.
Args:
sequence (List[int]): T... |
magic_evol_110k | 96,243 | Write a Python function to reverse an input string such that any numbers within the string are also reversed individually, and then prepend the string "Hola" to the result. The function should handle any alphanumeric string.
The code should start with:
```python
def reverse_string_with_numbers(input_str: str) -> str:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string_with_numbers(input_str: str) -> str:
"""
Reverses the input string such that any numbers within the string are also reversed individually,
and prepends "Hola" to the result.
Args:
input_str (s... |
magic_evol_110k | 96,263 | Write a Python function to sort a given list of integers in descending order. The function should return the sorted list. The code should start with:
```python
from typing import List
def sort_descending(num_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 sort_descending(num_list: List[int]) -> List[int]:
"""
Sorts a given list of integers in descending order.
Args:
num_list (List[int]): The list of integers to be sorted.
Returns:
... |
magic_evol_110k | 96,267 | Write a Python function to calculate the number of trailing zeros in the factorial of a given large number `n` (up to 10^8). The function should be optimized for large calculations and avoid directly computing the factorial, which would be computationally infeasible for very large numbers.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_trailing_zeros_in_factorial(n: int) -> int:
"""
Calculate the number of trailing zeros in the factorial of a given number `n`.
Args:
n (int): The number for which to calculate the factorial's trailing zero... |
magic_evol_110k | 96,268 | Write a Python function to verify a sequence of numerical values based on a corresponding sequence of boolean values. For each number in the sequence, if the corresponding boolean value is `True`, check if the number is even. If the corresponding boolean value is `False`, check if the number is a prime number. The func... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False oth... |
magic_evol_110k | 96,284 | Write a Python function to generate a dictionary that maps each number in a given list to its cubed representation. The function should handle lists of whole numbers and return a dictionary where the keys are the original numbers and the values are their respective cubes.
The code should start with:
```python
from typ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def generate_cubed_mapping(numbers: List[int]) -> Dict[int, int]:
"""
Generates a dictionary that maps each number in the input list to its cubed representation.
Args:
numbers (List[in... |
magic_evol_110k | 96,294 | Write a Python function to find the largest number among four given integers. The function should take four integers as input and return the largest one. The code should start with:
```python
def find_largest_number(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_largest_number(a: int, b: int, c: int, d: int) -> int:
"""
Find the largest number among four given integers.
Args:
a (int): The first integer.
b (int): The second integer.
c (int): The thir... |
magic_evol_110k | 96,306 | Write a Python function to simulate the behavior of a Subversion (SVN) commit notification system. The function should take a repository path and a revision number as input and generate a commit message that includes the repository path, revision number, and a list of changes made in that revision. The changes should b... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_commit_message(repository_path: str, revision_number: int, changes: List[str]) -> str:
"""
Generates a commit message for a Subversion (SVN) commit notification system.
Args:
re... |
magic_evol_110k | 96,311 | Write a Python function to determine if a given iterable contains at least one floating-point number. The function should return `True` if such a number exists, and `False` otherwise. The function should be able to handle any iterable type, including lists, tuples, and sets.
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 Iterable
def contains_float(iterable: Iterable) -> bool:
"""
Determines if the given iterable contains at least one floating-point number.
Args:
iterable (Iterable): The iterable to check for the... |
magic_evol_110k | 96,316 | Write a Python function that takes a unique string as input, converts it to its corresponding lowercase counterpart, and then inverts the order of the characters. The function should handle any numbers or special characters in the string by returning them as they are. If the inversion is unsuccessful or if the input st... | Here is the Python code to solve the given problem in the markdown block:
```python
def process_string(input_str: str) -> str:
"""
Processes a unique string by converting it to lowercase and then inverting the order of the characters.
Numbers and special characters are returned as they are.
Args:
... |
magic_evol_110k | 96,334 | Write a Python function to determine if two input strings are both anagrams of each other and palindromes. An anagram involves the permutation or rearrangement of characters to form different expressions, while a palindrome is a word, phrase, or other sequences of characters that reads the same forward or backward. The... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams_and_palindromes(str1: str, str2: str) -> bool:
"""
Determines if two input strings are both anagrams of each other and palindromes.
Args:
str1 (str): The first input string.
str2 (str): The ... |
magic_evol_110k | 96,342 | Write a Python function to count and print the number of occurrences of each character (excluding spaces) in a given sentence, along with the total number of distinct characters found in the sentence. Perform this in a case-insensitive manner so 'a' and 'A' are considered the same character. The sentence will be provid... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import Counter
def count_characters(sentence: str) -> None:
"""
Counts and prints the number of occurrences of each character (excluding spaces) in a given sentence,
along with the total number of distinct ... |
magic_evol_110k | 96,343 | Write a Python function to find the minimum elements from a given list by removing the largest k elements. The function should return the modified list containing only the smallest elements after removing the largest k elements. The code should start with:
```python
from typing import List
def minimum_elements(arr: Li... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def minimum_elements(arr: List[int], k: int) -> List[int]:
"""
Returns the list of minimum elements after removing the largest k elements.
Args:
arr (List[int]): The list of integers from ... |
magic_evol_110k | 96,348 | Write a Python function to find and return the recurring numerical elements within a given collection of integer values. The function should efficiently identify elements that appear more than once in the collection.
The code should start with:
```python
from typing import List
def find_recurring_elements(collection:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_recurring_elements(collection: List[int]) -> List[int]:
"""
Finds and returns the recurring numerical elements within the provided collection of integer values.
Args:
collection (Li... |
magic_evol_110k | 96,355 | Write a Python function to calculate the sum of all integer components in a given list of integers. The function should handle lists of varying lengths and ensure that the sum is computed accurately.
The code should start with:
```python
from typing import List
def sum_of_integers(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_integers(numbers: List[int]) -> int:
"""
Calculate the sum of all integer components in a given list of integers.
Args:
numbers (List[int]): A list of integers whose sum needs to ... |
magic_evol_110k | 96,367 | Write a Python function to print the squares of all odd numbers within a given range `[start, end]`. The function should handle both inclusive and exclusive ranges correctly. The code should start with:
```python
def print_odd_squares(start: int, end: int, inclusive: bool = True) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def print_odd_squares(start: int, end: int, inclusive: bool = True) -> None:
"""
Prints the squares of all odd numbers within the given range [start, end].
Args:
start (int): The starting value of the range.
... |
magic_evol_110k | 96,385 | Write a Python function to traverse a given dictionary and output both the keys (identifiers) and their corresponding values (data points) using a while-loop. The function should accept a dictionary as input and print each key-value pair in the specified format.
The code should start with:
```python
def traverse_dicti... | Here is the Python code to solve the given problem in the markdown block:
```python
def traverse_dictionary(dictionary: dict) -> None:
"""
Traverse a given dictionary and print each key (identifier) and its corresponding value (data point) using a while-loop.
Args:
dictionary (dict): The dictionary... |
magic_evol_110k | 96,386 | Write a Python function to convert a given list of integers into a list of their corresponding Roman numeral representations. The function should handle integers from 1 to 3999. The code should start with:
```python
from typing import List
def int_to_roman(nums: List[int]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def int_to_roman(nums: List[int]) -> List[str]:
"""
Converts a list of integers into their corresponding Roman numeral representations.
Args:
nums (List[int]): A list of integers to be con... |
magic_evol_110k | 96,394 | Write a Python function to merge two sorted arrays of integers into a single sorted array without using built-in sorting functions. The function should handle edge cases such as empty arrays and negative numbers. Additionally, the function should output the time complexity of the merging process.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Merge two sorted arrays of integers into a single sorted array.
Args:
arr1 (List[int]): The first sorted array.
... |
magic_evol_110k | 96,397 | Write a Python function to generate a multiplication table of numbers from 1 to 10. The function should handle potential errors and exceptions that might occur during runtime, particularly handling the exceptions related to type and range. The function should print the multiplication table in a formatted manner.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_multiplication_table():
"""
Generates a multiplication table of numbers from 1 to 10 and handles potential errors.
This function uses two nested loops to iterate through the numbers from 1 to 10.
It checks ... |
magic_evol_110k | 96,402 | Write a Python function to construct a regular expression that precisely matches the string pattern "xaaab" using elements such as quantifiers and character classes. The function should return a list of all occurrences of the pattern in a given text.
The code should start with:
```python
import re
from typing import L... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def find_pattern(text: str) -> List[str]:
"""
Constructs a regular expression to precisely match the string pattern "xaaab"
and returns a list of all occurrences of the pattern in the given... |
magic_evol_110k | 96,422 | Write a Python function to determine if a given integer `n` is a power of three without using any built-in math functions or operators (like `pow`, `log`, `*`, `/`, `sqrt`, etc.). You can only use addition, subtraction, and bitwise operators. The function should return `true` if `n` is a power of three, otherwise `fals... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_power_of_three(n: int) -> bool:
"""
Determines if a given integer `n` is a power of three without using any built-in math functions or operators.
Args:
n (int): The integer to check.
Returns:
boo... |
magic_evol_110k | 96,427 | Write a Python function to reverse the elements of a given array and return the reversed array. The function should handle arrays of any length, including empty arrays. The code should start with:
```python
from typing import List
def reverse_array(arr: 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_array(arr: List[int]) -> List[int]:
"""
Reverses the elements of a given array and returns the reversed array.
Args:
arr (List[int]): The input array to be reversed.
Retur... |
magic_evol_110k | 96,444 | Write a Python function to compare two strings for equality, disregarding case sensitivity and ignoring leading, trailing, and excess middle whitespace. The function should return `True` if the strings are considered equal under these conditions, and `False` otherwise. The code should start with:
```python
def compare_... | Here is the Python code to solve the given problem in the markdown block:
```python
def compare_strings(str1: str, str2: str) -> bool:
"""
Compare two strings for equality, disregarding case sensitivity and ignoring leading, trailing, and excess middle whitespace.
Args:
str1 (str): The first string... |
magic_evol_110k | 96,450 | Write a Python function to create an email address with additional mailing parameters. The function should take three arguments: `name`, `domain`, and `mail_parameters`. The `mail_parameters` is a dictionary where keys are parameter names and values are parameter values. The function should return a complete email addr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def create_email_with_parameters(name: str, domain: str, mail_parameters: Dict[str, str]) -> str:
"""
Creates an email address with additional mailing parameters.
Args:
name (str): The name ... |
magic_evol_110k | 96,456 | Write a Python function to check for duplicate tuples within a two-dimensional matrix. The function should return `True` if there are any duplicate tuples in the matrix, and `False` otherwise. The code should start with:
```python
from typing import List, Tuple
def has_duplicate_tuples(matrix: List[List[Tuple[int, int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def has_duplicate_tuples(matrix: List[List[Tuple[int, int]]]) -> bool:
"""
Check if there are any duplicate tuples within a two-dimensional matrix.
Args:
matrix (List[List[Tuple[int, ... |
magic_evol_110k | 96,468 | Write a Python function to sort a list of mixed variable types (integers, strings, and lists) according to the following rules:
1. Ignore any integers.
2. Sort the strings alphabetically.
3. For lists, sort them based on the concatenated string of their string elements (ignoring integers).
The function should return t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def custom_sort(lst: List[Union[int, str, List[Union[int, str]]]]) -> List[Union[int, str, List[Union[int, str]]]]:
"""
Sorts a list of mixed variable types (integers, strings, and lists) accordin... |
magic_evol_110k | 96,477 | Write a Python function to swap the case of each character in a given string. The function should convert all lowercase characters to uppercase and all uppercase characters to lowercase. Additionally, identify and explain a piece of erroneous code related to this task for educational purposes.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
def swap_case(s: str) -> str:
"""
Swaps the case of each character in the given string.
Args:
s (str): The input string whose characters' cases are to be swapped.
Returns:
str: The string with all lower... |
magic_evol_110k | 96,489 | Write a Python function to extract and return the first `n` character elements from a given string. If `n` is greater than the length of the string, return the entire string. The function should handle cases where `n` is less than or equal to zero by returning an empty string.
The code should start with:
```python
def... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_first_n_chars(string: str, n: int) -> str:
"""
Extracts and returns the first n characters from the given string.
Args:
string (str): The input string from which to extract characters.
n (int): The n... |
magic_evol_110k | 96,502 | Write a Python function to find the longest common subsequence (LCS) of two given strings. The function should return the length of the LCS.
The code should start with:
```python
from typing import List
def longest_common_subsequence(str1: str, str2: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def longest_common_subsequence(str1: str, str2: str) -> int:
"""
Calculate the length of the longest common subsequence (LCS) of two strings.
Args:
str1 (str): The first string.
st... |
magic_evol_110k | 96,514 | Write a Python function to determine if there exists a combination of exactly four elements in a given list of floats such that their product equals one. The function should return `True` if such a combination exists, otherwise `False`.
The code should start with:
```python
from typing import List
def four_elements_p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def four_elements_product_equals_one(l: List[float]) -> bool:
"""
Determines if there exists a combination of exactly four elements in the list
such that their product equals one.
Args:
... |
magic_evol_110k | 96,524 | Write a Python function that checks if each character in a given list appears in a string exactly the specified number of times. The function should handle errors for cases where a character in the list does not exist in the string or the specified number exceeds the length of the string. The function should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def check_char_times(s: str, char_list: List[str], num: int) -> bool:
"""
Checks if each character in the given list appears in the string exactly the specified number of times.
Args:
s (str... |
magic_evol_110k | 96,555 | Write a Python function to extract and validate email addresses from a given text dataset using regular expressions. The function should correctly handle emails with periods, plus signs, hyphens, numeric characters, and sub-domains in the local part and domain part of the email address. The function should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def extract_emails(content: str) -> list:
"""
Extracts and validates email addresses from a given text dataset using regular expressions.
Args:
content (str): The text content from which to extract email ... |
magic_evol_110k | 96,562 | Write a Python function to implement an interpolation search algorithm that can handle both sorted and unsorted lists, and return the index of a given integer `y` in the list if present. If `y` is not present, the function should return `-1`. The function should also handle edge cases such as empty lists and lists with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def interpolation_search(lst: List[int], y: int) -> int:
"""
Perform an interpolation search to find the index of the element `y` in the list `lst`.
Args:
lst (List[int]): The list of intege... |
magic_evol_110k | 96,576 | Write a Python function to convert a given string into a list of its constituent characters. The function should handle any string input and return a list of characters. The code should start with:
```python
from typing import List
def string_to_char_list(s: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def string_to_char_list(s: str) -> List[str]:
"""
Converts a given string into a list of its constituent characters.
Args:
s (str): The input string to be converted.
Returns:
Li... |
magic_evol_110k | 96,588 | Create a Python function that processes a list of integers and returns three separate lists based on the following criteria:
1. The first list should contain all even numbers from the input list in the order they appear.
2. The second list should contain all even numbers from the input list in reverse order of their ap... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def process_numbers(num_list: List[int]) -> Tuple[List[int], List[int], List[int]]:
"""
Processes a list of integers to return three separate lists based on the criteria:
1. All even numbers i... |
magic_evol_110k | 96,599 | Write a Python function to find the smallest and largest numbers in a given array of integers. The function should return a list containing these two numbers in ascending order. If the array is empty, the function should return an empty list.
The code should start with:
```python
from typing import List
def find_min_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_min_max(arr: List[int]) -> List[int]:
"""
Finds the smallest and largest numbers in a given array of integers and returns them in ascending order.
Args:
arr (List[int]): The array o... |
magic_evol_110k | 96,600 | Write a Python function to locate the penultimate minimum value within an array of discrete integers of a distinct length 'n'. The function should efficiently find the second smallest element in the array without modifying the original array.
The code should start with:
```python
from typing import List
def find_penu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_penultimate_minimum(arr: List[int]) -> int:
"""
Locate the penultimate minimum value within an array of discrete integers.
Args:
arr (List[int]): The array of integers from which to... |
magic_evol_110k | 96,601 | Write a Python function to generate a list of four randomly generated integer values ranging from 1 to 50, and then sort this list in descending order. The function should handle the generation and sorting of the list efficiently. Additionally, provide test cases to validate the sorting function with various scenarios,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_and_sort_array() -> List[int]:
"""
Generates a list of four random integers between 1 and 50, and sorts the list in descending order.
Returns:
List[int]: A list of... |
magic_evol_110k | 96,615 | Write a Python function to convert a 3-dimensional NumPy array into a 2-dimensional array by flattening the first two dimensions. The function should take a 3-dimensional NumPy array as input and return a 2-dimensional NumPy array. The code should start with:
```python
import numpy as np
def flatten_3d_to_2d(arr: np.n... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def flatten_3d_to_2d(arr: np.ndarray) -> np.ndarray:
"""
Converts a 3-dimensional NumPy array into a 2-dimensional array by flattening the first two dimensions.
Args:
arr (np.ndarray): A 3-dimens... |
magic_evol_110k | 96,634 | Write a Python function to remove all empty strings from a given list of strings. The function should return a new list that contains only the non-empty strings from the original list. The code should start with:
```python
from typing import List
def remove_empty_strings(strings: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_empty_strings(strings: List[str]) -> List[str]:
"""
Removes all empty strings from the given list of strings.
Args:
strings (List[str]): The list of strings from which to remove e... |
magic_evol_110k | 96,639 | Write a Python function to identify the individual who exclusively reads sci-fi literature from a given dictionary of bibliophiles and their preferred genres. The dictionary will map each bibliophile's name to their preferred genre. The function should return the name of the person who reads only sci-fi.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def find_sci_fi_reader(bibliophiles: Dict[str, str]) -> str:
"""
Identify and return the name of the individual who exclusively reads sci-fi literature.
Args:
bibliophiles (Dict[str, str]): ... |
magic_evol_110k | 96,645 | Write a Python function to find the second, third, and fourth smallest numbers in a given multidimensional array and return them in ascending order. The function should handle duplicate values and edge cases where the array has less than 4 unique numbers. If there are fewer than 4 unique numbers, the function should re... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_smallest_numbers(array: List[List[int]]) -> List[int]:
"""
Finds the second, third, and fourth smallest numbers in a given multidimensional array and returns them in ascending order.
If ther... |
magic_evol_110k | 96,659 | Write a Python function to convert a given time in 24-hour format to its equivalent in 12-hour format. The function should handle edge cases such as midnight (00:00) and noon (12:00). The input time is a string in the format "HH:MM" where HH is the hour (00 to 23) and MM is the minutes (00 to 59). The output should be ... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_24_to_12_hour_format(time_24: str) -> str:
"""
Converts a given time in 24-hour format to its equivalent in 12-hour format.
Args:
time_24 (str): The time in 24-hour format as a string "HH:MM".
Retur... |
magic_evol_110k | 96,660 | Write a Python function to compute the product of all elements in a given multidimensional array of integers. The array can be up to three dimensions. The function should handle arrays of varying dimensions and sizes. The code should start with:
```python
from typing import List
def product_of_elements(arr: List[int])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def product_of_elements(arr: List[int]) -> int:
"""
Compute the product of all elements in a given multidimensional array of integers.
Args:
arr (List[int]): The multidimensional array of in... |
magic_evol_110k | 96,663 | Write a Python function to calculate the product of two floating-point numbers and handle edge cases such as zero and negative numbers. The function should be named `multiply` and should accept two parameters, `number1` and `number2`, both of which are floating-point numbers. The function should return the product of t... | Here is the Python code to solve the given problem in the markdown block:
```python
def multiply(number1: float, number2: float) -> float:
"""
Calculate the product of two floating-point numbers.
Args:
number1 (float): The first floating-point number.
number2 (float): The second floating-po... |
magic_evol_110k | 96,686 | Write a Python function to convert a given integer `N` to its equivalent representation in base `-2`. The function should return a string composed of `"0"`s and `"1"`s, representing the value of `N` in base `-2`. The string should not contain any leading zeroes unless the string is `"0"`.
The code should start with:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
def int_to_base_neg2(N: int) -> str:
"""
Convert a given integer `N` to its equivalent representation in base `-2`.
Args:
N (int): The integer to be converted.
Returns:
str: A string representing the va... |
magic_evol_110k | 96,688 | Write a Python function to merge two lists in reverse order. The function should accept two lists as parameters and return a new list that contains all elements from both lists in reverse order. The code should start with:
```python
from typing import List
def reversed_merge(list1: List[any], list2: List[any]) -> List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reversed_merge(list1: List[any], list2: List[any]) -> List[any]:
"""
Merges two lists and returns the merged list in reverse order.
Args:
list1 (List[any]): The first list to be merged.
... |
magic_evol_110k | 96,715 | Write a Python function that determines whether a given number is even or odd. The function should return the string "even" if the number is divisible by 2, and "odd" otherwise. The function should handle both positive and negative integers.
The code should start with:
```python
def even_or_odd(number: int) -> str:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def even_or_odd(number: int) -> str:
"""
Determines whether a given number is even or odd.
Args:
number (int): The number to be checked.
Returns:
str: "even" if the number is divisible by 2, "odd" other... |
magic_evol_110k | 96,737 | Write a Python function to sort the keys of a dictionary based on their corresponding values. The values can be either numeric (integers or floats) or strings. Numeric values should be sorted in ascending order, and string values should be sorted in lexicographical order. The function should handle potential exceptions... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def sort_dictionary_by_values(d: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Sorts the keys of a dictionary based on their corresponding values.
Numeric values are sorted in ascending order, and stri... |
magic_evol_110k | 96,747 | Write a Python function to add two lists of integers element-wise. If the lists are not of the same length, consider the missing elements as 0. The function should not use any built-in Python functions or libraries for list manipulation. The code should start with:
```python
from typing import List
def add_lists(list1... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def add_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Adds two lists of integers element-wise. If the lists are not of the same length,
consider the missing elements as 0.
Args:
... |
magic_evol_110k | 96,751 | Write a Python function to filter out the odd numbers from a given list of integers. The function should return a new list containing only the odd numbers from the input list. The code should start with:
```python
from typing import List
def filter_odd_numbers(input_array: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_odd_numbers(input_array: List[int]) -> List[int]:
"""
Filters out the odd numbers from the given list of integers.
Args:
input_array (List[int]): The list of integers from which t... |
magic_evol_110k | 96,756 | Refactor and optimize the given Python code snippet to improve its readability, efficiency, and correctness. The original code contains unnecessary redundancy, inappropriate computations, and logical mistakes. Additionally, identify and correct the logical errors in the modified code provided. The task is to provide th... | Here is the Python code to solve the given problem in the markdown block:
```python
def optimize_code(x: int, z: int) -> int:
"""
Optimize the given code to determine the value of y based on the values of x and z.
Args:
x (int): The first integer value.
z (int): The second integer value.
... |
magic_evol_110k | 96,758 | Write a Python function to capitalize every single fruit name in a given array of fruit names represented as strings. The function should modify the original list in place and return the modified list. The code should start with:
```python
from typing import List
def capitalize_fruit_names(fruits: List[str]) -> List[s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def capitalize_fruit_names(fruits: List[str]) -> List[str]:
"""
Capitalizes every single fruit name in the given list of fruit names.
Args:
fruits (List[str]): A list of fruit names represen... |
magic_evol_110k | 96,781 | Write a Python function to translate a hierarchical tree structure represented as a nested dictionary into a list of tuples, where each tuple represents a node and its parent. The root node has no parent, so its parent should be `None`. The function should start with:
```python
from typing import Dict, List, Tuple, Opt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple, Optional
def tree_to_tuples(tree: Dict) -> List[Tuple[str, Optional[str]]]:
"""
Translates a hierarchical tree structure represented as a nested dictionary into a list of tuples.
Each t... |
magic_evol_110k | 96,789 | Write a Python function to filter out and return only the odd numbers from a given list of integers. If the input is not a list or if the list contains elements that are not integers, raise a `ValueError`. The function should start with:
```python
from typing import List
def 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 odd_numbers(lst: List[int]) -> List[int]:
"""
Filters out and returns only the odd numbers from a given list of integers.
Args:
lst (List[int]): The list of integers from which to extrac... |
magic_evol_110k | 96,805 | Write a Python function to find the index of the first unique character in a given string. If there are no unique characters, the function should return -1. The function should be efficient and handle various edge cases, such as empty strings and strings with all duplicate characters.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
def first_unique_char(s: str) -> int:
"""
Finds the index of the first unique character in the given string.
Args:
s (str): The input string to search for the first unique character.
Returns:
int: The i... |
magic_evol_110k | 96,826 | Write a Python function that implements a nested while loop structure. The outer loop should run from 0 to a specified maximum count, and the inner loop should count down from 5 to 1. If any of the counters (outer or inner) becomes negative during the execution, the function should raise a `ValueError` with an appropri... | Here is the Python code to solve the given problem in the markdown block:
```python
def nested_while_loops(max_count: int) -> None:
"""
Implements a nested while loop structure. The outer loop runs from 0 to max_count,
and the inner loop counts down from 5 to 1. If any counter becomes negative,
a ValueE... |
magic_evol_110k | 96,865 | Write a Python function to determine if two given phrases contain completely identical sets of words, considering both the word order and frequency. The function should return `True` if the phrases are identical in terms of word sequences and frequencies, 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 compare_word_sets_frequency_order(phrase1: str, phrase2: str) -> bool:
"""
Determines if two given phrases contain completely identical sets of words, considering both the word order and frequency.
Args:
phrase1... |
magic_evol_110k | 96,866 | Write a Python function to remove all empty strings from a given list of strings. The function should return a new list that contains only the non-empty strings from the original list. The code should start with:
```python
from typing import List
def remove_empty_strings(strings: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_empty_strings(strings: List[str]) -> List[str]:
"""
Removes all empty strings from the given list of strings.
Args:
strings (List[str]): The list of strings from which to remove e... |
magic_evol_110k | 96,872 | Write a Python function to convert a dictionary's key-value pairs into a list of strings, where each string is formatted as "key: value". The function should handle any dictionary with string keys and values. The code should start with:
```python
from typing import Dict, List
def dict_to_list_of_strings(dictionary: Di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def dict_to_list_of_strings(dictionary: Dict[str, str]) -> List[str]:
"""
Converts a dictionary's key-value pairs into a list of strings, where each string is formatted as "key: value".
Args:
... |
magic_evol_110k | 96,880 | Write a Python function to convert all string elements in a nested list to uppercase while maintaining the original structure of the nested list. The nested list can contain strings, integers, or other lists at any level of nesting. The function should only convert strings to uppercase and leave other types of elements... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def nested_to_uppercase(nested_list: List[Union[str, int, List]]) -> List[Union[str, int, List]]:
"""
Converts all string elements in a nested list to uppercase while maintaining the original stru... |
magic_evol_110k | 96,894 | Write a Python function to modify each element in a given 2D array (matrix) such that every element in a row is replaced with the maximum value present in that row. The function should return the modified matrix.
The code should start with:
```python
from typing import List
def replace_with_row_max(matrix: List[List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def replace_with_row_max(matrix: List[List[int]]) -> List[List[int]]:
"""
Modifies each element in a given 2D array such that every element in a row is replaced with the maximum value present in that row... |
magic_evol_110k | 96,905 | Write a Python function to determine if any string in a given list starts with a specified character. The function should return `True` if at least one string in the list starts with the specified character, and `False` otherwise. The function should be case-insensitive, meaning it should consider both uppercase and lo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def any_string_starts_with(lst: List[str], char: str) -> bool:
"""
Determines if any string in the given list starts with the specified character.
Args:
lst (List[str]): The list of strings ... |
magic_evol_110k | 96,907 | Write a Python function to identify and count the even prime numbers up to a given limit using a regular expression. The function should return a list of these even prime numbers and their count.
The code should start with:
```python
import re
from typing import List, Tuple
def find_even_primes(limit: int) -> Tuple[L... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List, Tuple
def is_prime(n: int) -> bool:
"""Returns True if given non-negative integer is prime, otherwise returns False"""
if n < 2:
return False
for i in range(2, int(n**0.5) + 1):
... |
magic_evol_110k | 96,919 | Write a Python function to manage a dictionary that maps common bird names (appellations) to their scientific names (taxonomy) for the Corvidae family. Implement functions to add, remove, and search for bird species by either their common name or scientific name. The search function should handle cases where the input ... | Here is the Python code to solve the given problem in the markdown block:
```python
def add_species(common_name: str, scientific_name: str) -> None:
"""
Add a bird species to the dictionary.
Args:
common_name (str): The common name of the bird.
scientific_name (str): The scientific name of ... |
magic_evol_110k | 96,923 | Write a Python function to calculate the sum of all numbers in a given list. The function should handle lists of integers and floating-point numbers. The code should start with:
```python
from typing import List
def sum_of_numbers(num_list: List[float]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_numbers(num_list: List[float]) -> float:
"""
Calculate the sum of all numbers in a given list.
Args:
num_list (List[float]): A list of numbers (integers or floating-point numbers)... |
magic_evol_110k | 96,954 | Write a Python function to create a 3D matrix of incrementing numbers starting from a given number `start`. The matrix should have dimensions `p`, `q`, and `r`. The function should return the 3D matrix as a NumPy array.
The code should start with:
```python
import numpy as np
def create_3d_matrix(start: int, p: int, ... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def create_3d_matrix(start: int, p: int, q: int, r: int) -> np.ndarray:
"""
Create a 3D matrix of incrementing numbers starting from a given number.
Args:
start (int): The starting number of the ... |
magic_evol_110k | 96,958 | Write a Python function to validate if a given string is a chain composed strictly of uppercase alphabetic characters and numerical figures. The string should not contain any lowercase letters, special characters, or spaces. The function should return `True` if the string meets the criteria, and `False` otherwise.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_uppercase_numeric_chain(s: str) -> bool:
"""
Validates if the given string is a chain composed strictly of uppercase alphabetic characters and numerical figures.
Args:
s (str): The string to be val... |
magic_evol_110k | 96,980 | Write a Python function to generate all possible combinations of strings of length `k` that can be formed using the given list of unique characters. The function should allow repetitions of characters. The code should start with:
```python
from typing import List
def string_combinations(chars: List[str], k: int) -> Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from itertools import product
def string_combinations(chars: List[str], k: int) -> List[str]:
"""
Generate all possible combinations of strings of length k that can be formed using the given characters.
... |
magic_evol_110k | 96,985 | Write a Python function to validate an International Mobile Equipment Identity (IMEI) number using a regular expression pattern. The function should check if the given IMEI number is valid based on the following criteria:
1. The IMEI number must be composed of exactly 15 digits.
2. The IMEI number should not contain an... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_imei(imei: str) -> bool:
"""
Validates an International Mobile Equipment Identity (IMEI) number.
Args:
imei (str): The IMEI number to validate.
Returns:
bool: True if the IMEI nu... |
magic_evol_110k | 96,986 | Write a Python function to calculate the cumulative sum of all elements in a given list. The function should return the cumulative sum as an integer. The code should start with:
```python
from typing import List
def cumulative_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 cumulative_sum(arr: List[int]) -> int:
"""
Calculate the cumulative sum of all elements in the given list.
Args:
arr (List[int]): The list of integers for which the cumulative sum is to ... |
magic_evol_110k | 96,997 | Write a Python function to calculate the maximum profit that can be generated by assigning jobs to workers based on their capabilities. Each job has a difficulty level and a corresponding profit. Each worker can only undertake jobs with difficulty levels not exceeding their capability. Each worker can be assigned at mo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_profit_assignment(difficulty: List[int], profit: List[int], worker: List[int]) -> int:
"""
Calculate the maximum profit that can be generated by assigning jobs to workers based on their capabilit... |
magic_evol_110k | 97,009 | Write a Python function to perform a binary search to find the indices of two given elements in a sorted list of numbers. The function should return a tuple containing two sorted lists: the indices of the first element and the indices of the second element, each in ascending order. If either element is not found, retur... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_two_elements_indices(lst: List[int], target1: int, target2: int) -> Tuple[List[int], List[int]]:
"""
Find the indices of two given elements in a sorted list of numbers.
Args:
... |
magic_evol_110k | 97,010 | Write a Python function to sort a list of positive integers in a specified order ("asc" for ascending, "desc" for descending) and remove all duplicates. The function should not use the built-in `sorted()` function, `.sort()` method, or `set` data type. The function 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 custom_sort_and_deduplicate(inp_list: List[int], order: str = "asc") -> List[int]:
"""
Sorts the input list of positive integers in the specified order ("asc" for ascending, "desc" for descending)
... |
magic_evol_110k | 97,030 | Write a Python function to efficiently retrieve the last element from a deque and ensure that the memory usage is handled optimally. The function should remove the last element from the deque and return it. If the deque is empty, the function should return `None`.
The code should start with:
```python
from collections... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import deque
def get_and_remove_last_element(d: deque) -> str:
"""
Retrieves and removes the last element from a deque, ensuring efficient memory handling.
Args:
d (deque): The deque from which to ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.