source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
evol_instruct_66k
45,077
Write a Python function to calculate the planar area of a rectangular structure using its length and width. The function should handle both integer and floating-point inputs and return the area as a float or integer. The code should start with: ```python def rectangle_area(length: float, width: float) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def rectangle_area(length: float, width: float) -> float: """ Calculate the planar area of a rectangular structure using its length and width. Args: length (float): The length of the rectangle. width (float)...
evol_instruct_66k
45,078
Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of a given m x n grid, where you can only move right or down. The function should start with: ```python from typing import List def unique_paths(m: int, n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def unique_paths(m: int, n: int) -> int: """ Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid. Args: m (int): The number of row...
evol_instruct_66k
45,086
Write a Python function to determine the corresponding ASCII character for a given numerical code and provide a brief explanation of how ASCII codes create a standardized correlation between numbers and characters. The function should take an integer as input and return the corresponding ASCII character as a string. Th...
Here is the Python code to solve the given problem in the markdown block: : ```python def get_ascii_char(code: int) -> str: """ Returns the corresponding ASCII character for a given numerical code. Args: code (int): The numerical code representing an ASCII character (0-127). Returns: s...
evol_instruct_66k
45,091
Write a Python function to generate the Fibonacci sequence up to the nth term. The function should return a list containing the first n terms of 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 generate...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: """ Generate the Fibonacci sequence up to the nth term. Args: n (int): The number of terms in the Fibonacci sequence to generate. Returns: ...
evol_instruct_66k
45,095
Write a Python function to identify the most frequent item in a given list and count how many times it appears. The function should return a tuple containing the most frequent item and its count. The code should start with: ```python from typing import List, Tuple def most_frequent_item_count(data: List[int]) -> Tuple...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def most_frequent_item_count(data: List[int]) -> Tuple[int, int]: """ Identifies the most frequent item in a given list and counts how many times it appears. Args: data (List[int]): T...
evol_instruct_66k
45,104
Write a Python function to calculate the sum of elements in an array of prime numbers. The function should accept an array of prime numbers as its input parameter and return the sum of the elements in the array. The function should be able to handle any array of prime numbers, not just the example provided. The code s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_primes(primes: List[int]) -> int: """ Calculate the sum of elements in an array of prime numbers. Args: primes (List[int]): A list of prime numbers. Returns: int: The...
evol_instruct_66k
45,113
Write a Python function to consolidate successive identical elements from a given list into distinct subarrays. Each subarray should contain all consecutive identical elements from the original list. The function should handle an empty list by returning an empty list. 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 consolidate_elements(lst: List[int]) -> List[List[int]]: """ Consolidates successive identical elements from a given list into distinct subarrays. Args: lst (List[int]): The input list o...
evol_instruct_66k
45,115
Write a Python function to calculate the Levenshtein Distance between two strings. The Levenshtein Distance is defined as the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other. The function should be efficient and handle strings of varying le...
Here is the Python code to solve the given problem in the markdown block: ```python def levenshtein_distance(s1: str, s2: str) -> int: """ Calculate the Levenshtein Distance between two strings. The Levenshtein Distance is the minimum number of single-character edits (insertions, deletions, or substitu...
evol_instruct_66k
45,123
Write a Python function to recursively extract all values from a nested structure of dictionaries and lists while maintaining the order of the original structure. The function should handle any level of nesting and return a flat list of all values encountered. The code should start with: ```python from typing import L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def extract_all_values(element: Union[dict, list, int, float, str]) -> List: """ Recursively extracts all values from a nested structure of dictionaries and lists. Args: element: A di...
evol_instruct_66k
45,124
Write a Python function to compute the Least Common Multiple (LCM) of two integers efficiently. The function should correct any errors in the provided preliminary code and enhance its efficiency. The function should take two integers `a` and `b` as parameters and return their LCM. The code should start with: ```python...
Here is the Python code to solve the given problem in the markdown block: ```python def gcd(a: int, b: int) -> int: """ Calculate the Greatest Common Divisor (GCD) using the Euclidean algorithm. Args: a (int): The first integer. b (int): The second integer. Returns: int: The GC...
evol_instruct_66k
45,144
Create a Python function that initializes and returns a data structure containing five distinct string components. The function should ensure that each component is a string and that the data structure maintains the integrity of the data architecture. The function should also provide a way to retrieve a specific compon...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def create_data_structure() -> List[str]: """ Initializes and returns a data structure containing five distinct string components. Returns: List[str]: A list containing five string component...
evol_instruct_66k
45,153
Write a Python function that converts a given string into its corresponding lowercase counterpart while ensuring that the string contains only alphabetical characters. If the input string contains any non-alphabetical characters, they should be removed before the conversion. The cleaned and converted string should be r...
Here is the Python code to solve the given problem in the markdown block: ```python def clean_convert_string(input_string: str) -> str: """ Converts a given string into its corresponding lowercase counterpart while ensuring that the string contains only alphabetical characters. Non-alphabetical characters ...
evol_instruct_66k
45,156
Write a Python function to safely print a list of integers, ensuring that any potential errors are caught and handled gracefully. The function should accept a list of integers as input and print the list. If an error occurs during the printing process, the function should print a custom error message instead of allowin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def safe_print_list(lst: List[int]) -> None: """ Safely prints a list of integers. If an error occurs during the printing process, a custom error message is printed instead of allowing the program to...
evol_instruct_66k
45,163
Write a Python function to print the phrase "I love Python" five times, followed by printing the reverse of the phrase "I love Python" five times. The function should not use any in-built or external libraries for reversing the string. The code should start with: ```python def print_phrases(): ```
Here is the Python code to solve the given problem in the markdown block: ```python def print_phrases(): """ Prints the phrase "I love Python" five times, followed by printing the reverse of the phrase "I love Python" five times. This function does not use any in-built or external libraries for reversing t...
evol_instruct_66k
45,187
Write a Python function to check if a given integer is divisible by both 7 and 13 without using direct division (e.g., using the '/' operator) or the modulo operator (e.g., using the '%' operator). The function should return `True` if the integer is divisible by both 7 and 13, and `False` otherwise. The code should st...
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_7_and_13(n: int) -> bool: """ Check if a given integer is divisible by both 7 and 13 without using direct division or the modulo operator. Args: n (int): The integer to check for divisibility. ...
evol_instruct_66k
45,200
Write a Python function to sort a given list of integers in descending 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 sort_descending(sequence: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_descending(sequence: List[int]) -> List[int]: """ Sorts a given list of integers in descending order. Args: sequence (List[int]): The list of integers to be sorted. Returns: ...
evol_instruct_66k
45,212
Write a Python function to shuffle a list of numbers such that each element is moved to a new position. The function should ensure that the shuffled list is different from the original list. The code should start with: ```python from typing import List import random def shuffle_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 import random def shuffle_numbers(numbers: List[int]) -> List[int]: """ Shuffles a list of numbers such that each element is moved to a new position. Args: numbers (List[int]): The list of...
evol_instruct_66k
45,226
Write a Python function to find the index of the maximum value in a given array of numerical values. The function should iterate over each element and compare it to the remaining ones to identify the maximum value and its respective position. The code should start with: ```python from typing import List def find_max_i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_index(arr: List[int]) -> int: """ Find the index of the maximum value in a given array of numerical values. Args: arr (List[int]): The array of numerical values. Returns: ...
evol_instruct_66k
45,228
Write a Python function to convert a matrix of hexadecimal strings to their corresponding decimal values. The matrix is represented as a list of strings, where each string is a hexadecimal number prefixed with '0x'. The function should return a list of integers, each representing the decimal equivalent of the correspon...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_hex_matrix_to_decimal(matrix: List[str]) -> List[int]: """ Converts a matrix of hexadecimal strings to their corresponding decimal values. Args: matrix (List[str]): A list of str...
evol_instruct_66k
45,229
Write a Python function to extract the final pair of elements from a given list of items. The function should handle lists of any length, including cases where the list has fewer than two elements. The code should start with: ```python from typing import List def get_final_pair(items: List[str]) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_final_pair(items: List[str]) -> List[str]: """ Extracts the final pair of elements from a given list of items. Args: items (List[str]): The list of items from which to extract the fi...
evol_instruct_66k
45,237
Write a Python function to convert a given collection of integers between different data types (list, set, tuple) and analyze the time and space complexity of the conversion process. The function should accept a collection of integers and a target data type as input, and return the converted collection. The function sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Set, Tuple, Union def convert_collection(collection: Union[List[int], Set[int], Tuple[int]], target_type: str) -> Union[List[int], Set[int], Tuple[int]]: """ Converts a given collection of integers to t...
evol_instruct_66k
45,238
Write a Python function to calculate the mode(s) of a given list of numbers using the `collections.Counter` class without directly using the `statistics.mode` function. The function should handle cases where the list may have more than one mode. The code should start with: ```python from typing import List from collect...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import Counter def calculate_modes(data: List[int]) -> List[int]: """ Calculate the mode(s) of a given list of numbers using the collections.Counter class. Args: data (List[...
evol_instruct_66k
45,261
Write a Python function to calculate the volume of a pyramid given its base area and height. The function should incorporate an intermediary step where the product of the base area and height is calculated before determining the final volume. The function should return the volume as a float. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_pyramid_volume(base_area: float, height: float) -> float: """ Calculate the volume of a pyramid given its base area and height. The volume is calculated using the formula: V = (1/3) * base_area * height ...
evol_instruct_66k
45,270
Write a Python function to eliminate repeated consecutive entries within an array and maintain a count of deleted duplicates for each unique string. The function should return two outputs: the modified array and a dictionary containing the count of deleted duplicates for each unique string. The function should use data...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def eliminate_duplicates_and_count(array: List[str]) -> (List[str], Dict[str, int]): """ Eliminates repeated consecutive entries within an array and maintains a count of deleted duplicates for each...
evol_instruct_66k
45,318
Write a Python function to compute the mathematical square of each element in a given list of integers and return a new list containing these squared values. The function should handle lists of any length, including empty lists. The code should start with: ```python from typing import List def square_elements(arr: Lis...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def square_elements(arr: List[int]) -> List[int]: """ Compute the square of each element in the given list of integers and return a new list containing these squared values. Args: arr (Lis...
evol_instruct_66k
45,320
Write a Python function to find all the positions of a specific value within a given array. The function should return a list of indices where the specific value occurs in the array. If the value is not found in the array, the function should return an empty list. The code should start with: ```python from typing impo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_positions(array: List[int], specific_value: int) -> List[int]: """ Find all positions of a specific value within a given array. Args: array (List[int]): The array in which to search...
evol_instruct_66k
45,322
Write a Python function to sort a list of numbers using the Bubble Sort algorithm. The function should take a list of integers as input and return the sorted list. The code should start with: ```python from typing import List def bubble_sort(number_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(number_list: List[int]) -> List[int]: """ Sorts a list of integers using the Bubble Sort algorithm. Args: number_list (List[int]): The list of integers to be sorted. Ret...
evol_instruct_66k
45,329
Write a Python function to generate a unique sequence of 12 characters containing only the letters 'x', 'y', and 'z'. The sequence must include at least one of each letter and no three of the same letters occur consecutively. The function should return the generated sequence as a string. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python import random def generate_unique_sequence() -> str: """ Generates a unique sequence of 12 characters containing only 'x', 'y', and 'z'. The sequence includes at least one of each letter and no three of the same letters occ...
evol_instruct_66k
45,332
Design a Python function to create a graph representation of locations and their respective neighbors using a dictionary. The function should take a list of tuples, where each tuple contains a location and its neighbors, and return a dictionary where each key is a location and the value is a list of its neighbors. The...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def create_location_graph(locations: List[Tuple[str, List[str]]]) -> Dict[str, List[str]]: """ Creates a graph representation of locations and their respective neighbors. Args: ...
evol_instruct_66k
45,337
Write a Python function to update the prices of fruits in a given dictionary. The function should take a dictionary of fruit names and their prices, and a list of tuples where each tuple contains a fruit name and its new price. The function should return the updated dictionary. The code should start with: ```python fr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def update_fruit_prices(fruit_prices: Dict[str, float], updates: List[Tuple[str, float]]) -> Dict[str, float]: """ Updates the prices of fruits in the given dictionary based on the provided ...
evol_instruct_66k
45,340
Write a Python function to generate a CSS Grid and Flexbox layout for a fluid webpage that contains 4 columns and 3 rows. Each cell should have a 15px padding and adjust proportionately when the browser window is resized. The layout should be fully responsive, adjusting to 2 columns/6 rows on tablet view and 1 column/1...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_responsive_layout() -> str: """ Generates a CSS string for a responsive webpage layout using CSS Grid and Flexbox. The layout contains 4 columns and 3 rows with 15px padding in each cell. It adjusts proporti...
evol_instruct_66k
45,341
Write a Python function to perform a linear search on sections of a large list concurrently using multi-threading. The function should be able to handle lists where the size isn't known until runtime. Additionally, measure and compare the performance of the multi-threaded algorithm against a single-threaded linear sear...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional import threading import time def linear_search_single_threaded(arr: List[int], target: int) -> Optional[int]: """ Perform a linear search on the entire list using a single thread. Args...
evol_instruct_66k
45,348
Write a Python function to remove all non-alphabetical characters from a given sentence, preserving spaces. The function should return the cleaned sentence. The code should start with: ```python def clean_sentence(sentence: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def clean_sentence(sentence: str) -> str: """ Removes all non-alphabetical characters from the given sentence, preserving spaces. Args: sentence (str): The input sentence from which non-alphabetical characters are t...
evol_instruct_66k
45,349
Write a Python function to transform a given list into a dictionary while maintaining the original values as dictionary values. The keys of the dictionary should be the indices of the corresponding elements in the list. The function should handle lists of various types and lengths. The code should start with: ```pytho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def list_to_dict(lst: List[Any]) -> Dict[int, Any]: """ Transforms a given list into a dictionary where the keys are the indices of the list elements and the values are the elements themselves...
evol_instruct_66k
45,350
Write a Python function to retrieve the 10th and 11th elements from a given numeric array, ensuring that the function checks the length of the array to prevent out-of-range errors. If the array is not large enough, the function should return a specific message indicating that the array is too short. The code should st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def get_10th_and_11th_elements(arr: List[int]) -> Tuple[int, int] or str: """ Retrieves the 10th and 11th elements from a given numeric array, ensuring the array is large enough to prevent out-of-...
evol_instruct_66k
45,363
Write a Python function to identify lists containing single-character strings and replace all such strings with a specified non-null value. The function should return the modified list. The code should start with: ```python from typing import List def replace_single_char_strings(arr: List[str], replacement: str) -> Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def replace_single_char_strings(arr: List[str], replacement: str) -> List[str]: """ Replaces all single-character strings in the given list with the specified replacement string. Args: arr (...
evol_instruct_66k
45,364
Write a Python function to find the longest common subsequence (LCS) between two given strings. The function should return the length of the LCS. The code should start with: ```python def longest_common_subsequence(str1: str, str2: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def longest_common_subsequence(str1: str, str2: str) -> int: """ Calculate the length of the longest common subsequence (LCS) between two strings. Args: str1 (str): The first string. str2 (str): The second...
evol_instruct_66k
45,372
Write a Python function to create a 4D array of a specified size where every element corresponds to a given value. The function should take three arguments: the dimensions of the array (a tuple of four integers), and the value to fill the array with (an integer). The function should return the created 4D array. The co...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np from typing import Tuple, Any def create_4d_array(dimensions: Tuple[int, int, int, int], fill_value: Any) -> np.ndarray: """ Create a 4D array of the specified dimensions and fill it with the given value. ...
evol_instruct_66k
45,381
Write a Python function to sort each row of a given matrix in ascending order without using any built-in sorting functions. The matrix should retain its original number of rows and columns after sorting. The function should start with: ```python from typing import List def sort_matrix_rows(matrix: List[List[int]]) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_matrix_rows(matrix: List[List[int]]) -> List[List[int]]: """ Sorts each row of the given matrix in ascending order without using built-in sorting functions. Args: matrix (List[List[...
evol_instruct_66k
45,383
Write a Python function to generate a JSON-LD prototype for housing comprehensive biographical particulars of an individual. The function should accept a dictionary containing the individual's details and return a JSON-LD formatted string. The JSON-LD prototype should include basic details like name, age, and gender, a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict import json def generate_json_ld_biography(biography: Dict) -> str: """ Generates a JSON-LD prototype for housing comprehensive biographical particulars of an individual. Args: biography (di...
evol_instruct_66k
45,384
Write a Python function to perform element-wise addition of two lists. The function should take two lists of integers as input and return a new list where each element is the sum of the corresponding elements from the input lists. If the input lists are of different lengths, the function should raise a `ValueError`. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def element_wise_addition(list1: List[int], list2: List[int]) -> List[int]: """ Perform element-wise addition of two lists. Args: list1 (List[int]): The first list of integers. list2...
evol_instruct_66k
45,391
Write a Python function to print the current date in 'Day/Month/Year' format. The function should handle the correct import and use of the `datetime` module to ensure the date is printed in the specified format. The code should start with: ```python import datetime def print_current_date(): ```
Here is the Python code to solve the given problem in the markdown block: ```python import datetime def print_current_date(): """ Prints the current date in 'Day/Month/Year' format. This function retrieves the current date and time using the `datetime` module, formats it to 'Day/Month/Year' format, an...
evol_instruct_66k
45,410
Write a Python function to implement a binary search algorithm to find the position of a target item in a sorted list. The function should return the index of the target item if it exists in the list, otherwise, it should return `None`. The code should start with: ```python from typing import List, Optional def binar...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def binary_search(lst: List[int], target: int) -> Optional[int]: """ Perform a binary search to find the position of a target item in a sorted list. Args: lst (List[int]): A sorted...
evol_instruct_66k
45,417
Write a Python function to calculate the sum of two arrays of numbers, the sum of each array separately, and the sum of all numbers combined. The function should handle edge cases such as empty arrays and non-numeric input by returning `None` for invalid inputs. 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, Optional def calculate_sums(array1: List[int], array2: List[int]) -> Optional[List[int]]: """ Calculate the sum of two arrays of numbers, the sum of each array separately, and the sum of all numbers com...
evol_instruct_66k
45,423
Write a Python function to generate a list of prime numbers up to a given limit `n` using the Sieve of Eratosthenes algorithm. The function should return a list of all prime numbers less than `n`. The code should start with: ```python from typing import List def generate_primes(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_primes(n: int) -> List[int]: """ Generate a list of prime numbers up to a given limit `n` using the Sieve of Eratosthenes algorithm. Args: n (int): The upper limit for generatin...
evol_instruct_66k
45,428
Write a Python function to find the first occurrence of a substring in a given string, and return its starting index. If the substring is not found, return -1. The function should handle edge cases such as empty strings and substrings, and should be implemented using a "For" loop to avoid potential infinite loops. The...
Here is the Python code to solve the given problem in the markdown block: ```python def find_substring(main_string: str, sub_string: str) -> int: """ Find the first occurrence of a substring in a given string and return its starting index. If the substring is not found, return -1. Args: main_st...
evol_instruct_66k
45,437
Write a Python function to concatenate two strings without using any built-in string concatenation functions or methods. The function should iterate through each character of the input strings and build the result string manually. The code should start with: ```python def concatenate_strings(str1: str, str2: str) -> s...
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_strings(str1: str, str2: str) -> str: """ Concatenates two strings without using any built-in string concatenation functions or methods. Args: str1 (str): The first string to concatenate. str...
evol_instruct_66k
45,444
Write a Python function to split a given string into words based on a specified delimiter. If no delimiter is provided, the function should split the string by whitespace. The function should handle both single and multiple delimiters. The code should start with: ```python from typing import List, Optional def split_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def split_string_into_words(s: str, delimiter: Optional[str] = None) -> List[str]: """ Splits a given string into words based on a specified delimiter. If no delimiter is provided, the stri...
evol_instruct_66k
45,447
Write a Python function to group a collection of email addresses by their domain, while ignoring malformatted email addresses. The function should discard any email addresses that do not conform to a valid email format. The code should start with: ```python from typing import List, Dict import re def group_emails_by_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict import re def group_emails_by_domain(emails: List[str]) -> Dict[str, List[str]]: """ Groups a collection of email addresses by their domain, ignoring malformatted email addresses. Args: ...
evol_instruct_66k
45,448
Write a Python function to flatten a given two-dimensional matrix into a one-dimensional list. The matrix is represented as a list of lists, where each nested list represents a row in the matrix. The function should return a single list containing all the elements of the matrix in row-major order. The code should star...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def flatten_matrix(matrix: List[List[int]]) -> List[int]: """ Flattens a given two-dimensional matrix into a one-dimensional list. Args: matrix (List[List[int]]): A list of lists representin...
evol_instruct_66k
45,453
Write a Python function to adjust a provided numerical value to adhere to a two decimal places precision format. The function should handle both floating-point numbers and integers, ensuring that the output is always a string formatted to two decimal places. The code should start with: ```python def adjust_to_two_deci...
Here is the Python code to solve the given problem in the markdown block: ```python def adjust_to_two_decimal_places(n: float) -> str: """ Adjusts a provided numerical value to adhere to a two decimal places precision format and returns it as a string. Args: n (float): The numerical value to be adj...
evol_instruct_66k
45,466
Write a Python function to determine if a given list of integers is strictly ascending, meaning each element is strictly greater than the previous element. The function should return `True` if the list is strictly ascending, and `False` otherwise. The code should start with: ```python from typing import List def is_st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_strictly_ascending(arr: List[int]) -> bool: """ Determines if a given list of integers is strictly ascending. Args: arr (List[int]): The list of integers to check. Returns: ...
evol_instruct_66k
45,471
Write a Python function to determine if a given string matches a specific pattern. The pattern requires the string to start with the letter "a", contain at least one digit, and at least one uppercase letter. The function should return `True` if the string matches the pattern, otherwise `False`. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python import re def match_string(s: str) -> bool: """ Determines if a given string matches the pattern: - Starts with the letter "a" - Contains at least one digit - Contains at least one uppercase letter Args: ...
evol_instruct_66k
45,476
Write a Python function to calculate the nth Fibonacci number using memoization to optimize the time complexity. The function should start with: ```python def fibonacci(n: int, memo: dict = None) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def fibonacci(n: int, memo: dict = None) -> int: """ Calculate the nth Fibonacci number using memoization to optimize the time complexity. Args: n (int): The position in the Fibonacci sequence to calculate. ...
evol_instruct_66k
45,478
Write a Python function to manage the inventory of a boutique grocery store. The function should allow adding new items to the inventory, updating the quantity of existing items, and retrieving the current inventory. The inventory should be stored in a dictionary where the keys are the item names and the values are the...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Union def manage_inventory(inventory: Dict[str, int], action: str, item: str = None, quantity: int = None) -> Dict[str, int]: """ Manages the inventory of a boutique grocery store by adding, updating, o...
evol_instruct_66k
45,494
Write a Python function to reverse the elements of a given list in-place without using any built-in functions or slicing. The function should modify the original list and return None. The code should start with: ```python from typing import List def reverse_list_in_place(arr: List[int]) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_list_in_place(arr: List[int]) -> None: """ Reverses the elements of the given list in-place. Args: arr (List[int]): The list of integers to be reversed. Returns: Non...
evol_instruct_66k
45,499
Write a Python function to extract a list of unique words from a given sentence, considering case insensitivity and handling punctuation. The function should return a list of unique words in lowercase. The code should start with: ```python from typing import List import re def extract_unique_words(sentence: str) -> L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def extract_unique_words(sentence: str) -> List[str]: """ Extracts a list of unique words from a given sentence, considering case insensitivity and handling punctuation. Args: sent...
evol_instruct_66k
45,505
Write a Python function to find the two elements in a list of real numbers that have the maximum spatial distance between them. The function should return these two elements in ascending order, with the smaller element first and the larger element second. The list will always contain at least two elements. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_furthest_elements(numbers: List[float]) -> Tuple[float, float]: """ Find the two elements in a list of real numbers that have the maximum spatial distance between them. Args: ...
evol_instruct_66k
45,508
Write a Python function to determine the number of ways to climb a staircase with `n` steps, where a person can take either 1 or 2 steps at a time. The function should return the total number of distinct ways to climb the staircase. The code should start with: ```python def climb_stairs(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def climb_stairs(n: int) -> int: """ Calculate the number of ways to climb a staircase with n steps, where a person can take either 1 or 2 steps at a time. Args: n (int): The number of steps in the staircase. R...
evol_instruct_66k
45,518
Write a Python function that generates the multiplication table for a given number `n` up to 10, and returns both the table and the sum of its elements. The function should start with: ```python def multiplication_table_with_sum(n: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def multiplication_table_with_sum(n: int) -> tuple: """ Generates the multiplication table for a given number `n` up to 10 and returns both the table and the sum of its elements. Args: n (int): The number for which ...
evol_instruct_66k
45,520
Write a Python function to reverse each word in a given sentence individually without reversing the order of the words in the sentence. The function should not use any built-in functions or methods for reversing strings or splitting sentences. The code should start with: ```python def reverse_words_in_sentence(sentence...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_words_in_sentence(sentence: str) -> str: """ Reverses each word in the given sentence individually without reversing the order of the words. Args: sentence (str): The input sentence whose words are to be...
evol_instruct_66k
45,523
Write a Python function to swap elements at two distinct positions within an integer numerical sequence. The function should take a list of integers and two indices, `i` and `j`, and swap the elements at these positions. Ensure the function handles invalid indices gracefully by returning `None` if either index is out o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def swap_elements(arr: List[int], i: int, j: int) -> Optional[List[int]]: """ Swaps the elements at positions i and j in the given list. Args: arr (List[int]): The list of integers...
evol_instruct_66k
45,530
Write a Python function to calculate the sum of all elements in a given list of integers. The function should iterate through the list using a loop and accumulate the sum of the elements. The code should start with: ```python from typing import List def calculate_sum(nums: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def calculate_sum(nums: List[int]) -> int: """ Calculate the sum of all elements in a given list of integers. Args: nums (List[int]): The list of integers to sum. Returns: int...
evol_instruct_66k
45,539
Write a Python function to sort a given list of integers using the Merge Sort algorithm, ensuring that the time complexity is O(n log n). The function should be able to handle lists of any length, including empty lists and lists with a single element. 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 merge_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the Merge Sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: List...
evol_instruct_66k
45,556
Write a Python function to find the nth character in a given string, where the string is provided as input and the position n is also provided as input. The function should handle cases where n is out of the bounds of the string by returning an empty string. The code should start with: ```python def get_nth_character(s...
Here is the Python code to solve the given problem in the markdown block: ```python def get_nth_character(s: str, n: int) -> str: """ Returns the nth character in the given string, where n is 1-based. If n is out of bounds, returns an empty string. Args: s (str): The input string from which to ...
evol_instruct_66k
45,558
Write a Python function to count the number of words in a given string. The function should handle various edge cases, such as strings with multiple spaces, leading and trailing spaces, and empty strings. The code should start with: ```python def count_words(string: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_words(string: str) -> int: """ Counts the number of words in a given string. Args: string (str): The input string to count words from. Returns: int: The number of words in the string. """ ...
evol_instruct_66k
45,576
Write a Python function to compute the remaining income after applying a tax rate deduction from the initial income. The function should consider a deduction that is subtracted from the gross income before the taxes are applied. The code should start with: ```python def compute_remaining_income(initial_income: float, t...
Here is the Python code to solve the given problem in the markdown block: ```python def compute_remaining_income(initial_income: float, tax_rate: float, deduction: float) -> float: """ Computes the remaining income after applying a tax rate deduction from the initial income. Args: initial_income (f...
evol_instruct_66k
45,578
Write a Python function to compute the aggregate of the bitwise exclusive OR (XOR) operation performed on each individual digit of two hexadecimal numerals. The function should take two hexadecimal strings as input and return the sum of the XOR results of their corresponding binary digits. The code should start with: ...
Here is the Python code to solve the given problem in the markdown block: ```python def hexadecimal_XOR_aggregate(num1: str, num2: str) -> int: """ Computes the aggregate of the bitwise exclusive OR (XOR) operation performed on each individual digit of two hexadecimal numerals. Args: num1 (str): Th...
evol_instruct_66k
45,582
Write a Python function to calculate the sum of the squares of all integers from 1 to a given integer `n` using a mathematical formula rather than iteration. The function should have a time complexity of O(1). The code should start with: ```python def sum_of_squares(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def sum_of_squares(n: int) -> int: """ Calculate the sum of the squares of all integers from 1 to n using a mathematical formula. Args: n (int): The upper limit of the range for which to calculate the sum of squar...
evol_instruct_66k
45,590
Write a Python function to calculate the circumference of a circle given its radius. The function should handle both positive and zero radius values. The code should start with: ```python import math def calculate_circumference(radius: float) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python import math def calculate_circumference(radius: float) -> float: """ Calculate the circumference of a circle given its radius. Args: radius (float): The radius of the circle. Returns: float: The circum...
evol_instruct_66k
45,593
Write a Python function to transform a list of string elements into a single string where each element is separated by a specified delimiter. The function should handle an empty list by returning an empty string. The code should start with: ```python from typing import List def join_strings_with_delimiter(lst: List[st...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def join_strings_with_delimiter(lst: List[str], delimiter: str) -> str: """ Transforms a list of string elements into a single string where each element is separated by a specified delimiter. Args...
evol_instruct_66k
45,598
Write a Python function to combine the elements of two dictionaries into a single dictionary, ensuring that if both dictionaries have the same key, the value from the second dictionary should overwrite the value from the first dictionary. The function should handle any number of dictionaries and return the combined dic...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def combine_dictionaries(dicts: List[Dict[str, any]]) -> Dict[str, any]: """ Combines the elements of multiple dictionaries into a single dictionary. If two dictionaries have the same key, the ...
evol_instruct_66k
45,602
Write a Python function to transform a list of strings into a list of individual characters, maintaining the order of characters from each string. The function should handle an empty list and strings with varying lengths. The code should start with: ```python from typing import List def transform_strings_to_chars(stri...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def transform_strings_to_chars(strings: List[str]) -> List[str]: """ Transforms a list of strings into a list of individual characters, maintaining the order of characters from each string. Args: ...
evol_instruct_66k
45,626
Write a Python function to calculate the absolute magnitude of the deviation between two numerical entities. The function should take two numerical inputs and return the absolute difference between them. The code should start with: ```python def absolute_deviation(a: float, b: float) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def absolute_deviation(a: float, b: float) -> float: """ Calculate the absolute magnitude of the deviation between two numerical entities. Args: a (float): The first numerical entity. b (float): The second n...
evol_instruct_66k
45,631
Write a Python function to encrypt a given message using a Caesar cipher with a specified shift value. The Caesar cipher shifts each letter in the message by a fixed number of positions down the alphabet. Non-alphabetic characters should remain unchanged. The function should handle both uppercase and lowercase letters ...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher(message: str, shift: int) -> str: """ Encrypts a given message using a Caesar cipher with a specified shift value. Args: message (str): The message to be encrypted. shift (int): The number ...
evol_instruct_66k
45,637
Write a Python function that constructs a lambda function to perform a mathematical operation on a given input. The lambda function should take a numeric input and return the result of the input raised to the power of 3 (i.e., cubed). The main function should then apply this lambda function to a list of numbers and ret...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def apply_cube_lambda(numbers: List[int]) -> List[int]: """ Applies a lambda function to each number in the input list, returning a list of the cubed values. Args: numbers (List[int]): A lis...
evol_instruct_66k
45,638
Write a Python function to generate all possible combinations of three numbers from a given list of integers. The function should return a list of tuples, where each tuple represents a combination of three numbers. The order of the combinations does not matter, and each number can only be used once in each combination....
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import itertools def generate_combinations(numbers: List[int]) -> List[Tuple[int, int, int]]: """ Generate all possible combinations of three numbers from the given list. Args: number...
evol_instruct_66k
45,647
Write a Python function to verify the existence of a specific element within a given numerical array and return its index if found, otherwise return -1. The function should also validate the input to ensure that all elements of the array are either integers or floats, and the target element is also either an integer or...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_element_index(arr: List[Union[int, float]], target: Union[int, float]) -> Union[int, str]: """ Verifies the existence of a specific element within a given numerical array and returns its ...
evol_instruct_66k
45,651
Write a Python function to generate a geometric progression series given the first term, the common ratio, and the number of terms. The function should handle edge cases such as invalid ratios and non-positive number of terms by returning `None` and printing appropriate error messages. The code should start with: ```py...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_geometric_progression(first_term: float, ratio: float, num_terms: int) -> list: """ Generates a geometric progression series given the first term, the common ratio, and the number of terms. Args: first_...
evol_instruct_66k
45,654
Write a Python function to sort a list of elements using the Bubble Sort algorithm. The function should take a list of integers as input and return the sorted list. The code should start with: ```python from typing import List def bubble_sort(arr: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the Bubble Sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: Li...
evol_instruct_66k
45,656
Write a Python function to check if a given integer `x` exists in a list of integers. The list may contain non-integer items, which should be corrected by converting them to integers if possible. If `x` is provided as a string, it should be converted to an integer before checking. If `x` or any list item cannot be conv...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def check_existence(x: Union[int, str], lst: List[Union[int, str]]) -> None: """ Check if the given integer `x` exists in the list of integers. Correct the list by converting non-integer items...
evol_instruct_66k
45,680
Write a Python function to remove a specified entity from a given list and return the updated list. The function should handle cases where the entity is not present in the list by returning the original list unchanged. The code should start with: ```python from typing import List def remove_entity(entity: str, lst: Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_entity(entity: str, lst: List[str]) -> List[str]: """ Removes a specified entity from a given list and returns the updated list. Args: entity (str): The entity to be removed f...
evol_instruct_66k
45,691
Write a Python function to remove consecutive duplicate elements from a given list of integers. The function should return a new list with all consecutive duplicates removed, preserving the order of the first occurrence of each element. The code should start with: ```python from typing import List def remove_consecut...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_consecutive_duplicates(sequence: List[int]) -> List[int]: """ Removes consecutive duplicate elements from the given list of integers. Args: sequence (List[int]): The list of integ...
evol_instruct_66k
45,700
Write a Python function to convert a sequence of numerical inputs into their corresponding hexadecimal notation. The function should handle both positive and negative integers, converting negative numbers using two's complement. Additionally, the function should perform error checking to ensure that each input is a val...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_to_hexadecimal(sequence: List[str]) -> List[str]: """ Converts a sequence of numerical inputs into their corresponding hexadecimal notation. Handles both positive and negative integers, c...
evol_instruct_66k
45,709
Write a Python function to reverse the order of words in a given sentence without using any inbuilt reverse functions or slicing. The function should handle sentences with multiple spaces between words and leading/trailing spaces. The code should start with: ```python def reverse_sentence(sentence: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_sentence(sentence: str) -> str: """ Reverses the order of words in a given sentence without using any inbuilt reverse functions or slicing. Args: sentence (str): The input sentence whose words need to be...
evol_instruct_66k
45,729
Write a Python function to validate if a given string is a valid IP address and classify it into one of the following categories: Class A, B, C, D, or E for IPv4 addresses, and IPv6 for IPv6 addresses. The function should handle both IPv4 and IPv6 addresses. The code should start with: ```python from ipaddress import i...
Here is the Python code to solve the given problem in the markdown block: ```python from ipaddress import ip_address, IPv4Address, IPv6Address def validate_and_classify_ip(ip: str) -> str: """ Validates if a given string is a valid IP address and classifies it into one of the following categories: Class A,...
evol_instruct_66k
45,730
Write a Python function to merge two distinct lists into a single list. The function should handle lists of different lengths and ensure that the elements from both lists are included in the merged list. The code should start with: ```python from typing import List def merge_lists(list1: List[any], list2: List[any]) -...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_lists(list1: List[any], list2: List[any]) -> List[any]: """ Merges two distinct lists into a single list. Args: list1 (List[any]): The first list to be merged. list2 (List[...
evol_instruct_66k
45,741
Write a Python function to find the first `n` prime numbers using the Sieve of Eratosthenes algorithm. The function should return a list of the first `n` prime numbers. The code should start with: ```python from typing import List def find_first_n_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 find_first_n_primes(n: int) -> List[int]: """ Find the first n prime numbers using the Sieve of Eratosthenes algorithm. Args: n (int): The number of prime numbers to find. Returns: ...
evol_instruct_66k
45,742
Write a Python function to sort an array of strings in ascending order based on the alphabetical order, while ignoring the case of the strings. The function should handle both uppercase and lowercase characters uniformly. The code should start with: ```python from typing import List def sort_strings_ignore_case(arr: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_strings_ignore_case(arr: List[str]) -> List[str]: """ Sorts an array of strings in ascending order based on the alphabetical order, ignoring case. Args: arr (List[str]): The array o...
evol_instruct_66k
45,750
Write a Python function to extract all distinct elements from a provided data collection. The data collection is a list of tuples, where each tuple contains two elements: a string and an integer. The function should return a list of tuples where each tuple's first element (the string) is unique. If there are multiple t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def extract_distinct_elements(data_collection: List[Tuple[str, int]]) -> List[Tuple[str, int]]: """ Extracts all distinct elements from a provided data collection. Args: data_collecti...
evol_instruct_66k
45,755
Write a Python function to swap the values of two distinct integer variables without using a third variable or arithmetic operations. The function should also check for any invalid inputs. The function should start with: ```python def swap_integers(x: int, y: int) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python def swap_integers(x: int, y: int) -> None: """ Swaps the values of two distinct integer variables without using a third variable or arithmetic operations. Args: x (int): The first integer variable. y (int): ...
evol_instruct_66k
45,770
Write a Python function to restructure a given dictionary into a list of dictionaries, where each dictionary represents an individual's data, including their name, age, occupation, and language. Ensure that no individual is below 20 years or above 40 years. The input dictionary has the following structure: - "names": ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def restructure_data(data: Dict[str, List[str]]) -> List[Dict[str, str]]: """ Restructures the given dictionary into a list of dictionaries, where each dictionary represents an individual's data. ...
evol_instruct_66k
45,780
Write a Python function to swap the first and last elements of a given matrix. The matrix is represented as a list of lists, where each inner list represents a row of the matrix. The function should handle matrices of any size, including empty matrices and matrices with a single element. 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 swap_first_last_elements(matrix: List[List[int]]) -> List[List[int]]: """ Swaps the first and last elements of a given matrix. Args: matrix (List[List[int]]): The matrix represented as a...
evol_instruct_66k
45,784
Write a Python function to efficiently merge two already sorted lists into a single sorted list. The function should avoid using the built-in `sort()` method and instead use a more efficient approach to merge the lists. The code should start with: ```python from typing import List def merge_sorted_lists(lst1: List[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_lists(lst1: List[int], lst2: List[int]) -> List[int]: """ Merges two already sorted lists into a single sorted list. Args: lst1 (List[int]): The first sorted list. l...
evol_instruct_66k
45,795
Write a Python function to traverse and print every element within a given 2D array. The function should handle any size of 2D array, not just a 3x3 array. The function should start with: ```python from typing import List def traverse_2d_array(arr: List[List[int]]) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def traverse_2d_array(arr: List[List[int]]) -> None: """ Traverse and print every element within a given 2D array. Args: arr (List[List[int]]): The 2D array to traverse. Returns: ...
evol_instruct_66k
45,796
Write a Python function to remove all duplicate values from a given list while preserving the original order of elements. The function should be efficient and should handle lists of various sizes. The code should start with: ```python from typing import List def remove_duplicates(arr: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates(arr: List[int]) -> List[int]: """ Removes duplicate values from the given list while preserving the original order of elements. Args: arr (List[int]): The list from whi...
evol_instruct_66k
45,812
Write a Python function to simulate the communication of different types of animals based on their species. The function should take a dictionary representing an animal with its species and other attributes, and return the sound that the animal makes. The function should handle different species and return appropriate ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def simulate_animal_communication(animal: Dict[str, str]) -> str: """ Simulate the communication of an animal based on its species. Args: animal (Dict[str, str]): A dictionary representing t...
evol_instruct_66k
45,826
Write a Python function to convert a list of integers into their absolute values without using any predefined or built-in functions for calculating absolute values. The function should handle integers of any length, including positive, negative, and zero values. 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 absolute_values(lst: List[int]) -> List[int]: """ Converts a list of integers into their absolute values without using built-in functions. Args: lst (List[int]): A list of integers to be...
evol_instruct_66k
45,829
Write a Python function to process a textual input, formatted as words divided by spaces. The function should produce a dictionary that maps each word to a tuple containing its length and frequency of occurrence in the input string. If there are words of identical length, the function must include all such words in the...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Tuple def word_length_frequency(text: str) -> Dict[str, Tuple[int, int]]: """ Processes a textual input and produces a dictionary that maps each word to a tuple containing its length and frequency. ...
evol_instruct_66k
45,838
Write a Python function to generate a random string of a specified length consisting of uppercase letters. The function should handle cases where the length is zero or negative by returning an empty string. The code should start with: ```python import random import string def generate_random_string(length: int) -> str...
Here is the Python code to solve the given problem in the markdown block: ```python import random import string def generate_random_string(length: int) -> str: """ Generates a random string of the specified length consisting of uppercase letters. Args: length (int): The length of the random string...