source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
evol_instruct_66k
7,944
Write a Python function to check if a given element is present in a numeric array. The function should return `True` if the element is found in the array, and `False` otherwise. The code should start with: ```python from typing import List def is_element_in_array(arr: List[int], element: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_element_in_array(arr: List[int], element: int) -> bool: """ Check if a given element is present in a numeric array. Args: arr (List[int]): The numeric array to search within. ...
evol_instruct_66k
7,956
Write a Python function to print a 2D array in a spiral order. The function should take a 2D list (matrix) as input and return a list of elements in spiral order. The matrix can range from 5x5 to 10x10. The function should handle matrices of any size, not just those within the specified range. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def spiral_order(matrix: List[List[int]]) -> List[int]: """ Returns a list of elements in spiral order from a given 2D matrix. Args: matrix (List[List[int]]): A 2D list representing the matr...
evol_instruct_66k
7,967
Write a Python function to split a given colloquial expression into an assortment of individual words. The function should handle expressions with varying punctuation and spacing. The code should start with: ```python from typing import List def split_expression(expression: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import string def split_expression(expression: str) -> List[str]: """ Splits a given colloquial expression into an assortment of individual words. Args: expression (str): The colloquial expr...
evol_instruct_66k
7,970
Write a Python function to calculate the factorial of a given non-negative integer `n`. The function should correctly handle edge cases such as `n = 0` and should be efficient in its computation. The code should start with: ```python def factorial(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def factorial(n: int) -> int: """ Calculate the factorial of a given non-negative integer n. Args: n (int): The non-negative integer for which to calculate the factorial. Returns: int: The factorial of ...
evol_instruct_66k
7,992
Write a Python function to search for a specific integer within a given array and return its index position if found. If the integer is not found, return -1. The function should be efficient and handle edge cases such as an empty array or the target not being present in the array. 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 search_integer(array: List[int], target: int) -> int: """ Searches for a specific integer within a given array and returns its index position if found. If the integer is not found, returns -1. ...
evol_instruct_66k
8,017
Write a Python function to efficiently merge two pre-sorted arrays into a single sorted array in linear time complexity, O(n). The function should handle arrays of different lengths and ensure that the merged array maintains the sorted order. The code should start with: ```python from typing import List def merge_sor...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_arrays(A: List[int], B: List[int]) -> List[int]: """ Merges two pre-sorted arrays into a single sorted array in linear time. Args: A (List[int]): The first pre-sorted array....
evol_instruct_66k
8,043
Write a Python function to generate the first `n` integers from the Fibonacci sequence, where each number is the sum of the two preceding ones. The function should start with: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: """ Generate the first n integers from the Fibonacci sequence. The Fibonacci sequence is a series of numbers where each number is the sum of the two prec...
evol_instruct_66k
8,090
Write a Python function to count the occurrences of a given character in a given text string. The function should be case-sensitive and should handle any printable ASCII characters. The code should start with: ```python def count_character_occurrences(text: str, character: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def count_character_occurrences(text: str, character: str) -> int: """ Counts the occurrences of a given character in a given text string. Args: text (str): The text string in which to count the character occurren...
evol_instruct_66k
8,095
Write a Python function to determine the square root of the smaller number between two given numeric values. The function should return the square root of the smaller number. The code should start with: ```python import math def square_root_of_smaller_number(num1: float, num2: float) -> float: ```
Here is the Python code to solve the given problem in the markdown block: : ```python import math def square_root_of_smaller_number(num1: float, num2: float) -> float: """ Calculate the square root of the smaller number between two given numeric values. Args: num1 (float): The first numeric value....
evol_instruct_66k
8,097
Write a Python function to randomly select one element from a given array. The function should handle arrays of various lengths, including empty arrays. If the array is empty, the function should return `None`. The code should start with: ```python from typing import List, Optional import random def select_random_elem...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional import random def select_random_element(arr: List[int]) -> Optional[int]: """ Selects a random element from the given array. Args: arr (List[int]): The array from which to select a...
evol_instruct_66k
8,111
Write a Python function to calculate the total number of iterations for a doubly embedded iterative process. The function should take two integers, `n` and `m`, as input, where `n` is the number of iterations for the outer loop and `m` is the number of iterations for the inner loop. The function should return the total...
Here is the Python code to solve the given problem in the markdown block: ```python def total_iterations(n: int, m: int) -> int: """ Calculate the total number of iterations for a doubly embedded iterative process. Args: n (int): The number of iterations for the outer loop. m (int): The num...
evol_instruct_66k
8,125
Write a Python function to reorder a list of exclusively positive integers based on the length of their binary representations in ascending order. If multiple integers have the same binary length, they should be sorted based on their decimal values in ascending order. 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 sort_by_binary_len(arr: List[int]) -> List[int]: """ Reorders a list of positive integers based on the length of their binary representations in ascending order. If multiple integers have the sam...
evol_instruct_66k
8,127
Write a Python function to calculate the greatest common divisor (GCD) of two given integers using the Euclidean algorithm. The function should handle both positive and negative integers, and should return the absolute value of the GCD. The code should start with: ```python def greatest_common_divisor(a: int, b: int) ...
Here is the Python code to solve the given problem in the markdown block: ```python def greatest_common_divisor(a: int, b: int) -> int: """ Calculate the greatest common divisor (GCD) of two integers using the Euclidean algorithm. Args: a (int): The first integer. b (int): The second intege...
evol_instruct_66k
8,130
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 value should not be updated, and a warning message should be printed. The function should be able to handle any list of tuples and return a dictionary. T...
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...
evol_instruct_66k
8,172
Write a Python function to find the index of a target string in a given array of strings. If the target string is not found in the array, the function should return -1. The function should be efficient and handle edge cases such as an empty array or a target string that does not exist in the array. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_target_index(arr: List[str], target: str) -> int: """ Find the index of the target string in the given array of strings. Args: arr (List[str]): The array of strings to search throug...
evol_instruct_66k
8,173
Write a Python function to generate all prime numbers less than or equal to a given number `n` using the Sieve of Eratosthenes algorithm. The function should be optimized for efficiency. The code should start with: ```python from typing import List def generate_primes(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_primes(n: int) -> List[int]: """ Generate all prime numbers less than or equal to a given number n using the Sieve of Eratosthenes algorithm. Args: n (int): The upper limit to f...
evol_instruct_66k
8,177
Write a Python function to concatenate two strings and then reverse the concatenated string without using any inbuilt string reverse functions. The function should start with: ```python def concatenate_and_reverse(string1: str, string2: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_and_reverse(string1: str, string2: str) -> str: """ Concatenates two strings and then reverses the concatenated string without using any inbuilt string reverse functions. Args: string1 (str): The fir...
evol_instruct_66k
8,179
Write a Python function to sort an array of integers using a recursive algorithm. The function should be based on the merge sort algorithm, which divides the array into two halves, recursively sorts each half, and then merges the sorted halves. The function should start with: ```python from typing import List def recu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def recursive_merge_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers using a recursive merge sort algorithm. Args: arr (List[int]): The array of integers to be sorted. ...
evol_instruct_66k
8,205
Write a Python function to concatenate a given string with a predefined prefix and return the result. The function should take a single string as input and return a new string that is the concatenation of the prefix "Salutations, " and the input string. The code should start with: ```python def concatenate_with_prefix...
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_with_prefix(greeting_text: str) -> str: """ Concatenates the given string with a predefined prefix and returns the result. Args: greeting_text (str): The string to be concatenated with the prefix. ...
evol_instruct_66k
8,207
Write a Python function to implement the insertion sort algorithm. The function should take a list of integers as input and return the sorted list. The insertion sort algorithm works by iterating through the list and inserting each element into its correct position in the sorted portion of the list. The code should st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def insertion_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the insertion sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: ...
evol_instruct_66k
8,217
Write a Python function to transform a given date and time string from one format to another. The function should accept the input date string, the input format, and the desired output format. The function should return the transformed date string in the desired format. The code should start with: ```python from datet...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime def transform_date_time(input_date_str: str, input_format: str, output_format: str) -> str: """ Transforms a given date and time string from one format to another. Args: input_date_str...
evol_instruct_66k
8,250
Write a Python function to convert an array of 24-hour formatted time strings into their corresponding 12-hour clock versions. The function should handle special cases such as midnight (00:00), noon (12:00), and early morning hours (00:00 - 03:59). Additionally, the function should return a specific error message for i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_to_12_hour_format(times: List[str]) -> List[str]: """ Converts an array of 24-hour formatted time strings into their corresponding 12-hour clock versions. Args: times (List[str])...
evol_instruct_66k
8,251
Design a Python function to query and filter rare manuscripts from a given dataset based on specified criteria. The dataset is a list of dictionaries, where each dictionary represents a manuscript with fields `unique_id`, `title`, `author`, `period`, and `condition`. The function should allow filtering by `author`, `pe...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Optional def filter_manuscripts(manuscripts: List[Dict[str, str]], author: Optional[str] = None, period: Optional[str] = None, condition: Optional[str] = None) -> List[Dict[str, str]]: """ Filters...
evol_instruct_66k
8,260
Write a Python function to classify three unique entities based on their characteristics using a decision tree model. Each entity is characterized by its shape, color, and size. The function should return a list of classifications for each entity. The entities are described as follows: - Entity 1: spherical, crimson h...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def classify_entities(entities: List[dict]) -> List[str]: """ Classify a list of entities based on their shape, color, and size using a decision tree model. Args: entities (List[dict]): A li...
evol_instruct_66k
8,274
Write a Python function to sort a list of dictionaries in ascending order based on the "grade" key, then by the "name" key. If both "grade" and "name" are the same for two dictionaries, sort them by the descending order of the "height" key. The function should start with: ```python from typing import List, Dict def so...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def sort_students(students: List[Dict[str, any]]) -> List[Dict[str, any]]: """ Sorts a list of dictionaries in ascending order based on the "grade" key, then by the "name" key. If both "grade" ...
evol_instruct_66k
8,286
Write a Python function to optimize an array based on the following conditions: - If an element is less than 50, it should be replaced with 50. - If an element is greater than or equal to 50, it should be replaced with 100. The function should start with: ```python from typing import List def optimize_array(arr: List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def optimize_array(arr: List[int]) -> List[int]: """ Optimizes the given array by replacing elements based on the following conditions: - If an element is less than 50, it is replaced with 50. - ...
evol_instruct_66k
8,287
Write a Python function to reverse the order of words in a given string containing ASCII characters only, while preserving the original case of each character. The function should handle strings with multiple spaces between words and leading/trailing spaces. The code should start with: ```python def reverse_words_in_st...
Here is the Python code to solve the given problem in the markdown block: : ```python def reverse_words_in_string(input_string: str) -> str: """ Reverses the order of words in a given string while preserving the original case of each character. Args: input_string (str): The input string containing ...
evol_instruct_66k
8,313
Write a Python function to perform an optimized linear search on a given list of integers. The function should return the index of the first occurrence of the target element if it exists in the list, otherwise return -1. The optimization should minimize the time complexity by reducing the number of comparisons. The co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def optimized_linear_search(arr: List[int], x: int) -> int: """ Perform an optimized linear search on a list of integers to find the index of the first occurrence of the target element. Args: ...
evol_instruct_66k
8,332
Write a Python function to calculate the factorial of a given non-negative integer `num` efficiently. The function should handle the input range where `num` is between 2 and 100, inclusive. The code should start with: ```python def factorial(num: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def factorial(num: int) -> int: """ Calculate the factorial of a given non-negative integer `num`. Args: num (int): The non-negative integer for which to calculate the factorial. Returns: int: The facto...
evol_instruct_66k
8,347
Write a Python function to remove all white spaces from a given string efficiently. The function should handle strings of varying lengths and ensure that all white spaces, including spaces, tabs, and newlines, are removed. 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 white spaces from the given string. Args: s (str): The input string from which white spaces are to be removed. Returns: str: The string with all whi...
evol_instruct_66k
8,353
Write a Python function that accepts a single input parameter and returns a string that explicitly characterizes the data type of the provided input argument. The function should handle various data types including but not limited to integers, floats, strings, lists, tuples, dictionaries, sets, and booleans. The functi...
Here is the Python code to solve the given problem in the markdown block: ```python def characterize_type(input_parameter): """ Returns a string that explicitly characterizes the data type of the provided input argument. Args: input_parameter: The input parameter whose data type needs to be charact...
evol_instruct_66k
8,354
Write a Python function to generate an array of 10 unique random integers within a specified range. The function should ensure that all integers in the array are distinct and within the given range. The code should start with: ```python from typing import List import random def generate_unique_random_integers(min_valu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_unique_random_integers(min_value: int, max_value: int) -> List[int]: """ Generates an array of 10 unique random integers within the specified range [min_value, max_value]. ...
evol_instruct_66k
8,358
Write a Python function to combine two lists such that the resulting list contains alternating elements from both lists. If the lists are of different lengths, the remaining elements from the longer list should be appended to the end of the combined list. The function should handle lists of any length, including empty ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def combine_lists(list1: List[int], list2: List[int]) -> List[int]: """ Combines two lists such that the resulting list contains alternating elements from both lists. If the lists are of different le...
evol_instruct_66k
8,369
Write a Python function to construct a regular expression pattern that accurately identifies the exact string "hello people" as well as variations where any character can be upper or lower case, and there can be multiple spaces between words. The function should return the constructed pattern. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python import re def construct_regex_pattern() -> str: """ Constructs a regular expression pattern that matches the exact string "hello people" with variations where any character can be upper or lower case, and there can be m...
evol_instruct_66k
8,374
Write a Python function to calculate the least common multiple (LCM) of two given integers `x` and `y`. The function should validate that both `x` and `y` are positive integers within the range of 1 to 1000. If the validation fails, the function should return `None`. The function should start with: ```python def lowest...
Here is the Python code to solve the given problem in the markdown block: ```python import math def lowest_common_multiple(x: int, y: int) -> int: """ Calculate the least common multiple (LCM) of two integers x and y. Args: x (int): The first integer, must be in the range [1, 1000]. y (int...
evol_instruct_66k
8,375
Write a Python function to remove leading and trailing whitespace characters from a given text string. The function should handle various types of whitespace characters, including spaces, tabs, and newlines. The code should start with: ```python def remove_whitespace(text: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def remove_whitespace(text: str) -> str: """ Removes leading and trailing whitespace characters from the given text string. Args: text (str): The input text string from which to remove the whitespace characters. ...
evol_instruct_66k
8,376
Write a Python function to merge two collections of integers, remove any duplicates, and return the result sorted in ascending order. The function should handle collections of any length, including empty collections, and ensure that the result is always sorted and contains no duplicates. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_and_sort_collections(A: List[int], B: List[int]) -> List[int]: """ Merges two collections of integers, removes duplicates, and returns the result sorted in ascending order. Args: A...
evol_instruct_66k
8,377
Write a Python function to calculate the total sum of all integer values present within nested lists. The function should ignore any non-integer values and continue processing the rest of the list. The code should start with: ```python from typing import List, Union def sum_nested_list(nested_list: List[Union[int, Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def sum_nested_list(nested_list: List[Union[int, List]]) -> int: """ Calculate the total sum of all integer values present within nested lists, ignoring non-integer values. Args: nest...
evol_instruct_66k
8,380
Write a Python function to analyze the frequency of every unique alphabetical symbol and the frequency of combinations of two adjacent characters in a given text string. The function should remove any punctuations and spaces before executing the calculations and should be case insensitive. The function should return tw...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict import re from collections import defaultdict def analyze_text_frequency(text: str) -> (Dict[str, int], Dict[str, int]): """ Analyzes the frequency of every unique alphabetical symbol and the frequency o...
evol_instruct_66k
8,429
Write a Python function to optimize the Bubble Sort algorithm by implementing advanced optimization strategies. The function should improve the efficiency of the algorithm by reducing unnecessary comparisons and iterations. The code should start with: ```python from typing import List def optimized_bubble_sort(lst: Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def optimized_bubble_sort(lst: List[int]) -> List[int]: """ Optimizes the Bubble Sort algorithm by reducing unnecessary comparisons and iterations. Args: lst (List[int]): The list of integer...
evol_instruct_66k
8,436
Write a Python function to interlace two strings by selecting and interleaving alternate characters from each string. If one string is longer than the other, the remaining characters of the longer string should be appended to the result. The function should start with: ```python def interlace_strings(str1: str, str2: s...
Here is the Python code to solve the given problem in the markdown block: ```python def interlace_strings(str1: str, str2: str) -> str: """ Interleaves two strings by selecting and interleaving alternate characters from each string. If one string is longer than the other, the remaining characters of the lon...
evol_instruct_66k
8,438
Write a Python function to find the longest common subsequence (LCS) among three given strings. The function should return the LCS as a string. The code should start with: ```python def longest_common_subsequence(s1: str, s2: str, s3: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def longest_common_subsequence(s1: str, s2: str, s3: str) -> str: """ Find the longest common subsequence among three given strings. Args: s1 (str): The first string. s2 (str): The second string. s3 ...
evol_instruct_66k
8,440
Write a Python function to calculate the product of all integers in a given list. The function should handle lists of any length, including empty lists. If the list is empty, the function should return 1. The code should start with: ```python from typing import List def product_of_list(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def product_of_list(numbers: List[int]) -> int: """ Calculate the product of all integers in the given list. Args: numbers (List[int]): A list of integers. Returns: int: The p...
evol_instruct_66k
8,452
Write a Python function to generate a valid JSON object for a user with nested address and contact information. The function should accept parameters for the user's name, age, address (street, city, state, zip), email, and phone number. The function should return a dictionary that represents the JSON object. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def generate_user_json(name: str, age: int, street: str, city: str, state: str, zip_code: str, email: str, phone: str) -> Dict: """ Generate a valid JSON object for a user with nested address and contact...
evol_instruct_66k
8,457
Write a Python function to reverse the sequence of a given list of whole numbers without using any built-in utility functions such as `reverse()`. The function should handle lists with up to \(10^6\) elements and complete execution in less than 2 seconds. 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 reverse_sequence(seq: List[int]) -> List[int]: """ Reverses the sequence of a given list of whole numbers without using built-in utility functions. Args: seq (List[int]): The list of who...
evol_instruct_66k
8,475
Write a Python function to compute the power of a given n x n homogeneous 2D array (matrix) to a specified exponential value. The function should use efficient matrix multiplication and exponentiation by squaring to achieve this. The code should start with: ```python from typing import List def matrix_power(matrix: Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def mat_multiply(A: List[List[int]], B: List[List[int]], mod: int) -> List[List[int]]: """ Multiplies two matrices A and B under a given modulo. Args: A (List[List[int]]): The first matrix. ...
evol_instruct_66k
8,495
Write a Python function to find the longest unbroken sequence of `1`s in a given binary array. The array will contain only `0`s and `1`s, and its length will not exceed 10,000. The function should return the length of the longest sequence of `1`s. The code should start with: ```python from typing import List def long...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_sequence_of_ones(arr: List[int]) -> int: """ Find the longest unbroken sequence of `1`s in a given binary array. Args: arr (List[int]): A list of integers containing only `0`s an...
evol_instruct_66k
8,501
Write a Python function to determine the ASCII code of a given character and classify it as either an uppercase character, a lowercase character, or neither. The function should return a tuple containing the ASCII code and the classification. The code should start with: ```python def character_info(character: str) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python def character_info(character: str) -> tuple: """ Determine the ASCII code of a given character and classify it as either an uppercase character, a lowercase character, or neither. Args: character (str): A single cha...
evol_instruct_66k
8,530
Write a Python function to reverse a given string using a non-slicing approach. The function should iterate through the string and build the reversed string character by character. The code should start with: ```python def reverse_string(string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(string: str) -> str: """ Reverses the given string using a non-slicing approach. Args: string (str): The input string to be reversed. Returns: str: The reversed string. """ # ...
evol_instruct_66k
8,533
Write a Python function to extract distinct integers from a collection of numerical intervals. Each interval is represented as a tuple of two integers, where the first integer is the start of the interval (inclusive) and the second integer is the end of the interval (inclusive). The function should return a sorted list...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def get_distinct_integers(intervals: List[Tuple[int, int]]) -> List[int]: """ Extracts distinct integers from a collection of numerical intervals. Args: intervals (List[Tuple[int, int...
evol_instruct_66k
8,535
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 return a list of all ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def extract_valid_emails(text: str) -> List[str]: """ Extracts all valid email addresses from the given text using regular expressions. Args: text (str): The text from which to ext...
evol_instruct_66k
8,538
Write a Python function to recursively remove all instances of a specified integer value from a list, including nested lists. The function should handle lists containing various data types and should be performance-optimized for larger lists. The code should start with: ```python from typing import List, Any def remov...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def remove_integer(target_int: int, list_val: List[Any]) -> List[Any]: """ Recursively removes all instances of the specified integer value from a list, including nested lists. Args: ta...
evol_instruct_66k
8,541
Write a Python function to generate the Fibonacci sequence of a given length `n`. The function should return a list containing the first `n` numbers in the Fibonacci sequence. If `n` is less than or equal to 0, the function should return an empty list. 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 generate_fibonacci_sequence(n: int) -> List[int]: """ Generate the Fibonacci sequence of a given length n. Args: n (int): The length of the Fibonacci sequence to generate. Returns: ...
evol_instruct_66k
8,543
Write a Python function to convert a given numerical date in the format "DDMMYYYY" into the corresponding weekday in the Gregorian calendar system. The function should return the weekday as a string (e.g., "Monday", "Tuesday", etc.). The code should start with: ```python from datetime import datetime def get_weekday(...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime def get_weekday(date: str) -> str: """ Converts a given numerical date in the format "DDMMYYYY" into the corresponding weekday in the Gregorian calendar system. Args: date (str): The d...
evol_instruct_66k
8,553
Write a Python function to generate a two-dimensional array (matrix) where each row represents the prime factors of the corresponding number, starting from 2 up to n. The prime factors should be listed in increasing order. The function should handle large inputs efficiently and ensure optimal space and time complexity....
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import defaultdict def generate_prime_factors_matrix(n: int) -> List[List[int]]: """ Generate a two-dimensional array where each row represents the prime factors of the corresponding num...
evol_instruct_66k
8,560
Refactor the given Python script to use a dictionary and a `for` loop control structure instead of a list and an `if` conditional. The script should check if a given value `x` is a key in the dictionary and print a corresponding message if it is. The code should start with: ```python def check_value_in_dict(x: int, di...
Here is the Python code to solve the given problem in the markdown block: ```python def check_value_in_dict(x: int, dict_: dict) -> None: """ Checks if the given value `x` is a key in the provided dictionary and prints a corresponding message if it is. Args: x (int): The value to check in the dicti...
evol_instruct_66k
8,568
Write a Python function to calculate the sum of all numbers in a nested list, where elements can be integers or nested lists. The function should handle invalid types by skipping them and printing an error message. The code should start with: ```python from typing import Union, List def nested_sum(nested_list: Union[i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Union, List def nested_sum(nested_list: Union[int, List]) -> int: """ Calculate the sum of all integers in a nested list, handling invalid types by skipping them and printing an error message. Args: ...
evol_instruct_66k
8,572
Write a Python function to swap the values of two variables without using a temporary variable. The function should take two parameters, `a` and `b`, and return a tuple containing the swapped values of `a` and `b`. The code should start with: ```python def swap_variables(a: int, b: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def swap_variables(a: int, b: int) -> tuple: """ Swaps the values of two variables without using a temporary variable. Args: a (int): The first variable. b (int): The second variable. Returns: t...
evol_instruct_66k
8,574
Write a Python function to calculate the Levenshtein distance between two given strings. The Levenshtein distance is a metric for measuring the difference between two sequences, defined as the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one word into the other. ...
Here is the Python code to solve the given problem in the markdown block: ```python def levenshtein_distance(word1: str, word2: str) -> int: """ Calculate the Levenshtein distance between two strings. The Levenshtein distance is the minimum number of single-character edits (insertions, deletions, or su...
evol_instruct_66k
8,578
Write a Python function to interchange whitespaces with underscores and underscores with whitespaces within a provided string. The function should handle any string input and return the modified string. The code should start with: ```python def swap_whitespace_and_underscore(string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def swap_whitespace_and_underscore(string: str) -> str: """ Interchanges whitespaces with underscores and underscores with whitespaces within a provided string. Args: string (str): The input string to be modified. ...
evol_instruct_66k
8,587
Write a Python function to convert a base-10 numerical value into a standardized dollar (USD) currency format. The function should handle both positive and negative amounts, and should format the amount to two decimal places, with commas as thousand separators. The code should start with: ```python def format_usd(amoun...
Here is the Python code to solve the given problem in the markdown block: ```python def format_usd(amount: float) -> str: """ Converts a base-10 numerical value into a standardized dollar (USD) currency format. Args: amount (float): The numerical value to be formatted. Returns: str: Th...
evol_instruct_66k
8,594
Write a Python function to calculate the Highest Common Factor (HCF) of four integers. The function should take four integers as input and return their HCF. The code should start with: ```python import math def calculate_hcf(x1: int, x2: int, x3: int, x4: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python import math def calculate_hcf(x1: int, x2: int, x3: int, x4: int) -> int: """ Calculate the Highest Common Factor (HCF) of four integers. Args: x1 (int): The first integer. x2 (int): The second integer. ...
evol_instruct_66k
8,605
Write a Python function to merge two numerical sequences (lists) into a single list. The merged list should contain all elements from the first list followed by all elements from the second list. The function should handle lists of any length, including empty lists. 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 merge_lists(list_1: List[int], list_2: List[int]) -> List[int]: """ Merges two numerical sequences (lists) into a single list. Args: list_1 (List[int]): The first list of integers. ...
evol_instruct_66k
8,609
Write a Python function to perform a ternary search on a sorted list of integers. The function should return the index of the target element if it exists in the list, otherwise return -1. Additionally, implement a performance comparison between the ternary search algorithm and the binary search algorithm. The compariso...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import time def ternary_search(arr: List[int], target: int) -> int: """ Perform a ternary search on a sorted list of integers to find the index of the target element. Args: arr (List[int]): ...
evol_instruct_66k
8,613
Write a Python function to generate a new list containing exclusively even integers drawn from a provided list of integers. The function should handle lists of any length, including empty lists. The code should start with: ```python from typing import List def extract_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 extract_even_numbers(numbers: List[int]) -> List[int]: """ Generates a new list containing exclusively even integers drawn from the provided list. Args: numbers (List[int]): The list of ...
evol_instruct_66k
8,623
Write a Python function to check if a given group of elements (which may include dictionaries) is contained within another group of elements without any repetition. The function should handle the comparison of dictionary values as well. The code should start with: ```python from typing import List, Any def is_subset(g...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def is_subset(group1: List[Any], group2: List[Any]) -> bool: """ Checks if group1 is a subset of group2 without any repetition, considering dictionaries as well. Args: group1 (List[Any]...
evol_instruct_66k
8,635
Write a Python function to decrypt a 2D grid by replacing every numeric value '1' with the symbolic representation '@'. The grid is represented as a list of lists, where each inner list represents a row in the grid. The function should return the decrypted grid. 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 decrypt_grid(grid: List[List[str]]) -> List[List[str]]: """ Decrypts a 2D grid by replacing every numeric value '1' with the symbolic representation '@'. Args: grid (List[List[str]]): A ...
evol_instruct_66k
8,637
Write a Python function to generate a three-dimensional stochastic matrix with specified dimensions. The matrix should have four strata, each containing seven ranks, and each rank should be organized along two columnar lines. The matrix should be normalized such that each rank in a column adds up to 1.0, making the mat...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def generate_stochastic_matrix(strata: int, rank: int, column: int) -> np.ndarray: """ Generates a three-dimensional stochastic matrix with the specified dimensions. Args: strata (int): The numbe...
evol_instruct_66k
8,649
Write a Python function to iterate over the characters of a given string and return a list of tuples where each tuple contains the character and its index in the string. The function should handle strings of any length, including empty strings. The code should start with: ```python from typing import List, Tuple def ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def character_index_pairs(s: str) -> List[Tuple[str, int]]: """ Returns a list of tuples where each tuple contains a character from the string and its index. Args: s (str): The input ...
evol_instruct_66k
8,679
Write a Python function to generate and print a multiplication table for the numbers 1 to 5. The function should print each multiplication result in the format "i x j = result" and should only iterate over the necessary range to achieve this. The code should start with: ```python def print_multiplication_table(): ```
Here is the Python code to solve the given problem in the markdown block: ```python def print_multiplication_table(): """ Generates and prints a multiplication table for the numbers 1 to 5. The function prints each multiplication result in the format "i x j = result" and only iterates over the necessar...
evol_instruct_66k
8,690
Write a Python function to extend a given string by repeating its characters until the string reaches a specified minimum length. If the input string is empty, return a specific error message. The function should start with: ```python def extend_string_to_length(s: str, min_length: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def extend_string_to_length(s: str, min_length: int) -> str: """ Extends the given string by repeating its characters until it reaches the specified minimum length. Args: s (str): The input string to be extended. ...
evol_instruct_66k
8,691
Write a Python function to find both the maximum and minimum values in an unsorted array of integers using a modified binary search algorithm. The algorithm should avoid comparing each element with every other element and should be adaptive to changes in the sorted order of the elements. The function should return a tu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_min_max(arr: List[int]) -> Tuple[int, int]: """ Find both the minimum and maximum values in an unsorted array of integers using a modified binary search algorithm. Args: arr ...
evol_instruct_66k
8,696
Write a Python function to calculate the product of elements in a dynamically allocated list using pointer arithmetic. The function should dynamically allocate memory for the list, compute the product of its elements, and then release the allocated memory. The function should also include checks to ensure no memory lea...
Here is the Python code to solve the given problem in the markdown block: ```python from ctypes import c_int, POINTER, cast, pointer, Structure, byref import gc def calculate_product_and_free_memory(size: int, values: list) -> int: """ Calculate the product of elements in a dynamically allocated list using poi...
evol_instruct_66k
8,706
Write a Python function that processes a given string and returns a new string where each alphabetic character from the original string is converted to its uppercase form, while non-alphabetic characters remain unchanged. The function should handle strings of any length, including empty strings. The code should start ...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_uppercase(input_string: str) -> str: """ Processes the input string and returns a new string where each alphabetic character is converted to its uppercase form, while non-alphabetic characters remain unchanged...
evol_instruct_66k
8,707
Write a Python function to determine the shortest sequence of commands required to reach a specific target position on an infinite number line using an advanced race car. The car begins at position 0 with a speed of +1 and can traverse negative positions. The car operates automatically based on three commands: "A" (acc...
Here is the Python code to solve the given problem in the markdown block: ```python def racecar(target: int) -> int: """ Calculate the minimum number of commands required to reach a specific target position on an infinite number line. Args: target (int): The target position to reach. Returns: ...
evol_instruct_66k
8,713
Write a Python function to calculate the absolute variance between two given numbers. The function should take two numeric inputs and return the absolute difference between them. The code should start with: ```python def absolute_variance(num1: float, num2: float) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def absolute_variance(num1: float, num2: float) -> float: """ Calculate the absolute variance between two given numbers. Args: num1 (float): The first number. num2 (float): The second number. Returns: ...
evol_instruct_66k
8,726
Write a Python function to check if a given string contains any numbers. The function should return `True` if the string contains at least one digit, and `False` otherwise. The code should start with: ```python def contains_number(input_string: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def contains_number(input_string: str) -> bool: """ Check if the given string contains any numbers. Args: input_string (str): The string to check for the presence of numbers. Returns: bool: True if the ...
evol_instruct_66k
8,732
Write a Python function to find the index of the final occurrence of a specific element in a given ordered array, which may include repeated elements. The function should not use any built-in Python methods for searching or sorting. The code should start with: ```python from typing import List def find_last_occurrence...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_last_occurrence(arr: List[int], num: int) -> int: """ Find the index of the final occurrence of a specific element in an ordered array. Args: arr (List[int]): The ordered array to s...
evol_instruct_66k
8,745
Write a Python function to calculate the sum of all elements in a given two-dimensional array (list of lists). The function should handle any rectangular two-dimensional array, including arrays with different row lengths. The code should start with: ```python from typing import List def sum_of_2d_array(array: List[Li...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def sum_of_2d_array(array: List[List[int]]) -> int: """ Calculate the sum of all elements in a given two-dimensional array. Args: array (List[List[int]]): A two-dimensional array (list of ...
evol_instruct_66k
8,747
Write a Python function to compute the cumulative mass in kilograms of grocery items contained within a shopping cart. The dataset `groceries` is a list of dictionaries where each dictionary represents a grocery item with its name and weight in kilograms. The function should start with: ```python from typing import Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def compute_total_mass(groceries: List[Dict[str, float]]) -> float: """ Computes the cumulative mass in kilograms of grocery items contained within a shopping cart. Args: groceries (Li...
evol_instruct_66k
8,756
Write a Python function to extract all numbers from a given string using regular expressions. The function should return a list of all numbers found in the string. The code should start with: ```python import re from typing import List def extract_numbers(text: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python import re from typing import List def extract_numbers(text: str) -> List[str]: """ Extracts all numbers from the given string using regular expressions. Args: text (str): The input string from which to extract nu...
evol_instruct_66k
8,761
Write a Python function to compute the average monetary recompense per distinct operational unit (department) in a corporate structure. The function should take a list of dictionaries representing employees, where each dictionary contains the employee's `id`, `name`, and `department`, and a list of integers representin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def compute_average_recompense(employees: List[Dict[str, any]], recompenses: List[int]) -> Dict[str, float]: """ Computes the average monetary recompense per distinct operational unit (department) ...
evol_instruct_66k
8,762
Write a Python function to perform a binary search on a pre-allocated sorted array of discrete integers to find the index of a given target element. If the target element is not found, return -1. The function should be efficient and handle edge cases such as an empty array or a target element that is outside the array'...
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], target: int) -> int: """ Perform a binary search on a sorted array to find the index of a target element. Args: arr (List[int]): A sorted list of integers. ...
evol_instruct_66k
8,765
Write a Python function to insert an element into a given sorted array at the appropriate index without using any built-in insert function. The function should handle duplicate values and maintain the sorted order. The function should also be able to handle negative numbers and zero. The code should start with: ```pyth...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def insert_into_sorted_array(sorted_array: List[int], num: int) -> List[int]: """ Inserts an element into a sorted array at the appropriate index without using any built-in insert function. The funct...
evol_instruct_66k
8,771
Write a Python function to identify and correct the anomaly in the given code snippet. The function should take a list of integers as input and print each element of the list using a `while` loop. The function should also ensure that the loop terminates correctly and that the code adheres to Python syntax and best prac...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_list_elements(array: List[int]) -> None: """ Prints each element of the given list of integers using a while loop. Args: array (List[int]): The list of integers to be printed. ...
evol_instruct_66k
8,797
Write a Python function to combine two lists into a dictionary, where the first list serves as the keys and the second list serves as the values. Ensure that the function handles cases where the lists are of different lengths by ignoring the extra elements in the longer list. The code should start with: ```python from...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def combine_lists_to_dict(keys: List[str], values: List[str]) -> Dict[str, str]: """ Combines two lists into a dictionary, where the first list serves as the keys and the second list serves as the ...
evol_instruct_66k
8,820
Write a Python function to create a hash table (dictionary) from a list of tuples, where each tuple contains a key-value pair. The function should then return the hash table and print each key-value pair in the hash table. The code should start with: ```python from typing import List, Tuple, Dict def create_hash_tabl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def create_hash_table(tuples: List[Tuple[str, str]]) -> Dict[str, str]: """ Creates a hash table (dictionary) from a list of tuples and prints each key-value pair. Args: tuples ...
evol_instruct_66k
8,847
Write a Python function to perform subtraction between two unique numerical integers and return the resultant difference value. The function should handle both positive and negative integers. The code should start with: ```python def subtract_numbers(num1: int, num2: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def subtract_numbers(num1: int, num2: int) -> int: """ Perform subtraction between two unique numerical integers and return the resultant difference value. Args: num1 (int): The first integer. num2 (int): Th...
evol_instruct_66k
8,850
Write a Python function to initialize and populate a multi-dimensional array (list of lists) with given values. The function should take a list of tuples, where each tuple represents the coordinates and the value to be placed at those coordinates in the multi-dimensional array. The function should return the populated ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def populate_multi_dimensional_array(dimensions: List[int], values: List[Tuple[int, int, int]]) -> List[List[int]]: """ Initializes and populates a multi-dimensional array with given values. ...
evol_instruct_66k
8,856
Write a Python function to calculate the sum of all odd integers from 1 up to a given input number `n` inclusively. The function should use a combination of conditionals and a for loop to achieve this. The code should start with: ```python def sum_of_odd_integers(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_odd_integers(n: int) -> int: """ Calculate the sum of all odd integers from 1 up to a given number n inclusively. Args: n (int): The upper limit of the range (inclusive). Returns: int: The su...
evol_instruct_66k
8,857
Write a Python function to create an outcome array where each individual element from a given list is magnified by a specified factor. The function should accept two parameters: the list of integers and the magnification factor. The function should return a new list with each element multiplied by the specified factor....
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def magnify_list_elements(lst: List[int], factor: int) -> List[int]: """ Magnifies each element in the given list by the specified factor. Args: lst (List[int]): The list of integers to be m...
evol_instruct_66k
8,865
Write a Python function to generate the first `n` Fibonacci numbers using an iterative approach. The function should return a list containing the Fibonacci sequence up to the `n`-th number. The code should start with: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def generate_fibonacci(n: int) -> List[int]: """ Generate the first n Fibonacci numbers using an iterative approach. Args: n (int): The number of Fibonacci numbers to generate. Return...
evol_instruct_66k
8,867
Write a Python function to return a list of unique elements from a given array of integers in ascending order. The function should handle any size of input array and ensure that the output list contains only unique elements sorted in ascending order. The code should start with: ```python from typing import List def un...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def unique_sorted_elements(arr: List[int]) -> List[int]: """ Returns a list of unique elements from the given array in ascending order. Args: arr (List[int]): The input array of integers. ...
evol_instruct_66k
8,874
Write a Python function to determine if two given alpha-numeric sequences are palindrome anagrams. A palindrome anagram is a sequence that can be rearranged to form a palindrome. The function should ignore non-alphanumeric characters and be case-insensitive. The code should start with: ```python def are_palindrome_ana...
Here is the Python code to solve the given problem in the markdown block: ```python def are_palindrome_anagrams(s1: str, s2: str) -> bool: """ Determines if two given alpha-numeric sequences are palindrome anagrams. Args: s1 (str): The first sequence to check. s2 (str): The second sequence ...
evol_instruct_66k
8,881
Write a Python function to reverse the order of elements in a given tuple. The function should return a new tuple with the elements in reverse order. The original tuple should remain unchanged. The code should start with: ```python from typing import Tuple def reverse_tuple(mytuple: Tuple[int]) -> Tuple[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def reverse_tuple(mytuple: Tuple[int]) -> Tuple[int]: """ Reverses the order of elements in the given tuple and returns a new tuple with the reversed elements. Args: mytuple (Tuple[int]): T...
evol_instruct_66k
8,888
Write a Python function to count the number of vowels in a given text without using any built-in functions or methods. The function should be case-insensitive, meaning both uppercase and lowercase vowels should be counted. The code should start with: ```python def count_vowels_in_text(text: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_vowels_in_text(text: str) -> int: """ Counts the number of vowels in a given text without using any built-in functions or methods. Args: text (str): The input text in which to count the vowels. Return...
evol_instruct_66k
8,891
Write a Python function to perform arithmetic operations on mixed data types (integers and floats) and return the result as a float. The function should take two parameters: an integer and a float. The function should add the integer and the float, and return the result as a float. The code should start with: ```pytho...
Here is the Python code to solve the given problem in the markdown block: ```python def add_int_float(integer: int, float_num: float) -> float: """ Adds an integer and a float and returns the result as a float. Args: integer (int): The integer to be added. float_num (float): The float to be...
evol_instruct_66k
8,907
Write a Python function to print prime numbers from 10 to 100 with an increment of 4 for each iteration. The function should include error checking for the allowable range and correct increments. The function should start with: ```python def print_prime_numbers_with_increment(): ```
Here is the Python code to solve the given problem in the markdown block: ```python def print_prime_numbers_with_increment(): """ Prints prime numbers from 10 to 100 with an increment of 4 for each iteration. Includes error checking for the allowable range and correct increments. Args: None ...
evol_instruct_66k
8,913
Write a Python function to implement the Shell Sort algorithm to sort a given numerical array in ascending order. The function should take a list of integers as input and return the sorted list. The code should start with: ```python from typing import List def shell_sort(lst: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def shell_sort(lst: List[int]) -> List[int]: """ Sorts a given numerical array in ascending order using the Shell Sort algorithm. Args: lst (List[int]): The list of integers to be sorted. ...
evol_instruct_66k
8,920
Write a Python function to rearrange a given dictionary based on its integer values in ascending order. The function should return a new dictionary with the same keys and values, but the keys should be ordered such that the corresponding values are in ascending order. 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 Dict def rearrange_dict_by_values(my_dict: Dict[str, int]) -> Dict[str, int]: """ Rearranges the given dictionary such that the keys are ordered by their corresponding integer values in ascending order. ...