source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
evol_instruct_66k
1,429
Write a Python function to implement the merge sort algorithm for a given array. The function should sort the array in ascending order. The code should start with: ```python from typing import List def merge_sort(array: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(array: List[int]) -> List[int]: """ Sorts the given array using the merge sort algorithm. Args: array (List[int]): The array to be sorted. Returns: List[int]: The...
evol_instruct_66k
1,452
Write a Python function to sort a list of string elements in alphabetical order. The function should handle lists of varying lengths and ensure that the sorting is case-insensitive. The code should start with: ```python from typing import List def sort_strings_alphabetically(names: List[str]) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def sort_strings_alphabetically(names: List[str]) -> List[str]: """ Sorts a list of string elements in alphabetical order, case-insensitively. Args: names (List[str]): The list of string e...
evol_instruct_66k
1,456
Write a Python function to verify the existence of a specific filesystem directory and, if it does not exist, create it. The function should also handle potential permission issues that may prevent the creation of the directory. The code should start with: ```python import os def ensure_directory_exists(directory_path...
Here is the Python code to solve the given problem in the markdown block: ```python import os def ensure_directory_exists(directory_path: str) -> None: """ Ensures that a specific filesystem directory exists. If it does not exist, the function creates it. Handles potential permission issues that may preven...
evol_instruct_66k
1,463
Write a Python function to sort an array using the Bubble Sort algorithm in descending order. The function should be able to handle arrays with negative numbers and duplicates. The code should start with: ```python from typing import List def bubble_sort_descending(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_descending(arr: List[int]) -> List[int]: """ Sorts the given array in descending order using the Bubble Sort algorithm. Args: arr (List[int]): The array to be sorted. Re...
evol_instruct_66k
1,481
Write a Python function to decode a string of colors defined in an uncommon hex format into a list of RGB tuples. Each color in the string is represented by a 4-character string starting with a `#` followed by three characters representing the Red, Green, and Blue components. The characters can be digits (`0-9`) or low...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def decode_colors(color_string: str) -> List[Tuple[int, int, int]]: """ Decodes a string of colors defined in an uncommon hex format into a list of RGB tuples. Args: color_string (str...
evol_instruct_66k
1,482
Write a Python function to calculate the sum of all integer elements in a given array, while ignoring any non-integer elements. The array may contain a mix of integers and other types of elements (e.g., strings, floats, etc.). The function should handle arrays of varying lengths and types of elements. The code should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_integers(arr: List[object]) -> int: """ Calculate the sum of all integer elements in a given array, ignoring any non-integer elements. Args: arr (List[object]): The array containi...
evol_instruct_66k
1,498
Write a Python function to detect the unique elements in two unsorted arrays of integers and output their count. The function should handle cases where the arrays are of different lengths and should not use any pre-existing library function for handling collections or arrays. The function should start with: ```python f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_unique_elements_count(array1: List[int], array2: List[int]) -> int: """ Detects the unique elements in two unsorted arrays of integers and returns their count. Args: array1 (List[in...
evol_instruct_66k
1,503
Write a Python function to calculate the total value gained by summing up the integer elements in a given list. The function should handle lists of arbitrary length and ensure that only integer elements are summed. If the list contains non-integer elements, they should be ignored. The code should start with: ```python...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_integers_in_list(my_list: List[int]) -> int: """ Calculate the total value gained by summing up the integer elements in a given list. Args: my_list (List[int]): The list of integers ...
evol_instruct_66k
1,507
Write a Python function to find all prime numbers within a given range [start, end]. The function should return a list of all prime numbers in that range, inclusive of both endpoints. The code should start with: ```python from typing import List def find_primes_in_range(start: int, end: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_primes_in_range(start: int, end: int) -> List[int]: """ Find all prime numbers within the given range [start, end]. Args: start (int): The starting number of the range (inclusive). ...
evol_instruct_66k
1,530
Write a Python function to verify the equality of two given strings, considering case sensitivity and ignoring leading and trailing whitespace. The function should return `True` if the strings are equal, and `False` otherwise. The code should start with: ```python def are_strings_equal(str1: str, str2: str) -> bool: ``...
Here is the Python code to solve the given problem in the markdown block: ```python def are_strings_equal(str1: str, str2: str) -> bool: """ Verifies if two given strings are equal, considering case sensitivity and ignoring leading and trailing whitespace. Args: str1 (str): The first string to comp...
evol_instruct_66k
1,540
Write a Python function to extract all alphanumeric characters from a given string. The function should return a list of these characters. The code should start with: ```python from typing import List def extract_alphanumeric_characters(text: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def extract_alphanumeric_characters(text: str) -> List[str]: """ Extracts all alphanumeric characters from the given text. Args: text (str): The input string from which to extract alphanumer...
evol_instruct_66k
1,554
Write a Python function to calculate the sum of the first `n` natural numbers. The function should take an integer `n` as input and return the sum of the first `n` natural numbers. The code should start with: ```python def sum_of_first_n_natural_numbers(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_first_n_natural_numbers(n: int) -> int: """ Calculate the sum of the first n natural numbers. Args: n (int): The number of natural numbers to sum. Returns: int: The sum of the first n natural...
evol_instruct_66k
1,557
Write a Python function to generate all prime numbers within a given range using the Sieve of Eratosthenes method. Additionally, create another function that calculates the prime factorization of every non-prime number within the same range. The functions should handle edge cases where the range might be less than 2. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict import math def generate_primes(start: int, end: int) -> List[int]: """ Generate all prime numbers within the given range [start, end] using the Sieve of Eratosthenes method. Args: sta...
evol_instruct_66k
1,559
Write a Python function to reverse a given string without using built-in functions or methods. The function should iterate through the string and construct the reversed string manually. 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 without using built-in functions or methods. Args: s (str): The input string to be reversed. Returns: str: The reversed string. """ ...
evol_instruct_66k
1,570
Write a Python function to generate a list of 10 random non-repeating numbers from a given range from 0 to `x` (where `x > 10`). The function should also include a mechanism to validate that the numbers generated are unique and within the specified range. The code should start with: ```python from typing import List im...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_unique_numbers(x: int) -> List[int]: """ Generates a list of 10 random non-repeating numbers from the range [0, x] (where x > 10). Also validates that the numbers generated...
evol_instruct_66k
1,577
Write a Python function to concatenate two strings with a specified delimiter and return the resulting string. The function should handle cases where the delimiter is an empty string or one of the strings is empty. The code should start with: ```python def concatenate_with_delimiter(first_string: str, second_string: s...
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_with_delimiter(first_string: str, second_string: str, delimiter: str) -> str: """ Concatenates two strings with a specified delimiter and returns the resulting string. Args: first_string (str): The f...
evol_instruct_66k
1,582
Write a Python function to reverse the order of keys in a given dictionary without sorting the values. The function should return a new dictionary with the keys in reversed order while maintaining the original values. The code should start with: ```python from typing import Dict def reverse_keys(original_dict: Dict[s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def reverse_keys(original_dict: Dict[str, int]) -> Dict[str, int]: """ Reverses the order of keys in a given dictionary without sorting the values. Args: original_dict (Dict[str, int]): The ...
evol_instruct_66k
1,583
Write a Python function to sort an input list of integer elements in ascending order and determine if the sorting algorithm used is stable. The function should also provide the time complexity of the sorting algorithm. The code should start with: ```python from typing import List, Tuple def sort_and_analyze(arr: List[...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Tuple def sort_and_analyze(arr: List[int]) -> Tuple[List[int], str, bool]: """ Sorts the input list of integers in ascending order and provides information about the sorting algorithm. Args: ...
evol_instruct_66k
1,584
Write a Python function to reverse a string in a case-sensitive manner without using any built-in functions or methods. The function should handle special characters and white spaces efficiently. The code should start with: ```python def reverse_string_case_sensitive(input_string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string_case_sensitive(input_string: str) -> str: """ Reverses the input string in a case-sensitive manner without using any built-in functions or methods. Args: input_string (str): The string to be rever...
evol_instruct_66k
1,598
Write a Python function to display the values from a given dictionary in a specified order. The dictionary contains key-value pairs representing attributes of a celestial body. The function should accept a dictionary and a list of keys, and it should print the values corresponding to the keys in the order they appear i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def display_values_in_order(data: Dict[str, any], keys: List[str]) -> None: """ Display the values from the given dictionary in the order specified by the list of keys. Args: data (Dic...
evol_instruct_66k
1,641
Write a Python function to transform a string containing multiple person profiles into a dictionary. Each profile is separated by a semi-colon (`;`), and each profile's details are separated by a comma and a space (`, `). The profiles should be transformed into a dictionary where the person's name is the key, and the v...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def transform_profiles_to_dict(input_string: str) -> Dict[str, Dict[str, str]]: """ Transforms a string containing multiple person profiles into a dictionary. Args: input_string (str): A str...
evol_instruct_66k
1,651
Write a Python function to calculate the total number of iterations for a given nested loop structure. The function should take two integers, `outer_range` and `inner_range`, representing the range of the outer and inner loops respectively. The function should return the total number of iterations of the nested loops. ...
Here is the Python code to solve the given problem in the markdown block: ```python def total_iterations(outer_range: int, inner_range: int) -> int: """ Calculate the total number of iterations for a nested loop structure. Args: outer_range (int): The range of the outer loop. inner_range (i...
evol_instruct_66k
1,675
Write a Python function to convert a natural number to its octal representation without using Python's built-in `oct()` function. The function should handle natural numbers (positive integers) and return the octal representation as a string. The code should start with: ```python def convert_to_octal(n: int) -> str: ``...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_octal(n: int) -> str: """ Convert a natural number to its octal representation without using Python's built-in `oct()` function. Args: n (int): The natural number to convert. Returns: str...
evol_instruct_66k
1,678
Refactor the given Python code to eliminate redundancy and improve readability. The original code creates a dictionary `allSubjects` where each key is a string representation of a number from 0 to 4, and each value is a dictionary `subjectData`. The code then creates another dictionary `addedSubjects` using a dictionar...
Here is the Python code to solve the given problem in the markdown block: ```python def create_subject_data(subject_data: dict, num_subjects: int) -> dict: """ Creates a dictionary with keys as string representations of numbers from 0 to num_subjects-1, and each value as the provided subject_data dictionary...
evol_instruct_66k
1,687
Write a Python function to perform integer division of two integers, `X` and `Y`, where `X` is always greater than `Y`. The function should handle the case where `Y` is zero by returning an error message. The function should be implemented using a lambda function. The code should start with: ```python def integer_divi...
Here is the Python code to solve the given problem in the markdown block: ```python def integer_division(X: int, Y: int) -> int or str: """ Perform integer division of X by Y, with error handling for division by zero. Args: X (int): The dividend, always greater than Y. Y (int): The divisor....
evol_instruct_66k
1,701
Write a Python function to search for specific subsets of characters within a provided text fragment. The function should implement a customized searching algorithm without using Python's built-in substring search functions like `in`, `find()`, or `index()`. The function should return the exact indices at which each su...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def search_substrings(text: str, subsets: List[str]) -> Dict[str, List[int]]: """ Searches for specific subsets of characters within a provided text fragment and returns the exact indices at which ...
evol_instruct_66k
1,704
Write a Python function to flatten a nested list of arbitrary depth and unpredictable structure. The function should recursively traverse through the nested lists and return a single flattened list containing all the elements in a linear order. The code should start with: ```python from typing import List, Any def fl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def flatten_nested_list(nested_list: List[Any]) -> List[Any]: """ Flattens a nested list of arbitrary depth and unpredictable structure. Args: nested_list (List[Any]): The nested list t...
evol_instruct_66k
1,730
Write a Python function to identify all prime numbers within a given array and calculate their sum. The function should handle arrays of arbitrary size and include edge cases such as empty arrays and arrays containing negative numbers. Avoid using in-built functions for identifying primes and ensure the program can eff...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(num: int) -> bool: """ Check if a given number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime, False other...
evol_instruct_66k
1,733
Write a Python function to perform multiple mathematical operations on elements within a given array: the cumulative total, product, and average. The function should handle edge cases such as empty arrays, negative numbers, floating-point numbers, and large arrays efficiently. Additionally, implement error handling for...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Union def process_array(arr: List[Union[int, float]]) -> Union[Tuple[float, float, float], str]: """ Perform multiple mathematical operations on elements within a given array: the cumulative tota...
evol_instruct_66k
1,742
Write a Python function to identify a celebrity at a social gathering with `n` individuals, each identified by a unique label from `0` to `n - 1`. A celebrity is defined as someone who is known by all the other `n - 1` attendees but doesn't know any of them in return. The function should return the label of the celebri...
Here is the Python code to solve the given problem in the markdown block: ```python def find_celebrity(n: int) -> int: """ Identify a celebrity at a social gathering with `n` individuals. A celebrity is defined as someone who is known by all the other `n - 1` attendees but doesn't know any of them in r...
evol_instruct_66k
1,743
Write a Python function to generate a list of `n` random numbers within a specified range `[start, end]`, ensuring that each number in the list is unique and sorted in ascending order. The function should handle cases where `n` is greater than the number of unique integers in the range `[start, end]` by returning as ma...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_unique_sorted_numbers(n: int, start: int, end: int) -> List[int]: """ Generates a list of `n` unique random numbers within the specified range `[start, end]` and returns them s...
evol_instruct_66k
1,746
Write a Python function to organize a list of paired data (tuples) by their scores in descending order. If there are ties in scores, the tied scores should be ordered alphabetically by the names. The function should start with: ```python from typing import List, Tuple def organize_by_score(data: List[Tuple[str, int]])...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def organize_by_score(data: List[Tuple[str, int]]) -> List[Tuple[str, int]]: """ Organizes a list of paired data (tuples) by their scores in descending order. If there are ties in scores, the ...
evol_instruct_66k
1,756
Write a Python function to compute the greatest common divisor (GCD) of two integers using the Euclidean Algorithm. The function should be able to handle both positive and negative integers. The code should start with: ```python def gcd(a: int, b: 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
1,760
Write a Python function to calculate the cumulative total of a given list of integers. The function should take a list of integers as input and return the sum of all elements in the list. The code should start with: ```python from typing import List def cumulative_total(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def cumulative_total(arr: List[int]) -> int: """ Calculate the cumulative total of a given list of integers. Args: arr (List[int]): A list of integers for which the cumulative total is to be...
evol_instruct_66k
1,762
Write a Python function to compute the derivative of a given series of complex exponential functions. The input is a list of coefficients representing the exponential series, where each coefficient corresponds to an exponential function of the form \( a_i \cdot e^{x / i} \). The function should return a list of coeffic...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def compute_derivative(coefficients: List[float]) -> List[float]: """ Compute the derivative of a series of complex exponential functions. The input is a list of coefficients representing the expone...
evol_instruct_66k
1,768
Write a Python function to find the length of the longest increasing subsequence (LIS) in a given list of integers. The function should use dynamic programming to achieve this. The code should start with: ```python from typing import List def longest_increasing_subsequence(nums: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_increasing_subsequence(nums: List[int]) -> int: """ Calculate the length of the longest increasing subsequence in a given list of integers. Args: nums (List[int]): The list of in...
evol_instruct_66k
1,769
Write a Python function to calculate the median of three given integers without using sorting. The function should determine the median by comparing the integers directly. The code should start with: ```python def median_of_three(num1: int, num2: int, num3: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def median_of_three(num1: int, num2: int, num3: int) -> int: """ Calculate the median of three given integers without using sorting. Args: num1 (int): The first integer. num2 (int): The second integer. ...
evol_instruct_66k
1,773
Write a Python function to construct a regular expression pattern that accurately identifies the exact string "hello people". The function should return the constructed pattern as a string. Additionally, write a helper function to test if a given string matches the pattern. The code should start with: ```python import...
Here is the Python code to solve the given problem in the markdown block: ```python import re def construct_pattern() -> str: """ Constructs a regular expression pattern that matches the exact string "hello people". Returns: str: The regular expression pattern. """ return r"^hello people$"...
evol_instruct_66k
1,779
Write a Python function to find the smallest number in a given list of integers. The function should efficiently handle lists of varying sizes and return the smallest number. The code should start with: ```python from typing import List def find_smallest_number(num_list: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_smallest_number(num_list: List[int]) -> int: """ Find the smallest number in a given list of integers. Args: num_list (List[int]): A list of integers from which to find the smallest...
evol_instruct_66k
1,786
Write a Python function to convert a given binary number represented as a string to its hexadecimal equivalent. The function should handle binary strings of any length and return the hexadecimal value as a string. The code should start with: ```python def binary_to_hex(binary_str: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def binary_to_hex(binary_str: str) -> str: """ Converts a given binary number represented as a string to its hexadecimal equivalent. Args: binary_str (str): The binary number to convert, represented as a string. ...
evol_instruct_66k
1,804
Write a Python function to search for a given element in a matrix and return `True` if the element is found, otherwise return `False`. The matrix is a 2D list where each sublist represents a row. The function should iterate through each row and check if the element is present in that row. 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 search_element_in_matrix(matrix: List[List[int]], element: int) -> bool: """ Searches for a given element in a matrix and returns True if the element is found, otherwise False. Args: mat...
evol_instruct_66k
1,834
Write a Python function to merge two lists of strings that represent the nomenclature of various fruits, ensuring that any duplicate fruit names are removed from the merged list. The function should return the merged list in alphabetical order. The code should start with: ```python from typing import List def merge_f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_fruit_lists(arr1: List[str], arr2: List[str]) -> List[str]: """ Merge two lists of fruit names, removing duplicates and returning the result in alphabetical order. Args: arr1 (List...
evol_instruct_66k
1,850
Write a Python function to repeat each word in a given sentence a specified number of times, reverse the order of characters in each repeated word, and separate each repetition with a chosen symbol. The function should return the modified sentence as a single string. The code should start with: ```python def repeat_an...
Here is the Python code to solve the given problem in the markdown block: ```python def repeat_and_reverse_words(sentence: str, num: int, symbol: str = "*") -> str: """ Repeats each word in the given sentence a specified number of times, reverses the order of characters in each repeated word, and separates ...
evol_instruct_66k
1,852
Write a Python function to calculate the number of distinct ways to climb a staircase with `n` steps, where a person can either take 1 step or 2 steps at a time. The function should return the number of distinct ways to reach the top of the staircase. The code should start with: ```python def climb_stairs(n: int) -> i...
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 distinct ways to climb a staircase with n steps. A person can either take 1 step or 2 steps at a time. Args: n (int): The number of steps in the sta...
evol_instruct_66k
1,855
Write a Python function that takes a list of integers as input and fulfills the following requirements: It should use a loop to print out the values and their respective indices, and it should include an optional second parameter to filter out values that are less than the given filter value. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def print_array_with_filter(arr: List[int], filter_value: Optional[int] = None) -> None: """ Prints the values and their respective indices from the given list, optionally filtering out values ...
evol_instruct_66k
1,872
Write a Python function to simulate a simple machine learning algorithm that takes a list of input data and generates predictions based on a predefined rule. The function should double each element in the input list and return the resulting list of predictions. 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 def simple_machine_learning(data: List[int]) -> List[int]: """ Simulates a simple machine learning algorithm that doubles each element in the input list. Args: data (List[int]): A list of in...
evol_instruct_66k
1,886
Write a Python function to convert a given Roman numeral string to its corresponding integer value. The Roman numeral system uses symbols to represent values as follows: - `I` = 1 - `V` = 5 - `X` = 10 - `L` = 50 - `C` = 100 - `D` = 500 - `M` = 1000 Roman numerals are usually written from largest to smallest from left ...
Here is the Python code to solve the given problem in the markdown block: ```python def roman_to_int(roman_numeral: str) -> int: """ Convert a Roman numeral string to its corresponding integer value. Args: roman_numeral (str): The Roman numeral string to convert. Returns: int: The inte...
evol_instruct_66k
1,887
Write a Python function that safely performs a series of operations that might raise exceptions. The function should handle specific exceptions and provide meaningful error messages. The operations include converting a string to an integer, dividing two numbers, and accessing an element in a list. If any operation fail...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def safe_operations(string: str, numerator: int, denominator: int, lst: List[int], index: int) -> List[str]: """ Safely performs a series of operations that might raise exceptions and returns a list of e...
evol_instruct_66k
1,888
Write a Python function to filter and display elements from a given numerical array that are greater than a specified threshold. The function should return a list of these filtered elements. The code should start with: ```python from typing import List def filter_elements_greater_than(arr: List[int], threshold: int) ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_elements_greater_than(arr: List[int], threshold: int) -> List[int]: """ Filters and returns elements from the given array that are greater than the specified threshold. Args: arr ...
evol_instruct_66k
1,895
Write a Python function to merge two sorted lists into a single sorted list. The function should efficiently combine the elements of both lists while maintaining the sorted order. The code should start with: ```python from typing import List def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]: """ Merge two sorted lists into a single sorted list. Args: list1 (List[int]): The first sorted list. list2 (...
evol_instruct_66k
1,898
Write a Python function to create and return a dictionary with a specified structure. The dictionary should have keys 'a', 'b', and 'c' with corresponding values 1, 2, and 3 respectively. The function should ensure that the dictionary is created correctly and returned as specified. The code should start with: ```pytho...
Here is the Python code to solve the given problem in the markdown block: ```python def create_specified_dictionary() -> dict: """ Creates and returns a dictionary with the specified structure: {'a': 1, 'b': 2, 'c': 3}. Returns: dict: A dictionary with keys 'a', 'b', and 'c' and corresponding value...
evol_instruct_66k
1,903
Write a Python function to traverse and print each character of a given string using a while loop. The function should start with: ```python def traverse_string(string_value: str) -> None: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def traverse_string(string_value: str) -> None: """ Traverse and print each character of the given string using a while loop. Args: string_value (str): The string to be traversed. Returns: None: The f...
evol_instruct_66k
1,908
Write a Python function to compute the Least Common Multiple (LCM) of two integers `x` and `y` using an efficient algorithm. The function should handle the constraints where `1 <= x, y <= 10^9`. The function should start with: ```python import math def lcm(x: int, y: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python import math def lcm(x: int, y: int) -> int: """ Compute the Least Common Multiple (LCM) of two integers x and y using an efficient algorithm. Args: x (int): The first integer. y (int): The second integer. ...
evol_instruct_66k
1,915
Write a Python function to encrypt a given text using the Caesar Cipher technique. The Caesar Cipher involves shifting each letter in the text by a specified number of positions down the alphabet. Non-alphabet characters should remain unchanged. The function should handle both uppercase and lowercase letters. The code...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher(text: str, shift: int) -> str: """ Encrypts the given text using the Caesar Cipher technique. Args: text (str): The text to be encrypted. shift (int): The number of positions to shift each ...
evol_instruct_66k
1,917
Write a Python function to count the number of trailing zeros in the factorial of a given number `n`. The function should efficiently compute the result without calculating the factorial itself, which can be very large and computationally expensive. The code should start with: ```python def count_trailing_zeros_in_fac...
Here is the Python code to solve the given problem in the markdown block: ```python def count_trailing_zeros_in_factorial(n: int) -> int: """ Count the number of trailing zeros in the factorial of a given number n. Args: n (int): The number for which to count the trailing zeros in its factorial. ...
evol_instruct_66k
1,928
Write a Python function to find all occurrences of a specified integer in a given two-dimensional numerical array and return their index positions as tuples. If the integer is not found, the function should return an empty list. The function should handle arrays of varying sizes and return all positions where the integ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_all_positions(num: int, array: List[List[int]]) -> List[Tuple[int, int]]: """ Find all occurrences of a specified integer in a two-dimensional numerical array and return their index posit...
evol_instruct_66k
1,931
Write a Python function to repeat a given string a specified number of times and return the resultant string. The function should handle cases where the repetition count is zero or negative by returning an empty string. The code should start with: ```python def repeat_string(s: str, n: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def repeat_string(s: str, n: int) -> str: """ Repeats the given string `s` exactly `n` times and returns the resultant string. If `n` is zero or negative, returns an empty string. Args: s (str): The string to ...
evol_instruct_66k
1,933
Write a Python function to generate the Fibonacci sequence up to the nth term. The function should take an integer `n` as input and return a list containing the Fibonacci sequence up to the nth term. If `n` is less than or equal to 0, the function should return an empty list. If `n` is 1, the function should return a l...
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
1,935
Write a Python function to calculate the greatest common divisor (GCD) of two given non-negative integers using the Euclidean algorithm. The function should handle the case where one or both of the numbers are zero. The code should start with: ```python def gcd(num1: int, num2: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def gcd(num1: int, num2: int) -> int: """ Calculate the greatest common divisor (GCD) of two non-negative integers using the Euclidean algorithm. Args: num1 (int): The first non-negative integer. num2 (int...
evol_instruct_66k
1,955
Write a Python function to capitalize the first letter of each string in a given list of lowercase strings. The function should return a new list with the modified strings, leaving the original list unchanged. The code should start with: ```python from typing import List def capitalize_first_letter(strings: List[str]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def capitalize_first_letter(strings: List[str]) -> List[str]: """ Capitalizes the first letter of each string in the given list of lowercase strings. Args: strings (List[str]): A list of low...
evol_instruct_66k
1,963
Write a Python function to remove specific tuples from an initially provided tuple. The function should take two arguments: the initial tuple of tuples and the tuple of tuples to be removed. The function should return a new tuple with the specified tuples removed. 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 Tuple def remove_tuples(initial_tuple: Tuple[Tuple[int, int], ...], remove_tuple: Tuple[Tuple[int, int], ...]) -> Tuple[Tuple[int, int], ...]: """ Removes specific tuples from an initially provided tuple. ...
evol_instruct_66k
1,969
Write a Python function to filter out elements from a given list that are divisible by 2 using a generative approach. The function should return a new list containing only the elements that are divisible by 2. The code should start with: ```python from typing import List def filter_even_numbers(data_list: List[int]) -...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_even_numbers(data_list: List[int]) -> List[int]: """ Filters out elements from the given list that are divisible by 2 and returns a new list containing only the even numbers. Args: ...
evol_instruct_66k
1,971
Write a Python function to extract and count the occurrences of even numbers from a given list of integers. The function should return a dictionary where the keys are the even numbers sorted in descending order, and the values are their respective counts. Assume that the input list does not contain duplicate values. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_even_numbers(nums: List[int]) -> Dict[int, int]: """ Counts the occurrences of even numbers from a given list of integers and returns a dictionary with the even numbers sorted in desc...
evol_instruct_66k
1,983
Write a Python function to disassemble a given string into its individual word components, reverse the order of these words, and then recombine them back into a single string. The function should handle any whitespace correctly, including multiple spaces and leading/trailing spaces. The code should start with: ```pyth...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_words_in_string(input_string: str) -> str: """ Disassembles a given string into its individual word components, reverses the order of these words, and then recombines them back into a single string. Args: ...
evol_instruct_66k
1,987
Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of a m x n grid, where you can only move either down or right at any point in time. 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 a m x n grid. Args: m (int): The number of rows...
evol_instruct_66k
1,992
Write a Python function to split an array of integers into two equal-length sections. If the length of the array is odd, add the smallest possible integer (0) to make the length even before dividing it. The function should be optimized for efficiency. 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 split_array_into_equal_sections(arr: List[int]) -> List[List[int]]: """ Splits an array of integers into two equal-length sections. If the length of the array is odd, appends the smallest possibl...
evol_instruct_66k
1,997
Write a Python function to create a dictionary of ten distinct words and their corresponding definitions. The function should ensure that each word is unique and that the definitions are accurate. The function should then return the dictionary. The code should start with: ```python from typing import Dict def create_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def create_word_dictionary() -> Dict[str, str]: """ Creates a dictionary of ten distinct words and their corresponding definitions. Returns: Dict[str, str]: A dictionary where each key is a ...
evol_instruct_66k
2,014
Write a Python function to manage and manipulate a dictionary of countries and their populations. The function should allow for adding new countries, updating existing populations, searching for a country's population, and sorting the countries by name or population. The function should be designed to handle a large nu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def manage_population_data( population_dict: Dict[str, int], operation: str, country: str = None, population: int = None ) -> List[Tuple[str, int]]: """ Manages a dictionary ...
evol_instruct_66k
2,016
Write a Python function to generate a sentence that contains the given name and age. The function should take two parameters: a string representing the name and an integer representing the age. The function should return a formatted string that includes the name and age in a specific sentence format. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_sentence(name: str, age: int) -> str: """ Generates a sentence that includes the given name and age. Args: name (str): The name to include in the sentence. age (int): The age to include in the s...
evol_instruct_66k
2,017
Write a Python function to calculate the arithmetic summation of two unique integral numerical elements. The function should take two integers as input and return their sum. The code should start with: ```python def arithmetic_summation(a: int, b: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def arithmetic_summation(a: int, b: int) -> int: """ Calculate the arithmetic summation of two unique integral numerical elements. Args: a (int): The first integral number. b (int): The second integral numbe...
evol_instruct_66k
2,019
Write a Python function to determine if a given element is present in a predefined numeric array. The function should return a boolean value indicating whether the element is found in the array. The code should start with: ```python from typing import List def is_element_in_array(arr: List[int], element: int) -> bool...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_element_in_array(arr: List[int], element: int) -> bool: """ Determines if a given element is present in a predefined numeric array. Args: arr (List[int]): The predefined numeric array...
evol_instruct_66k
2,022
Write a Python function that performs a binary search-based insertion sort on a list of integers. The function should efficiently sort the list by repeatedly finding the correct position for each element using binary search and then inserting it into the correct position. 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 binary_search(arr: List[int], key: int, start: int, end: int) -> int: """ Perform a binary search to find the correct insertion position for the key in the sorted subarray. Args: arr (Li...
evol_instruct_66k
2,023
Write a Python function to rearrange the elements of a given tuple such that all even numbers appear first, followed by all odd numbers, both in ascending order. The function should return the rearranged tuple. The code should start with: ```python from typing import Tuple def rearrange_tuple(tup: Tuple[int]) -> Tupl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def rearrange_tuple(tup: Tuple[int]) -> Tuple[int]: """ Rearranges the elements of a given tuple such that all even numbers appear first, followed by all odd numbers, both in ascending order. A...
evol_instruct_66k
2,037
Write a Python function to filter and return a list of even integers from a given list of digit-based entities. The function should handle lists containing integers and strings that can be converted to integers. The code should start with: ```python from typing import List def filter_even_numbers(entities: List[str]) ...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def filter_even_numbers(entities: List[str]) -> List[int]: """ Filters and returns a list of even integers from a given list of digit-based entities. Args: entities (List[str]): A list of ...
evol_instruct_66k
2,044
Write a Python function to find all the shared elements between two given lists. The function should return a list containing only the elements that appear in both input lists, without any duplicates. The order of elements in the output list does not matter. 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 find_shared_elements(list1: List[int], list2: List[int]) -> List[int]: """ Find all the shared elements between two lists and return them as a list. Args: list1 (List[int]): The first li...
evol_instruct_66k
2,060
Write a Python function to create an instance of the `Human` class with predefined attributes `name` and `age`. The function should return the created instance. The `Human` class is provided with an `__init__` method that initializes the `name` and `age` attributes. The function should ensure that the instance's `name`...
Here is the Python code to solve the given problem in the markdown block: ```python class Human: def __init__(self, name, age): self.name = name self.age = age def create_human_instance() -> Human: """ Creates an instance of the Human class with predefined attributes. Returns: ...
evol_instruct_66k
2,068
Write a Python function to calculate the incidence rate of a specific integer value within a given list. The incidence rate is defined as the ratio of the count of the specific integer to the total number of elements in the list. The function should handle cases where the list is empty by returning 0. The code should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def incidence_rate(arr: List[int], num: int) -> float: """ Calculate the incidence rate of a specific integer within a given list. The incidence rate is defined as the ratio of the count of the spec...
evol_instruct_66k
2,072
Write a Python function to retrieve the substring that comes after a designated special character in a given string. If the special character is not found in the string, return a specific error message. The function should handle cases where the special character is at the end of the string, returning an empty string i...
Here is the Python code to solve the given problem in the markdown block: ```python def retrieve_substring_after_special_character(string: str, special_character: str) -> str: """ Retrieves the substring that comes after a designated special character in a given string. Args: string (str): The inpu...
evol_instruct_66k
2,082
Write a Python function to round off a collection of complex numbers to the nearest integer part while maintaining their imaginary components intact. The function should take a list of complex numbers as input and return a list of complex numbers with the real part rounded to the nearest integer and the imaginary part ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def round_complex_numbers(numbers: List[complex]) -> List[complex]: """ Rounds off the real part of each complex number in the input list to the nearest integer, while maintaining the imaginary part ...
evol_instruct_66k
2,085
Write a Python function to calculate the cumulative sum of the digits of a given integer. The function should handle both positive and negative integers. The code should start with: ```python def sum_of_digits(num: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def sum_of_digits(num: int) -> int: """ Calculate the cumulative sum of the digits of a given integer. Args: num (int): The integer whose digits are to be summed. Returns: int: The cumulative sum of t...
evol_instruct_66k
2,089
Write a Python function to sort a given list of integers in ascending order using two different techniques: in-place sorting and creating a new sorted list. The function should return a tuple containing the sorted list using the in-place method and the sorted list using the new list method. 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_list_two_ways(numbers: List[int]) -> Tuple[List[int], List[int]]: """ Sorts a given list of integers using two different techniques: in-place sorting and creating a new sorted list. ...
evol_instruct_66k
2,096
Write a Python function to calculate the net income after applying a tax rate and a deduction to the gross income. The function should take three parameters: `income`, `tax_rate`, and `deduction`. The function should return the net income after subtracting the tax and the deduction from the income. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_net_income(income: float, tax_rate: float, deduction: float) -> float: """ Calculate the net income after applying a tax rate and a deduction to the gross income. Args: income (float): The gross income...
evol_instruct_66k
2,100
Write a Python function to apply dual transformations to a given text: first, convert all characters to lowercase, and second, replace all exclamation marks with full stops. The function should return the modified text. The code should start with: ```python def dual_transform(text: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def dual_transform(text: str) -> str: """ Applies dual transformations to the given text: 1. Converts all characters to lowercase. 2. Replaces all exclamation marks with full stops. Args: text (str): The inp...
evol_instruct_66k
2,101
Write a Python function to create an array of student dictionaries, each containing a student's first name and age. The function should then return a list of the students' first names in the order they appear in the array. The code should start with: ```python from typing import List, Dict def get_student_names(studen...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Dict def get_student_names(students: List[Dict[str, int]]) -> List[str]: """ Extracts and returns the first names of students from a list of student dictionaries. Args: students (List[Dic...
evol_instruct_66k
2,103
Write a Python function to check if two provided arrays have the same elements in reverse order, considering the order of duplicates. The function should handle variable data types, non-numeric data, and data inconsistencies. The code should start with: ```python from typing import List, Any def are_arrays_reverse(arr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def are_arrays_reverse(arr1: List[Any], arr2: List[Any]) -> bool: """ Check if two provided arrays have the same elements in reverse order, considering the order of duplicates. Args: ar...
evol_instruct_66k
2,124
Write a Python function to create a dictionary mapping each word in a space-separated string to its length. If there are words with equal length, all must be included in the dictionary. The function should handle the input string in a multistep manner, ensuring that the solution involves more than just straightforward ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def word_length(text: str) -> Dict[str, int]: """ Create a dictionary mapping each word in a space-separated string to its length. Args: text (str): A space-separated string of words. R...
evol_instruct_66k
2,126
Write a Python function to determine the position of a specified character in a given string. The position should be 1-based, meaning the first character in the string has a position of 1. If the character is not found in the string, the function should return -1. The code should start with: ```python def find_charact...
Here is the Python code to solve the given problem in the markdown block: ```python def find_character_position(s: str, char: str) -> int: """ Determine the 1-based position of a specified character in a given string. Args: s (str): The string in which to search for the character. char (str...
evol_instruct_66k
2,137
Write a Python function to reverse the order of elements in a given list of integers. The function should return a new list with the elements in the reversed order. The original list should not be modified. The code should start with: ```python from typing import List def reverse_list(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 reverse_list(arr: List[int]) -> List[int]: """ Reverses the order of elements in a given list of integers and returns a new list. Args: arr (List[int]): The list of integers to be reve...
evol_instruct_66k
2,146
Write a Python function to determine if two given strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should be case-insensitive and should ignore spaces. The code should ...
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(string1: str, string2: str) -> bool: """ Determines if two given strings are anagrams of each other. Args: string1 (str): The first string to compare. string2 (str): The second string to com...
evol_instruct_66k
2,162
Write a Python function to perform a 90-degree rotation about the central axis of a 3-dimensional cube expressed as an array of 2-dimensional matrices. The rotation should begin from the periphery of the cube and proceed towards the middle, one layer after another. The function should handle cubes of any size, not just...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def rotate_3d_cube(cube: List[List[List[int]]]) -> List[List[List[int]]]: """ Rotates a 3-dimensional cube by 90 degrees about its central axis. Args: cube (List[List[List[int]]]): A 3-dimen...
evol_instruct_66k
2,206
Write a Python function to reverse the order of characters in each word of a given sentence while maintaining the original position of each word within the sentence. The sentence can include special characters and punctuation. The function should handle sentences with varying lengths and different types of characters. ...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_words_in_sentence(sentence: str) -> str: """ Reverses the order of characters in each word of a given sentence while maintaining the original position of each word. Args: sentence (str): The input senten...
evol_instruct_66k
2,209
Write a Python function to compute the factorial of a given number using a recursive algorithm with memoization. The function should store intermediate results to avoid redundant calculations and improve efficiency. The code should start with: ```python def factorial_memoized(n: int, memo: dict = None) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def factorial_memoized(n: int, memo: dict = None) -> int: """ Compute the factorial of a given number using a recursive algorithm with memoization. Args: n (int): The number for which to compute the factorial. ...
evol_instruct_66k
2,212
Write a Python function to generate an SQL query that counts the number of exclusive clients who have executed transactions within the preceding lunar cycle. A client is considered exclusive if they have executed transactions only within the specified lunar cycle and not before. The function should take the table name ...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_exclusive_clients_query(table_name: str) -> str: """ Generates an SQL query to count the number of exclusive clients who have executed transactions within the preceding lunar cycle (approximately 29.5 days). ...
evol_instruct_66k
2,215
Write a Python function that provides feedback based on a given score using a ternary operator. The feedback should be categorized into three levels: "Excellent!", "Good job!", and "You need to improve". The function should handle the score as an integer and return the appropriate feedback string. The code should star...
Here is the Python code to solve the given problem in the markdown block: ```python def get_feedback(score: int) -> str: """ Provides feedback based on the given score using a ternary operator. Args: score (int): The score to evaluate. Returns: str: The feedback message based on the sc...
evol_instruct_66k
2,217
Write a Python function to find all symmetric pairs in a given list of integers. A symmetric pair is defined as a pair of integers that appear at the same distance from the start and end of the list. For example, in the list `[1, 2, 3, 3, 2, 1]`, the pairs `(1, 1)`, `(2, 2)`, and `(3, 3)` are symmetric pairs. The code...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_symmetric_pairs(nums: List[int]) -> List[Tuple[int, int]]: """ Find all symmetric pairs in a given list of integers. A symmetric pair is defined as a pair of integers that appear at ...
evol_instruct_66k
2,230
Write a Python function to invert an array of integers. The function should take a list of integers as input and return a new list with the elements in reverse order. The function should not modify the original list. The code should start with: ```python from typing import List def invert_array(array: List[int]) -> Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def invert_array(array: List[int]) -> List[int]: """ Inverts the order of elements in the given array of integers. Args: array (List[int]): The array of integers to be inverted. Returns...
evol_instruct_66k
2,236
Write a Python function to calculate the cubic values of a given list of integers. The function should return a list of these cubic values. The input list can contain any integers, not just the numbers from 1 to 8. The code should start with: ```python from typing import List def calculate_cubes(numbers: List[int]) -...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_cubes(numbers: List[int]) -> List[int]: """ Calculate the cubic values of a given list of integers. Args: numbers (List[int]): A list of integers for which to calculate the cub...
evol_instruct_66k
2,241
Write a Python function to find the maximum element in a given two-dimensional array and calculate the sum of all elements in the sub-array where the maximum element is found. The function should return a tuple containing the maximum value and the sum of the sub-array. 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, Tuple def find_max_and_sum(array: List[List[int]]) -> Tuple[int, int]: """ Find the maximum element in a given two-dimensional array and calculate the sum of all elements in the sub-array where the maxi...
evol_instruct_66k
2,248
Write a Python function that converts a given list of numbers into an asynchronous generator that yields the cube of each number. The function should be able to handle asynchronous iteration using `async for` loops. The code should start with: ```python from typing import List import asyncio async def async_cube_gener...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import asyncio async def async_cube_generator(numbers: List[int]): """ Asynchronously generates the cube of each number in the given list. Args: numbers (List[int]): A list of integers for w...
evol_instruct_66k
2,249
Write a Python function to calculate the sum of two numbers, ensuring that the inputs are either integers or floats. If the inputs are strings that can be converted to numbers, convert them to floats. If the inputs cannot be converted to numbers, raise a `ValueError` with an appropriate message. The code should start ...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_sum(a, b): """ Calculate the sum of two numbers, ensuring that the inputs are either integers, floats, or convertible strings. Args: a (int, float, str): The first number or a string that can be conver...