source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_evol_110k
88,601
Write a Python function to sort an array in ascending order using the Bubble Sort algorithm and then count the number of elements greater than 5 in the sorted array. The function should not use the built-in `sort` or `sorted` functions. The code should start with: ```python from typing import List def sort_array_and_c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_array_and_count(array: List[int]) -> int: """ Sorts the given array in ascending order using the Bubble Sort algorithm and returns the count of elements greater than 5. Args: array ...
magic_evol_110k
88,618
Write a Python function to remove all punctuation marks from a given ASCII string. The function should return the cleaned string without any punctuation. The code should start with: ```python from typing import List def remove_punctuation(sentence: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import string def remove_punctuation(sentence: str) -> str: """ Removes all punctuation marks from the given ASCII string. Args: sentence (str): The input string from which punctuation marks...
magic_evol_110k
88,623
Write a Python function to identify all prime numbers within a specified list of numerical values, including nested lists. The function should return a list of prime numbers sorted in ascending order. The function should be implemented using a lambda function combined with a filter operation. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union import math def find_primes_in_list(data: Union[List[int], List[Union[int, List[int]]]]) -> List[int]: """ Identify all prime numbers within a specified list of numerical values, including nested ...
magic_evol_110k
88,624
Write a Python function that takes a list of integers as input and identifies all prime numbers within the list. The function should print each prime number along with its original index in the list. For composite numbers (non-prime numbers), the function should print "composite" next to their index position. The code...
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 given integer n is a prime number. Args: n (int): The integer to check for primality. Returns: bool: True if n is a prime number, ...
magic_evol_110k
88,626
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 optimized for time complexity and should correctly handle all possible input cases, including strings with non-alphabetic characters and case sensitiv...
Here is the Python code to solve the given problem in the markdown block: ```python def is_pangram(s: str) -> bool: """ Determine if the 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-alphabetic ...
magic_evol_110k
88,636
Write a Python function to generate an hourglass shape using asterisks (`*`). The hourglass shape consists of a pyramid followed by an inverted pyramid, both aligned such that the base of the pyramid and the apex of the inverted pyramid are perfectly aligned, forming a symmetrical hourglass shape. The function should t...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_hourglass(rows: int): """ Generates an hourglass shape using asterisks. The hourglass shape consists of a pyramid followed by an inverted pyramid, both aligned such that the base of the pyramid and the apex...
magic_evol_110k
88,645
Write a Python function to merge two lists of dictionaries, where each dictionary has a unique key, into a single list. If there are duplicate keys in both lists, the function should return a collection of these duplicate keys. Additionally, the function should handle cases where one or both lists are empty. The code s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any, Set def merge_lists_with_unique_keys(list1: List[Dict[Any, Any]], list2: List[Dict[Any, Any]]) -> (List[Dict[Any, Any]], Set[Any]): """ Merges two lists of dictionaries with unique keys into ...
magic_evol_110k
88,659
Write a Python function to interweave a fresh and unrepeated key-value pair into an existing dictionary structure. If the key already exists in the dictionary, the function should return the original dictionary without any modifications. The function should start with: ```python from typing import Dict, Any def interw...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def interweave_key_value(existing_dict: Dict[str, Any], new_key: str, new_value: Any) -> Dict[str, Any]: """ Interweave a fresh and unrepeated key-value pair into an existing dictionary. If the ...
magic_evol_110k
88,682
Write a Python function to remove duplicates from a list of integers and sort the remaining elements in descending order. The input list can contain up to 100,000 elements, each ranging from -100,000 to 100,000. The function should be efficient and handle large inputs effectively. 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 remove_duplicates_and_sort_desc(list_of_integers: List[int]) -> List[int]: """ Removes duplicates from a list of integers and sorts the remaining elements in descending order. Args: list...
magic_evol_110k
88,690
Write a Python function to find and return the maximum numeric value in a list that can contain a mix of different data types (integers, floats, strings). Handle the situation where the provided list is empty or contains no numeric values. The function should return `None` in such cases. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_maximum_numeric_value(input_list: List[Union[int, float, str]]) -> Union[int, float, None]: """ Find and return the maximum numeric value in a list containing a mix of different data type...
magic_evol_110k
88,696
Write a Python function to remove consecutive duplicate characters from a given string. The function should return a new string where all successive duplicate characters have been removed. The code should start with: ```python def remove_consecutive_duplicates(input_string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def remove_consecutive_duplicates(input_string: str) -> str: """ Removes consecutive duplicate characters from the given string. Args: input_string (str): The input string from which to remove consecutive duplicates...
magic_evol_110k
88,699
Write a Python function to remove duplicates from a given list without using any built-in Python functions or libraries. The function should be memory efficient and consider time complexity. The function should start with: ```python def remove_duplicates(input_list: list) -> list: ```
Here is the Python code to solve the given problem in the markdown block: ```python def remove_duplicates(input_list: list) -> list: """ Removes duplicates from a given list without using any built-in Python functions or libraries. Args: input_list (list): The list from which duplicates are to be r...
magic_evol_110k
88,702
Write a Python function to merge two sorted lists in ascending order and then reverse their elements. The function should handle lists of various sizes and should not use built-in Python methods for sorting and reversing. The code should start with: ```python from typing import List def merge_and_reverse(list1: List[i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_and_reverse(list1: List[int], list2: List[int]) -> List[int]: """ Merges two sorted lists in ascending order and then reverses the merged list. Args: list1 (List[int]): The first s...
magic_evol_110k
88,704
Write a Python function to calculate the absolute difference between two numbers. The function should take two numerical inputs and return the absolute value of their difference. The code should start with: ```python def absolute_difference(num1: float, num2: float) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def absolute_difference(num1: float, num2: float) -> float: """ Calculate the absolute difference between two numbers. Args: num1 (float): The first number. num2 (float): The second number. Returns: ...
magic_evol_110k
88,714
Write a Python function to compute the scalar product of two given arrays `a` and `b`, and then perform element-wise multiplication of the resulting scalar product with a third array `c`. The final result should be stored back in the array `c`. The function should not use any standard library functions for the calculat...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def compute_and_multiply(a: List[int], b: List[int], c: List[int]) -> List[int]: """ Computes the scalar product of arrays `a` and `b`, and then performs element-wise multiplication of the resulting scal...
magic_evol_110k
88,719
Write a Python function to find and print the maximum and minimum item from a given list, without using any pre-built list functions like `min()`, `max()`, or `index()`. Additionally, print the index positions of these items in the list. The code should start with: ```python from typing import List, Tuple def find_mi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_min_max_with_indices(arr: List[int]) -> Tuple[int, int, int, int]: """ Find the minimum and maximum items in the given list along with their indices. Args: arr (List[int]): T...
magic_evol_110k
88,743
Write a Python function to extract the value of the element located at a specified position in a given numerical series. The function should handle cases where the specified position is out of bounds by returning `None`. The code should start with: ```python from typing import List, Optional def extract_element_at_po...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def extract_element_at_position(series: List[int], position: int) -> Optional[int]: """ Extracts the value of the element located at the specified position in the given numerical series. A...
magic_evol_110k
88,757
Write a Python function to find the smallest element in an array that satisfies a given condition, and return its value along with its index. If no elements satisfy the condition, return an empty list. If multiple elements satisfy the condition and share the same minimum value, return the one with the smallest index. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable, Union def pluck(arr: List[int], cond_fn: Callable[[int], bool]) -> Union[List[int], List]: """ Finds the smallest element in an array that satisfies a given condition and returns its value alo...
magic_evol_110k
88,761
Write a Python function to find and return the indices of all occurrences of a specified element within a given array. The function should handle arrays of any data type and return a list of indices where the specified element is found. The code should start with: ```python from typing import List, Any def find_all_in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def find_all_indices(array: List[Any], element: Any) -> List[int]: """ Find and return the indices of all occurrences of a specified element within a given array. Args: array (List[Any]...
magic_evol_110k
88,764
Write a Python function to detect the lowest points (nadirs) within a list of numerical values. A nadir is defined as a point in the list that is lower than both its immediate neighbors. The function should return a list of these nadirs. The code should start with: ```python from typing import List def find_nadirs(nu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_nadirs(nums: List[int]) -> List[int]: """ Detects the lowest points (nadirs) within a list of numerical values. A nadir is defined as a point in the list that is lower than both its immedia...
magic_evol_110k
88,776
Write a Python function to calculate the number of decades in a given number of years. The function should take an integer representing the number of years and return an integer representing the number of decades. If the input is less than 10, the function should return 0, as a decade consists of at least 10 years. Th...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_decades(years: int) -> int: """ Calculate the number of decades in a given number of years. Args: years (int): The number of years to convert into decades. Returns: int: The number of deca...
magic_evol_110k
88,777
Write a Python function to convert a given Roman numeral string to its corresponding decimal (integer) value. The Roman numeral system uses symbols to represent values as follows: 'I' (1), 'V' (5), 'X' (10), 'L' (50), 'C' (100), 'D' (500), 'M' (1000). The function should handle cases where a smaller numeral precedes a ...
Here is the Python code to solve the given problem in the markdown block: ```python def roman_to_decimal(roman: str) -> int: """ Converts a Roman numeral string to its corresponding decimal (integer) value. Args: roman (str): The Roman numeral string to be converted. Returns: int: The ...
magic_evol_110k
88,785
Write a Python function to convert a given list of integers into a list of their corresponding Roman numeral representations. The function should handle integers from 1 to 3999. The code should start with: ```python from typing import List def int_to_roman(nums: List[int]) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def int_to_roman(nums: List[int]) -> List[str]: """ Converts a list of integers to their corresponding Roman numeral representations. Args: nums (List[int]): A list of integers to be convert...
magic_evol_110k
88,788
Write a Python function to convert a given string into its binary representation using the ASCII standard for each character. The function should return a string where each byte (8 bits) of the binary representation is separated by a space. The code should start with: ```python def string_to_binary(s: str) -> str: ```...
Here is the Python code to solve the given problem in the markdown block: ```python def string_to_binary(s: str) -> str: """ Converts a given string into its binary representation using the ASCII standard. Args: s (str): The input string to be converted. Returns: str: A string where ea...
magic_evol_110k
88,791
Write a Python function to find the most frequently occurring item in a given array. If there are multiple items with the same highest frequency, return the first one encountered in the array. The function should handle arrays with any type of elements, including integers, strings, and other data types. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def most_frequent_item(array: List[Any]) -> Any: """ Find the most frequently occurring item in a given array. Args: array (List[Any]): The array from which to find the most frequent it...
magic_evol_110k
88,809
Write a Python function to generate a hint for the Bulls and Cows game based on the given secret number and a guess. The hint should be formatted as "xAyB", where `x` is the number of bulls (digits in the guess that are in the correct position) and `y` is the number of cows (digits in the guess that are in the secret n...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple import random import collections def get_hint(secret: str, guess: str) -> str: """ Generates a hint for the Bulls and Cows game based on the given secret number and a guess. Args: secret (s...
magic_evol_110k
88,814
Write a Python function to filter a dictionary and remove key-value pairs where the value is less than a specified threshold. The function should return the filtered dictionary. The code should start with: ```python from typing import Dict def filter_dictionary(dictionary: Dict[str, int], threshold: int) -> Dict[str,...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def filter_dictionary(dictionary: Dict[str, int], threshold: int) -> Dict[str, int]: """ Filters a dictionary to remove key-value pairs where the value is less than the specified threshold. Args: ...
magic_evol_110k
88,850
Write a Python function to parse and extract nested values from a JSON-like string representing a GitHub event payload. The function should take a JSON-like string and a list of keys representing the path to the desired value, and return the value at that path. If the path does not exist, the function should return `No...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional import json def extract_nested_value(payload: str, keys: List[str]) -> Optional[str]: """ Extracts a nested value from a JSON-like string based on a list of keys. Args: payload (st...
magic_evol_110k
88,873
Write a Python function to randomly select an integer from a given two-dimensional array of numerical elements ranging from one to five. The function should also return the index positions (row and column) of the chosen integer in the array. The code should start with: ```python from typing import Tuple, List import ra...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, List import random def choose_random_element(array: List[List[int]]) -> Tuple[int, Tuple[int, int]]: """ Randomly selects an integer from a given two-dimensional array and returns the integer along wit...
magic_evol_110k
88,874
Write a Python function to determine if a given number is divisible by 5. If the number is divisible by 5, the function should return the string "Good Day". Otherwise, it should return the string "The number is not perfectly divisible by 5". The code should start with: ```python def check_divisibility_by_5(number: int...
Here is the Python code to solve the given problem in the markdown block: ```python def check_divisibility_by_5(number: int) -> str: """ Check if the given number is divisible by 5 and return a specific string based on the result. Args: number (int): The number to check for divisibility by 5. ...
magic_evol_110k
88,877
Write a Python function to merge two given arrays of numerical elements and return a new array where each element is the sum of the corresponding elements from the two input arrays. If the arrays are of different lengths, the function should handle the extra elements by appending them to the result array as they are. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_and_sum_arrays(array1: List[int], array2: List[int]) -> List[int]: """ Merges two arrays of numerical elements and returns a new array where each element is the sum of the corresponding element...
magic_evol_110k
88,888
Write a Python function to determine whether each element in a given list of integers is a prime number. The function should return a list of booleans where each boolean corresponds to whether the respective integer in the input list is a prime number. The code should start with: ```python from typing import List def...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_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, Fal...
magic_evol_110k
88,889
Write a Python function to intersperse a delimiter between each pair of consecutive integers in a list, while also validating that the list is strictly ascending. If the list is not strictly ascending, the function should return `None`. The function should take a list of integers `numbers` and an integer `delimiter` as...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def intersperse(numbers: List[int], delimiter: int) -> Optional[List[int]]: """ Intersperses the given delimiter between each pair of consecutive integers in the list. Additionally, validat...
magic_evol_110k
88,892
Write a Python function to extract all unique digits and letters from a given string and provide a frequency count of each unique digit and letter that occurs in the string. The function should return a dictionary where the keys are the unique digits and letters, and the values are their respective frequencies. The co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict from collections import Counter def extract_unique_chars_with_frequency(s: str) -> Dict[str, int]: """ Extracts all unique digits and letters from a given string and provides a frequency count of each un...
magic_evol_110k
88,895
Write a Python function to calculate the absolute product of the last digits of two given integers. The function should convert the integers to strings, extract the last digits, convert them back to integers, multiply them, and return the absolute value of the product. The code should start with: ```python def multipl...
Here is the Python code to solve the given problem in the markdown block: ```python def multiply_last_digits(a: int, b: int) -> int: """ Calculate the absolute product of the last digits of two given integers. Args: a (int): The first integer. b (int): The second integer. Returns: ...
magic_evol_110k
88,901
Write a Python function to calculate the height of a strictly binary tree given the number of nodes `N`. A strictly binary tree is a tree where every non-leaf node has exactly two children. The height of the tree is defined as the number of edges in the longest path from the root to a leaf. The function should handle t...
Here is the Python code to solve the given problem in the markdown block: ```python import math def calculate_binary_tree_height(N: int) -> int: """ Calculate the height of a strictly binary tree given the number of nodes N. Args: N (int): The number of nodes in the binary tree. Returns: ...
magic_evol_110k
88,905
Write a Python function to filter out and return a list of even numbers from a given list of integers. The function should be efficient and should handle lists of varying sizes. The code should start with: ```python from typing import List def filter_even_numbers(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 filter_even_numbers(numbers: List[int]) -> List[int]: """ Filters out and returns a list of even numbers from the given list of integers. Args: numbers (List[int]): A list of integers fr...
magic_evol_110k
88,924
Write a Python function to find the smallest prime number in a given list of integers. If the list contains no prime numbers, the function should return `None`. The function should be efficient and handle various edge cases, such as an empty list or a list with no prime numbers. 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, Optional 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...
magic_evol_110k
88,925
Write a Python function to insert a value at a specified index in an array and then delete the element at the same index without using built-in functions for adding or reducing the length of an array. The function should handle exceptions such as index out of bounds. 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 def insert_and_delete_element(arr: List[int], idx: int, value: int) -> List[int]: """ Inserts a value at a specified index in an array and then deletes the element at the same index without using bui...
magic_evol_110k
88,942
Write a Python function named `is_prime_and_largest_prime_factor` that takes an integer `n` as input and returns a tuple `(is_prime, largest_prime_factor)`. The first element of the tuple, `is_prime`, is a boolean indicating whether `n` is a prime number. The second element, `largest_prime_factor`, is the greatest prim...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime_and_largest_prime_factor(n: int) -> tuple: """ Determine if the given integer `n` is a prime number and find its largest prime factor. Args: n (int): The integer to check for primality and find the larg...
magic_evol_110k
88,953
Write a Python function to generate all unique combinations of three elements from a given list of integers. The function should be highly efficient in terms of both time and space complexity. The function should not use any in-built Python libraries, functions, or data structures except for lists. Implement your own m...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_combinations(num_list: List[int]) -> List[tuple]: """ Generates all unique combinations of three elements from the given list of integers. Args: num_list (List[int]): The list o...
magic_evol_110k
88,956
Write a Python function to compute the Fibonacci sequence for a given number \( N \) efficiently, handling input validation and optimizing for large values of \( N \) up to 5000. The function should avoid recursion errors and use efficient memory usage. 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: """ Compute the Fibonacci sequence for a given number N efficiently. Args: n (int): The position in the Fibonacci sequence to compute. Returns: int: The Fibonacci number at...
magic_evol_110k
88,967
Write a Python function to convert a given binary number to its equivalent octal notation. The function should handle the conversion by grouping the binary digits into sets of three, converting each group to its octal equivalent, and then concatenating the results. The function should also handle padding the binary num...
Here is the Python code to solve the given problem in the markdown block: ```python def binary_to_octal(binary_num: str) -> str: """ Converts a given binary number to its equivalent octal notation. Args: binary_num (str): The binary number to be converted, represented as a string. Returns: ...
magic_evol_110k
88,976
Write a Python function to greet a user based on their name. If the name is "John", the function should return "Hello, John". For any other name, the function should return "Name not found". The function should handle the case where the input name is not a string and return "Invalid input". The code should start with:...
Here is the Python code to solve the given problem in the markdown block: ```python def greet_user(name): """ Greet a user based on their name. Args: name: The name of the user. Returns: str: A greeting message. Returns "Hello, John" if the name is "John", "Name not found"...
magic_evol_110k
88,978
Write a Python function to filter out words from a given list that can be typed using only the letters from a single row of the American keyboard. The function should return a list of such words. The American keyboard has three rows: - Top row: `"qwertyuiop"` - Middle row: `"asdfghjkl"` - Bottom row: `"zxcvbnm"` The f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_words_by_keyboard_row(words: List[str]) -> List[str]: """ Filters out words from a given list that can be typed using only the letters from a single row of the American keyboard. Args: ...
magic_evol_110k
88,986
Write a Python function to find the smallest positive integer that is not present in a given list of integers. The function should handle arrays with negative numbers and non-contiguous sequences efficiently. The code should start with: ```python from typing import List def find_smallest_missing_positive(arr: List[in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_smallest_missing_positive(arr: List[int]) -> int: """ Finds the smallest positive integer that is not present in the given list. Args: arr (List[int]): The list of integers to searc...
magic_evol_110k
89,014
Write a Python function to determine if a given integer is a prime number. The function should handle different types of inputs and edge cases, including non-integer inputs, negative numbers, zero, and one. The function should also optimize the prime-checking process by only checking up to the square root of the number...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n: int) -> bool: """ Determines if a given integer is a prime number. Args: n (int): The integer to check for primality. Returns: bool: True if the integer is prime, False otherwise. R...
magic_evol_110k
89,023
Write a Python function to convert a given hexadecimal string into a binary string. Additionally, create a secondary function to verify if the binary conversion is correct by re-converting the binary string back to the original hexadecimal string. Ensure that your solution can handle large hexadecimal strings of up to ...
Here is the Python code to solve the given problem in the markdown block: ```python def hex_to_bin(hex_string: str) -> str: """ Convert a given hexadecimal string into a binary string. Args: hex_string (str): The hexadecimal string to be converted. Returns: str: The binary string repre...
magic_evol_110k
89,026
Write a Python function to print all elements of a list of strings, along with the count of occurrences of a specified character in each string. The function should iterate through each string in the list, count the occurrences of the specified character, and print the string followed by the count. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_strings_with_char_count(strings: List[str], char: str) -> None: """ Prints each string in the list along with the count of occurrences of a specified character in each string. Args: ...
magic_evol_110k
89,028
Write a Python function to identify and return the first three words from a given text string. If the text contains fewer than three words, return the entire text. The function should handle cases where the input text is empty or contains only one or two words. 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 first_three_words(text: str) -> str: """ Extracts and returns the first three words from the given text string. If the text contains fewer than three words, returns the entire text. Args: ...
magic_evol_110k
89,038
Write a Python function to remove all duplicate characters from a given string while preserving the order of the first occurrences of each character. The function should return the modified string. The code should start with: ```python def remove_duplicate_characters(string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def remove_duplicate_characters(string: str) -> str: """ Removes all duplicate characters from the given string while preserving the order of the first occurrences of each character. Args: string (str): The input st...
magic_evol_110k
89,047
Write a Python function to compute the cumulative sum and product of the individual numerals within a given range of positive natural numbers. The function should handle potential anomalies, such as zero in the multiplication sequence. The code should start with: ```python def compute_cumulative_sum_and_product(start: ...
Here is the Python code to solve the given problem in the markdown block: ```python def compute_cumulative_sum_and_product(start: int, end: int) -> tuple: """ Computes the cumulative sum and product of the individual numerals within a given range of positive natural numbers. Args: start (int): The ...
magic_evol_110k
89,055
Write a Python function to find and return the sorted distinct common elements between two lists without using any built-in Python list functions or set operations. Implement custom functions for sorting and duplicate removal. Additionally, incorporate functional programming concepts to achieve the goal. The function s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(lst: List[int]) -> List[int]: """ Sorts the elements of a list in ascending order using the merge sort algorithm. Args: lst (List[int]): The list to be sorted. Returns: ...
magic_evol_110k
89,059
Write a Python function to find all the prime numbers from 2 to a given number `n` and their corresponding prime factors in descending order. Additionally, implement a check against a secondary input `k` which represents the maximum prime number size. If a prime number found exceeds `k`, exclude it from the results. Th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def find_prime_numbers_and_factors(n: int, k: int) -> Dict[int, List[int]]: """ Find all prime numbers from 2 to n and their corresponding prime factors in descending order, excluding primes gr...
magic_evol_110k
89,064
Write a Python function to calculate the mean (average) of a given list of integers. The function should handle lists of any length, including empty lists, and return the mean as a float. If the list is empty, the function should return 0.0 to avoid division by zero. The code 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 calculate_mean(numbers: List[int]) -> float: """ Calculate the mean (average) of a list of integers. Args: numbers (List[int]): A list of integers for which the mean is to be calculated....
magic_evol_110k
89,070
Write a Python function to implement the Cocktail Shaker Sort algorithm, which sorts an array in ascending order. The function should start with: ```python from typing import List def cocktail_shaker_sort(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 cocktail_shaker_sort(arr: List[int]) -> List[int]: """ Sorts the given array in ascending order using the Cocktail Shaker Sort algorithm. Args: arr (List[int]): The array to be sorted. ...
magic_evol_110k
89,075
Write a Python function to find the maximum element of each sublist within a list of sublists. The function should return a new list where each sublist contains only the maximum element of the corresponding sublist in the input list. The code should start with: ```python from typing import List def find_max_elements(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_elements(nested_list: List[List[List[float]]]) -> List[List[float]]: """ Find the maximum element of each sublist within a list of sublists and return a new list where each sublist conta...
magic_evol_110k
89,076
Write a Python function to determine if one list of numbers is a subset of another list of numbers, ensuring that there are no repeated elements in either list. The function should return `True` if the first list is a subset of the second list, and `False` otherwise. 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 def is_subset_without_repeats(list1: List[int], list2: List[int]) -> bool: """ Determines if list1 is a subset of list2 without any repeated elements in either list. Args: list1 (List[int]):...
magic_evol_110k
89,081
Write a Python function to merge two ordered numerical sequences into a single ordered sequence efficiently. The function should take two lists of integers as input, where each list is already sorted in ascending order. The function should return a new list that contains all elements from both input lists, also sorted ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_ordered_sequences(seq1: List[int], seq2: List[int]) -> List[int]: """ Merges two ordered numerical sequences into a single ordered sequence. Args: seq1 (List[int]): The first order...
magic_evol_110k
89,088
Write a Python function to concatenate two strings with a specified delimiter between them. The function should take three parameters: the first string, the second string, and an optional delimiter. If the delimiter is not provided, it should default to an empty string. The function should return the concatenated strin...
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_with_delimiter(string_1: str, string_2: str, delimiter: str = '') -> str: """ Concatenates two strings with a specified delimiter between them. Args: string_1 (str): The first string to be concatenat...
magic_evol_110k
89,099
Write a Python function that processes a list containing both strings and integers. The function should separate the integers from the strings into two different lists. Additionally, the function should provide a mechanism to swap two elements in the integer list based on given indices. The function should not use any ...
Here is the Python code to solve the given problem in the markdown block: ```python def process_list(data, ind1=-1, ind2=-1): """ Processes a list containing both strings and integers, separating them into two lists. Optionally, swaps two elements in the integer list based on provided indices. Args: ...
magic_evol_110k
89,105
Write a Python function to find the integer with the maximum absolute value from a given list of integers. The function should handle both positive and negative integers. The code should start with: ```python from typing import List def find_max_abs_value(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_abs_value(numbers: List[int]) -> int: """ Find the integer with the maximum absolute value from a given list of integers. Args: numbers (List[int]): A list of integers from whic...
magic_evol_110k
89,130
Write a Python function to remove all whitespace characters (spaces, tabs, and newline characters) from a given string. The function should be efficient and handle various types of whitespace characters. The code should start with: ```python def remove_whitespace(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def remove_whitespace(s: str) -> str: """ Removes all whitespace characters (spaces, tabs, and newline characters) from the given string. Args: s (str): The input string from which to remove whitespace characters. ...
magic_evol_110k
89,131
Write a Python function to find the smallest number among three given whole numbers. The function should take three integers as input and return the smallest one. The code should start with: ```python def find_smallest_number(a: int, b: int, c: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def find_smallest_number(a: int, b: int, c: int) -> int: """ Find the smallest number among three given whole numbers. Args: a (int): The first whole number. b (int): The second whole number. c (int)...
magic_evol_110k
89,132
Write a Python function to convert a list of tuples into a dictionary, ensuring that duplicate keys are handled appropriately. If a duplicate key is encountered, the function should print a warning message and not update the dictionary with the duplicate key. The function should be able to handle any list of tuples and...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def list_to_dict(lst: List[Tuple[str, int]]) -> Dict[str, int]: """ Converts a list of tuples into a dictionary, handling duplicate keys by printing a warning message. Args: lst...
magic_evol_110k
89,145
Write a Python function to determine if two given strings can be rearranged to form anagrams of each other. The function should return a boolean value indicating whether the strings are anagrams. The function should handle alphanumeric characters and ignore case sensitivity. The code should start with: ```python from ...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import Counter def are_anagrams(string1: str, string2: str) -> bool: """ Determine if two strings can be rearranged to form anagrams of each other. Args: string1 (str): The first string to check. ...
magic_evol_110k
89,146
Write a Python function to extract all valid email addresses from a given text using regular expressions. The function should be able to handle various formats of email addresses, including those with dots, underscores, and dashes in the local part and domain part of the email. The function should also ensure that the ...
Here is the Python code to solve the given problem in the markdown block: ```python import re def extract_valid_emails(text: str) -> list: """ Extracts all valid email addresses from the given text using regular expressions. Args: text (str): The text from which to extract email addresses. Re...
magic_evol_110k
89,151
Write a Python function to remove the last character from a given string. The function should handle cases where the input string is empty or has only one character. The code should start with: ```python def remove_last_character(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def remove_last_character(s: str) -> str: """ Removes the last character from the given string. Args: s (str): The input string from which the last character is to be removed. Returns: str: The string w...
magic_evol_110k
89,154
Write a Python function to remove an element from a list at a specified index. The function should handle cases where the index is out of bounds by returning the original list unchanged. The function should also handle negative indices correctly. The code should start with: ```python from typing import List def remov...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_element_at_index(my_list: List[int], index: int) -> List[int]: """ Removes an element from the list at the specified index. Args: my_list (List[int]): The list from which to remov...
magic_evol_110k
89,159
Write a Python function to concatenate an array of individual alphabetic characters into a single, continuous textual string. The function should handle any list of characters, including spaces and special characters. The code should start with: ```python from typing import List def concatenate_characters(characters: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def concatenate_characters(characters: List[str]) -> str: """ Concatenates an array of individual alphabetic characters into a single, continuous textual string. Args: characters (List[str])...
magic_evol_110k
89,168
Write a Python function to create a MongoDB document for storing a musician's profile. The document should include the following fields: `stage_name`, `email_address`, and `artist_image`. The function should return a dictionary representing the document. The code should start with: ```python from typing import Dict de...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def create_musician_profile(stage_name: str, email_address: str, artist_image: str) -> Dict: """ Creates a MongoDB document for storing a musician's profile. Args: stage_name (str): The stag...
magic_evol_110k
89,178
Write a Python function to compute the sum of two integers without using the `+` operator. The function should use bitwise operations to achieve the sum. The function should be able to handle both positive and negative integers. The code should start with: ```python def add_without_plus(x: int, y: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def add_without_plus(x: int, y: int) -> int: """ Computes the sum of two integers using bitwise operations, without using the '+' operator. Args: x (int): The first integer to be added. y (int): The second i...
magic_evol_110k
89,181
Write a Python function to calculate the frequency distribution of individual alphabetical characters in a given string. The function should return a dictionary where the keys are the characters and the values are their respective frequencies. The function should be case-insensitive, meaning 'A' and 'a' should be treat...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def character_frequency(word: str) -> Dict[str, int]: """ Calculate the frequency distribution of individual alphabetical characters in a given string. Args: word (str): The input string for...
magic_evol_110k
89,183
Write a Python function to sort a given list of numbers in ascending order using the merge sort algorithm. The merge sort algorithm is a divide-and-conquer algorithm that recursively divides the list into halves until each sublist contains a single element, then merges these sublists back together in sorted order. The...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(number_list: List[int]) -> List[int]: """ Sorts a given list of numbers in ascending order using the merge sort algorithm. Args: number_list (List[int]): The list of numbers t...
magic_evol_110k
89,187
Write a Python function to combine two lists of fruit names, removing any duplicates, and return the combined list in alphabetical order. The function should handle lists of varying lengths and ensure that the final list contains only unique fruit names. The code should start with: ```python from typing import List d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def combine_fruit_lists(arr1: List[str], arr2: List[str]) -> List[str]: """ Combines two lists of fruit names, removes duplicates, and returns the combined list in alphabetical order. Args: ...
magic_evol_110k
89,193
Write a Python function to filter a list of integers, retaining only those values that are perfectly divisible by 2, and then sort the filtered list in descending order. The function should handle both positive and negative integers. The code should start with: ```python from typing import List def filter_and_sort_di...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_and_sort_divisible_by_2(lst: List[int]) -> List[int]: """ Filters the given list of integers to retain only those values that are perfectly divisible by 2, and then sorts the filtered list...
magic_evol_110k
89,196
Write a Python function to replace all spaces in a given string with underscores. The function should handle strings of varying lengths, including empty strings, and should not modify any other characters in the string. The code should start with: ```python def replace_spaces_with_underscores(text: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def replace_spaces_with_underscores(text: str) -> str: """ Replace all spaces in the given string with underscores. Args: text (str): The input string in which spaces need to be replaced. Returns: str: ...
magic_evol_110k
89,199
Write a Python function to add two large numbers represented as arrays of digits in reverse order. Each array simulates a large number where each element is a single digit of the number, with the least significant digit at index zero. The function should return the result in the same format (an array of digits in rever...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def add_large_numbers(number1: List[int], number2: List[int]) -> List[int]: """ Adds two large numbers represented as arrays of digits in reverse order. Args: number1 (List[int]): The first ...
magic_evol_110k
89,202
Write a Python function to find the largest numerical value from an input array of integers and report all indices where this value appears. The function should handle edge cases such as an empty array and arrays with multiple occurrences of the maximum value. The input array can be very large, scaling up to ten millio...
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_indices(array: List[int]) -> Union[str, Tuple[int, List[int]]]: """ Finds the largest numerical value in the input array and returns the value along with all indices where ...
magic_evol_110k
89,211
Write a Python function to process an iterable collection of integer values and return a list of distinct elements sorted in ascending order. The function should handle any iterable input, such as lists, tuples, or sets. The code should start with: ```python from typing import Iterable, List def process_elements(inpu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Iterable, List def process_elements(input_collection: Iterable[int]) -> List[int]: """ Processes an iterable collection of integer values and returns a list of distinct elements sorted in ascending order. ...
magic_evol_110k
89,224
Write a Python function to transform a given text by converting all capitalized letters to lowercase and replacing all punctuation marks with spaces. The function should handle any string input and return the transformed string. The code should start with: ```python import string def transform_text(text: str) -> str:...
Here is the Python code to solve the given problem in the markdown block: ```python import string def transform_text(text: str) -> str: """ Transforms the given text by converting all capitalized letters to lowercase and replacing all punctuation marks with spaces. Args: text (str): The input text...
magic_evol_110k
89,229
Write a Python function to eliminate redundant numerical values from a list of lists, ensuring that each sublist contains only unique values. The function should return a new list of lists where each sublist has its duplicates removed, while preserving the order of the first occurrence of each unique element. The code...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def eliminate_redundant_values(list_of_lists: List[List[int]]) -> List[List[int]]: """ Eliminates redundant numerical values from a list of lists, preserving the order of the first occurrence of each uni...
magic_evol_110k
89,240
Write a Python function to generate an 'n x n' identity matrix and provide a function to convert the resulting identity matrix into a sparse matrix representation. The sparse matrix representation should be a list of tuples, where each tuple contains the row index, column index, and the value of the non-zero elements. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def generate_identity_matrix(n: int) -> List[List[int]]: """ Generate an 'n x n' identity matrix. Args: n (int): The size of the identity matrix. Returns: List[List[int]]...
magic_evol_110k
89,242
Write a Python function to determine if two provided input strings have the same unique words, considering case sensitivity and ignoring any punctuation marks or numbers. The function should return `True` if the two strings have the same unique words, and `False` otherwise. The code should start with: ```python import...
Here is the Python code to solve the given problem in the markdown block: ```python import string def compare_word_sets(phrase1: str, phrase2: str) -> bool: """ Determines if two provided input strings have the same unique words, considering case sensitivity and ignoring punctuation and numbers. Args: ...
magic_evol_110k
89,247
Write a Python function to calculate the mean of a list of integers accurately and efficiently. The function should be robust enough to handle large lists (with lengths over 10,000) within a reasonable time frame. The function should also include input validation to ensure the list is not empty. The code should start ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_mean(numbers: List[int]) -> float: """ Calculate the mean of a list of integers. Args: numbers (List[int]): A list of integers for which the mean is to be calculated. Retu...
magic_evol_110k
89,251
Write a Python function to calculate the absolute difference between corresponding elements of two integer lists. The function should return a new list where each element is the absolute difference between the corresponding elements from the two input lists. If the input lists are of different lengths, the function sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_difference(l1: List[int], l2: List[int]) -> List[int]: """ Calculate the absolute difference between corresponding elements of two integer lists. Args: l1 (List[int]): The first lis...
magic_evol_110k
89,253
Write a Python function to extract email addresses from a list of strings using regular expressions. The function should be able to handle various formats of email addresses and return a list of all found email addresses. The code should start with: ```python from typing import List import re def extract_emails(text_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def extract_emails(text_list: List[str]) -> List[str]: """ Extracts email addresses from a list of strings using regular expressions. Args: text_list (List[str]): A list of strings...
magic_evol_110k
89,269
Write a Python function to create an unpopulated dictionary and insert a specified number of key-value pairs into it. The function should return the populated dictionary. The code should start with: ```python from typing import Dict, List, Tuple def create_and_populate_dict(key_value_pairs: List[Tuple[str, str]]) -> D...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def create_and_populate_dict(key_value_pairs: List[Tuple[str, str]]) -> Dict[str, str]: """ Creates an unpopulated dictionary and inserts the specified key-value pairs into it. Args: ...
magic_evol_110k
89,270
Write a Python function to convert a binary number represented as a string into its equivalent decimal number. The function should handle binary numbers of any length and should return the decimal equivalent. The code should start with: ```python def binary_to_decimal(binary: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def binary_to_decimal(binary: str) -> int: """ Converts a binary number represented as a string to its equivalent decimal number. Args: binary (str): The binary number to be converted, represented as a string. ...
magic_evol_110k
89,282
Write a Python function to filter a list based on a condition function that includes multiple reasoning steps. The condition function should be designed to filter out elements that are either even numbers or numbers greater than a specified threshold. The function should start with: ```python from typing import List, C...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable def pluck(arr: List[int], cond_fn: Callable[[int], bool]) -> List[int]: """ Filters a list of integers based on a condition function that includes multiple reasoning steps. Args: a...
magic_evol_110k
89,283
Write a Python function to find the middle-most element in a given list of integers. If the list has an even number of elements, return the element at the index just before the middle. The function should handle lists of any length, including empty lists. The code should start with: ```python from typing import List ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_middle_element(arr: List[int]) -> int: """ Find the middle-most element in a given list of integers. If the list has an even number of elements, return the element just before the middle. ...
magic_evol_110k
89,289
Write a Python function to sort a given list of strings that contains both fruit names and animal names in alphabetical order. The function should handle lists of varying lengths and ensure that the sorting is case-insensitive. The code should start with: ```python from typing import List def sort_mixed_list(items: Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_mixed_list(items: List[str]) -> List[str]: """ Sorts a given list of strings containing both fruit names and animal names in alphabetical order. Args: items (List[str]): The list of...
magic_evol_110k
89,304
Write a Python function to convert a MySQL timestamp string to epoch time. The MySQL timestamp format is `YYYY-MM-DD HH:MM:SS`. The function should handle the conversion efficiently and return the epoch time as an integer. The code should start with: ```python import datetime def mysql_timestamp_to_epoch(mysql_timest...
Here is the Python code to solve the given problem in the markdown block: ```python import datetime def mysql_timestamp_to_epoch(mysql_timestamp: str) -> int: """ Convert a MySQL timestamp string to epoch time. Args: mysql_timestamp (str): The MySQL timestamp string in the format 'YYYY-MM-DD HH:MM...
magic_evol_110k
89,323
Write a Python function to compress a given string by replacing all repeating characters with a single instance and its count. If a character does not repeat, it should be included in the result without any count. The function should handle strings of any length, including empty strings. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python def compress_string(s: str) -> str: """ Compresses a given string by replacing all repeating characters with a single instance and its count. If a character does not repeat, it is included in the result without any count. ...
magic_evol_110k
89,324
Write a Python function to compute the discounted price of an item given the original cost and a discount rate. The function should handle cases where the discount rate is not provided by using a default discount rate of 15%. The function should also ensure that the discount rate is within a valid range (0 to 1). If th...
Here is the Python code to solve the given problem in the markdown block: ```python def compute_discounted_price(cost: float, discount_rate: float = 0.15) -> float: """ Compute the discounted price of an item given the original cost and a discount rate. Args: cost (float): The original price of the...
magic_evol_110k
89,363
Write a Python function to generate a random number within a specified range. The function should allow the user to specify a range within 1 to 100 from which the random number should be generated. The function should also handle any invalid range inputs by the user, such as non-integer values, ranges outside the 1 to ...
Here is the Python code to solve the given problem in the markdown block: ```python import random def generate_random_number(range_start: int = 1, range_end: int = 100) -> int: """ Generates a random number within a specified range. Args: range_start (int): The start of the range (default is 1). ...
magic_evol_110k
89,365
Write a Python function to transform a given textual string into an array of distinct words, sorted in lexicographical order. The function should handle multiple spaces and leading/trailing spaces gracefully. The code should start with: ```python from typing import List def distinct_words_sorted(text: str) -> List[str...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def distinct_words_sorted(text: str) -> List[str]: """ Transforms a given textual string into an array of distinct words, sorted in lexicographical order. Args: text (str): The input textual...
magic_evol_110k
89,369
Create 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 rows ...
magic_evol_110k
89,371
Write a Python function to multiply two matrices. The function should take two matrices as input and return the resulting matrix after multiplication. The code should start with: ```python from typing import List def matrix_multiplication(A: List[List[int]], B: List[List[int]]) -> List[List[int]]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def matrix_multiplication(A: List[List[int]], B: List[List[int]]) -> List[List[int]]: """ Multiplies two matrices A and B. Args: A (List[List[int]]): The first matrix. B (List[List[i...
magic_evol_110k
89,377
Write a Python function to perform Caesar cipher encryption and decryption on a given input string. The function should handle both lowercase and uppercase alphabetic characters, preserving their case. Non-alphabetic characters such as digits, punctuation, and whitespace should remain unchanged. The function should acc...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher(action: str, shift: int, text: str) -> str: """ Encrypts or decrypts a given input string using the Caesar cipher method. Args: action (str): The action to be performed, either 'encode' or 'decode'...