source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
evol_instruct_66k
44,327
Write a Python function to flatten a nested list of arbitrary depth into a single-dimensional list. The function should handle lists containing other lists, which may themselves contain other lists, and so on. The code should start with: ```python from typing import List, Any def flatten_list(nested_list: List[Any]) -...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def flatten_list(nested_list: List[Any]) -> List[Any]: """ Flattens a nested list of arbitrary depth into a single-dimensional list. Args: nested_list (List[Any]): The nested list to be...
evol_instruct_66k
44,334
Write a Python function to generate all possible combinations of elements between two lists `l1` and `l2`. For each combination, compute the sum if both elements are numbers, or concatenate the elements if one of them is a character. The function should return a list of these combinations. 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 generate_combinations(l1: List[Union[int, float, str]], l2: List[Union[int, float, str]]) -> List[Union[int, float, str]]: """ Generate all possible combinations of elements between two lists....
evol_instruct_66k
44,342
Write a Python function to convert a given binary number represented as a string to its equivalent hexadecimal value. The function should perform the conversion step-by-step, ensuring clarity and understanding of each conversion stage. The code should start with: ```python def binary_to_hexadecimal(bin_str: str) -> str...
Here is the Python code to solve the given problem in the markdown block: : ```python def binary_to_hexadecimal(bin_str: str) -> str: """ Converts a given binary number represented as a string to its equivalent hexadecimal value. Args: bin_str (str): The binary number as a string. Returns: ...
evol_instruct_66k
44,350
Write a Python function to transform a list of dictionaries into a dictionary of dictionaries, where each inner dictionary is indexed by the value of a specified key. Additionally, add a new key-value pair `'isActive': True` to each inner dictionary. The function should handle cases where the specified key is not uniqu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def transform_to_indexed_dict(arr: List[Dict[str, Any]], key: str) -> Dict[Any, Dict[str, Any]]: """ Transforms a list of dictionaries into a dictionary of dictionaries, indexed by the value o...
evol_instruct_66k
44,354
Write a Python function to compute the factorial of a given non-negative integer `n`. The factorial of a number `n` is the product of all positive integers less than or equal to `n`. The function should handle edge cases such as `n = 0` and `n = 1` correctly. The code should start with: ```python def factorial(n: int)...
Here is the Python code to solve the given problem in the markdown block: ```python def factorial(n: int) -> int: """ Compute the factorial of a given non-negative integer n. The factorial of n (denoted as n!) is the product of all positive integers less than or equal to n. By definition, 0! is 1. ...
evol_instruct_66k
44,371
Write a Python function to generate an exclusive series of numeric values that adhere to the principles of a geometric progression within the domain of Number Theory. The function should take three parameters: the starting value of the series, the common ratio, and the number of terms to generate. The function should r...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_geometric_series(start: int, ratio: int, num_terms: int) -> List[int]: """ Generates an exclusive series of numeric values that adhere to the principles of a geometric progression. Args...
evol_instruct_66k
44,379
Write a Python function to calculate the cumulative sum of elements in a given list of integers. The cumulative sum at each position `i` in the list should be the sum of all elements from the start of the list up to and including the element at position `i`. The function should return a new list containing these cumula...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def cumulative_sum(array: List[int]) -> List[int]: """ Calculate the cumulative sum of elements in a given list of integers. Args: array (List[int]): The list of integers for which to calcul...
evol_instruct_66k
44,382
Write a Python function to implement the Shell Sort algorithm to sort a given numerical collection efficiently. The function should progressively sort the collection by intermittently sorting component sublists using a decreasing gap sequence. The code should start with: ```python from typing import List def shell_sor...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def shell_sort(collection: List[int]) -> List[int]: """ Sorts the given numerical collection using the Shell Sort algorithm. Args: collection (List[int]): The numerical collection to be sort...
evol_instruct_66k
44,384
Write a Python function to sort a tuple of strings in descending alphabetical order (from Z to A) based on their lexical value. The function should return the sorted tuple. The code should start with: ```python from typing import Tuple def sort_tuple_descending(data_tuple: Tuple[str]) -> Tuple[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def sort_tuple_descending(data_tuple: Tuple[str]) -> Tuple[str]: """ Sorts a tuple of strings in descending alphabetical order (from Z to A) based on their lexical value. Args: data_tuple (...
evol_instruct_66k
44,398
Write a Python function to convert a list of characters into a single string without using any in-built functions or methods that directly handle string concatenation or list conversion. The function should iterate through the list and manually concatenate each character to form the final string. The code should start...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def list_to_string(char_list: List[str]) -> str: """ Converts a list of characters into a single string without using in-built functions or methods. Args: char_list (List[str]): A list of ch...
evol_instruct_66k
44,403
Write a Python function to create a two-dimensional matrix from a given list of numbers, with specified dimensions (rows and columns). The function should ensure that the matrix is filled row by row from the list of numbers. If the list of numbers does not perfectly fit into the specified dimensions, the remaining cell...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def create_matrix(numbers: List[int], rows: int, cols: int) -> List[List[int]]: """ Create a two-dimensional matrix from a given list of numbers with specified dimensions. Args: numbers (Lis...
evol_instruct_66k
44,431
Write a Python function to calculate the cumulative sum of all numerical values contained within a provided list of tuples. The function should be capable of navigating nested tuple structures and disregarding any non-numeric entities. The code should start with: ```python from typing import Tuple, Union def cumulativ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Union def cumulative_sum_of_tuples(tuples: Tuple[Union[int, float, Tuple], ...]) -> float: """ Calculate the cumulative sum of all numerical values contained within a provided list of tuples. This ...
evol_instruct_66k
44,433
Write a Python function to replace all exclamation marks with underscores in a given string. The function should return the modified string. The code should start with: ```python def replace_exclamation_marks(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def replace_exclamation_marks(s: str) -> str: """ Replace all exclamation marks in the given string with underscores. Args: s (str): The input string in which exclamation marks need to be replaced. Returns: ...
evol_instruct_66k
44,435
Write a Python function that checks if a given number is divisible by 5 and returns the string "Good Day" if it is. If the number is not divisible by 5, the function should return the string "Bad Day". The code should start with: ```python def check_divisibility(number: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def check_divisibility(number: int) -> str: """ Checks if the given number is divisible by 5 and returns the appropriate message. Args: number (int): The number to check for divisibility by 5. Returns: ...
evol_instruct_66k
44,437
Write a Python function to replace the first occurrence of a given initial sequence with a secondary sequence in a pre-determined text. The function should take three parameters: the initial sequence, the secondary sequence, and the text in which the replacement should occur. The function should return the modified tex...
Here is the Python code to solve the given problem in the markdown block: ```python def replace_first_occurrence(initial_seq: str, secondary_seq: str, text: str) -> str: """ Replaces the first occurrence of the initial sequence with the secondary sequence in the given text. Args: initial_seq (str):...
evol_instruct_66k
44,443
Write a Python function to find all prime factors of a given positive integer `n` efficiently. The function should return a list of prime factors in ascending order. The code should start with: ```python from typing import List def prime_factors(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def prime_factors(n: int) -> List[int]: """ Find all prime factors of a given positive integer `n` and return them in ascending order. Args: n (int): The positive integer for which to find...
evol_instruct_66k
44,446
Write a Python function to filter a list of strings and return only those strings that contain a specified character. The function should accept two parameters: a list of strings and a single character. The function should return a list of strings where each string contains the specified character. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_strings_by_char(lst: List[str], char: str) -> List[str]: """ Filters a list of strings and returns only those strings that contain the specified character. Args: lst (List[str]): ...
evol_instruct_66k
44,455
Write a Python function to format a given string as a URL slug. The function should validate and clean the input string to remove any non-alphanumeric and special characters before conversion. The input string can be up to 500 characters long. The function should also ensure that the resulting slug does not exceed 500 ...
Here is the Python code to solve the given problem in the markdown block: ```python import re def format_as_url_slug(text: str) -> str: """ Formats a given string as a URL slug by removing non-alphanumeric characters and converting spaces to hyphens. Args: text (str): The input string to be conver...
evol_instruct_66k
44,467
Write a Python function to convert an array of hexadecimal string representations into an array of their corresponding decimal integers. The function should handle both uppercase and lowercase alphabets in the hexadecimal strings and include input validation to ensure the legitimacy of the hexadecimal strings. If an in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def hex_to_decimal(hex_array: List[str]) -> List[int]: """ Converts an array of hexadecimal string representations into an array of their corresponding decimal integers. Args: hex_array (Lis...
evol_instruct_66k
44,474
Write a Python function to determine the median value from a given sorted sequence of digits. The sequence is guaranteed to be in ascending order. The function should handle both even and odd lengths of the sequence. The code should start with: ```python from typing import List def find_median(numbers: List[int]) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_median(numbers: List[int]) -> float: """ Calculate the median value from a given sorted sequence of digits. Args: numbers (List[int]): A sorted list of integers. Returns: ...
evol_instruct_66k
44,488
Write a Python function to reverse a given unidimensional array of fundamental elements without using any built-in or predefined algorithms for reversing the array. The function should manually swap elements from the start and end of the array, moving towards the center until the entire array is reversed. The code sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_array_manual(input_array: List[int]) -> List[int]: """ Reverses a given unidimensional array of fundamental elements without using any built-in or predefined algorithms. Args: in...
evol_instruct_66k
44,513
Write a Python function to determine the type of a given mathematical function and identify any issues in the provided code snippet related to the function. The function should classify the given function as "Exponential" if it matches the form \( f(x) = 2^x \). The code should start with: ```python def function_type(f...
Here is the Python code to solve the given problem in the markdown block: ```python def function_type(func) -> str: """ Determine the type of the given mathematical function. Args: func: The function to be classified. Returns: str: The type of the function, either "Exponential" or "Unk...
evol_instruct_66k
44,518
Write a Python function to sort a given list of integers using the Bubble Sort algorithm. The function should modify the list in place and return the sorted list. The code should start with: ```python from typing import List def bubble_sort(unsorted_list: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(unsorted_list: List[int]) -> List[int]: """ Sorts a given list of integers using the Bubble Sort algorithm. Args: unsorted_list (List[int]): The list of integers to be sorted...
evol_instruct_66k
44,520
Write a Python function to find all duplicate characters in a given string efficiently. The function should return a list of characters that appear more than once in the string, without altering the original functionality. The code should start with: ```python from typing import List def find_duplicate_characters(stri...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_duplicate_characters(string: str) -> List[str]: """ Finds all duplicate characters in a given string and returns them as a list. Args: string (str): The input string to search for d...
evol_instruct_66k
44,522
Write a Python function to invert both an input string and its individual words, discarding any characters that aren't part of the standard English alphabet. The output should exclusively contain lowercase letters and should mirror the reversed words. The internal Python `reverse()` function and slicing techniques are ...
Here is the Python code to solve the given problem in the markdown block: ```python def invert_string(s: str) -> str: """ Inverts both an input string and its individual words, discarding any characters that aren't part of the standard English alphabet. The output contains only lowercase letters and mirrors...
evol_instruct_66k
44,546
Write a Python function to calculate the sum of the squares of the elements in a given 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 sum_of_squares(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_squares(arr: List[int]) -> int: """ Calculate the sum of the squares of the elements in a given list of integers. Args: arr (List[int]): The list of integers for which to calculat...
evol_instruct_66k
44,547
Write a Python function to perform simple arithmetic operations on two given numbers. The function should support addition, subtraction, multiplication, and division. The operation to be performed should be specified as a string ('add', 'subtract', 'multiply', 'divide'). The function should handle division by zero by r...
Here is the Python code to solve the given problem in the markdown block: ```python def arithmetic_operations(num1: float, num2: float, operation: str) -> float or str: """ Perform simple arithmetic operations on two given numbers. Args: num1 (float): The first number. num2 (float): The sec...
evol_instruct_66k
44,551
Write a Python function to concatenate two strings and return the result. The function should handle both string and numeric inputs, converting numeric inputs to strings before concatenation. The code should start with: ```python def concatenate_strings(a, b): ```
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_strings(a, b): """ Concatenates two inputs after converting them to strings if necessary. Args: a: The first input to concatenate. b: The second input to concatenate. Returns: st...
evol_instruct_66k
44,560
Write a Python function to check if all elements in a given list are strings. The function should return `True` if all elements are strings, and `False` otherwise. The function should also return `False` if the input is not a list. The code should start with: ```python from typing import List def check_all_strings(ar...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def check_all_strings(array: List[str]) -> bool: """ Check if all elements in the given list are strings. Args: array (List[str]): The list to check. Returns: bool: True if all ...
evol_instruct_66k
44,565
Write a Python function to calculate the arithmetic mean of numerical values contained within a given list. The function should handle lists of integers and floating-point numbers. The code should start with: ```python from typing import List def calculate_mean(numbers: List[float]) -> float: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def calculate_mean(numbers: List[float]) -> float: """ Calculate the arithmetic mean of a list of numerical values. Args: numbers (List[float]): A list of numerical values (integers or flo...
evol_instruct_66k
44,568
Write a Python function to extract all palindromic numerals (numbers that read the same forwards and backwards) from a given text string using a Regular Expression pattern. The function should return a list of all such palindromic numerals found in the text. The code should start with: ```python import re from typing ...
Here is the Python code to solve the given problem in the markdown block: ```python import re from typing import List def find_palindromic_numerals(text: str) -> List[str]: """ Extracts all palindromic numerals from a given text string. Args: text (str): The input text string from which to extract...
evol_instruct_66k
44,571
Write a Python function to compute an array where each element is the product of all the elements in the input array except the element at the same index. The solution must not use division and should operate in O(n) time complexity. The code should start with: ```python from typing import List def product_of_all_exce...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def product_of_all_except_self(nums: List[int]) -> List[int]: """ Compute an array where each element is the product of all elements in the input array except the element at the same index. Args: ...
evol_instruct_66k
44,573
Write a Python function to reverse a given string without using any built-in string reversal functions or methods. The function should iterate through the string manually and construct the reversed string step by step. The code should start with: ```python def reverse_string(input_string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(input_string: str) -> str: """ Reverses the given string without using any built-in string reversal functions or methods. Args: input_string (str): The string to be reversed. Returns: ...
evol_instruct_66k
44,582
Write a Python function to find all elements in a given array that appear more than once, excluding the number 1 even if it repeats. Additionally, return a separate array of these repeated elements as strings. The code should start with: ```python from typing import List, Tuple def find_repeated_elements(arr: List[in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_repeated_elements(arr: List[int]) -> Tuple[List[int], List[str]]: """ Find all elements in the given array that appear more than once, excluding the number 1. Additionally, return a s...
evol_instruct_66k
44,586
Write a Python function to compute the Lowest Common Multiple (LCM) of three given integers. The function should be able to handle any positive integers and should return the LCM of the three numbers. The code should start with: ```python def lcm_of_three(a: int, b: int, c: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def gcd(a: int, b: int) -> int: """ Compute the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm. Args: a (int): The first integer. b (int): The second integer. Returns: ...
evol_instruct_66k
44,594
Write a Python function to shuffle a given list of numbers in place without using the built-in `random.shuffle` function. The function should return the shuffled list. The code should start with: ```python from typing import List def shuffle_list(numbers: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List import random def shuffle_list(numbers: List[int]) -> List[int]: """ Shuffles a given list of numbers in place using the Fisher-Yates shuffle algorithm. Args: numbers (List[int]): The list...
evol_instruct_66k
44,605
Write a Python function to validate if a given string is a valid phone number in the format "555-555-5555" and ensure it contains only numeric characters and hyphens. The function should return `True` if the phone number is valid and `False` otherwise. The code should start with: ```python import re def is_valid_phon...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_phone_number(phone_number: str) -> bool: """ Validates if the given string is a valid phone number in the format "555-555-5555". Args: phone_number (str): The phone number string to validate....
evol_instruct_66k
44,624
Write a Python function to convert a given numerical diamond grid into a single numerical representation. The diamond grid is represented as a list of lists, where each sublist represents a layer of the diamond. The function should concatenate the numbers in the grid in a specific order: starting from the outermost lay...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_diamond_grid_to_number(diamond_grid: List[List[int]]) -> int: """ Converts a numerical diamond grid into a single numerical representation. The diamond grid is represented as a list of l...
evol_instruct_66k
44,631
Write a Python function to sort a collection of floating-point values in ascending order. The function should handle both positive and negative values, as well as duplications. The sorting should be stable, meaning that the order of equal elements should not change. The code should start with: ```python from typing imp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_float_values(values: List[float]) -> List[float]: """ Sorts a collection of floating-point values in ascending order. Args: values (List[float]): The collection of floating-point va...
evol_instruct_66k
44,634
Write a Python function to calculate the cube root of a large integer. The function should handle both positive and negative integers, and return the integer part of the cube root. The code should start with: ```python def cube_root(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def cube_root(n: int) -> int: """ Calculate the integer part of the cube root of a given large integer. Args: n (int): The integer for which to calculate the cube root. Returns: int: The integer part ...
evol_instruct_66k
44,638
Write a Python function to rotate a given array by `n` places to the right. If `n` is negative, the array should be rotated counter-clockwise. The function should handle cases where `n` is greater than the length of the array by using modulo operation. 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 rotate_array(arr: List[int], n: int) -> List[int]: """ Rotates the given array by n places to the right. If n is negative, the array is rotated counter-clockwise. Args: arr (List[int]): ...
evol_instruct_66k
44,641
Write a Python function to generate a unique geometric sequence of numbers given the starting term, the common ratio, and the length of the sequence. The sequence should be generated such that each term is the product of the previous term and the common ratio. The function should handle cases where the length is zero o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_geometric_sequence(start: float, ratio: float, length: int) -> List[float]: """ Generates a geometric sequence given the starting term, the common ratio, and the length of the sequence. ...
evol_instruct_66k
44,644
Write a Python function to calculate the arithmetic mean of a given numerical array using the `numpy` library. The function should handle arrays of any length and return the mean value as a floating-point number. The code should start with: ```python from typing import List import numpy as np def calculate_mean(array:...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import numpy as np def calculate_mean(array: List[int]) -> float: """ Calculate the arithmetic mean of a given numerical array using the numpy library. Args: array (List[int]): The numerical...
evol_instruct_66k
44,647
Write a Python function to find and return a list of duplicate elements from a given list. The function should efficiently identify duplicates by improving the computational time complexity compared to the original code snippet. The code should start with: ```python from typing import List def find_duplicates(lst: Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_duplicates(lst: List[int]) -> List[int]: """ Find and return a list of duplicate elements from the given list. Args: lst (List[int]): The list of integers from which to find duplica...
evol_instruct_66k
44,653
Write a Python function to sort a list of movie titles and their release years in descending order based on the release years. Each movie is represented as a tuple where the first element is the title and the second element is the release year. The function should return the sorted list. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def sort_movies_by_year(movies: List[Tuple[str, int]]) -> List[Tuple[str, int]]: """ Sorts a list of movie titles and their release years in descending order based on the release years. Args:...
evol_instruct_66k
44,660
Write a Python function to validate if a given JSON string represents a structurally correct entity. The entity should have a specific structure: it must contain a "user" object with the following keys: "id" (an integer), "name" (a string), "email" (a string), "roles" (a list of strings), "profile" (an object with keys...
Here is the Python code to solve the given problem in the markdown block: ```python import json from datetime import datetime def validate_json_entity(json_string: str) -> bool: """ Validates if a given JSON string represents a structurally correct entity. The entity must contain a "user" object with spec...
evol_instruct_66k
44,662
Write a Python function to extract all distinct elements from a given data collection that meet a specified condition. The data collection is a list of tuples, where each tuple contains two elements: a key and a value. The function should allow the user to specify the condition for the key or the value. The code should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Any, Callable def extract_unique_elements(data: List[Tuple[Any, Any]], condition: Callable[[Any], bool]) -> set: """ Extracts all distinct elements from a given data collection that meet a specif...
evol_instruct_66k
44,683
Write a Python function to generate a CSS stylesheet that aligns text vertically and sets the background color to a light blue hue. The function should take a single parameter `selector` which is a string representing the CSS selector for the elements to be styled. The function should return a string containing the CSS...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_vertical_text_stylesheet(selector: str) -> str: """ Generates a CSS stylesheet that aligns text vertically and sets the background color to a light blue hue. Args: selector (str): The CSS selector for t...
evol_instruct_66k
44,685
Write a Python function to generate the first `n` numbers in the Fibonacci sequence and return them as a list. Additionally, create a function to print each number in the sequence with its position (starting from 1). The code should start with: ```python from typing import List def generate_fibonacci_sequence(n: int)...
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 first n numbers in the Fibonacci sequence. Args: n (int): The number of Fibonacci numbers to generate. Returns: ...
evol_instruct_66k
44,705
Write a Python function to calculate the average of the smallest and largest values from a given list of integers. The function should use the `numpy` library to find the minimum and maximum values in the list. The code should start with: ```python from typing import List import numpy as np def average_of_extremes(arr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import numpy as np def average_of_extremes(arr: List[int]) -> float: """ Calculate the average of the smallest and largest values from a given list of integers. Args: arr (List[int]): The li...
evol_instruct_66k
44,706
Write a Python function to sort a list of dictionaries based on the 'age' key in ascending order. If two dictionaries have the same 'age', sort them by the 'name' key in alphabetical order. The function should return the sorted list. The code should start with: ```python from typing import List, Dict def sort_by_age_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def sort_by_age_and_name(data: List[Dict[str, any]]) -> List[Dict[str, any]]: """ Sorts a list of dictionaries based on the 'age' key in ascending order. If two dictionaries have the same 'age'...
evol_instruct_66k
44,721
Write a Python function to filter sentences that contain the word "dog" followed by any number of characters except the letters "x" and "y". Additionally, ensure that sentences containing the word "god" or any other permutations of "dog" are excluded. The function should return a list of sentences that match the criter...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def filter_sentences(sentences: List[str]) -> List[str]: """ Filters sentences that contain the word "dog" followed by any number of characters except "x" and "y". Additionally, excludes se...
evol_instruct_66k
44,740
Write a Python function to convert a time string in the format 'hh:mm:ss' into the equivalent time in seconds. The function should handle input validation to ensure the time string is in the correct format and that the hours, minutes, and seconds are within their respective valid ranges. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python import re def time_to_seconds(time_string: str) -> int: """ Converts a time string in the format 'hh:mm:ss' to the equivalent time in seconds. Args: time_string (str): The time string to convert, in the format 'hh:...
evol_instruct_66k
44,743
Write a Python function to find all pairs of numbers (i, j) such that their sum equals a given integer `n`. The function should return a list of tuples, where each tuple represents a pair of numbers. The pairs should be stored in a list instead of being printed. The code should start with: ```python from typing import ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_pairs(n: int) -> List[Tuple[int, int]]: """ Find all pairs of numbers (i, j) such that their sum equals the given integer n. Args: n (int): The target sum for the pairs. ...
evol_instruct_66k
44,746
Write a Python function to find the second smallest element in an unsorted array of integers, considering that the array may contain duplicate elements. The function should be efficient and should handle cases where the array has fewer than two elements. The code should start with: ```python from typing import List, O...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_second_smallest(arr: List[int]) -> Optional[int]: """ Find the second smallest element in an unsorted array of integers. Args: arr (List[int]): The input array of integers...
evol_instruct_66k
44,749
Write a Python function to check if a given text contains the exact sequence "Hello World!" using a regular expression. The function should return `True` if the sequence is found, and `False` otherwise. The code should start with: ```python import re def contains_hello_world(text: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python import re def contains_hello_world(text: str) -> bool: """ Check if the given text contains the exact sequence "Hello World!" using a regular expression. Args: text (str): The text to search within. Returns: ...
evol_instruct_66k
44,754
Write a Python function to reverse a given string and return the reversed string. The function should handle strings of varying lengths, including empty strings. The code should start with: ```python def reverse_string(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses the given string and returns the reversed string. Args: s (str): The input string to be reversed. Returns: str: The reversed string. """ # Use sli...
evol_instruct_66k
44,761
Write a Python function to calculate the least common multiple (LCM) of a list of numbers using the prime factorization method. The function should start with: ```python from typing import List def lcm_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, Dict from collections import defaultdict def prime_factors(n: int) -> Dict[int, int]: """ Compute the prime factors and their powers for a given number. Args: n (int): The number to factori...
evol_instruct_66k
44,766
Write a Python function to iterate over a list of strings and return a new list containing the lengths of each string in the original list. The function should handle lists of varying lengths and ensure that the returned list maintains the same order as the original list. The code should start with: ```python from typ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def string_lengths(strings: List[str]) -> List[int]: """ Returns a list of the lengths of each string in the input list. Args: strings (List[str]): A list of strings for which to calculate t...
evol_instruct_66k
44,772
Write a Python function to create a two-dimensional array of size `m x n` filled with alternating 0s and 1s. The initial value of each row should start with 0 and end with 1. The function should take two integer parameters `m` and `n` representing the dimensions of the array. The function should return the created 2D a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def create_alternating_array(m: int, n: int) -> List[List[int]]: """ Create a two-dimensional array of size m x n filled with alternating 0s and 1s. Each row starts with 0 and ends with 1. Args:...
evol_instruct_66k
44,777
Write a Python function to calculate the arithmetic average (mean) of a given list of numerical data points. The function should handle lists of any length, including empty lists, and return the mean value. If the list is empty, the function should return `None`. The code should start with: ```python from typing impor...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def calculate_mean(data_points: List[float]) -> Optional[float]: """ Calculate the arithmetic average (mean) of a given list of numerical data points. Args: data_points (List[float...
evol_instruct_66k
44,779
Write a Python function to recursively flatten a nested list, specifically a 2D matrix, into a single linear list. The function should handle lists of varying depths and ensure that all elements are included in the resulting linear list. The code should start with: ```python from typing import List def flatten_nested_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def flatten_nested_list(nested_list: List) -> List[int]: """ Recursively flattens a nested list into a single linear list. Args: nested_list (List): The nested list to be flattened. Ret...
evol_instruct_66k
44,781
Write a Python function to calculate the sum of all elements in a given 2D array while traversing it in a spiral order starting from the top-left corner and moving clockwise. The function should handle any rectangular 2D array, including non-square matrices. The code should start with: ```python from typing import Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def spiral_sum(matrix: List[List[int]]) -> int: """ Calculate the sum of all elements in a given 2D array while traversing it in a spiral order starting from the top-left corner and moving clockwise....
evol_instruct_66k
44,791
Write a Python function to find a target word or its reversed version in a list of words. The function should return the word if found, otherwise return `None`. The code should start with: ```python from typing import List, Optional def find_word_or_reverse(words: List[str], target: str) -> Optional[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_word_or_reverse(words: List[str], target: str) -> Optional[str]: """ Find a target word or its reversed version in a list of words. Args: words (List[str]): A list of word...
evol_instruct_66k
44,809
Write a Python function to analyze the structure of a provided collection of variables, potentially consisting of a diverse medley of data types such as floating point numbers, strings, and special symbols. The function should return a dictionary where the keys are the data types found in the collection and the values ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def analyze_collection(collection: List[Any]) -> Dict[type, List[Any]]: """ Analyzes the structure of a provided collection of variables and returns a dictionary where the keys are the dat...
evol_instruct_66k
44,828
Write a Python function to count the number of distinct elements in a given list. The function should efficiently handle the task using a set to track unique elements. The code should start with: ```python from typing import List def count_distinct_elements(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_distinct_elements(arr: List[int]) -> int: """ Count the number of distinct elements in the given list. Args: arr (List[int]): The list of integers from which to count distinct elem...
evol_instruct_66k
44,829
Write a Python function to calculate the sum of the highest K elements in a given array. The function should efficiently handle the input and return the sum of the top K elements. The code should start with: ```python from typing import List def sum_of_top_k(arr: List[int], k: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_top_k(arr: List[int], k: int) -> int: """ Calculate the sum of the highest K elements in a given array. Args: arr (List[int]): The array of integers from which to extract the high...
evol_instruct_66k
44,832
Write a Python function to analyze a given dictionary of numerical lists. The function should return a dictionary containing the sum and average of each list in the input dictionary. The input dictionary has string keys and lists of integers as values. The function should start with: ```python from typing import Dict, ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def analyze_numerical_data(data: Dict[str, List[int]]) -> Dict[str, Dict[str, float]]: """ Analyzes a dictionary of numerical lists and returns a dictionary containing the sum and average of each l...
evol_instruct_66k
44,839
Write a Python function to extract and return the digit that is positioned immediately to the left of the decimal point in a given floating-point number. The function should handle both positive and negative floating-point numbers. The code should start with: ```python def get_digit_left_of_decimal(num: float) -> int:...
Here is the Python code to solve the given problem in the markdown block: ```python def get_digit_left_of_decimal(num: float) -> int: """ Extracts and returns the digit immediately to the left of the decimal point in a given floating-point number. Args: num (float): The floating-point number from w...
evol_instruct_66k
44,846
Write a Python function to extract and return the keys from a given dictionary as a list. The function should handle dictionaries with various data types as values. The code should start with: ```python from typing import Dict, List, Any def extract_keys(dictionary: Dict[Any, Any]) -> List[Any]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import Dict, List, Any def extract_keys(dictionary: Dict[Any, Any]) -> List[Any]: """ Extracts and returns the keys from a given dictionary as a list. Args: dictionary (Dict[Any, Any]): The dictionary...
evol_instruct_66k
44,849
Write a Python function to remove duplicate elements from a given list while preserving the original order of elements. The function should take a list as input and return a new list with all unique elements in the order they first appear. The code should start with: ```python from typing import List def remove_dupli...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_preserve_order(input_list: List[int]) -> List[int]: """ Removes duplicate elements from the input list while preserving the original order of elements. Args: input_list...
evol_instruct_66k
44,866
Write a Python function to extract all unique values from a given dictionary and return them as a tuple. The function should not use any built-in functions specifically designed for dictionary value extraction. The code should start with: ```python from typing import Dict, Tuple def extract_unique_values(dictionary: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Tuple def extract_unique_values(dictionary: Dict[str, str]) -> Tuple[str]: """ Extracts all unique values from a given dictionary and returns them as a tuple. Args: dictionary (Dict[str, st...
evol_instruct_66k
44,868
Write a Python function to create and initialize a 2D array (matrix) with dimensions `m x n`, where each element is initialized to a specified value. The function should handle cases where `m` or `n` is zero, returning an empty list in such cases. The code should start with: ```python from typing import List def creat...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def create_2d_array(m: int, n: int, initial_value: int) -> List[List[int]]: """ Creates and initializes a 2D array (matrix) with dimensions m x n, where each element is set to the specified initial value...
evol_instruct_66k
44,870
Write a Python function to calculate the shipping cost based on the weight of the item and the rate per pound. The function should handle different weight and rate inputs and return the calculated shipping cost. The code should start with: ```python def calculate_shipping_cost(weight: float, rate: float) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_shipping_cost(weight: float, rate: float) -> float: """ Calculate the shipping cost based on the weight of the item and the rate per pound. Args: weight (float): The weight of the item in pounds. ...
evol_instruct_66k
44,871
Write a Python function that constructs a novel tuple using the provided string and list as input parameters. The function should ensure that the tuple contains the string as its first element and the list as its second element. The function should also handle cases where the input string or list might be empty. The c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def construct_tuple(input_string: str, input_list: List[int]) -> Tuple[str, List[int]]: """ Constructs a tuple using the provided string and list as input parameters. Args: input_stri...
evol_instruct_66k
44,874
Write a Python function to check if a given string matches the exact identifier "hello people" using regular expressions. The function should return `True` if the string matches exactly, and `False` otherwise. The code should start with: ```python import re def is_exact_match(string: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_exact_match(string: str) -> bool: """ Check if the given string matches the exact identifier "hello people" using regular expressions. Args: string (str): The string to be checked. Returns: ...
evol_instruct_66k
44,875
Write a Python function to reverse a given list of integers without using any built-in Python functions or methods that directly reverse a list. The function should use basic list operations to achieve the reversal. The code should start with: ```python from typing import List def reverse_list(input_list: List[int]) ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_list(input_list: List[int]) -> List[int]: """ Reverses the given list of integers without using any built-in reverse functions or methods. Args: input_list (List[int]): The list ...
evol_instruct_66k
44,884
Write a Python function to filter a list of dictionaries based on a specified key-value pair. The function should return a new list containing only the dictionaries that match the specified key-value pair. The code should start with: ```python from typing import List, Dict def filter_list_of_dicts(list_of_dicts: List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def filter_list_of_dicts(list_of_dicts: List[Dict[str, any]], key: str, value: any) -> List[Dict[str, any]]: """ Filters a list of dictionaries based on a specified key-value pair. Args: ...
evol_instruct_66k
44,890
Write a Python function to efficiently check if a specific element is present in a given list. The function should return `True` if the element is found, and `False` otherwise. The function should be optimized for both computational complexity and speed. 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 is_element_in_list(my_list: List[int], element: int) -> bool: """ Efficiently checks if a specific element is present in a given list. Args: my_list (List[int]): The list in which to sea...
evol_instruct_66k
44,892
Write a Python function to determine if any element from the first vector exists in the second vector. The function should return a boolean value indicating whether such an element exists. If no element from the first vector is found in the second one, the function should return `False`. 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 has_common_element(vector1: List[int], vector2: List[int]) -> bool: """ Determines if any element from the first vector exists in the second vector. Args: vector1 (List[int]): The first ...
evol_instruct_66k
44,893
Write a Python function to perform a binary search on a sorted array to find the index of a target value. The function should be optimized to reduce time complexity and should not use any in-built Python functions or libraries. The code should start with: ```python from typing import List def binary_search(arr: List[i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search(arr: List[int], x: int) -> int: """ Perform a binary search on a sorted array to find the index of a target value. Args: arr (List[int]): A sorted list of integers. ...
evol_instruct_66k
44,899
Write a Python function to determine if one string (`s2`) is a substring of another string (`s1`). The function should return `True` if `s2` is a substring of `s1`, and `False` otherwise. The function should handle edge cases such as empty strings and strings where `s2` is longer than `s1`. The code should start with:...
Here is the Python code to solve the given problem in the markdown block: ```python def is_substring(s1: str, s2: str) -> bool: """ Determines if the string `s2` is a substring of the string `s1`. Args: s1 (str): The main string in which to search for the substring. s2 (str): The substring ...
evol_instruct_66k
44,908
Write a Python function to split a nested list of pairs into two separate lists: one containing the first elements of each pair and the other containing the second elements of each pair. The function should handle any number of pairs in the nested list. The code should start with: ```python from typing import List de...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def split_nested_pairs(pairs_list: List[List[int]]) -> List[List[int]]: """ Splits a nested list of pairs into two separate lists: one containing the first elements of each pair and the other containing ...
evol_instruct_66k
44,910
Write a Python function to trace the occurrence of all unique numbers and non-integer types in a complex multi-dimensional array. The function should handle nested arrays and non-integer types. The code should start with: ```python from typing import List, Dict, Any def trace_unique_elements(arr: List[Any]) -> Dict[An...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def trace_unique_elements(arr: List[Any]) -> Dict[Any, int]: """ Trace the occurrence of all unique numbers and non-integer types in a complex multi-dimensional array. Args: arr (...
evol_instruct_66k
44,915
Write a Python function that calculates and yields the minimum and maximum integers from a given list of numbers. The function should handle lists of any length, including empty lists. If the list is empty, the function should yield `None` for both the minimum and maximum values. The function should start with: ```pyth...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Optional def find_min_max(numbers: List[int]) -> Tuple[Optional[int], Optional[int]]: """ Calculate and yield the minimum and maximum integers from a given list of numbers. Args: num...
evol_instruct_66k
44,924
Write a Python function to compute the height of an antenna where a guy-wire is attached, given the length of the guy-wire and the angle it makes with the ground. The function should use trigonometric functions to calculate the height. The code should start with: ```python import math def compute_antenna_height(guy_w...
Here is the Python code to solve the given problem in the markdown block: ```python import math def compute_antenna_height(guy_wire_length: float, angle_degrees: float) -> float: """ Compute the height of an antenna where a guy-wire is attached. Args: guy_wire_length (float): The length of the guy...
evol_instruct_66k
44,927
Write a Python function to find the distinct prime factors of a given integer `n` along with their frequencies, and ensure that the integer `n` is the multiplication of all the prime factors raised to their corresponding frequencies. The function should have a time complexity no greater than O(sqrt(n)) and space comple...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import math def prime_factors(n: int) -> List[Tuple[int, int]]: """ Find the distinct prime factors of a given integer `n` along with their frequencies. Ensure that the integer `n` is the mult...
evol_instruct_66k
44,937
Write a Python function to validate if an email address is associated with the domain "example.com" using a regular expression. The function should return `True` if the email is valid and `False` otherwise. The code should start with: ```python import re def is_example_com_email(email: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_example_com_email(email: str) -> bool: """ Validates if the given email address is associated with the domain "example.com". Args: email (str): The email address to validate. Returns: ...
evol_instruct_66k
44,952
Write a Python function to find and return the sentences with the most words from a given list of sentences. The function should handle cases where there are multiple sentences with the same maximum word count. The code should start with: ```python from typing import List def sentences_with_most_words(sentences: List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sentences_with_most_words(sentences: List[str]) -> List[str]: """ Returns a list of sentences that have the most words from the given list of sentences. Args: sentences (List[str]): A li...
evol_instruct_66k
44,974
Write a Python function to combine two lists such that the elements of the first list are followed by the elements of the second list. The function should handle lists of different lengths and return a new list that contains all elements from both input lists in the specified order. 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 combine_lists(list1: List[int], list2: List[int]) -> List[int]: """ Combines two lists such that the elements of the first list are followed by the elements of the second list. Args: lis...
evol_instruct_66k
44,975
Write a Python function to reverse a given list of integers using a recursive approach. The function should handle lists containing both positive and negative integers. The code should start with: ```python from typing import List def reverse_list(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 reverse_list(lst: List[int]) -> List[int]: """ Reverses a given list of integers using a recursive approach. Args: lst (List[int]): The list of integers to be reversed. Returns: ...
evol_instruct_66k
44,983
Write a Python function to validate if a given string strictly adheres to the pattern of three capital letters immediately followed by a pair of lowercase letters. The function should return `True` if the string matches the pattern and `False` otherwise. The code should start with: ```python import re def validate_str...
Here is the Python code to solve the given problem in the markdown block: ```python import re def validate_string_pattern(s: str) -> bool: """ Validates if the given string strictly adheres to the pattern of three capital letters immediately followed by a pair of lowercase letters. Args: s (st...
evol_instruct_66k
45,003
Write a Python function to identify and extract all the odd numerals from a given numerical string, and then compute their cumulative sum. The function should return the cumulative sum of the extracted odd numerals. The code should start with: ```python def cumulative_sum_of_odd_numerals(numerical_string: str) -> int:...
Here is the Python code to solve the given problem in the markdown block: ```python def cumulative_sum_of_odd_numerals(numerical_string: str) -> int: """ Identifies and extracts all the odd numerals from a given numerical string and computes their cumulative sum. Args: numerical_string (str): A str...
evol_instruct_66k
45,014
Write a Python function to find the distinct common elements between two lists, sorted in increasing order, without using Python's built-in sorting or set operations. The function should have a time complexity of O(n log n) or better. The code should start with: ```python from typing import List def shared_elements(li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def partition(arr: List[int]) -> (List[int], List[int], List[int]): """ Partitions the array into three parts: elements less than the pivot, elements equal to the pivot, and elements greater than the...
evol_instruct_66k
45,029
Write a Python function to convert an octal number represented as a string into its corresponding decimal representation also as a string. The function should handle any valid octal input and return the decimal equivalent as a string. The code should start with: ```python def octal_to_decimal(x: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def octal_to_decimal(x: str) -> str: """ Convert an octal input (string) into its corresponding decimal representation (string). Args: x (str): The octal number to be converted, represented as a string. Returns...
evol_instruct_66k
45,044
Write a Python function to shuffle a given array in place. The function should modify the original array and return it. The array contains integers. The code should start with: ```python from typing import List import random def shuffle_array(arr: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List import random def shuffle_array(arr: List[int]) -> List[int]: """ Shuffles the given array in place and returns the shuffled array. Args: arr (List[int]): The array to be shuffled. Re...
evol_instruct_66k
45,048
Write a Python function to construct a full-fledged HTTPS hyperlink using the provided sub-domain, main domain, and path components. The function should handle the construction of the URL in a flexible manner, allowing for the inclusion of an optional top-level domain (TLD) and query parameters. The function should ret...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Optional, Dict def construct_url(subdomain: str, main_domain: str, path: str, tld: Optional[str] = 'com', query_params: Optional[Dict[str, str]] = None) -> str: """ Constructs a full-fledged HTTPS hyperlink u...
evol_instruct_66k
45,051
Write a Python function to evaluate the equivalence or disparity of two integers and handle overflow and underflow conditions during the comparison. Additionally, the function should check whether the integers are positive, negative, or zero and return corresponding flags for each condition. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python import sys def compare_integers(a: int, b: int) -> dict: """ Compare two integers and handle overflow and underflow conditions. Additionally, check if the integers are positive, negative, or zero. Args: a (int)...
evol_instruct_66k
45,055
Write a Python function to generate a list of integers that populate the numerically inclusive spectrum from a given start integer to a given end integer (inclusive). The function should handle cases where the start integer is greater than the end integer by generating an empty list. 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 generate_integer_spectrum(start: int, end: int) -> List[int]: """ Generates a list of integers that populate the numerically inclusive spectrum from start to end (inclusive). Args: start...
evol_instruct_66k
45,066
Write a Python function to create a 5x5 multidimensional array filled with unique random prime numbers each lying within the numerical boundaries of 1 to 500. The prime numbers should be derived from a custom function that implements the Sieve of Eratosthenes algorithm instead of using built-in functions or libraries. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def sieve_of_eratosthenes(limit: int) -> List[int]: """ Generate a list of prime numbers up to the given limit using the Sieve of Eratosthenes algorithm. Args: limit (int): The...