source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_evol_110k
91,108
Write a Python function to search for a specific set of alphabets within a given segment of lexemes. The function should return `True` if the set is found in the segment, and `False` otherwise. The function should handle case-insensitive comparisons and should be able to handle multiple occurrences of the set within th...
Here is the Python code to solve the given problem in the markdown block: ```python def find_lexeme_set(lexeme_segment: str, alphabet_set: str) -> bool: """ Searches for a specific set of alphabets within a given segment of lexemes. Args: lexeme_segment (str): The segment of lexemes to search withi...
magic_evol_110k
91,128
Write a Python function to calculate the product of two integers and return the result. The function should handle the case where one or both of the integers are negative. The code should start with: ```python def multiply_integers(a: int, b: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def multiply_integers(a: int, b: int) -> int: """ Calculate the product of two integers. Args: a (int): The first integer. b (int): The second integer. Returns: int: The product of the two integ...
magic_evol_110k
91,137
Write a Python function that merges two dictionaries and filters the merged dictionary by a list of keys. If there are duplicate keys, the value from the second dictionary should override the value from the first dictionary. The function should return a new dictionary containing only the specified keys from the merged ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def merge_and_filter_dicts(dict1: Dict[str, str], dict2: Dict[str, str], keys: List[str]) -> Dict[str, str]: """ Merges two dictionaries and filters the merged dictionary by a list of keys. If ...
magic_evol_110k
91,138
Write a Python function to merge two numerical lists into a single string, with each element separated by a comma. The function should handle lists of different lengths and ensure that all elements from both lists are included in the final string. The code should start with: ```python from typing import List def merge...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_lists_to_string(list1: List[int], list2: List[int]) -> str: """ Merges two numerical lists into a single string, with each element separated by a comma. Args: list1 (List[int]): Th...
magic_evol_110k
91,141
Write a Python function to count the number of distinct subsequences of a given substring within a primary string. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. The function should not count overlapping subsequ...
Here is the Python code to solve the given problem in the markdown block: ```python def count_subsequences(string: str, substring: str) -> int: """ Count the number of distinct subsequences of a given substring within a primary string. Args: string (str): The primary string. substring (str)...
magic_evol_110k
91,142
Write a Python function to identify the most frequent item in a given list and count how many times it appears. The function should return a tuple containing the most frequent item and its count. The code should start with: ```python from typing import List, Tuple def most_frequent_item_count(data: List[int]) -> Tuple...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Optional def most_frequent_item_count(data: List[int]) -> Optional[Tuple[int, int]]: """ Identifies the most frequent item in a given list and counts how many times it appears. Args: ...
magic_evol_110k
91,144
Write a Python function to remove duplicate tuples from a list while preserving the order of their first occurrence. The input list consists of tuples containing pairs of integers. The function should return a new list with all duplicate tuples removed. The code should start with: ```python from typing import List, Tu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def remove_duplicates(input_list: List[Tuple[int, int]]) -> List[Tuple[int, int]]: """ Removes duplicate tuples from the input list while preserving the order of their first occurrence. Args:...
magic_evol_110k
91,160
Write a Python function to insert a given element at the second to last position in a list. The function should handle lists of any length, including empty lists. If the list has fewer than two elements, the element should be inserted at the end of the list. The code should start with: ```python from typing import List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def insert_second_last(arr: List[Any], element: Any) -> List[Any]: """ Inserts the given element at the second to last position in the list. Args: arr (List[Any]): The list in which...
magic_evol_110k
91,164
Write a Python function to calculate the cumulative sum of a 1D array and find the maximum cumulative sum. The function should return both the cumulative sum array and the maximum cumulative sum. The code should start with: ```python from typing import List, Tuple def cumulative_sum_and_max(nums: List[int]) -> Tuple[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def cumulative_sum_and_max(nums: List[int]) -> Tuple[List[int], int]: """ Calculate the cumulative sum of a 1D array and find the maximum cumulative sum. Args: nums (List[int]): The i...
magic_evol_110k
91,175
Write a Python function to compute an output array where each element at index `i` is the product of all elements in the input array except the one at index `i`. The function should avoid using division and should efficiently compute the result in O(n) time complexity. 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 def product_except_self(nums: List[int]) -> List[int]: """ Compute an output array where each element at index i is the product of all elements in the input array except the one at index i. Args: ...
magic_evol_110k
91,178
Write a Python function to find the character with the highest frequency in a given string, ignoring spaces. The function should return the character and its frequency. The code should start with: ```python from typing import Tuple def highest_frequency_char(phrase: str) -> Tuple[str, int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def highest_frequency_char(phrase: str) -> Tuple[str, int]: """ Finds the character with the highest frequency in the given string, ignoring spaces. Args: phrase (str): The input string to ...
magic_evol_110k
91,183
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
91,203
Write a Python function to filter out odd numbers and numbers divisible by 5 from a given list of integers. The function should not use any built-in filter functions. The code should start with: ```python from typing import List def filter_numbers(num_list: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_numbers(num_list: List[int]) -> List[int]: """ Filters out odd numbers and numbers divisible by 5 from the given list of integers. Args: num_list (List[int]): The list of integers...
magic_evol_110k
91,223
Write a Python function to calculate the product of all the non-zero integer elements within a given list, while also handling any potential edge cases such as non-integer elements and zero values. The function should ignore non-integer elements and skip zero values, but it should raise an error if the list contains no...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def product_of_non_zero_integers(my_list: List[int]) -> int: """ Calculate the product of all non-zero integer elements in the given list. Args: my_list (List[int]): The list of integers fro...
magic_evol_110k
91,224
Write a Python function to remove duplicate elements from a given numerical array 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 array or an array with all unique elements. The code 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 remove_duplicates_preserve_order(input_array: List[int]) -> List[int]: """ Removes duplicate elements from the given numerical array while preserving the order of the first occurrence of each element...
magic_evol_110k
91,236
Write a Python function to identify and retrieve the smallest alphanumeric string from a given array of mixed type elements. The array may contain integers, floats, strings, and sublists. The function should consider case sensitivity and handle nested sublists recursively. 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, Union def find_smallest_alphanumeric_string(mixed_list: List[Union[str, int, float, List]]) -> str: """ Finds the smallest alphanumeric string from a given array of mixed type elements. Args: ...
magic_evol_110k
91,244
Write a Python function to implement a parallel quicksort algorithm using the `concurrent.futures` module. The function should take a list of integers as input and return the sorted list. The function should leverage the `ThreadPoolExecutor` to parallelize the sorting process. The code should start with: ```python fro...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from concurrent.futures import ThreadPoolExecutor, as_completed def parallel_quicksort(arr: List[int]) -> List[int]: """ Sorts a list of integers using a parallel quicksort algorithm. Args: ...
magic_evol_110k
91,258
Write a Python function to generate a dictionary that includes the elements from two given lists, `x` and `y`, with corresponding values being their occurrence frequency in both lists combined. The function should start with: ```python from typing import List, Dict def generate_frequency_dict(x: List[int], y: List[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict from collections import Counter def generate_frequency_dict(x: List[int], y: List[int]) -> Dict[int, int]: """ Generates a dictionary that includes the elements from two lists, x and y, with co...
magic_evol_110k
91,267
Write a Python function to flatten a given n-dimensional list of integers and strings, and return the flattened list in lexicographical order. The function should handle nested mixtures of lists and non-list elements. The code should start with: ```python from typing import List, Union def flatten_and_sort(nested_list...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def flatten_and_sort(nested_list: List[Union[int, str, List]]) -> List[str]: """ Flattens a given n-dimensional list of integers and strings, and returns the flattened list in lexicographical orde...
magic_evol_110k
91,270
Write a Python function to generate the Fibonacci sequence up to the n-th position. The function should return a list containing the Fibonacci sequence up to the n-th position. If n is less than 0, the function should return an empty list. If n is 0, the function should return a list containing only the first Fibonacci...
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 Fibonacci sequence up to the n-th position. Args: n (int): The position up to which the Fibonacci sequence should be generated. ...
magic_evol_110k
91,283
Write a Python function to determine if two given integers are both "happy numbers". A number is considered a "happy number" if, by repeatedly replacing it with the sum of the squares of its digits, it eventually reaches 1. If it enters a cycle that does not include 1, it is not a happy number. The function should sta...
Here is the Python code to solve the given problem in the markdown block: ```python def are_both_happy_numbers(num1: int, num2: int) -> bool: """ Determine if both given integers are happy numbers. A number is considered a happy number if, by repeatedly replacing it with the sum of the squares of its digit...
magic_evol_110k
91,295
Write a Python function to identify the cheapest item in an array of product prices. The function should return the price of the cheapest item. Additionally, the function should handle cases where the input list is empty by returning `None`. The code should start with: ```python from typing import List, Optional def ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_cheapest_item(price_list: List[int]) -> Optional[int]: """ Identify the cheapest item in an array of product prices. Args: price_list (List[int]): A list of integers repre...
magic_evol_110k
91,310
Write a Python function to return the complement of a given list of integers, where the complement of an integer is defined as its additive inverse (i.e., the number that, when added to the original number, equals zero). The function should handle both positive and negative integers. 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 get_complement(lst: List[int]) -> List[int]: """ Returns a list of complements for each integer in the input list. The complement of an integer is defined as its additive inverse, i.e., the numb...
magic_evol_110k
91,315
Write a Python function that takes a string as input and returns a new string where each character in the input string is doubled. For example, if the input string is "Hello", the output should be "HHeelllloo". The function should handle any string, including those with spaces and special characters. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python def double_each_character(input_string: str) -> str: """ Returns a new string where each character in the input string is doubled. Args: input_string (str): The input string to be processed. Returns: st...
magic_evol_110k
91,327
Write a Python function to find all unique prime factors of a given positive integer. The function should return a list of these prime factors in ascending order. The code should start with: ```python from typing import List def get_unique_prime_factors(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_unique_prime_factors(n: int) -> List[int]: """ Returns a list of unique prime factors of the given positive integer in ascending order. Args: n (int): The positive integer for which ...
magic_evol_110k
91,350
Write a Python function to merge two dictionaries based on their keys. If there is a key collision (i.e., both dictionaries have the same key), the function should append the values from both dictionaries into a list. The function should handle cases where the values are already lists by extending them. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def merge_dicts(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]: """ Merge two dictionaries based on their keys. If there is a key collision, append the values from both dictionaries...
magic_evol_110k
91,353
Write a Python function to create a backup copy of a given directory with the current timestamp and move it to a different location. The function should handle the creation of the backup directory if it does not exist and ensure that the backup is named with the current timestamp. The code should start with: ```python...
Here is the Python code to solve the given problem in the markdown block: ```python import os import shutil from datetime import datetime def create_backup(src_dir: str, dst_dir: str) -> None: """ Creates a backup copy of the given source directory with the current timestamp and moves it to the destination dir...
magic_evol_110k
91,362
Write a Python function to filter out and return a list of prime numbers from a given list of integers. The function should use a helper function to determine if a number is prime. The code should start with: ```python from typing import List def filter_primes(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 is_prime(num: int) -> bool: """ Check if a number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. ...
magic_evol_110k
91,365
Write a Python function to implement the Bubble Sort algorithm, which sorts a list of integers in ascending order. The function should repeatedly step through the list, compare adjacent elements, and swap them if they are in the wrong order. The process should be repeated until the list is sorted. The code should start...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(numbers: List[int]) -> List[int]: """ Sorts a list of integers in ascending order using the Bubble Sort algorithm. Args: numbers (List[int]): The list of integers to be sorte...
magic_evol_110k
91,372
Write a Python function to identify prime numbers from a given list of integers and then determine the smallest prime number among them. The function should start with: ```python from typing import List def find_smallest_prime(numbers: List[int]) -> int: ```
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 given 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
91,389
Write a Python function to calculate the quotient and remainder of a division operation between two integers. The function should return both the quotient and the remainder as a tuple. The code should start with: ```python def divide_with_remainder(dividend: int, divisor: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def divide_with_remainder(dividend: int, divisor: int) -> tuple: """ Calculate the quotient and remainder of the division of two integers. Args: dividend (int): The number to be divided. divisor (int): The n...
magic_evol_110k
91,398
Write a Python function to generate a dictionary from a given list where the keys are the elements of the list and the values are their corresponding indices. The function should handle lists of any length and ensure that the dictionary is correctly formed. The code should start with: ```python from typing import List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def list_to_dict(lst: List[str]) -> Dict[str, int]: """ Generates a dictionary from a list of strings where each string is a key and its index in the list is the value. Args: lst (List...
magic_evol_110k
91,425
Write a Python function to categorize a list of numerical data into even, odd, and error categories. The function should handle lists up to one million entries and include error checking for non-numerical data types. If a data type is not numerical, the program should raise an exception and continue processing the rest...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def categorize_numbers(data: List[str]) -> Dict[str, List[int]]: """ Categorizes a list of numerical data into even, odd, and error categories. Args: data (List[str]): A list of string...
magic_evol_110k
91,431
Refactor and enhance the given function `foo(nums_data)` to perform a more complex computation on each integer in the input list. Specifically, the function should square each integer and then add 2 to the result. The function should also be corrected to avoid premature termination of the loop and to ensure that all el...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def foo(nums_data: List[int]) -> List[int]: """ Perform a complex computation on each integer in the input list. The computation involves squaring each integer and then adding 2 to the result. A...
magic_evol_110k
91,441
Write a Python function to remove all occurrences of specific characters from a given string. These characters include spaces, special characters, and numbers. Maintain the order of the remaining string characters intact. The function should start with: ```python def remove_specific_chars(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def remove_specific_chars(s: str) -> str: """ Removes all occurrences of spaces, special characters, and numbers from the given string. Maintains the order of the remaining alphabet characters. Args: s (str): Th...
magic_evol_110k
91,454
Write a Python function to calculate the total value of unique integer elements in a given list. The function should take a list of integers as input and return the sum of the unique elements. The code should start with: ```python from typing import List def sum_of_unique_elements(elements: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_unique_elements(elements: List[int]) -> int: """ Calculate the total value of unique integer elements in a given list. Args: elements (List[int]): A list of integers from which to...
magic_evol_110k
91,467
Write a Python function to generate a list of the first `n` prime numbers in sequential order. The function should use a helper function to check if a number is prime. 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 is_prime(n: int) -> bool: """ Check if a given 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
91,473
Write a Python function to find the complex numbers with the smallest and largest magnitudes in a given array of complex numbers. If there are multiple complex numbers with the same magnitude, the function should return all of them. The function should start with: ```python from typing import List, Tuple def find_min_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_min_max_magnitudes(array: List[complex]) -> Tuple[List[complex], List[complex]]: """ Finds the complex numbers with the smallest and largest magnitudes in a given array. Args: ...
magic_evol_110k
91,500
Write a Python function to determine if a given string is a valid palindrome considering only alphanumeric characters and ignoring cases. The function should return `True` if the string is a valid palindrome, otherwise `False`. The code should start with: ```python def is_valid_palindrome(s: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_valid_palindrome(s: str) -> bool: """ Determine if a given string is a valid palindrome considering only alphanumeric characters and ignoring cases. Args: s (str): The input string to check. Returns: ...
magic_evol_110k
91,506
Write a Python function that converts a given list of integers into a list of their corresponding English words. The function should use a `while` loop to iterate over the list and convert each integer to its English word representation. The function should handle integers from 0 to 9. 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 def convert_to_english_words(numbers: List[int]) -> List[str]: """ Converts a list of integers (0-9) into their corresponding English words. Args: numbers (List[int]): A list of integers to ...
magic_evol_110k
91,522
Write a Python function to calculate the product of two positive integers \( X \) and \( Y \) without using the multiplication operator `*`. The function should be optimized to minimize the number of additions and subtractions. The code should start with: ```python def multiply_without_operator(x: int, y: int) -> int: ...
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 positive integers x and y without using the multiplication operator. Args: x (int): The first positive integer. y (int):...
magic_evol_110k
91,526
Write a Python function to calculate the total and average marks of a student given a list of marks. The function should return a tuple containing the total marks and the average marks. If the list of marks is empty, the function should return `(0, 0)`. The code should start with: ```python from typing import List, Tu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def calculate_total_and_average(marks: List[int]) -> Tuple[int, float]: """ Calculate the total and average marks of a student given a list of marks. Args: marks (List[int]): A list o...
magic_evol_110k
91,527
Write a Python function to find the intersection of two arrays, each containing 20 distinct randomly generated numerical integers, without using built-in functions like `set.intersection`. Additionally, ensure that any duplicates in the intersection are removed. The function should start with: ```python from typing imp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def find_intersection(arr1: List[int], arr2: List[int]) -> List[int]: """ Finds the intersection of two arrays, ensuring that any duplicates in the intersection are removed. Args: ...
magic_evol_110k
91,538
Write a Python function to calculate the number of trailing zeros in the factorial of a given number `n`. The factorial of a number `n` is the product of all positive integers less than or equal to `n`. Trailing zeros are created by factors of 10 in the number, which are in turn created by pairs of 2 and 5. Since there...
Here is the Python code to solve the given problem in the markdown block: ```python def count_trailing_zeros_in_factorial(n: int) -> int: """ Calculate the number of trailing zeros in the factorial of a given number n. Args: n (int): The number for which to calculate the factorial and count trailin...
magic_evol_110k
91,560
Write a Python function to generate a list of 25 distinct prime numbers between 100 and 400, excluding primes that end with the digits 2 or 5. The function should start with: ```python from typing import List def generate_special_primes() -> List[int]: ```
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
91,572
Write a Python function to find all occurrences of strings from a given list of search terms in another list of strings and return a dictionary. The keys of the dictionary should be the strings from the search terms list, and their corresponding values should be lists containing all indexes at which these strings occur...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def find_occurrences(string_list: List[str], search_terms: List[str]) -> Dict[str, List[int]]: """ Finds all occurrences of the strings from the search terms list in the string list and returns a d...
magic_evol_110k
91,578
Write a Python function to determine if the balance of an account ever goes below zero given a sequence of financial operations (deposits and withdrawals). The function should return `True` if the balance goes below zero at any point, and `False` otherwise. The function should handle edge cases such as an empty list of...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def below_zero(operations: List[int]) -> bool: """ Determines if the balance of an account ever goes below zero given a sequence of financial operations. Args: operations (List[int]): A list...
magic_evol_110k
91,579
Write a Python function to find and count all occurrences of the substring "CAT" in a given string that matches the following criteria: 1. The string must start with the substring "dog". 2. The string must contain the substring "CAT" anywhere in the middle with an arbitrary number of occurrences. 3. The string must inc...
Here is the Python code to solve the given problem in the markdown block: ```python import re def count_cat_occurrences(string: str) -> int: """ Counts the occurrences of "CAT" in a string that matches the following criteria: 1. The string must start with "dog". 2. The string must contain "CAT" anywher...
magic_evol_110k
91,581
Write a Python function that prints each element of a given list using a `while` loop instead of a `for` loop. The function should take a list as input and print each element on a new line. The code should start with: ```python from typing import List def print_elements_while_loop(elements: List[int]) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_elements_while_loop(elements: List[int]) -> None: """ Prints each element of the given list using a while loop. Args: elements (List[int]): The list of integers to be printed. ...
magic_evol_110k
91,597
Write a Python function to remove duplicate elements from a given list while preserving the order of the remaining unique items. The function should be efficient and should handle lists of various sizes and types of elements. The code should start with: ```python from typing import List def remove_duplicates_preserve...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_preserve_order(lst: List) -> List: """ Removes duplicate elements from a list while preserving the order of the remaining unique items. Args: lst (List): The list from ...
magic_evol_110k
91,598
Write a Python function to generate a new list where each element is the product of the corresponding element in the input list and a given multiplier. The function should use list comprehension for this purpose. The code should start with: ```python from typing import List def multiply_list_elements(input_list: List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def multiply_list_elements(input_list: List[int], multiplier: int) -> List[int]: """ Generates a new list where each element is the product of the corresponding element in the input list and the given mu...
magic_evol_110k
91,603
Write a Python function to generate the first N prime numbers. The function should take an integer N as input and return a list of the first N prime numbers. The function should be efficient and handle edge cases such as N being 0 or negative. The code should start with: ```python from typing import List def generate...
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
91,606
Write a Python function to compute the smallest lexical distance between two distinct words in a given list of words. The function should return the minimum distance between the two words, where the distance is defined as the absolute difference between their indices in the list. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def minimum_lexical_distance(wordsDict: List[str], word1: str, word2: str) -> int: """ Compute the smallest distance between two distinct words in a list of words. Args: wordsDict (List[str]...
magic_evol_110k
91,608
Write a Python function to convert a given list into a dictionary where the keys are the index positions of the elements in the list, and the values are the elements themselves. The function should handle lists of any length and ensure that the dictionary is correctly populated. 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, Dict def list_to_dict(arr: List[int]) -> Dict[int, int]: """ Converts a given list into a dictionary where the keys are the index positions of the elements in the list, and the values are the elemen...
magic_evol_110k
91,642
Write a Python function to perform a comparative analysis on two numerical arrays and identify the missing elements in the second array compared to the first array. The function should return a list of these missing elements. The code should start with: ```python from typing import List def find_missing_elements(arra...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_missing_elements(array1: List[int], array2: List[int]) -> List[int]: """ Identify and return the elements that are present in the first array but missing in the second array. Args: ...
magic_evol_110k
91,651
Write a Python function to calculate the nth Fibonacci number using the tabulation method (bottom-up dynamic programming). The function should efficiently compute the Fibonacci number by storing intermediate results in a list to avoid redundant calculations. The code should start with: ```python def fibonacci_tabulati...
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci_tabulation(n: int) -> int: """ Calculate the nth Fibonacci number using the tabulation method (bottom-up dynamic programming). Args: n (int): The position in the Fibonacci sequence to compute. Ret...
magic_evol_110k
91,659
Write a Python function to identify unique elements from three different lists, `l1`, `l2`, and `l3`. These elements should only appear once across all three lists and should be under the same index. The function should return a list of these unique elements. The function should be able to handle lists of varying lengt...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_unique_elements(l1: List[Union[int, str, float]], l2: List[Union[int, str, float]], l3: List[Union[int, str, float]]) -> List[Union[int, str, float]]: """ Identifies unique elements from ...
magic_evol_110k
91,668
Write a Python function to extract exclusively even numbers from a pair of lists, combine them, and sort them in descending numerical order. The function should use a helper function to perform the merging and sorting operations. The code should start with: ```python from typing import List def filter_merge_sort_even_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_merge_sort_even_numbers(l1: List[int], l2: List[int]) -> List[int]: """ Extracts exclusively even numbers from a pair of lists, combines, and sorts them in descending numerical order. Arg...
magic_evol_110k
91,690
Write a Python function to perform a binary search on a sorted array and return the index of the target item if it exists in the array, or -1 if it does not. The function should be efficient and implement the binary search algorithm. The code should start with: ```python from typing import List def binary_search(arr:...
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], item: int) -> int: """ Perform a binary search on a sorted array to find the index of the target item. Args: arr (List[int]): A sorted list of integers. ...
magic_evol_110k
91,703
Write a Python function to count the number of even and odd digits in a given integer, correctly handling both positive and negative integers. The function should return a tuple containing the total count of even and odd digits. The code should start with: ```python def even_odd_count(num: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def even_odd_count(num: int) -> tuple: """ Counts the number of even and odd digits in a given integer. Args: num (int): The integer to analyze. Returns: tuple: A tuple containing the count of even digi...
magic_evol_110k
91,705
Write a Python function that uses a lambda expression to perform arithmetic operations on two numerical values. The function should handle different arithmetic operations (addition, subtraction, multiplication, and division) based on a provided operator. Additionally, the function should validate the input values and t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Union def arithmetic_operation(num1: Union[int, float], num2: Union[int, float], operator: str) -> Union[int, float, str]: """ Perform an arithmetic operation on two numerical values using a lambda expression...
magic_evol_110k
91,711
Write a Python function to transform a given string according to the following rules: 1. Flip the case of alphabetical characters (lowercase to uppercase and vice versa). 2. Replace odd numbers with the next even number. 3. Repeat special characters (non-alphabetical and non-numeric characters). The function should st...
Here is the Python code to solve the given problem in the markdown block: ```python def flip_case_and_modify(string: str) -> str: """ Transform a given string by flipping the case of alphabetical characters, replacing odd numbers with the next even number, and repeating special characters. Args: ...
magic_evol_110k
91,730
Write a Python function to search for an element in an unsorted list and return its position if found, or a message indicating that the element is not present in the list. The function should handle edge cases such as an empty list or when the element is not found. The code should start with: ```python from typing imp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def search_element(lst: List[int], ele: int) -> Union[str, int]: """ Searches for an element in an unsorted list and returns its position if found, or a message indicating that the element is ...
magic_evol_110k
91,732
Write a Python function to calculate the total distance between all occurrences of a specific element within a sorted array. The function should return the sum of the distances between consecutive occurrences of the element. If the element occurs less than twice, the function should return 0. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def total_distance_between_elements(arr: List[int], elem: int) -> int: """ Calculate the total distance between all occurrences of a specific element in a sorted array. Args: arr (List[int])...
magic_evol_110k
91,752
Write a Python function to find the maximum of three numbers using a ternary conditional expression. The function should not use any prebuilt functions or methods (such as `max()`), and it should avoid using if-else statements. The function should start with: ```python def find_max_of_three(a: int, b: int, c: int) -> i...
Here is the Python code to solve the given problem in the markdown block: ```python def find_max_of_three(a: int, b: int, c: int) -> int: """ Find the maximum of three numbers using a ternary conditional expression. Args: a (int): The first number. b (int): The second number. c (int...
magic_evol_110k
91,756
Write a Python function to remove all prime numbers from a given array of integers. Additionally, the function should handle special cases where the numbers are either negative or zero. The function should be robust enough to handle non-integer inputs gracefully. 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 def is_prime(n: int) -> bool: """ Check if the 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
91,773
Write a Python function to calculate the nth Fibonacci number using an iterative approach. The function should efficiently compute the Fibonacci number by storing the results of previous computations in a list. The code should start with: ```python def fibonacci(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci(n: int) -> int: """ Calculate the nth Fibonacci number using an iterative approach. Args: n (int): The position of the Fibonacci number to calculate. Returns: int: The nth Fibonacci number...
magic_evol_110k
91,777
Write a Python function to calculate the mean, mode, median, and range of a given list of numbers. The function should return a dictionary with keys 'mean', 'mode', 'median', and 'range', each containing the corresponding calculated value. The code should start with: ```python from typing import List, Dict, Union def...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Union from collections import Counter def calculate_statistics(numbers: List[int]) -> Dict[str, Union[int, float]]: """ Calculate the mean, mode, median, and range of a given list of numbers. ...
magic_evol_110k
91,778
Write a Python function to replicate each element of a given list a specified number of times. The function should take two parameters: the list to be replicated and the number of times each element should be replicated. The function should return a new list containing the replicated elements in the same order as they ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def replicate_elements(lst: List[str], n: int) -> List[str]: """ Replicates each element in the given list `n` times and returns a new list. Args: lst (List[str]): The list of elements to be...
magic_evol_110k
91,793
Write a Python function to find the smallest prime number from a given list of eight distinct integers. The function should return the smallest prime number if found, otherwise it should return `None`. The code should start with: ```python from typing import List, Optional def find_smallest_prime(numbers: List[int]) ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def is_prime(num: int) -> bool: """ Check if a number is prime. Args: num (int): The number to check. Returns: bool: True if the number is prime, False otherwise. ...
magic_evol_110k
91,812
Write a Python function to find and return all prime numbers from a given list of integers. The function should be efficient and handle various edge cases, such as an empty list or a list containing non-prime numbers. The code should start with: ```python from typing import List def find_prime_numbers(numbers: List[i...
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 given 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
91,817
Write a Python function to remove duplicate elements from a given list while maintaining the original order of elements. Additionally, implement error checks to ensure that the input is indeed a list and each item in the input list is a number. If the input is not a list or contains non-numeric elements, the function s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def remove_duplicates(my_list: List[Union[int, float]]) -> Union[List[Union[int, float]], str]: """ Removes duplicate elements from a given list while maintaining the original order. Ensures t...
magic_evol_110k
91,834
Write a Python function to sort a dictionary by its values in ascending or descending order and return the sorted list of tuples. The function should accept a dictionary and a boolean flag indicating the sorting order (True for descending, False for ascending). 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 Dict, List, Tuple, Union def sort_dict_by_values(dictionary: Dict[str, int], reverse: bool = False) -> List[Tuple[str, int]]: """ Sorts a dictionary by its values in ascending or descending order and returns ...
magic_evol_110k
91,835
Write a Python function to perform a Fibonacci search on a sorted array to find the index of a target element. The Fibonacci search is a comparison-based technique that uses Fibonacci numbers to search for an element in a sorted array. The function should return the index of the target element if it exists in the array...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def fibonacci_search(arr: List[int], target: int) -> int: """ Perform a Fibonacci search on a sorted array to find the index of a target element. Args: arr (List[int]): A sorted list of inte...
magic_evol_110k
91,842
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 strings. Args: str1 (str): The first string. str2 (str): The second stri...
magic_evol_110k
91,848
Write a Python function to search for a specific sequence of characters within a given body of text using regular expressions. The function should return the matched sequence if found, otherwise return `None`. The function should handle case-insensitive searches and should be able to handle different patterns and texts...
Here is the Python code to solve the given problem in the markdown block: ```python import re def find_sequence(text: str, pattern: str) -> str: """ Searches for a specific sequence of characters within a given body of text using regular expressions. Args: text (str): The body of text to search wi...
magic_evol_110k
91,853
Write a Python function to shuffle an array of integers in place. The function should use the Fisher-Yates (Knuth) shuffle algorithm to ensure a uniform random permutation of the array. The code should start with: ```python from typing import List def shuffle_array(array: List[int]) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def shuffle_array(array: List[int]) -> None: """ Shuffles the given array of integers in place using the Fisher-Yates (Knuth) shuffle algorithm. Args: array (List[int]): The ar...
magic_evol_110k
91,856
Write a Python function to generate a list of all prime numbers within a given range `[start, end]`. The function should return a list of prime numbers that are greater than or equal to `start` and less than or equal to `end`. The code should start with: ```python from typing import List def generate_primes_in_range(...
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 given 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
91,857
Write a Python function to determine if the length of a given string is a prime number. The function should return `True` if the length is a prime number and `False` otherwise. The code should start with: ```python def is_prime_length(s: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n: int) -> bool: """ Check if a given integer is a prime number. Args: n (int): The integer to check for primality. Returns: bool: True if the integer is prime, False otherwise. """ ...
magic_evol_110k
91,859
Write a Python function to convert a given three-dimensional NumPy array into a two-dimensional matrix. The resulting matrix should have the same number of columns as the last dimension of the original 3D array, and the rows should be formed by flattening the first two dimensions of the original array. The code should...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np from typing import List def flatten_3d_to_2d(three_dimensional_array: np.ndarray) -> np.ndarray: """ Converts a given three-dimensional NumPy array into a two-dimensional matrix. The resulting matrix has...
magic_evol_110k
91,869
Write a Python function that multiplies two input numbers and returns the result. The function should handle both integer and floating-point inputs. The code should start with: ```python def multiply_numbers(a: float, b: float) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def multiply_numbers(a: float, b: float) -> float: """ Multiplies two input numbers and returns the result. Args: a (float): The first number to be multiplied. b (float): The second number to be multiplied. ...
magic_evol_110k
91,873
Write a Python function to determine the number of mangoes in a fruit basket given a string that describes the total quantity of apples and oranges, and an integer that represents the total number of fruits in the basket. The basket contains apples, oranges, and mangoes. The function should return the count of mangoes ...
Here is the Python code to solve the given problem in the markdown block: ```python import re def fruit_distribution(fruit_string: str, total_fruits: int) -> int: """ Calculate the number of mangoes in a fruit basket given the total number of fruits and a string describing the number of apples and oranges. ...
magic_evol_110k
91,899
Write a Python function that deletes an element from a specified index in a list and handles various edge cases. The function should: 1. Return an error message if the input is not a list. 2. Return an error message if the list is empty. 3. Return an error message if the index is out of the valid range of the list. 4. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def delete_element(lst: List[int], index: int) -> Union[List[int], str]: """ Deletes an element from a specified index in a list and handles edge cases. Args: lst (List[int]): The lis...
magic_evol_110k
91,909
Write a Python function to iterate over a given list in reverse order and print each element twice. The function should be efficient and elegant, leveraging Python's built-in functions for manipulating lists and for-loops. The code should start with: ```python from typing import List def print_elements_twice_reverse(n...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_elements_twice_reverse(nums: List[int]) -> None: """ Iterates over the given list in reverse order and prints each element twice. Args: nums (List[int]): The list of integers to it...
magic_evol_110k
91,929
Write a Python function to print a message a specified number of times, but only display the message during even-numbered iterations. The function should take two parameters: the message to be printed and the total number of iterations. The function should start counting from 1. The code should start with: ```python d...
Here is the Python code to solve the given problem in the markdown block: ```python def print_message_on_even_iterations(message: str, total_iterations: int) -> None: """ Prints the given message during even-numbered iterations up to the specified total number of iterations. Args: message (str): Th...
magic_evol_110k
91,948
Write a Python function to check whether a large number is a palindrome, considering memory and computation time constraints. The function should handle large numbers efficiently without converting the entire number to a string. The code should start with: ```python def is_large_number_palindrome(num: int) -> bool: ``...
Here is the Python code to solve the given problem in the markdown block: ```python def is_large_number_palindrome(num: int) -> bool: """ Check if a large number is a palindrome without converting the entire number to a string. Args: num (int): The large number to check. Returns: bool:...
magic_evol_110k
91,979
Write a Python function to implement the merge sort algorithm for a given array. The function should sort the array in ascending order. The code should start with: ```python from typing import List def merge_sort(array: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(array: List[int]) -> List[int]: """ Sorts the given array using the merge sort algorithm. Args: array (List[int]): The array to be sorted. Returns: List[int]: The...
magic_evol_110k
91,989
Write a Python function to process a given dictionary that contains both numerical and string values. The function should compute the sum of all numerical values and concatenate all string values together. These computations should occur in reverse order of their appearance in the dictionary. The output should be a tup...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Tuple def process_dictionary(an_dict: Dict[str, any]) -> Tuple[float, str]: """ Processes a dictionary containing both numerical and string values. Computes the sum of all numerical values and conca...
magic_evol_110k
91,990
Write a Python function to reverse a given string and return a new string. The function should handle strings of varying lengths, including empty strings. The code should start with: ```python def reverse_string(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses the given string and returns a new string. Args: s (str): The input string to be reversed. Returns: str: The reversed string. If the input is not a string...
magic_evol_110k
92,008
Write a Python function to implement the Gradient Descent Algorithm for finding the minimum of a given function. The function should take an initial guess, a learning rate, and the number of iterations as inputs and return the value of the variable at which the function is minimized. The gradient of the function should...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def gradient_descent(x_start, learning_rate, num_iterations, compute_gradient): """ Implements the Gradient Descent Algorithm to find the minimum of a function. Args: x_start (float): The initial...
magic_evol_110k
92,011
Write a Python function to determine the maximum number of cubes that can be stacked one on top of another, given a list of cubes where each cube is represented by its length, width, and height. A cube can only be stacked on top of another if its dimensions (length, width, and height) are all strictly smaller than the ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_stackable_cubes(cubes: List[List[int]]) -> int: """ Calculate the maximum number of cubes that can be stacked one on top of another. Args: cubes (List[List[int]]): A list of cubes wh...
magic_evol_110k
92,029
Write a Python function to find the smallest numerical value within a provided array. The function should be efficient and handle various edge cases, such as an empty array or an array with negative numbers. The code should start with: ```python from typing import List def find_min_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_min_value(arr: List[int]) -> int: """ Find the smallest numerical value within a provided array. Args: arr (List[int]): The array of integers from which to find the smallest value. ...
magic_evol_110k
92,032
Write a Python function to generate all possible subsets of a given integer array `nums` of unique elements, along with the sum of elements in each subset. The function should return a list of tuples where each tuple contains a subset and its corresponding sum. The solution set must not contain duplicate subsets and sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def subsets_with_sums(nums: List[int]) -> List[Tuple[List[int], int]]: """ Generate all possible subsets of the given integer array `nums` along with the sum of elements in each subset. Args:...
magic_evol_110k
92,058
Write a Python function to count the number of elements in a given list that are less than a specified threshold value. The function should efficiently handle large lists and return the count of elements that satisfy the condition. The code should start with: ```python from typing import List def count_elements_less_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_elements_less_than(dataset: List[float], threshold: float) -> int: """ Counts the number of elements in the given dataset that are less than the specified threshold. Args: dataset ...
magic_evol_110k
92,068
Write a Python function to create a dictionary representing a person's professional profile. The dictionary should include the following keys: "Occupation", "Experience(Years)", "Location", "Specialization", and "Certification". The function should allow for optional parameters for "Specialization" and "Certification"....
Here is the Python code to solve the given problem in the markdown block: ```python def create_professional_profile(occupation: str, experience: int, location: str, specialization: str = None, certification: str = None) -> dict: """ Creates a dictionary representing a person's professional profile. Args: ...
magic_evol_110k
92,085
Write a Python function to shuffle a list of real numbers using the Fisher-Yates algorithm. The function should return a new list that is a randomly shuffled version of the input list. The input list is composed of real numbers, such as fractions and numbers that require a decimal point. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def shuffle_real_numbers(lst: List[float]) -> List[float]: """ Shuffles a list of real numbers using the Fisher-Yates algorithm. Args: lst (List[float]): The list of real numbe...
magic_evol_110k
92,088
Write a Python function to reverse-sort a given list of integers. The function should return the sorted list in descending order. The code should start with: ```python from typing import List def reverse_sort_list(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 reverse_sort_list(numbers: List[int]) -> List[int]: """ Reverse-sorts a given list of integers and returns the sorted list in descending order. Args: numbers (List[int]): The list of int...
magic_evol_110k
92,104
Write a Python function to add a set of elements to the beginning of a given tuple, ensuring that the elements are only added if they do not already exist in the tuple. If an element already exists in the tuple, it should be skipped. The function should return the modified tuple. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Set def add_unique_elements_to_tuple(tuple1: Tuple[int], set1: Set[int]) -> Tuple[int]: """ Adds unique elements from a set to the beginning of a tuple. Args: tuple1 (Tuple[int]): The init...
magic_evol_110k
92,132
Write a Python function to remove all non-alphanumeric characters from a given input string while preserving the order of alphanumeric characters. Additionally, implement an error handler to raise a `TypeError` if the input is not a string. The function should start with: ```python def remove_non_alphanum(input_str: st...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_non_alphanum(input_str: str) -> str: """ Removes all non-alphanumeric characters from the input string while preserving the order of alphanumeric characters. Args: input_str (str): The input string from w...
magic_evol_110k
92,145
Write a Python function to remove all even elements from a given list. The function should also handle the case where the input is not a list by returning an appropriate error message. The function should be efficient enough to handle lists with up to one million elements without using built-in functions like `filter()...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_even_elements(lst): """ Removes all even elements from the given list and returns a new list containing only odd elements. If the input is not a list, returns an error message. Args: lst (list): The l...