source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_evol_110k
107,753
Write a Python function to concatenate multiple text segments into a single string with a specified delimiter. The function should handle an arbitrary number of text segments and allow the user to specify the delimiter. The code should start with: ```python from typing import List def concatenate_text_segments(text_se...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def concatenate_text_segments(text_segments: List[str], delimiter: str = " ") -> str: """ Concatenates multiple text segments into a single string with a specified delimiter. Args: text_segm...
magic_evol_110k
107,765
Write a Python function to print the numbers from 0 to n (inclusive) without using any loops, built-in iteration tools, or recursion methods. The function should use a functional programming approach to achieve this. The code should start with: ```python def print_numbers_up_to(n: int) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python def print_numbers_up_to(n: int) -> None: """ Prints numbers from 0 to n (inclusive) without using loops, built-in iteration tools, or recursion. Args: n (int): The upper limit of the range of numbers to print. ...
magic_evol_110k
107,766
Write a Python function to verify if an array has any mirrored pairs. A mirrored pair is defined as a pair of elements that appear in the array such that the first element of the pair appears before the second element, and the second element appears after the first element. For example, in the array `[1, 2, 3, 3, 2, 1]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def has_mirrored_pairs(arr: List[int]) -> bool: """ Verifies if an array has any mirrored pairs. A mirrored pair is defined as a pair of elements that appear in the array such that the first ele...
magic_evol_110k
107,768
Write a Python function to count the number of distinct alphanumeric characters in a given text string, ignoring case and spaces. The function should return the count of unique alphanumeric characters. The code should start with: ```python def count_distinct_alphanumeric_chars(text_string: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_distinct_alphanumeric_chars(text_string: str) -> int: """ Counts the number of distinct alphanumeric characters in a given text string, ignoring case and spaces. Args: text_string (str): The input text str...
magic_evol_110k
107,783
Write a Python function to calculate the maximum sum of a subarray of a given array using the Kadane's Algorithm. The function should return the maximum sum of the subarray. The code should start with: ```python from typing import List def max_subarray_sum(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def max_subarray_sum(arr: List[int]) -> int: """ Calculate the maximum sum of a subarray using Kadane's Algorithm. Args: arr (List[int]): The input array of integers. Returns: ...
magic_evol_110k
107,788
Write a Python function to compute the cumulative sum of integers ranging from 1 to a given positive integer `n` (including both extremes). The function should ensure that the solution requires multiple steps to address, such as initializing a variable to hold the cumulative sum, iterating over the range, and updating ...
Here is the Python code to solve the given problem in the markdown block: ```python def cumulative_sum(n: int) -> int: """ Compute the cumulative sum of integers ranging from 1 to n (inclusive). Args: n (int): The upper limit of the range (inclusive). Returns: int: The cumulative sum o...
magic_evol_110k
107,792
Write a Python function to count the occurrences of a specific number in a given list of integers. The function should take two parameters: the first parameter is the list of integers, and the second parameter is the number to count. The function should return the count of the specified number in the list. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_occurrences(numbers: List[int], target: int) -> int: """ Counts the occurrences of a specific number in a given list of integers. Args: numbers (List[int]): The list of integers in...
magic_evol_110k
107,802
Write a Python function to check if a given string contains a semi-colon symbol (`;`) and does not contain any type of brackets (`()`, `[]`, `{}`). The string can be of any length (up to a maximum length of 500) and can contain different symbols, characters, and spaces. The function should also be capable of identifyin...
Here is the Python code to solve the given problem in the markdown block: ```python import re def contains_semicolon_without_brackets(s: str) -> bool: """ Check if the given string contains a semi-colon symbol and does not contain any type of brackets. Args: s (str): The string to be checked. ...
magic_evol_110k
107,808
Write a Python function to filter even numbers from a given list, square them, and return the length of the updated list. The function should start with: ```python from typing import List def even_square_length(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def even_square_length(arr: List[int]) -> int: """ Filters even numbers from the given list, squares them, and returns the length of the updated list. Args: arr (List[int]): The list of inte...
magic_evol_110k
107,815
Write a Python function to reverse the order of characters in a given string. The function should handle strings of varying lengths, including empty strings. The code should start with: ```python def reverse_string(input_string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(input_string: str) -> str: """ Reverses the order of characters in the given string. Args: input_string (str): The string to be reversed. Returns: str: The reversed string. """ ...
magic_evol_110k
107,819
Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should start with: ```python from typing import List def unique_paths(m: int, n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def unique_paths(m: int, n: int) -> int: """ Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid. Args: m (int): The number of row...
magic_evol_110k
107,820
Write a Python function to find the position of the first occurrence of a specified integer in a given list of numbers. The position should be 1-based, meaning the first element of the list is considered to be at position 1. If the specified integer is not found in the list, the function should return -1. The code sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_first_occurrence(numbers: List[int], target: int) -> int: """ Find the 1-based position of the first occurrence of a specified integer in a list. Args: numbers (List[int]): The list...
magic_evol_110k
107,828
Write a Python function to calculate the width of a row of houses given the total area (in square meters) and the total length (in meters) of the row. The houses are arranged in such a way that they form a rectangle when combined, where the length is the distance along the row of houses and the width is the distance fr...
Here is the Python code to solve the given problem in the markdown block: ```python def find_width(total_area: float, total_length: float) -> float: """ Calculate the width of a row of houses given the total area and total length. Args: total_area (float): The total area covered by the houses in sq...
magic_evol_110k
107,837
Write a Python function to switch the cases of every character in a given string. The function should handle both uppercase and lowercase letters, and any non-alphabetic characters should remain unchanged. The function should start with: ```python def switch_cases(text: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def switch_cases(text: str) -> str: """ Switches the case of every character in the given string. Args: text (str): The input string whose characters' cases need to be switched. Returns: str: A new stri...
magic_evol_110k
107,842
Write a Python function to count the number of prime digits in a given hexadecimal string. The function should recursively determine the count of prime digits in the input string. The prime digits in hexadecimal are '2', '3', '5', '7', 'B', and 'D'. The input string will always be reliable and may be an empty string. T...
Here is the Python code to solve the given problem in the markdown block: ```python def hexKey(hexadecimal_string: str) -> int: """ Recursively count the number of prime digits in a given hexadecimal string. Args: hexadecimal_string (str): The input hexadecimal string. Returns: int: Th...
magic_evol_110k
107,844
Write a Python function to find the peak index in a mountain array using an efficient `O(log(n))` solution. The function should return the index `i` such that the array elements before `i` are strictly increasing and the elements after `i` are strictly decreasing. The function should start with: ```python from typing i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def peak_index_in_mountain_array(arr: List[int]) -> int: """ Find the peak index in a mountain array using a binary search approach. Args: arr (List[int]): A list of integers that is guarant...
magic_evol_110k
107,855
Write a Python function that applies a lambda function to each element in a list, where the lambda function squares the number and then doubles the result. The function should handle cases where the input list is empty or contains non-numeric elements. The solution should have linear time complexity. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def transform_list(input_list: List[int]) -> List[int]: """ Transforms each element in the input list by squaring the number and then doubling the result. Args: input_list (List[int]): The l...
magic_evol_110k
107,858
Write a Python function to factorize a given integer `n` into its prime factors and return both the list of prime factors and a dictionary with the count of each prime factor. The function should be efficient and handle large integers. The code should start with: ```python from typing import Dict, List, Tuple from col...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple from collections import Counter def factorize(n: int) -> Tuple[List[int], Dict[int, int]]: """ Factorizes the given integer `n` into its prime factors and returns a tuple containing: 1. ...
magic_evol_110k
107,877
Write a Python function to flatten a three-dimensional matrix into a one-dimensional list of its elements. The function should efficiently navigate through the matrix and return the elements in a single list, maintaining the order of elements as they appear in the matrix. 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 def flatten_3d_matrix(matrix: List[List[List[int]]]) -> List[int]: """ Flattens a three-dimensional matrix into a one-dimensional list of its elements. Args: matrix (List[List[List[int]]]): ...
magic_evol_110k
107,883
Write a Python function to validate if a given string is a valid voucher code. A valid voucher code consists of four groups of four alphabetic characters each, separated by hyphens. The format should be exactly "XXXX-XXXX-XXXX-XXXX", where 'X' is an uppercase or lowercase alphabetic character. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_voucher(voucher_code: str) -> bool: """ Validates if the given string is a valid voucher code. A valid voucher code consists of four groups of four alphabetic characters each, separated by hyphen...
magic_evol_110k
107,892
Write a Python function to sort a dictionary by its keys in ascending order. The function should return a new dictionary with the same key-value pairs as the original, but with the keys sorted. The code should start with: ```python from typing import Dict def sort_dictionary_by_keys(d: Dict[str, str]) -> Dict[str, str...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dictionary_by_keys(d: Dict[str, str]) -> Dict[str, str]: """ Sorts a dictionary by its keys in ascending order and returns a new dictionary. Args: d (Dict[str, str]): The dictionary...
magic_evol_110k
107,896
Write a Python function to build an array using stack operations based on a given target array and an integer `n`. The function should return a list of operations (`"Push"` or `"Pop"`) required to build the target array and the minimum number of operations required. The code should start with: ```python from typing im...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def build_array_with_stack_operations(target: List[int], n: int) -> Tuple[List[str], int]: """ Build an array using stack operations based on the given target array and integer n. Args: ...
magic_evol_110k
107,898
Write a Python function to efficiently identify and retrieve all occurrences of a specific target element within a nested array that contains both numerical and string elements. The function should be able to handle any level of nesting within the array. The code should start with: ```python from typing import List, Un...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_elements_in_nested_array(nested_array: List[Union[int, str, List]], target: Union[int, str]) -> List[Union[int, str]]: """ Find all occurrences of a specific target element within a neste...
magic_evol_110k
107,915
Write a Python function to calculate the product of two integers `x` and `y` without using the multiplication operator. The function should handle negative numbers and have a time complexity that does not exceed O(N), where N is the magnitude of the second input `y`. The function should start with: ```python def multip...
Here is the Python code to solve the given problem in the markdown block: ```python def multiply_without_operator(x: int, y: int) -> int: """ Calculate the product of two integers x and y without using the multiplication operator. Handles negative numbers and has a time complexity of O(N), where N is the ma...
magic_evol_110k
107,919
Write a Python function to convert between heat measurement units, specifically British Thermal Units (BTUs) to Joules and vice versa. The function should be able to handle both conversions and should be flexible enough to accept either BTUs or Joules as input and return the corresponding value in the other unit. The ...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_heat_units(value: float, from_unit: str) -> float: """ Converts between British Thermal Units (BTUs) and Joules. Args: value (float): The value to be converted. from_unit (str): The unit of the i...
magic_evol_110k
107,929
Write a Python function to find the position of the first occurrence of a given subsequence within a specified text string. The function should be case-insensitive and should return the position of the first character of the subsequence. If the subsequence is not found, the function should return -1. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python def find_subsequence_position(text: str, subsequence: str) -> int: """ Find the position of the first occurrence of a given subsequence within a text string. The search is case-insensitive. Args: text (str): The...
magic_evol_110k
107,946
Write a Python function to count the number of vowel letters 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(text: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_vowels(text: str) -> int: """ Count the number of vowel letters in a given string. Args: text (str): The input string to count vowels from. Returns: int: The number of vowel letters in the inp...
magic_evol_110k
107,949
Write a Python function to generate and return a list of strings representing a right-angled triangle pattern using a specified character and height. The function should start with: ```python from typing import List def generate_triangle_pattern(character: str, height: int) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_triangle_pattern(character: str, height: int) -> List[str]: """ Generates a list of strings representing a right-angled triangle pattern using the specified character and height. Args: ...
magic_evol_110k
107,963
Write a Python function to find the intersection of two sets of integers. The function should take two sets as input and return a new set containing the elements that are present in both sets. The code should start with: ```python from typing import Set def find_intersection(set1: Set[int], set2: Set[int]) -> Set[int]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set def find_intersection(set1: Set[int], set2: Set[int]) -> Set[int]: """ Find the intersection of two sets of integers. Args: set1 (Set[int]): The first set of integers. set2 (Set[int])...
magic_evol_110k
107,998
Write a Python function to calculate the average of a given list of integers and find the number that is closest to this average. The list can contain up to 10,000 numbers ranging from -10,000 to 10,000. The average should be returned as a floating-point number. If the list is empty, the function should return 0 for th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Optional def calculate_average_and_closest(lst: List[int]) -> Tuple[float, Optional[int]]: """ Calculate the average of a list of integers and find the number closest to this average. Args: ...
magic_evol_110k
108,019
Write a Python function to calculate the expected number of rounds before the game concludes for a given number of participants in a probability-based contest. The game involves a pair of dice and a group of participants seated in a circular arrangement. Two diametrically opposite participants start with a single die e...
Here is the Python code to solve the given problem in the markdown block: ```python def expected_rounds(n: int) -> float: """ Calculate the expected number of rounds before the game concludes for a given number of participants. The game involves a pair of dice and a group of participants seated in a circul...
magic_evol_110k
108,040
Write a Python function to loop through a given list and print each item on a new line. The function should accept a list of strings as input and print each string element on a separate line. The code should start with: ```python from typing import List def print_list_items(items: List[str]) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_list_items(items: List[str]) -> None: """ Prints each item in the given list on a new line. Args: items (List[str]): A list of strings to be printed. Returns: None: Th...
magic_evol_110k
108,044
Write a Python function to split a given string into a list of characters, including spaces, without ignoring them. The function should return a list where each character, including spaces, is an individual element. The code should start with: ```python from typing import List def split_string_with_spaces(s: str) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def split_string_with_spaces(s: str) -> List[str]: """ Splits a given string into a list of characters, including spaces. Args: s (str): The input string to be split. Returns: L...
magic_evol_110k
108,051
Write a Python function to normalize the spacing in a given string by converting all instances of multiple consecutive spaces into a single space. The function should handle strings with varying numbers of consecutive spaces and should not use regular expressions. The code should start with: ```python def normalize_spa...
Here is the Python code to solve the given problem in the markdown block: ```python def normalize_spacing(text: str) -> str: """ Normalizes the spacing in a given string by converting all instances of multiple consecutive spaces into a single space. Args: text (str): The input string with potential...
magic_evol_110k
108,064
Write a Python function to generate a list of all prime numbers up to a given number `n` using the Sieve of Eratosthenes algorithm. The function should return a list of prime numbers. The code should start with: ```python from typing import List def generate_primes(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_primes(n: int) -> List[int]: """ Generate a list of all prime numbers up to a given number n using the Sieve of Eratosthenes algorithm. Args: n (int): The upper limit for genera...
magic_evol_110k
108,067
Write a Python function that implements a nested for-loop with integrated break and continue statements based on specific conditions. The function should handle exceptions using try and except blocks. The conditions for break and continue should involve complex logical operators. The function should also print the resu...
Here is the Python code to solve the given problem in the markdown block: ```python def nested_loop_with_conditions(): """ Implements a nested for-loop with integrated break and continue statements based on specific conditions. Handles exceptions using try and except blocks. The function performs the f...
magic_evol_110k
108,080
Write a Python function to scan through a multi-dimensional array and output every alternate element from each sub-array. The function should handle any size of multi-dimensional array and ensure that the output is correct and efficient. The code should start with: ```python from typing import List def print_alternat...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_alternate_elements(multi_array: List[List[int]]) -> None: """ Prints every alternate element from each sub-array in a multi-dimensional array. Args: multi_array (List[List[int]]): ...
magic_evol_110k
108,083
Write a Python function to sort a list of numbers using the Insertion Sort algorithm. The function should take a list of integers as input and return the sorted list. The code should start with: ```python from typing import List def insertion_sort(numbers: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def insertion_sort(numbers: List[int]) -> List[int]: """ Sorts a list of integers using the Insertion Sort algorithm. Args: numbers (List[int]): The list of integers to be sorted. Retur...
magic_evol_110k
108,095
Write a Python function to evaluate a given logical expression and print the result based on the evaluation. The function should take five variables `a`, `b`, `c`, `d`, and `e` as inputs and evaluate the expression `((a > b) or (b < c)) and str((b ** a * d/c) > e)`. If the expression evaluates to `True`, the function s...
Here is the Python code to solve the given problem in the markdown block: ```python def evaluate_expression(a: int, b: int, c: int, d: int, e: str) -> None: """ Evaluates a given logical expression and prints the result based on the evaluation. The expression to evaluate is: ((a > b) or (b < c)) and str((b...
magic_evol_110k
108,114
Write a Python function that takes an array of integers and a single integer as input. The function should add the single integer to each element in the array and return the updated array. The function should handle edge cases such as an empty array or a single-element array. The code should start with: ```python from ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def add_numeral_to_array(arr: List[int], num: int) -> List[int]: """ Adds a given integer to each element in the provided array and returns the updated array. Args: arr (List[int]): The arra...
magic_evol_110k
108,128
Write a Python function to divide a given sequence of characters into equal segments by slicing it at every fourth character. The function should return a list of these segments. The code should start with: ```python from typing import List def divide_into_segments(sequence: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def divide_into_segments(sequence: str) -> List[str]: """ Divides a given sequence of characters into equal segments by slicing it at every fourth character. Args: sequence (str): The input ...
magic_evol_110k
108,135
Write a Python function to generate the first `n` terms of the Fibonacci sequence. The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. The function should handle edge cases such as `n` being 0 or 1. The code should start with: ```python f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: """ Generate the first n terms of the Fibonacci sequence. The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding...
magic_evol_110k
108,157
Write a Python function to merge two strings together without using any built-in functions. The function should concatenate the characters from the first string followed by the characters from the second string. The code should start with: ```python def merge_strings(str1: str, str2: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def merge_strings(str1: str, str2: str) -> str: """ Merges two strings together by concatenating the characters from the first string followed by the characters from the second string. Args: str1 (str): The first st...
magic_evol_110k
108,159
Write a Python function to format a person's name according to a specific pattern. The function should take three parameters: the first name, the middle name, and the last name. The formatted name should be returned in the following order: the middle name followed by a single space, the first initial of the first name ...
Here is the Python code to solve the given problem in the markdown block: ```python def format_name(first_name: str, middle_name: str, last_name: str) -> str: """ Formats the given first name, middle name, and last name into a specific pattern. The formatted name is structured as follows: - The middle ...
magic_evol_110k
108,172
Write a Python function to sort a list of strings in alphabetical order, considering both case-sensitive and case-insensitive sorting. The function should allow the user to choose between case-sensitive and case-insensitive sorting. The code should start with: ```python from typing import List def sort_strings(lst: Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_strings(lst: List[str], case_sensitive: bool = True) -> List[str]: """ Sorts a list of strings in alphabetical order with an option for case-sensitive or case-insensitive sorting. Args: ...
magic_evol_110k
108,174
Write a Python function to find the maximum value in a given array without using any library functions. The function should iterate through the array and keep track of the maximum value encountered so far. The code should start with: ```python from typing import List def find_max_value(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_value(arr: List[int]) -> int: """ Find the maximum value in a given array without using any library functions. Args: arr (List[int]): The array of integers from which to find th...
magic_evol_110k
108,176
Write a Python function to identify all distinct alphabetical characters present in two given alphanumeric sequences. The function should be case-sensitive and ignore any non-alphabet characters. The function should return a set of unique alphabetical characters found in both sequences. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python def find_unique_alphabets(string1: str, string2: str) -> set: """ Identify all distinct alphabetical characters present in two given alphanumeric sequences. The function is case-sensitive and ignores any non-alphabet charact...
magic_evol_110k
108,178
Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should start with: ```python from typing import List def unique_paths(m: int, n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def unique_paths(m: int, n: int) -> int: """ Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid. Args: m (int): The number of row...
magic_evol_110k
108,182
Write a Python function to remove the last `n` elements from a given list. The function should handle invalid inputs and edge cases by raising appropriate exceptions. Specifically, the function should: 1. Raise a `ValueError` if the first argument is not a list. 2. Raise a `ValueError` if the second argument `n` is not...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_last_n_elements(lst, n): """ Remove the last n elements from a given list. Args: lst (list): The list from which to remove elements. n (int): The number of elements to remove from the end of the l...
magic_evol_110k
108,198
Write a Python function to generate an array containing all the integers from 0 up to and including a given integer `n` that are not divisible by 2. The function should also print a message each time an integer is added to the array. The code should start with: ```python from typing import List def generate_indivisibl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_indivisible_by_2_array(n: int) -> List[int]: """ Generates an array containing all integers from 0 up to and including `n` that are not divisible by 2. Also prints a message each time an...
magic_evol_110k
108,211
Write a Python function to convert a given tuple containing only integer data types into a nested dictionary format. The function should recursively convert each element of the tuple into a key in the dictionary, with the value being the dictionary created from the remaining elements of the tuple. The function should h...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Dict, Any def tuple_to_nested_dict(input_tuple: Tuple[int, ...]) -> Dict[int, Any]: """ Converts a tuple of integers into a nested dictionary format. Args: input_tuple (Tuple[int, ...]): A...
magic_evol_110k
108,228
Write a Python function to generate the nth term of the Fibonacci series using an iterative approach for optimal performance. The function should efficiently compute the Fibonacci number by avoiding the inefficiencies of recursion and ensuring that the algorithm runs in linear time and constant space. The code should ...
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci(n: int) -> int: """ Generate the nth term of the Fibonacci series using an iterative approach. Args: n (int): The position in the Fibonacci series to generate. Returns: int: The nth term o...
magic_evol_110k
108,247
Write a Python function to perform a ternary search on a sorted array to find the index of a given target element. The ternary search divides the array into three parts and recursively narrows down the search space based on comparisons with the target element. The function should return the index of the target element ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def ternary_search(arr: List[int], l: int, r: int, x: int) -> int: """ Perform a ternary search on a sorted array to find the index of a given target element. Args: arr (List[int]): The sort...
magic_evol_110k
108,265
Write a Python function to identify the largest element in a multilayered, non-uniform hierarchical array and return both the largest element and its location hierarchy in the structure. The hierarchical array may contain nested lists and unoccupied spots should be filled with `None`. The function should start with: `...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Union def find_max_and_path(lst: Union[List, int]) -> Tuple[int, List[int]]: """ Identify the largest element in a multilayered, non-uniform hierarchical array and return both the largest element...
magic_evol_110k
108,266
Write a Python function to sort a dictionary by its values in ascending order. The function should take a dictionary with string keys and integer values as input and return a new dictionary with the same keys and values, but sorted by the values. The code should start with: ```python from typing import Dict def sort_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_values(my_dict: Dict[str, int]) -> Dict[str, int]: """ Sorts a dictionary by its values in ascending order. Args: my_dict (Dict[str, int]): The dictionary to be sorted. Keys...
magic_evol_110k
108,286
Write a Python function to calculate the number of palindromic substrings in a given string. A palindromic substring is a contiguous sequence of characters within the string that reads the same forward and backward. The function should efficiently count all such substrings. The code should start with: ```python def co...
Here is the Python code to solve the given problem in the markdown block: ```python def count_palindromic_substrings(s: str) -> int: """ Calculate the number of palindromic substrings in a given string. Args: s (str): The input string. Returns: int: The number of palindromic substrings...
magic_evol_110k
108,292
Write a Python function to create a new array by multiplying each element of a given array by a given number. The function should handle any length of the input array and any integer number. The code should start with: ```python from typing import List def create_new_array(arr: List[int], num: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def create_new_array(arr: List[int], num: int) -> List[int]: """ Creates a new array by multiplying each element of the given array by the given number. Args: arr (List[int]): The input arra...
magic_evol_110k
108,310
Write a Python function to convert a given string into a list of Unicode code points. The function should handle any Unicode character that might be in the string. The code should start with: ```python from typing import List def convert_to_unicode(string: str) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_to_unicode(string: str) -> List[int]: """ Converts a given string into a list of Unicode code points. Args: string (str): The input string to be converted. Returns: ...
magic_evol_110k
108,316
Write a Python function to calculate the accumulated total of elements in a two-dimensional numerical array, treating negative elements as zero. The function should start with: ```python from typing import List def accumulated_total(array: List[List[int]]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def accumulated_total(array: List[List[int]]) -> int: """ Calculate the accumulated total of elements in a two-dimensional numerical array, treating negative elements as zero. Args: array (L...
magic_evol_110k
108,319
Write a Python function that accepts two lists and returns a dictionary where the keys are elements from the second list, and the values are lists of indices from the first list where the corresponding key appears. Each element from the second list can appear multiple times in the first list, and the function needs to ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def map_elements_to_indices(first_list: List[int], second_list: List[int]) -> Dict[int, List[int]]: """ Maps elements from the second list to their indices in the first list. Args: fir...
magic_evol_110k
108,325
Write a Python function to track and sort words in a given text string. The function should return a list of words sorted in alphabetical order, with each word appearing only once. The function should handle various edge cases, such as empty strings, strings with only whitespace, and strings with punctuation. The code...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import string def sort_words_in_text(text: str) -> List[str]: """ Track and sort words in a given text string, returning a list of unique words sorted alphabetically. Args: text (str): The i...
magic_evol_110k
108,326
Write a Python function to determine if the multiplication of any two distinct integers in a given list results in an even number. The function should be optimized for performance and should handle lists of varying sizes efficiently. The code should start with: ```python from typing import List def has_even_product(n...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def has_even_product(numbers: List[int]) -> bool: """ Determines if the multiplication of any two distinct integers in the given list results in an even number. Args: numbers (List[int]): A ...
magic_evol_110k
108,331
Write a Python function to calculate the standard deviation of a given numerical collection using the `numpy` library. The function should accept a list of numbers as input and return the standard deviation as a float. The code should start with: ```python from typing import List import numpy as np def calculate_stand...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import numpy as np def calculate_standard_deviation(numbers: List[float]) -> float: """ Calculate the standard deviation of a given numerical collection. Args: numbers (List[float]): A list ...
magic_evol_110k
108,335
Create a Python function that takes a product catalog dictionary as input and returns a list of products that are in stock. Each product in the catalog is represented as a dictionary with at least five associated attributes, including nested dictionaries or lists. The function should filter out products that are marked...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def filter_in_stock_products(product_catalog: Dict[str, Dict[str, any]]) -> List[Dict[str, any]]: """ Filters and returns a list of products that are in stock from the given product catalog. A...
magic_evol_110k
108,337
Write a Python function to implement the bubble sort algorithm to sort an array of floating point numbers in ascending order. The function should take a list of floating point numbers as input and return the sorted list. The code should start with: ```python from typing import List def bubble_sort(num_array: List[floa...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(num_array: List[float]) -> List[float]: """ Sorts an array of floating point numbers in ascending order using the bubble sort algorithm. Args: num_array (List[float]): The ar...
magic_evol_110k
108,342
Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an `m x n` grid. The only moves allowed are moving right or down. The function should start with: ```python def unique_paths(m: int, n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def unique_paths(m: int, n: int) -> int: """ Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid. Args: m (int): The number of rows in the grid. n (i...
magic_evol_110k
108,349
Write a Python function to find the sum of two numbers provided as arguments to the function. Additionally, validate the input to ensure they are whole numbers and return the sum. If the input is invalid, return `None`. The code should start with: ```python def sum_of_two_numbers(num1: str, num2: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python import re def sum_of_two_numbers(num1: str, num2: str) -> int: """ Calculate the sum of two whole numbers provided as strings. Args: num1 (str): The first number as a string. num2 (str): The second number a...
magic_evol_110k
108,358
Write a Python function to organize a numerical array and identify the median figure using different sorting methodologies like Bubble Sort, Insertion Sort, and Quick Sort. Additionally, create a function to measure the duration consumed by each sorting method. The code should start with: ```python from typing import ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import time def bubble_sort(arr: List[int]) -> List[int]: """ Sorts the array using the Bubble Sort algorithm. Args: arr (List[int]): The array to be sorted. Returns: Lis...
magic_evol_110k
108,363
Write a Python function to find the longest common subsequence (LCS) between two given strings. The function should return the length of the LCS. The code should start with: ```python def longest_common_subsequence(str1: str, str2: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def longest_common_subsequence(str1: str, str2: str) -> int: """ Calculate the length of the longest common subsequence (LCS) between two strings. Args: str1 (str): The first string. str2 (str): The second s...
magic_evol_110k
108,367
Write a Python function to search for multiple strings in a given 2D array of strings and return the coordinates (row and column) of each occurrence of the strings. The function should handle a 2D array and return a dictionary where the keys are the search strings and the values are lists of coordinates where each stri...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def find_strings_in_2d_array(array: List[List[str]], strings: List[str]) -> Dict[str, List[List[int]]]: """ Searches for multiple strings in a given 2D array of strings and returns the coordinates ...
magic_evol_110k
108,368
Write a Python function to generate the first 1000 prime numbers and group them sequentially into sub-arrays of 20, maintaining the original order of appearance. The function should return a list of these sub-arrays. The code should start with: ```python from typing import List def generate_prime_numbers(n: int) -> L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List 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 otherwise. ...
magic_evol_110k
108,372
Write a Python function to simulate a simplified version of the given Java code snippet. The function should mimic the behavior of the `simpleExe` method in the `MainClass` service, which makes a POST request and processes the response using a helper method `add`. The function should return the result of the `add` meth...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Dict def simple_exe(url: str, headers: Dict[str, str], body: Any) -> Any: """ Simulate a POST request and process the response using a helper function. Args: url (str): The URL to which the ...
magic_evol_110k
108,377
Write a Python function to reverse the order of elements in a given list of integers. The function should return a new list with the elements in the reversed order. The original list should not be modified. The code should start with: ```python from typing import List def reverse_list(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_list(arr: List[int]) -> List[int]: """ Reverses the order of elements in a given list of integers and returns a new list. Args: arr (List[int]): The list of integers to be revers...
magic_evol_110k
108,382
Write a Python function to determine if a common subsequence of length `m` exists in two given strings `str1` and `str2`. The function should return `True` if such a subsequence exists, otherwise `False`. The code should start with: ```python def has_common_subsequence(str1: str, str2: str, m: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def has_common_subsequence(str1: str, str2: str, m: int) -> bool: """ Determine if a common subsequence of length `m` exists in two given strings `str1` and `str2`. Args: str1 (str): The first string. str2 (...
magic_evol_110k
108,393
Write a Python function to perform a 90-degree rotational transformation on a 3-dimensional cube representation. The cube is structured as a list of 2-dimensional matrices. The rotation should be performed layer by layer, starting from the outermost layer and moving towards the center. Each layer's rotation should simu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def rotate_cube_90_degree(cube: List[List[List[int]]]) -> List[List[List[int]]]: """ Rotates a 3-dimensional cube representation by 90 degrees. The cube is structured as a list of 2-dimensional matr...
magic_evol_110k
108,396
Write a Python function to filter and return a list of all elements greater than a specified threshold from a given list of numbers. The function should be able to handle any list of integers and any threshold value. The code should start with: ```python from typing import List def filter_elements_greater_than(number...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_elements_greater_than(numbers: List[int], threshold: int) -> List[int]: """ Filters and returns a list of all elements greater than the specified threshold from the given list of numbers. ...
magic_evol_110k
108,405
Write a Python function to find the position of the last occurrence of a target integer in a given list of numerical integers. If the target is not found in the list, the function should return -1. The function should be efficient and handle edge cases such as an empty list or a list that does not contain the target. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_last_occurrence(numbers: List[int], target: int) -> int: """ Find the position of the last occurrence of a target integer in a given list. Args: numbers (List[int]): The list of int...
magic_evol_110k
108,434
Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should start with: ```python from typing import List def unique_paths(m: int, n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def unique_paths(m: int, n: int) -> int: """ Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid. Args: m (int): The number of row...
magic_evol_110k
108,451
Write a Python function to flatten a two-dimensional matrix of integers and sort the resultant array in ascending order without using built-in sort functions. The function should start with: ```python from typing import List def flatten_and_sort_matrix(matrix: 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 flatten_and_sort_matrix(matrix: List[List[int]]) -> List[int]: """ Flattens a two-dimensional matrix of integers and sorts the resultant array in ascending order without using built-in sort functions...
magic_evol_110k
108,453
Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The code should start with: ```python def unique_paths(m: int, n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def unique_paths(m: int, n: int) -> int: """ Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid. Args: m (int): The number of rows in the grid. n ...
magic_evol_110k
108,457
Write a Python function to merge two sorted arrays into a single sorted array. The function should efficiently combine the elements from both arrays while maintaining the ascending order. The code should start with: ```python from typing import List def merge_sorted_arrays(array_a: List[int], array_b: List[int]) -> Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_arrays(array_a: List[int], array_b: List[int]) -> List[int]: """ Merge two sorted arrays into a single sorted array. Args: array_a (List[int]): The first sorted array. ...
magic_evol_110k
108,473
Write a Python function to insert an element at a specified index into a given list and then sort the list in non-descending order. The function should handle the following edge cases: - Check if the given index is valid for the list. - Handle situations where the index may be negative. - Ensure the inserted element is...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def insert_and_sort(test_list: List[int], inserted_element: int, index: int) -> Union[List[int], str]: """ Inserts an element at a specified index into a given list and then sorts the list in non-...
magic_evol_110k
108,481
Write a Python function to iterate over a given dictionary and return a list of formatted strings, where each string contains a key-value pair from the dictionary. The function should handle dictionaries with various data types as values, including nested dictionaries. If a value is a nested dictionary, the function sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Any def format_dictionary(dictionary: Dict[str, Any]) -> List[str]: """ Formats a dictionary into a list of strings, where each string contains a key-value pair. If a value is a nested diction...
magic_evol_110k
108,488
Write a Python function to calculate the sum of an arbitrary number of integers. The function should accept a variable number of arguments and return the sum of all the integers provided. The code should start with: ```python def sum_of_integers(*args: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_integers(*args: int) -> int: """ Calculate the sum of an arbitrary number of integers. Args: *args (int): Variable number of integer arguments. Returns: int: The sum of all the provided integ...
magic_evol_110k
108,514
Write a Python function to count the number of distinct words in a given string, considering words as sequences of alphanumeric characters uninterrupted by spaces or punctuation marks. The function should be case-insensitive, meaning words with different casing should be considered the same. The function should also ha...
Here is the Python code to solve the given problem in the markdown block: ```python import re def count_distinct_words(s: str) -> int: """ Count the number of distinct words in a given string, considering words as sequences of alphanumeric characters uninterrupted by spaces or punctuation marks. The functi...
magic_evol_110k
108,528
Write a Python function to check for the existence of a given value in a sorted list and return its index if it exists. Implement a recursive binary search algorithm to achieve this. The function should handle edge cases such as an empty list or a value not present in the list. The code should start with: ```python fr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def binary_search(arr: List[int], value: int) -> Optional[int]: """ Recursively searches for the index of a given value in a sorted list using binary search. Args: arr (List[int]):...
magic_evol_110k
108,531
Write a Python function to sort a given list of integers in an increasingly progressive fashion. The function should use a custom sorting algorithm that does not rely on built-in sorting functions like `sorted()` or `list.sort()`. The custom sorting algorithm should be based on the concept of selection sort. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def custom_sort(sequence: List[int]) -> List[int]: """ Sorts a given list of integers in an increasingly progressive fashion using a custom selection sort algorithm. Args: sequence (List[int...
magic_evol_110k
108,567
Write a Python function to generate a numbered list of items from a given array in reverse alphabetical order, excluding any items that are not strings. The function should return a list of strings where each string is formatted as "number. item". The code should start with: ```python from typing import List def gene...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_numbered_list(arr: List[any]) -> List[str]: """ Generates a numbered list of items from a given array in reverse alphabetical order, excluding non-string items. Args: arr (List[...
magic_evol_110k
108,612
Write a Python function to count the number of punctuation marks in a given string. The function should return the total count of punctuation marks found in the string. The code should start with: ```python from typing import List def count_punctuations(text: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_punctuations(text: str) -> int: """ Counts the number of punctuation marks in a given string. Args: text (str): The input string to count punctuation marks in. Returns: ...
magic_evol_110k
108,614
Write a Python function to generate all unique pairs of elements from a given list of integers efficiently. The function should use a more efficient approach than nested loops to reduce time complexity and memory usage. The code should start with: ```python from typing import List, Tuple def generate_unique_pairs(num_...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Tuple from itertools import combinations def generate_unique_pairs(num_list: List[int]) -> List[Tuple[int, int]]: """ Generates all unique pairs of elements from the given list of integers. Args:...
magic_evol_110k
108,641
Write a Python function to compute the Kronecker product of two given matrices using the NumPy library. The function should take two 2D NumPy arrays as input and return the resulting Kronecker product matrix. The code should start with: ```python import numpy as np def kronecker_product(matrix1: np.ndarray, matrix2: n...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def kronecker_product(matrix1: np.ndarray, matrix2: np.ndarray) -> np.ndarray: """ Compute the Kronecker product of two given matrices. Args: matrix1 (np.ndarray): The first 2D NumPy array (matri...
magic_evol_110k
108,650
Write a Python function to calculate the frequency of each element in a given integer array and return the result as a dictionary where the keys are the elements and the values are their respective frequencies. The function should handle an empty array by returning an empty dictionary. The code should start with: ```p...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def calculate_frequencies(arr: List[int]) -> Dict[int, int]: """ Calculate the frequency of each element in a given integer array. Args: arr (List[int]): The integer array for which to...
magic_evol_110k
108,654
Write a Python function to calculate the product of two given integers `x` and `y` and return the result. The function should be named `multiply_numbers` and should accept two parameters, `x` and `y`. The function should return the product of `x` and `y`. The code should start with: ```python def multiply_numbers(x: i...
Here is the Python code to solve the given problem in the markdown block: ```python def multiply_numbers(x: int, y: int) -> int: """ Calculate the product of two integers x and y. Args: x (int): The first integer. y (int): The second integer. Returns: int: The product of x and ...
magic_evol_110k
108,660
Write a Python function that takes a list of integers as input and returns a new list where each element is the original element multiplied by a constant integer value. The function should be efficient and handle edge cases such as an empty list or a list with a single element. The code should start with: ```python fr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def multiply_elements(numbers: List[int], multiplier: int) -> List[int]: """ Multiplies each element in the input list by the given multiplier and returns a new list with the results. Args: ...
magic_evol_110k
108,665
Write a Python function to extract unique elements from a given array of integers and return their frequencies. The function should maintain a time complexity of O(n). The code should start with: ```python from typing import List, Tuple def get_unique_elements_with_frequencies(arr: List[int]) -> Tuple[List[int], List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def get_unique_elements_with_frequencies(arr: List[int]) -> Tuple[List[int], List[int]]: """ Extracts unique elements from a given array of integers and returns their frequencies. Args: ...
magic_evol_110k
108,672
Create a Python function that simulates the dynamic loading of content segments from a JSON object, similar to how a webpage would load content via AJAX requests. The function should take a JSON object as input and return a dictionary containing the loaded content segments. One of the segments should be a carousel that...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List import time def load_content_segments(json_data: Dict[str, any]) -> Dict[str, any]: """ Simulates the dynamic loading of content segments from a JSON object. Args: json_data (Dict[str,...
magic_evol_110k
108,682
Write a Python function to calculate the product of all non-zero elements in a 2D array, handling elements in nested sub-arrays as well. The function should be able to handle nested lists of arbitrary depth. The code should start with: ```python from typing import List, Any def deep_product_of_non_zero_elements(input_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def deep_product_of_non_zero_elements(input_array: List[Any]) -> int: """ Calculate the product of all non-zero elements in a 2D array, handling nested sub-arrays of arbitrary depth. Args: ...
magic_evol_110k
108,703
Write a Python function to remove all occurrences of a specified value from a given list and return the modified list in reverse order. The function should handle lists of integers and the value to be removed can be any integer. The code should start with: ```python from typing import List def remove_and_reverse(arr: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_and_reverse(arr: List[int], val: int) -> List[int]: """ Removes all occurrences of a specified value from a list and returns the modified list in reverse order. Args: arr (List[in...
magic_evol_110k
108,707
Write a Python function to determine if a given string is a pangram. A pangram is a sentence that uses every letter of the alphabet at least once. The function should be case-insensitive and should ignore non-alphabetic characters. The code should start with: ```python def is_pangram(input_string: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_pangram(input_string: str) -> bool: """ Determine if a given string is a pangram. A pangram is a sentence that uses every letter of the alphabet at least once. This function is case-insensitive and ignores non-al...
magic_evol_110k
108,712
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 find_common_elements(list1: List[int], list2: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_common_elements(list1: List[int], list2: List[int]) -> List[int]: """ Find the common elements between two lists of integers and return them in ascending order. Args: list1 (List[in...