source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 103,142 | Write a Python function to compute the cumulative sum of elements in a given list of integers. The cumulative sum at each position `i` in the list is the sum of all elements from the start of the list up to and including the element at position `i`. The function should return a new list containing these cumulative sums... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_sum(array: List[int]) -> List[int]:
"""
Compute the cumulative sum of elements in a given list of integers.
Args:
array (List[int]): The list of integers for which to compute ... |
magic_evol_110k | 103,158 | Write a Python function to perform a binary search on a sorted list of integers to find the index of a specified value. If the value is not found, return -1. The function should be efficient and follow the binary search algorithm.
The code should start with:
```python
from typing import List
def binary_search(nums: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(nums: List[int], val: int) -> int:
"""
Perform a binary search on a sorted list of integers to find the index of a specified value.
Args:
nums (List[int]): A sorted list of... |
magic_evol_110k | 103,159 | Write a Python function to remove all occurrences of a specified element from a given list of integers, while maintaining the original order of the remaining elements. The function should not use any built-in or external library functions for list manipulation, such as `remove`, `filter`, or `del`. The function should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_element(arr: List[int], elem: int) -> List[int]:
"""
Removes all occurrences of a specified element from a list of integers, maintaining the original order.
Args:
arr (List[int]):... |
magic_evol_110k | 103,199 | Write a Python function to determine if there exist three unique elements in a given list of integers that sum up to a specified target value. The function should return `True` if such a triplet exists, otherwise `False`.
The code should start with:
```python
from typing import List
def find_three_elements_equal_to_t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_three_elements_equal_to_target(array: List[int], targetNumericalValue: int) -> bool:
"""
Determines if there exist three unique elements in the given list that sum up to the specified target val... |
magic_evol_110k | 103,200 | Write a Python function to find the lowest odd number within a specified range in a given list, along with its index and the count of all odd numbers within that range. The list may contain negative numbers and zero. The function should return a tuple containing the lowest odd number, its index, and the count of all od... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_lowest_odd_in_range(num_list: List[int], range_list: List[int]) -> Tuple[int, int, int] or str:
"""
Finds the lowest odd number within a specified range in a given list, along with its in... |
magic_evol_110k | 103,201 | Write a Python function to concatenate two lists and handle potential errors such as different data types. The function should return an error message if the provided inputs are not lists. The code should start with:
```python
from typing import List, Union
def concatenate_lists(list1: Union[List, None], list2: Union[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def concatenate_lists(list1: Union[List, None], list2: Union[List, None]) -> Union[List, str]:
"""
Concatenate two lists and handle potential errors such as different data types.
Args:
... |
magic_evol_110k | 103,205 | Write a Python function to count the number of strings in a given list that begin with a consonant. The function should accept a list of strings as input and return the count of strings that start with any consonant.
The code should start with:
```python
from typing import List
def count_strings_starting_with_consona... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_strings_starting_with_consonant(string_list: List[str]) -> int:
"""
Counts the number of strings in a given list that begin with a consonant.
Args:
string_list (List[str]): A list ... |
magic_evol_110k | 103,231 | Write a Python function to determine if a given singly linked list is a palindrome. A linked list is a palindrome if it reads the same backward as forward. The function should return `True` if the linked list is a palindrome, otherwise `False`.
The code should start with:
```python
class ListNode:
def __init__(sel... | Here is the Python code to solve the given problem in the markdown block:
```python
class ListNode:
def __init__(self, value=0, next=None):
self.value = value
self.next = next
def is_palindrome(head: ListNode) -> bool:
"""
Determine if a given singly linked list is a palindrome.
Args:
... |
magic_evol_110k | 103,232 | Write a Python function to find all the keys in a nested dictionary whose corresponding values are of type string. The function should handle possible `TypeError` exceptions and gracefully manage cases where the supplied argument is not a dictionary. The function should also maintain the efficiency of the algorithm as ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Any
def find_string_keys(data: Dict[str, Any]) -> List[str]:
"""
Find all keys in a nested dictionary whose corresponding values are of type string.
Args:
data (Dict[str, Any]): The n... |
magic_evol_110k | 103,234 | Write a Python function to find the minimum number of subsequences of a given `source` string that can be concatenated to form a `target` string. If it is impossible to form the `target` string from the `source` string, return `-1`. Additionally, return the list of subsequences used to form the `target` string.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def shortest_way_to_form_string(source: str, target: str) -> Tuple[int, List[str]]:
"""
Find the minimum number of subsequences of `source` that can be concatenated to form `target`.
Args:
... |
magic_evol_110k | 103,253 | Write a Python function to generate the multiplication table for a given number `n` from 1 to a specified limit `limit`. The function should return a list of strings, where each string represents an individual product in the format `"{n} * {i} = {product}"`.
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
def generate_multiplication_table(n: int, limit: int) -> List[str]:
"""
Generate the multiplication table for a given number `n` from 1 to `limit`.
Args:
n (int): The number for which the mu... |
magic_evol_110k | 103,263 | Write a Python function to split a list of lists into two separate lists. The first list should contain the first element of each sublist, and the second list should contain the second element of each sublist. If a sublist has fewer than two elements, the second list should not include any corresponding element. The fu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def split_sublists(input_list: List[List[int]]) -> List[List[int]]:
"""
Splits a list of lists into two separate lists. The first list contains the first element of each sublist,
and the second list ... |
magic_evol_110k | 103,285 | Write a Python function to calculate the area of an equilateral triangle given the length of one of its sides. The function should use the correct mathematical formula for the area of an equilateral triangle. The code should start with:
```python
import math
def calculate_equilateral_triangle_area(side: float) -> floa... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_equilateral_triangle_area(side: float) -> float:
"""
Calculate the area of an equilateral triangle given the length of one of its sides.
Args:
side (float): The length of one side of the e... |
magic_evol_110k | 103,316 | Write a Python function to reverse the contents of a given array in place. The function should modify the original array and return it. 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 contents of a given array in place and returns the modified array.
Args:
arr (List[int]): The array to be reversed.
Re... |
magic_evol_110k | 103,328 | Write a Python function to determine if a given list of integers is a strictly ascending sequence and forms an arithmetic progression. If the sequence meets both criteria, the function should return the common difference of the arithmetic progression. Otherwise, it should return `None`.
The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def check_arithmetic_progression(arr: List[int]) -> Optional[int]:
"""
Determines if a given list of integers is a strictly ascending sequence and forms an arithmetic progression.
If both c... |
magic_evol_110k | 103,357 | Write a Python function to filter a list of arbitrary Python elements and return a new list containing only the float data types. The function should be able to handle various data types such as integers, strings, dictionaries, lists, and floats. The code should start with:
```python
from typing import List, Any
def o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def only_floats(values: List[Any]) -> List[float]:
"""
Filters the provided collection of arbitrary Python elements and returns a new list containing only the float data types.
Args:
va... |
magic_evol_110k | 103,393 | Write a Python function to determine if two given lists maintain an inverse symmetrical relationship, meaning that one list is the mirror image of the other. The function should return `True` if the lists are inverse symmetrical, and `False` otherwise. The code should start with:
```python
from typing import List
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_inverse_symmetrical(arr1: List[int], arr2: List[int]) -> bool:
"""
Determines if two lists maintain an inverse symmetrical relationship.
Args:
arr1 (List[int]): The first list to comp... |
magic_evol_110k | 103,395 | 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 | 103,398 | Write a Python function to check if all the strings in a given list are unique and if each string in the list contains unique characters. The function should be optimized for time complexity, considering the possibility of large lists and long strings.
The code should start with:
```python
from typing import List
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def check_unique_strings(input_list: List[str]) -> bool:
"""
Check if all strings in the given list are unique and if each string contains unique characters.
Args:
input_list (List[str]): A ... |
magic_evol_110k | 103,410 | Design a Python class `PrimeNumberStore` that efficiently stores and retrieves prime numbers up to a given limit using the Sieve of Eratosthenes algorithm. The class should be optimized for both storage and retrieval operations. The class should include methods to initialize the store with prime numbers up to a specifi... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
class PrimeNumberStore:
def __init__(self, limit: int):
"""
Initialize the PrimeNumberStore with prime numbers up to the given limit.
Args:
limit (int): The upper limit for p... |
magic_evol_110k | 103,412 | Write a Python function to find all sequences in a given text that match a specific pattern. The pattern should start with a lowercase alphabetic character 'a', contain at least one numeric digit in the middle, at least one special character, and end with an uppercase alphabetic character 'Z'. The function should retur... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def find_sequences(text: str) -> List[str]:
"""
Finds all sequences in the given text that match the specified pattern.
The pattern requires the sequence to start with 'a', contain at least... |
magic_evol_110k | 103,431 | Write a Python function to implement a custom `map` function that applies a given lambda function to each element of multiple arrays of varying lengths. The function should return a list of lists, where each internal list corresponds to the result of applying the given function to each respective array. The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable
def custom_map(function: Callable, *arrays: List) -> List[List]:
"""
Applies a given function to each element of multiple arrays and returns a list of lists.
Args:
function (Callab... |
magic_evol_110k | 103,434 | Write a Python function to rearrange a list of numbers (both integers and decimal numbers) in an alternating minimum-maximum sequence using binary search tree (BST) principles. The sequence should start with the smallest number, followed by the largest number, then the next smallest number, and so on. The function shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def alternating_minimum_maximum_bst(array: List[float]) -> List[float]:
"""
Rearranges a list of numbers in an alternating minimum-maximum sequence using BST principles.
Args:
array (List[fl... |
magic_evol_110k | 103,436 | Write a Python function to check if a given string is a palindrome, ignoring case, punctuation, and spacing. The function should efficiently handle strings of varying lengths and should consider punctuation and spaces as part of the string but ignore them while checking for palindrome properties.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_palindrome(raw_string: str) -> bool:
"""
Check if a given string is a palindrome, ignoring case, punctuation, and spacing.
Args:
raw_string (str): The input string to check for palindrome propertie... |
magic_evol_110k | 103,444 | Write a Python function to create a dictionary from two lists, where the elements of the first list serve as keys and the elements of the second list serve as corresponding values. Ensure that the function handles cases where the lists are of different lengths by ignoring the extra elements in the longer list. The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def lists_to_dict(keys: List[str], values: List[int]) -> Dict[str, int]:
"""
Creates a dictionary from two lists, where the elements of the first list serve as keys
and the elements of the seco... |
magic_evol_110k | 103,461 | Write a Python function to convert a given hexadecimal number to its binary representation. The function should handle hexadecimal number systems that include a-F values and should be able to process large hexadecimal numbers. The function should start with:
```python
def hex_to_binary(hex_num: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_binary(hex_num: str) -> str:
"""
Converts a given hexadecimal number to its binary representation.
Args:
hex_num (str): The hexadecimal number to be converted. It can include digits 0-9 and letters A-F (c... |
magic_evol_110k | 103,465 | Write a Python function to transform a given alphanumeric text into its corresponding leetspeak representation. Leetspeak is a digital language where certain letters are replaced by numbers or other characters. The standard leetspeak conventions are as follows:
- 'A' -> '4'
- 'E' -> '3'
- 'I' -> '1'
- 'O' -> '0'
- 'S' ... | Here is the Python code to solve the given problem in the markdown block:
```python
def to_leetspeak(text: str) -> str:
"""
Transforms the given alphanumeric text into its corresponding leetspeak representation.
Args:
text (str): The input text to be transformed.
Returns:
str: The leet... |
magic_evol_110k | 103,470 | Write a Python function to remove duplicate strings from a given list while preserving the order of the first occurrence of each string. The function should be efficient and handle large lists.
The code should start with:
```python
from typing import List
def remove_duplicates_preserve_order(lst: List[str]) -> List[s... | 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[str]) -> List[str]:
"""
Removes duplicate strings from the given list while preserving the order of their first occurrence.
Args:
lst (List[str... |
magic_evol_110k | 103,485 | Write a Python function to calculate the sum of all elements in a multi-dimensional array. The multi-dimensional array can have any number of dimensions, and the function should handle arrays of varying depths. The function should start with:
```python
from typing import List
def sum_multi_dimensional_array(arr: List)... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_multi_dimensional_array(arr: List) -> int:
"""
Calculate the sum of all elements in a multi-dimensional array.
Args:
arr (List): The multi-dimensional array to sum.
Returns:
... |
magic_evol_110k | 103,499 | Write a Python function to remove all text after a specified special character (e.g., `$`) from a given list of strings. The function should return a new list of strings with the text after the special character removed.
The code should start with:
```python
from typing import List
def remove_text_after_special_char(... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_text_after_special_char(texts: List[str], special_char: str) -> List[str]:
"""
Removes all text after a specified special character from each string in the given list.
Args:
texts... |
magic_evol_110k | 103,505 | Write a Python function to sum nested lists of N rows and N columns, producing a single list with N rows and N columns. The function should handle any level of nested lists, ensuring that the innermost lists are summed element-wise.
The code should start with:
```python
from typing import List
def sum_nested_lists(ls... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_nested_lists(lst: List[List[List[int]]]) -> List[List[int]]:
"""
Sum nested lists of N rows and N columns, producing a single list with N rows and N columns.
Args:
lst (List[List[Lis... |
magic_evol_110k | 103,517 | Write a Python function to swap the elements at two given positions in a list of integers. The function should handle cases where the positions are out of bounds by returning the original list unchanged. The code should start with:
```python
from typing import List
def swap_elements(array: List[int], i: int, j: int) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def swap_elements(array: List[int], i: int, j: int) -> List[int]:
"""
Swaps the elements at positions i and j in the given list of integers.
Args:
array (List[int]): The list of integers... |
magic_evol_110k | 103,531 | Write a Python function to determine if there are three distinct elements in a given list that sum to zero. The function should have a time complexity of O(n^2). The code should start with:
```python
from typing import List
def triples_sum_to_zero(l: List[int]) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def triples_sum_to_zero(l: List[int]) -> bool:
"""
Determines if there are three distinct elements in the list that sum to zero.
Args:
l (List[int]): The list of integers to check.
Retu... |
magic_evol_110k | 103,533 | Write a Python function to find the minimum value in a list that satisfies a given condition using multi-threading. The function should return the minimum value and its index in the list. If no value satisfies the condition, the function should return an empty list. The function should be able to handle multiple thread... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable, Optional
import threading
def pluck(arr: List[int], cond_fn: Callable[[int], bool], threads: int = 1) -> List[Optional[int]]:
"""
Find the minimum value in a list that satisfies a given condit... |
magic_evol_110k | 103,542 | Write a Python function to remove all even numbers from a given list of integers. The function should return a new list containing only the odd numbers from the original list. The code should start with:
```python
from typing import List
def remove_even_numbers(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 remove_even_numbers(arr: List[int]) -> List[int]:
"""
Removes all even numbers from the given list of integers and returns a new list containing only the odd numbers.
Args:
arr (List[i... |
magic_evol_110k | 103,551 | Write a Python function to find and return the bottom `k` lowest numbers from a given list of integers. The function should handle cases where `k` is greater than the length of the list, and it should be efficient.
The code should start with:
```python
from typing import List
def find_bottom_k_lowest(arr: List[int], ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import heapq
def find_bottom_k_lowest(arr: List[int], k: int) -> List[int]:
"""
Finds and returns the bottom k lowest numbers from the given list of integers.
Args:
arr (List[int]): The list... |
magic_evol_110k | 103,567 | Write a Python function to count the number of vowel characters in a given string. The function should be case-insensitive and should consider both uppercase and lowercase vowels.
The code should start with:
```python
def count_vowels(sentence: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_vowels(sentence: str) -> int:
"""
Count the number of vowel characters in a given string.
Args:
sentence (str): The input string to count vowels in.
Returns:
int: The number of vowel character... |
magic_evol_110k | 103,569 | Write a Python function to generate a two-dimensional matrix of dimensions `n` by `m` based on the following rules:
1. All border elements should be `0`.
2. All non-border elements should be `1`.
3. If either `n` or `m` equals `1`, the matrix should be filled with `0`s.
The function should start with:
```python
from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_matrix(n: int, m: int) -> List[List[int]]:
"""
Generates a two-dimensional matrix of dimensions n by m based on the following rules:
1. All border elements are 0.
2. All non-border e... |
magic_evol_110k | 103,585 | Write a Python function to reverse the order of words in a given string. The function should split the string into words, reverse the order of these words, and then join them back into a single string. The code should start with:
```python
def reverse_words_in_string(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_words_in_string(input_string: str) -> str:
"""
Reverses the order of words in a given string.
Args:
input_string (str): The input string containing words to be reversed.
Returns:
str: A st... |
magic_evol_110k | 103,596 | Write a Python function to combine two lists without duplication, maintaining the original order of elements, and ensuring that the combined list contains only strings. The function should start with:
```python
from typing import List
def combine_lists_without_duplicates(list_one: List[str], list_two: List[str]) -> Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def combine_lists_without_duplicates(list_one: List[str], list_two: List[str]) -> List[str]:
"""
Combines two lists without duplication, maintaining the original order of elements,
and ensuring that ... |
magic_evol_110k | 103,599 | Write a Python function to flatten a given two-dimensional matrix into a one-dimensional list. The function should handle matrices of varying sizes and ensure that all elements are included in the resulting list in row-major order. The code should start with:
```python
from typing import List
def flatten_matrix(matrix... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def flatten_matrix(matrix: List[List[int]]) -> List[int]:
"""
Flattens a given two-dimensional matrix into a one-dimensional list.
Args:
matrix (List[List[int]]): A two-dimensional list of i... |
magic_evol_110k | 103,613 | Write a Python function to find the length of the longest contiguous subarray of 1s in a given binary array. The binary array contains only the digits `0` and `1`. The function should return the length of the longest sequence of consecutive 1s.
The code should start with:
```python
from typing import List
def longest... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_sequence_of_ones(arr: List[int]) -> int:
"""
Find the length of the longest contiguous subarray of 1s in a given binary array.
Args:
arr (List[int]): A list of integers containin... |
magic_evol_110k | 103,614 | Write a Python function to generate a unique identifier of a specified length, consisting of random alphanumeric characters and special characters. The function should ensure that the generated identifier is unique by checking against a list of previously generated identifiers. If a duplicate is found, the function sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
import string
def generate_unique_id(length: int, existing_ids: List[str]) -> str:
"""
Generates a unique identifier of the specified length, consisting of random alphanumeric and special c... |
magic_evol_110k | 103,617 | Write a Python function to perform a binary search on a sorted array. The function should return the index of the target element if it is present in the array, otherwise it should return -1. The code should start with:
```python
from typing import List
def binary_search(arr: List[int], x: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(arr: List[int], x: int) -> int:
"""
Perform a binary search on a sorted array to find the index of the target element.
Args:
arr (List[int]): The sorted array to search in.... |
magic_evol_110k | 103,621 | Write a Python function to categorize a list of alphanumeric strings into two separate lists: one for numeric strings and one for alphabetic strings. The function should use regular expressions to determine the category of each string.
The code should start with:
```python
from typing import List, Tuple
import re
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import re
def categorize_alphanumeric_strings(strings: List[str]) -> Tuple[List[str], List[str]]:
"""
Categorizes a list of alphanumeric strings into numeric and alphabetic strings using regular e... |
magic_evol_110k | 103,624 | Write a Python function to find the maximum number in each sub-list of a given 2D list of integers and then return the maximum of these maximum numbers. The function should handle empty sub-lists by treating them as if the maximum of that sub-list is 0. The function should have a time complexity better than O(n^2).
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_max_in_2D(lst: List[List[int]]) -> int:
"""
Find the maximum number in each sub-list of a given 2D list of integers and return the maximum of these maximum numbers.
Treat empty sub-lists as ... |
magic_evol_110k | 103,637 | Write a Python function to convert a given tuple of strings into a list and then extract and return the element at a specified position in the transformed list. The function should handle cases where the specified position is out of bounds by returning `None`.
The code should start with:
```python
from typing import T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, List, Optional
def convert_tuple_to_list_and_get_element(creatures: Tuple[str], position: int) -> Optional[str]:
"""
Converts a given tuple of strings into a list and returns the element at the specifi... |
magic_evol_110k | 103,664 | Write a Python function to find all the unique common elements between two lists without using any built-in functions or libraries for set operations. The function should optimize for time complexity. The code should start with:
```python
from typing import List
def find_unique_common_elements(list1: List[int], list2:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_unique_common_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Finds all unique common elements between two lists without using built-in set operations.
Args:
list1 (L... |
magic_evol_110k | 103,676 | Write a Python function that generates the first `n` even numbers, calculates their cumulative sum, and computes the average of these numbers. The function should validate the user's input to ensure it is a positive integer. If the input is invalid, the function should return an error message.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_even_numbers_and_stats(n: int) -> tuple:
"""
Generates the first n even numbers, calculates their cumulative sum, and computes the average.
Args:
n (int): The number of even numbers to generate.
Re... |
magic_evol_110k | 103,684 | Write a Python function to generate a stochastic floating-point number within a specified range. The function should allow for custom lower and upper bounds, with default values of -5 and 5 respectively. The function should also ensure that the generated number is within the specified bounds.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_random_number(lower_bound: float = -5, upper_bound: float = 5) -> float:
"""
Generates a stochastic floating-point number within the specified range.
Args:
lower_bound (float): The lower ... |
magic_evol_110k | 103,696 | Write a Python function to generate a distinct sequence of 20 elements that includes alphabetic characters, numerical characters, and unique typographical characters. The function should ensure that the sequence is unique and random each time it is called. The code should start with:
```python
from typing import List
i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
import string
def generate_unique_sequence() -> List[str]:
"""
Generates a distinct sequence of 20 elements that includes alphabetic characters,
numerical characters, and unique typogra... |
magic_evol_110k | 103,718 | Write a Python function to convert a given string to lowercase and remove all digits while preserving other characters such as spaces, punctuation, and special symbols. The function should return the modified string.
The code should start with:
```python
def convert_to_lowercase_and_remove_digits(text: str) -> str:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_lowercase_and_remove_digits(text: str) -> str:
"""
Convert a given string to lowercase and remove all digits while preserving other characters.
Args:
text (str): The input string to be processed.
... |
magic_evol_110k | 103,763 | Write a Python function to shuffle a given list of floating point numbers without modifying the original list. The function should either return a new shuffled list or yield the shuffled items one by one. The code should start with:
```python
from typing import List, Generator
import random
def shuffle_list(numbers: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def shuffle_list(numbers: List[float]) -> List[float]:
"""
Shuffles a given list of floating point numbers without modifying the original list.
Args:
numbers (List[float]): The... |
magic_evol_110k | 103,779 | Write a Python function to check if each number within a list is within a specified range. The function should be optimized for larger inputs and have a time complexity of O(n). The function should return `True` if all numbers in the list are within the range `[lower_limit, upper_limit]`, and `False` otherwise.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def within_range(lst: List[int], lower_limit: int, upper_limit: int) -> bool:
"""
Check if every number in the list is within the specified range [lower_limit, upper_limit].
Args:
lst (List[... |
magic_evol_110k | 103,799 | Write a Python function to find the common singular elements from two inputted lists, arranged in increasing sequence. The function should use a custom sorting algorithm and avoid using Python's native list functions for eliminating recurring items. The function should start with:
```python
from typing import List
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def shared_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Find the common singular elements from two inputted lists and return them in increasing sequence.
Args:
list1 (List[... |
magic_evol_110k | 103,801 | Write a Python function to determine if a given string is an anagram of its reversed form, considering multiple words (strings separated by spaces) and ignoring case differences. The function should be recursive and handle the input string by breaking it down into smaller parts until a base case is reached.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_reverse_anagram(text: str) -> bool:
"""
Determine if a given string is an anagram of its reversed form, considering multiple words and ignoring case differences.
Args:
text (str): The input string to check.
... |
magic_evol_110k | 103,806 | Write a Python function to remove duplicates from a list of strings and sort the list alphabetically. The function should handle lists of varying lengths and ensure that the output is a new list with unique and sorted strings.
The code should start with:
```python
from typing import List
def remove_duplicates_and_sor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_and_sort(lst: List[str]) -> List[str]:
"""
Removes duplicates from a list of strings and sorts the list alphabetically.
Args:
lst (List[str]): A list of strings from wh... |
magic_evol_110k | 103,808 | Write a Python function to find the prime factors of a given number `n` as efficiently as possible, considering both time and space complexity. The function should be able to handle large inputs and edge cases. The code should start with:
```python
def prime_factors(n: int) -> list:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def prime_factors(n: int) -> list:
"""
Find the prime factors of a given number n.
Args:
n (int): The number for which to find the prime factors.
Returns:
list: A list of prime factors of n.
"""
... |
magic_evol_110k | 103,822 | Write a Python function to calculate a hash value for each row in a 2D array and return a new 2D array that includes the hash value followed by the original row elements. The function should handle 2D arrays with an undefined number of rows and columns. The code should start with:
```python
from typing import List
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_hash_with_rows(arr: List[List[int]]) -> List[List[int]]:
"""
Calculate a hash value for each row in a 2D array and return a new 2D array
that includes the hash value followed by the ori... |
magic_evol_110k | 103,835 | Write a Python function to generate a two-dimensional array of non-repeating random integers within a specified range, and then find all prime numbers within that array. The function should return a list of prime numbers found in the array.
The code should start with:
```python
from typing import List
import random
im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
import math
def generate_and_find_primes(rows: int, cols: int, min_val: int, max_val: int) -> List[int]:
"""
Generate a two-dimensional array of non-repeating random integers within a speci... |
magic_evol_110k | 103,853 | Write a Python function to compute the cross product of two 2D numpy arrays. The function should take two 2D numpy arrays as input and return the resultant 2D numpy array after performing the cross product operation. The cross product should be calculated using the `numpy` library's `cross` function.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def compute_cross_product(array1: np.ndarray, array2: np.ndarray) -> np.ndarray:
"""
Compute the cross product of two 2D numpy arrays.
Args:
array1 (np.ndarray): The first 2D numpy array.
... |
magic_evol_110k | 103,865 | Write a Python function to count the number of even numbers in each sublist of a given two-dimensional list of integers and also count the total number of even numbers in the entire list. The function should return a list where the first part contains the count of even numbers for each sublist, and the last element is ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_even_numbers(arr: List[List[int]]) -> List[int]:
"""
Counts the number of even numbers in each sublist of a given two-dimensional list
and also counts the total number of even numbers in th... |
magic_evol_110k | 103,867 | Write a Python function to calculate the total number of vowels (both lowercase and uppercase) in a given input string. The function should be case-insensitive and should count all occurrences of the vowels 'a', 'e', 'i', 'o', 'u' in the input string.
The code should start with:
```python
def count_vowels(input_string... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_vowels(input_string: str) -> int:
"""
Calculate the total number of vowels (both lowercase and uppercase) in the input string.
Args:
input_string (str): The input string in which to count the vowels.
... |
magic_evol_110k | 103,869 | Write a Python function to compute the difference between two lists of integers. The function should return a new list that contains only elements that are present in the first list (`lst1`) and not in the second list (`lst2`). The function should be optimized for performance, and the time complexity should be discusse... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def list_difference(lst1: List[int], lst2: List[int]) -> List[int]:
"""
Compute the difference between two lists of integers.
This function returns a new list containing elements that are present in... |
magic_evol_110k | 103,872 | Write a Python function to determine if the sum of the product of all elements in a list and an additional value falls within a specified range. The function should be efficient, with a time complexity less than O(n^2). The code should start with:
```python
from typing import List
def product_in_range(l: List[int], mi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from functools import reduce
from operator import mul
def product_in_range(l: List[int], min_val: int, max_val: int, add_val: int) -> bool:
"""
Determines if the sum of the product of all elements in the... |
magic_evol_110k | 103,883 | Write a Python function to calculate the total cost of purchasing a specified number of products, considering the unit cost and an optional bulk discount. The bulk discount is applied if the number of products purchased meets or exceeds a given threshold. The function should handle cases where the bulk discount is not ... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_total_cost(no_of_products: int, unit_cost: float, bulk_threshold: int = None, discount_rate: float = None) -> float:
"""
Calculate the total cost of purchasing a specified number of products, considering the unit c... |
magic_evol_110k | 103,888 | Write a Python function to rearrange the words in a given sentence into alphabetical order, considering edge cases where the words include numbers or special characters. The function should handle any given sentence and return the new sentence with words in alphabetical order.
The code should start with:
```python
def... | Here is the Python code to solve the given problem in the markdown block:
```python
def alphabetize_sentence(sentence: str) -> str:
"""
Rearranges the words in a given sentence into alphabetical order.
Args:
sentence (str): The input sentence to be alphabetized.
Returns:
str: The sente... |
magic_evol_110k | 103,890 | Write a Python function to find the smallest number in a given list of integers without using Python's built-in `min()` function. The function should handle both positive and negative integers. The code should start with:
```python
from typing import List
def find_smallest_number(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_smallest_number(numbers: List[int]) -> int:
"""
Find the smallest number in a given list of integers without using Python's built-in min() function.
Args:
numbers (List[int]): A lis... |
magic_evol_110k | 103,896 | Write a Python function to check if two given strings are isomorphic. Two strings are isomorphic if there is a one-to-one mapping (bijection) between characters of the first string and characters of the second string. The function should handle edge cases, including empty strings.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_isomorphic(s: str, t: str) -> bool:
"""
Check if two strings are isomorphic. Two strings are isomorphic if there is a one-to-one mapping
between characters of the first string and characters of the second string.
... |
magic_evol_110k | 103,908 | Write a Python function to find the element at a specific position in a given row of Pascal's Triangle. Pascal's Triangle is a triangular array of binomial coefficients. The element at position `k` in row `n` (both `n` and `k` are zero-indexed) is given by the binomial coefficient `C(n, k)`, which can be calculated usi... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def pascal_triangle_element(row: int, position: int) -> int:
"""
Calculate the element at a specific position in a given row of Pascal's Triangle.
Args:
row (int): The row number in Pascal's Triangle (0... |
magic_evol_110k | 103,918 | Write a Python function to expand the final component within a given numerical sequence by augmenting its value by a specified increment. The function should handle sequences of integers and ensure that the increment is applied only to the last element. The code should start with:
```python
from typing import List
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def expand_final_component(sequence: List[int], increment: int) -> List[int]:
"""
Expands the final component within a given numerical sequence by augmenting its value by a specified increment.
Args... |
magic_evol_110k | 103,928 | Write a Python function to create a dictionary from a given list of strings, where each unique string (case-insensitive) maps to its length. Duplicate strings should be ignored, and the dictionary should only contain unique strings.
The code should start with:
```python
from typing import List, Dict
def create_length... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_length_dict(strings: List[str]) -> Dict[str, int]:
"""
Creates a dictionary from a list of strings where each unique string (case-insensitive) maps to its length.
Args:
stri... |
magic_evol_110k | 103,929 | Write a Python function to join a list of text strings using a specified distinct character as a delimiter. The function should handle cases where the list is empty or contains only one string. The code should start with:
```python
from typing import List
def join_strings_with_delimiter(list_of_strings: List[str], del... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def join_strings_with_delimiter(list_of_strings: List[str], delimiter: str) -> str:
"""
Joins a list of text strings using the specified delimiter.
Args:
list_of_strings (List[str]): A list ... |
magic_evol_110k | 103,951 | Write a Python function to perform a binary search on a sorted array to find the index of a given element. If the element is not found, return -1. The function should be efficient and handle edge cases such as an empty array or an element not present in the array.
The code should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(arr: List[int], x: int) -> int:
"""
Perform a binary search on a sorted array to find the index of a given element.
Args:
arr (List[int]): A sorted list of integers.
... |
magic_evol_110k | 103,953 | Write a Python function to compute the absolute differences between each unique pair of elements from two given numerical arrays `a` and `b`. The function should return a new numerical array `c` that contains all the computed absolute differences. The function should handle arrays of different lengths efficiently.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def compute_absolute_differences(a: List[int], b: List[int]) -> List[int]:
"""
Computes the absolute differences between each unique pair of elements from two given numerical arrays `a` and `b`.
Arg... |
magic_evol_110k | 103,954 | Write a Python function to sort a list of movies by their release year in reverse chronological order. Each movie is represented as a tuple where the first element is the movie title and the second element is the release year. The function should return a list of tuples sorted by the release year in descending order.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_movies_by_year(movies: List[Tuple[str, int]]) -> List[Tuple[str, int]]:
"""
Sorts a list of movies by their release year in reverse chronological order.
Args:
movies (List[Tu... |
magic_evol_110k | 103,956 | Write a Python function to construct two dictionaries: one that maps the occurrence counts of each element in list `x`, and another that maps the occurrence counts of the intersection of elements from list `x` in list `y`. The function should efficiently achieve this with a time complexity not exceeding O(n). The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_occurrences(x: List[int], y: List[int]) -> (Dict[int, int], Dict[int, int]):
"""
Constructs two dictionaries:
1. dict_x: Maps the occurrence counts of each element in list x.
2. d... |
magic_evol_110k | 103,960 | Write a Python function to simulate the MongoDB query described in the given code snippet. The function should filter documents where the state is 'CA', sort them in reverse chronological order based on a 'created_at' timestamp field, and return only the 'name', 'address', and 'details' fields. If any of these fields a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def filter_and_sort_documents(documents: List[Dict]) -> List[Dict]:
"""
Filters and sorts documents based on the given criteria.
Args:
documents (List[Dict]): A list of dictionaries re... |
magic_evol_110k | 103,973 | Write a Python function to implement a linear search algorithm and find the index of a given element in a given array. If the element is not found, return -1. The function should be efficient and handle various edge cases, such as an empty array or the target element being larger or smaller than any element in the arra... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def linear_search(arr: List[int], target: int) -> int:
"""
Implements a linear search algorithm to find the index of a given element in an array.
Args:
arr (List[int]): The array in which to... |
magic_evol_110k | 103,977 | Write a Python function to dynamically route HTTP requests to Firebase functions based on a custom domain and a wildcard path. The function should take a base URL and a list of function paths, and return a dictionary mapping each path to its corresponding Firebase function. The function should be able to handle any num... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def dynamic_firebase_routing(base_url: str, function_paths: List[str]) -> Dict[str, str]:
"""
Dynamically routes HTTP requests to Firebase functions based on a custom domain and a list of function ... |
magic_evol_110k | 103,992 | 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
def longest_common_subsequence(str1: str, str2: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
"""
Calculate the length of the longest common subsequence (LCS) of two given strings.
Args:
str1 (str): The first string.
str2 (str): The second ... |
magic_evol_110k | 104,001 | Write a Python function to sort a list of dictionaries by a specified numerical property. The function should take a list of dictionaries and a string representing the key of the numerical property to sort by. The function should return the sorted list of dictionaries.
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 List, Dict
def sort_by_property(data: List[Dict[str, any]], property_key: str) -> List[Dict[str, any]]:
"""
Sorts a list of dictionaries by a specified numerical property.
Args:
data (List[Dict[s... |
magic_evol_110k | 104,025 | Write a Python function to sort an array of integers in ascending order. The function should handle arrays with lengths between 1 and 50,000 and integers within the range of -50,000 to 50,000. The function should be efficient and should not use Python's built-in `sort` or `sorted` functions. Instead, implement a sortin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_array(nums: List[int]) -> List[int]:
"""
Sorts an array of integers in ascending order using the MergeSort algorithm.
Args:
nums (List[int]): The array of integers to be sorted.
... |
magic_evol_110k | 104,026 | Write a Python function to replace special values (empty strings, `None`, and `NaN`) with `0` in a given list. The function should return a new list with the special values replaced. The function should handle the following special values:
- Empty strings (`''`)
- `None`
- `NaN` (Not a Number)
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def replace_special_values(lst: List[float]) -> List[float]:
"""
Replaces special values (empty strings, None, and NaN) with 0 in the given list.
Args:
lst (List[float]): The lis... |
magic_evol_110k | 104,054 | Write a Python function to process a given array by adding a specified increment to each value and then filtering out any values that are even after the addition. The function should return the modified array.
The code should start with:
```python
from typing import List
def process_and_filter_array(arr: List[int], i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def process_and_filter_array(arr: List[int], increment: int) -> List[int]:
"""
Process the given array by adding the specified increment to each value and then filter out any values that are even after t... |
magic_evol_110k | 104,055 | Write a Python generator function that yields the first ten numbers that are quintic (fifth power) by nature. A quintic number is defined as a number that can be expressed as \( n^5 \) for some integer \( n \). The generator should yield these numbers in ascending order.
The code should start with:
```python
def gener... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_quintics():
"""
A generator function that yields the first ten numbers that are quintic (fifth power) by nature.
Yields:
int: The next quintic number in ascending order.
"""
count = 0 # Counter... |
magic_evol_110k | 104,068 | Write a Python function to perform a modified binary search on a given array that is not sorted and contains elements at staggered intervals. The function should return the positions of all occurrences of a specified target element within the array.
The code should start with:
```python
from typing import List
def mo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def modified_binary_search(array: List[int], target: int) -> List[int]:
"""
Perform a modified binary search to find all occurrences of a target element in an unsorted array with staggered intervals.
... |
magic_evol_110k | 104,076 | Write a Python function to determine the specific day of the week for a given date and calculate the number of days until the next occurrence of the same weekday. The date is provided as three separate integers representing the `day`, `month`, and `year`. The function should return a tuple where the first element is th... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def get_weekday_and_next_occurrence(day: int, month: int, year: int) -> tuple:
"""
Determine the weekday for a given date and calculate the number of days until the next occurrence of the same weekday.
Args... |
magic_evol_110k | 104,079 | Write a Python function to calculate the Euclidean distance between two points in a 2D space. The function should take two lists as input, each representing the coordinates of a point in the format `[x, y]`. The function should return the Euclidean distance between these two points.
The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def euclidean_distance(point1: List[float], point2: List[float]) -> float:
"""
Calculate the Euclidean distance between two points in a 2D space.
Args:
point1 (List[float]): The ... |
magic_evol_110k | 104,087 | Write a Python function to calculate the difference between two numbers, ensuring that the result is always non-negative. The function should handle both integer and floating-point numbers. The code should start with:
```python
def non_negative_difference(x: float, y: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def non_negative_difference(x: float, y: float) -> float:
"""
Calculate the non-negative difference between two numbers.
Args:
x (float): The first number.
y (float): The second number.
Returns:
... |
magic_evol_110k | 104,089 | Write a Python function to calculate the final price of an item after applying discounts based on the given conditions. The function should handle both compounded and non-compounded discounts and validate the input data. Additionally, create a checkout function that calculates the total price for a list of items, consi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional, Union
def calculate_final_price(original_price: float, compound_discount: bool) -> float:
"""
Calculate the final price of an item after applying discounts.
Args:
original_price (... |
magic_evol_110k | 104,095 | Write a Python function that processes a list of tuples, where each tuple contains a list of numbers and an operator. The function should calculate the greatest difference between any two numbers in the list and then apply the specified operation to this difference. The result of the operation should be appended to a n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def process_tuples(list_tuples: List[Tuple[List[int], str]]) -> List[int]:
"""
Processes a list of tuples, where each tuple contains a list of numbers and an operator.
The function calculates ... |
magic_evol_110k | 104,108 | Write a Python function to perform subtraction between two unique numerical integers and return the resultant difference value. Additionally, ensure that the function handles cases where the result is negative by returning the absolute value of the difference.
The code should start with:
```python
def subtract_and_abs... | Here is the Python code to solve the given problem in the markdown block:
```python
def subtract_and_abs(num1: int, num2: int) -> int:
"""
Perform subtraction between two unique numerical integers and return the absolute value of the resultant difference.
Args:
num1 (int): The first integer.
... |
magic_evol_110k | 104,109 | Write a Python function to remove duplicates from a given list and return the new list while preserving the order of the first occurrence of each element. The function should be efficient and handle various edge cases, such as an empty list or a list with all elements being the same.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_preserve_order(arr: List[int]) -> List[int]:
"""
Removes duplicates from the given list while preserving the order of the first occurrence of each element.
Args:
arr (L... |
magic_evol_110k | 104,110 | Write a Python function to construct a hashtable (dictionary) where the keys are the elements from two given arrays, `arrayA` and `arrayB`, and the values hold the aggregate of occurrences from both arrays. The function should start with:
```python
from typing import List, Dict
def aggregate_occurrences(arrayA: List[i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def aggregate_occurrences(arrayA: List[int], arrayB: List[int]) -> Dict[int, int]:
"""
Constructs a hashtable where the keys are the elements from two given arrays,
and the values hold the aggr... |
magic_evol_110k | 104,129 | Write a Python function to perform the same tasks as the given bash shell script. The function should accept two integers as input parameters, validate them, and return their sum. If the input parameters are not valid integers or if the number of parameters is not exactly two, the function should raise a `ValueError` w... | Here is the Python code to solve the given problem in the markdown block:
```python
def add_two_integers(a: int, b: int) -> int:
"""
Adds two integers after validating their types and count.
Args:
a (int): The first integer to be added.
b (int): The second integer to be added.
Returns:... |
magic_evol_110k | 104,133 | Write a Python function to recursively identify and return the prime factors of a given positive integer using dynamic programming principles. The function should store intermediate results to avoid redundant calculations and improve efficiency. The code should start with:
```python
from typing import List
def recursi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def recursive_prime_factors(n: int, memo: dict = None) -> List[int]:
"""
Recursively identifies and returns the prime factors of a given positive integer using dynamic programming.
Args:
n (... |
magic_evol_110k | 104,135 | Write a Python function to count the number of unique elements in a given list. Additionally, provide a piece of erroneous code that demonstrates a common mistake in achieving this task. Explain why the erroneous code does not work.
The code should start with:
```python
from typing import List
def count_unique_elemen... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_unique_elements(lst: List[int]) -> int:
"""
Counts the number of unique elements in a given list.
Args:
lst (List[int]): The list of integers from which to count unique elements.
... |
magic_evol_110k | 104,167 | Write a Python function to calculate the total number of words used in each article of an encyclopedia. The encyclopedia is represented as a dictionary where each key is the title of an article and the value is a list of words in that article. The function should return a dictionary where the keys are the article title... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def count_words_in_articles(encyclopedia: Dict[str, List[str]]) -> Dict[str, int]:
"""
Calculate the total number of words used in each article of an encyclopedia.
Args:
encyclopedia (... |
magic_evol_110k | 104,178 | Write a Python function to remove duplicates from a given list and return a new sorted list in descending order. The function should handle lists containing both integers and strings. The code should start with:
```python
from typing import List, Union
def remove_duplicates_and_sort(my_list: List[Union[int, str]]) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def remove_duplicates_and_sort(my_list: List[Union[int, str]]) -> List[Union[int, str]]:
"""
Remove duplicates from the given list and return a new sorted list in descending order.
The functio... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.