source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
evol_instruct_66k
43,284
Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should start with: ```python from typing import List def unique_paths(m: int, n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def unique_paths(m: int, n: int) -> int: """ Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid. Args: m (int): The number of row...
evol_instruct_66k
43,290
Write a Python function to merge two dictionaries, where the second dictionary's key-value pairs are added to the first dictionary. If a key exists in both dictionaries, the value from the second dictionary should overwrite the value in the first dictionary. The function should return the updated first dictionary. The...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def merge_dictionaries(dict1: Dict, dict2: Dict) -> Dict: """ Merges two dictionaries, where the second dictionary's key-value pairs are added to the first dictionary. If a key exists in both diction...
evol_instruct_66k
43,306
Write a Python function to determine if a given string matches the pattern where it starts with "dog", contains only uppercase letters in between, and ends with "X". The function should use regular expressions to perform this check. The code should start with: ```python import re def is_match(str: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_match(str: str) -> bool: """ Determines if the given string matches the pattern where it starts with "dog", contains only uppercase letters in between, and ends with "X". Args: str (str): The s...
evol_instruct_66k
43,312
Write a Python function to transform an array such that each element is replaced with the sum of all numeric elements before it. Additionally, implement error handling to exclude non-numeric elements from the sum and provide a reverse operation that can undo the array modifications. The code should start with: ```pyth...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def transform_array(array: List[Union[int, float, str]]) -> List[Union[int, float]]: """ Transform the array such that each element is replaced with the sum of all numeric elements before it. ...
evol_instruct_66k
43,317
Write a Python function to sort a given list of integers in ascending order without using any built-in sorting functions or methods. The function should implement the Bubble Sort algorithm. 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 in ascending order using the Bubble Sort algorithm. Args: arr (List[int]): The list of integers to be sorted. ...
evol_instruct_66k
43,322
Write a Python function to extract all valid email addresses from a given text using a regular expression. The function should return a list of all email addresses found in the text. The code should start with: ```python from typing import List import re def extract_emails(text: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List import re def extract_emails(text: str) -> List[str]: """ Extracts all valid email addresses from the given text using a regular expression. Args: text (str): The text from which to extrac...
evol_instruct_66k
43,323
Write a Python function to calculate the product of all elements in a given array, handling arrays with negative numbers and zero. The function should efficiently handle arrays with sizes up to \(10^6\). The code should start with: ```python from typing import List def calculate_product(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_product(arr: List[int]) -> int: """ Calculate the product of all elements in the given array. Args: arr (List[int]): The array of integers for which the product is to be calcul...
evol_instruct_66k
43,325
Write a Python function to interpret a given textual input and yield an array of lexemes. The function should handle various delimiters such as spaces, commas, and semicolons. Additionally, it should be able to handle multiple consecutive delimiters and ignore leading and trailing delimiters. The function should start ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def interpret_text(input_text: str, delimiters: str = " ,;") -> List[str]: """ Interpret the given textual input and yield an array of lexemes based on the provided delimiters. Args: ...
evol_instruct_66k
43,338
Write a Python function to verify if a given number is a prime number by finding all its divisors. If the number is prime, the function should return a list containing only 1 and the number itself. If the number is not prime, the function should return a list of all its divisors. 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 verify_prime(P: int) -> List[int]: """ Verifies if a given number P is a prime number by finding all its divisors. Args: P (int): The number to verify. Returns: List[int]: A...
evol_instruct_66k
43,362
Write a Python function to check if a given string contains all the words in a list, regardless of their order and case sensitivity. The function should return `True` if all words are found in the string, and `False` otherwise. The code should start with: ```python from typing import List def contains_all_words(s: str...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def contains_all_words(s: str, words: List[str]) -> bool: """ Check if the given string contains all the words in the list, regardless of their order and case sensitivity. Args: s (str): The...
evol_instruct_66k
43,370
Write a Python function to convert a date from the Julian calendar system to the Gregorian calendar system. The input date is provided as a string in the format 'YYYY-MM-DD'. The function should return the corresponding Gregorian date in the same string format. The conversion should only be applied to dates after Octob...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime, timedelta def julian_to_gregorian(julian_date_str: str) -> str: """ Converts a Julian date to a Gregorian date. Args: julian_date_str (str): The Julian date in the format 'YYYY-MM-DD'...
evol_instruct_66k
43,377
Write a Python function to remove duplicate elements from a given tuple and return the result as a new tuple. The order of elements in the resulting tuple should be preserved based on their first occurrence in the input tuple. The code should start with: ```python from typing import Tuple def remove_duplicates(input_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def remove_duplicates(input_tuple: Tuple[int]) -> Tuple[int]: """ Removes duplicate elements from a given tuple while preserving the order of first occurrences. Args: input_tuple (Tuple[int...
evol_instruct_66k
43,379
Write a Python function to calculate the sum of all numerical elements in a given array. The function should handle arrays with integers, floating-point numbers, and nested arrays containing integers or floating-point numbers. The function should recursively sum all elements, including those in nested arrays. The code...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def sum_nested_array(arr: List[Union[int, float, List]]) -> Union[int, float]: """ Calculate the sum of all numerical elements in a given array, including those in nested arrays. Args: ...
evol_instruct_66k
43,400
Write a Python function to remove all instances of numbers that appear more than once in a given list. The function should return a new list containing only the numbers that appear exactly once in the original list. The code should start with: ```python from typing import List def remove_duplicates(arr: 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 all instances of numbers that appear more than once in the given list. Args: arr (List[int]): The list of integers from which ...
evol_instruct_66k
43,404
Write a Python function to find the intersection of two sets without using Python's built-in set operations. The function should return the distinct elements in ascending order. The code should start with: ```python from typing import Set, List def set_intersection(s1: Set[int], s2: Set[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set, List def set_intersection(s1: Set[int], s2: Set[int]) -> List[int]: """ Calculate the intersection of two sets without using Python's built-in set operations. Returns the distinct elements in ascendi...
evol_instruct_66k
43,411
Write a Python function to process a given list containing both strings and integers. The function should remove all non-repeating string elements and sort the integers in descending order. The function should return a new list containing the processed strings followed by the sorted integers. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def process_list(lst: List[Union[str, int]]) -> List[Union[str, int]]: """ Processes a list containing both strings and integers by removing non-repeating string elements and sorting the integ...
evol_instruct_66k
43,419
Write a Python function to print "Hello World!" a specified number of times. The function should take an integer `n` as input and print "Hello World!" exactly `n` times. The code should start with: ```python def print_hello_world(n: int) -> None: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def print_hello_world(n: int) -> None: """ Prints "Hello World!" exactly n times. Args: n (int): The number of times to print "Hello World!". Returns: None: This function does not return any value. ...
evol_instruct_66k
43,435
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 return `True` if the strings are anagrams, and `False` otherwis...
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(string_1: str, string_2: str) -> bool: """ Determine if two given strings are anagrams of each other. Args: string_1 (str): The first string to compare. string_2 (str): The second string to ...
evol_instruct_66k
43,442
Write a Python function to compute the product of all elements in a given array of integers. The function should handle arrays with zero or more elements. The code should start with: ```python from typing import List def product_of_elements(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def product_of_elements(arr: List[int]) -> int: """ Compute the product of all elements in a given array of integers. Args: arr (List[int]): The array of integers whose product is to be co...
evol_instruct_66k
43,469
Write a Python function to create a nested dictionary structure from a given list of keys and their associated numerical values. The function should ensure that each key in the list of keys is nested within the previous key, and the final key in the list should hold the corresponding value from the list of values. The ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def create_nested_dict(list_keys: List[str], list_vals: List[int]) -> Dict[str, Any]: """ Creates a nested dictionary structure from a list of keys and their associated values. Args: ...
evol_instruct_66k
43,477
Write a Python function to find the longest palindromic subsequence in a given string. The function should return the length of the longest palindromic subsequence. The code should start with: ```python def longest_palindromic_subseq(s: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def longest_palindromic_subseq(s: str) -> int: """ Calculate the length of the longest palindromic subsequence in a given string. Args: s (str): The input string. Returns: int: The length of the longest...
evol_instruct_66k
43,485
Write a Python function to sort a list of integers using the merge sort algorithm. Merge sort is a divide-and-conquer algorithm that recursively divides the list into halves until each sublist contains a single element, then merges these sublists back together in sorted order. The function should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(int_list: List[int]) -> List[int]: """ Sorts a list of integers using the merge sort algorithm. Args: int_list (List[int]): The list of integers to be sorted. Returns: ...
evol_instruct_66k
43,487
Write a Python function to generate the first n Fibonacci numbers. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the previous two. The function should handle cases where n is less than or equal to 0 by returning an empty list. The code should start with: ```python from typing imp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: """ Generate the first n Fibonacci numbers. Args: n (int): The number of Fibonacci numbers to generate. Returns: List[int]: A list c...
evol_instruct_66k
43,490
Write a Python function to detect if a linked list contains a cycle and, if a cycle is present, determine the node at which the cycle begins. The function should return `None` if there is no cycle. The linked list is represented by a class `ListNode` with an integer `val` and a `next` pointer to the next node in the li...
Here is the Python code to solve the given problem in the markdown block: ```python class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def detect_cycle(head: ListNode) -> ListNode: """ Detects if a linked list contains a cycle and returns the node at which...
evol_instruct_66k
43,509
Write a Python function to sort an array of strings containing both letters and numbers based on the numerical part in descending order. Each string in the array consists of a number followed by a letter. The function should return the sorted array. The code should start with: ```python from typing import List def so...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_strings_by_number(arr: List[str]) -> List[str]: """ Sorts an array of strings containing both letters and numbers based on the numerical part in descending order. Args: arr (List[st...
evol_instruct_66k
43,516
Write a Python function to validate two strings based on specific criteria: 1. The string must not be empty. 2. The string must contain at least one numerical character. 3. The string must contain at least one uppercase letter. The function should return `True` if all criteria are met, otherwise `False`. The code sho...
Here is the Python code to solve the given problem in the markdown block: ```python import re def validate_strings(s1: str, s2: str) -> bool: """ Validates two strings based on the following criteria: 1. The string must not be empty. 2. The string must contain at least one numerical character. 3. T...
evol_instruct_66k
43,521
Write a Python function to calculate the median value among a trio of numerical entities. The function should take a list of exactly three integers as input and return the median value. The code should start with: ```python from typing import List def calculate_median_of_trio(trio: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def calculate_median_of_trio(trio: List[int]) -> int: """ Calculate the median value among a trio of numerical entities. Args: trio (List[int]): A list containing exactly three integers. ...
evol_instruct_66k
43,547
Write a Python function to multiply all the elements of a given nested array, including any nested arrays present. The array may contain both single digits and other arrays. The function should return the product of all elements. The code should start with: ```python from typing import List, Union def multiply_nested...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Union def multiply_nested_array(arr: List[Union[int, List]]) -> int: """ Multiply all the elements of a given nested array, including any nested arrays present. Args: arr (List[Union[int,...
evol_instruct_66k
43,555
Write a Python function to find the index of the first unique character in a given string. If there are no unique characters, the function should return -1. The function should be efficient and handle various edge cases, such as empty strings and strings with all duplicate characters. The code should start with: ```py...
Here is the Python code to solve the given problem in the markdown block: ```python def first_unique_char(s: str) -> int: """ Finds the index of the first unique character in the given string. Args: s (str): The input string to search for the first unique character. Returns: int: The i...
evol_instruct_66k
43,579
Write a Python function to create an array composed of 10 unique random numerical elements within the range of 1 to 100 inclusive. Ensure that the array contains unique numbers only. Analyze the time complexity of your solution. The code should start with: ```python from typing import List import random def generate_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_unique_random_array() -> List[int]: """ Generates an array of 10 unique random numbers within the range of 1 to 100 inclusive. Returns: List[int]: A list containin...
evol_instruct_66k
43,593
Write a Python function to calculate the product of the digits of a given positive integer. The function should handle any positive integer and return the product of its digits. The code should start with: ```python def product_of_digits(num: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def product_of_digits(num: int) -> int: """ Calculate the product of the digits of a given positive integer. Args: num (int): The positive integer whose digits' product is to be calculated. Returns: i...
evol_instruct_66k
43,610
Write a Python function to determine the frequency distribution of every unique item in a given list. The function should be optimized for computational efficiency and accuracy. The code should start with: ```python from typing import List, Dict def frequency_distribution(input_list: List[str]) -> Dict[str, int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Dict from collections import Counter def frequency_distribution(input_list: List[str]) -> Dict[str, int]: """ Determine the frequency distribution of every unique item in a given list. Args: ...
evol_instruct_66k
43,615
Write a Python function to combine two dictionaries into a new dictionary, where the values from the second dictionary override the values from the first dictionary in case of duplicate keys. The function should start with: ```python from typing import Dict def combine_dictionaries(dict1: Dict, dict2: Dict) -> Dict: `...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def combine_dictionaries(dict1: Dict, dict2: Dict) -> Dict: """ Combines two dictionaries into a new dictionary, where the values from the second dictionary override the values from the first diction...
evol_instruct_66k
43,619
Write a Python function to convert a given timestamp in the format "Month Day, Year" into a standardized date format "mm/dd/yyyy". The function should handle the conversion of month names to their corresponding numerical values. The code should start with: ```python from typing import List def convert_timestamp(timest...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def convert_timestamp(timestamp: str) -> str: """ Converts a timestamp from the format "Month Day, Year" to "mm/dd/yyyy". Args: timestamp (str): The input timestamp in the format "Month Da...
evol_instruct_66k
43,622
Write a Python function to count the occurrences of each character in a given string, considering case sensitivity and punctuation marks. The function should return a dictionary where the keys are the distinct characters from the string and the values are their respective counts. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def count_characters(text: str) -> Dict[str, int]: """ Counts the occurrences of each character in the given string, considering case sensitivity and punctuation marks. Args: text (str): The...
evol_instruct_66k
43,626
Write a Python function to generate a random probability distribution that adheres to a specified mean and standard deviation. The function should return a list of random numbers that closely match the specified statistical properties. The code should start with: ```python from typing import List import numpy as np d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import numpy as np def generate_random_distribution(mean: float, std_dev: float, size: int) -> List[float]: """ Generates a list of random numbers that follow a normal distribution with the specified mea...
evol_instruct_66k
43,627
Write a Python function to find the longest palindromic substring within a given string. A palindrome is a string that reads the same backward as forward. The function should return the longest palindromic substring found in the input string. The code should start with: ```python def longest_palindromic_substring(s: s...
Here is the Python code to solve the given problem in the markdown block: ```python def longest_palindromic_substring(s: str) -> str: """ Find the longest palindromic substring within the given string. Args: s (str): The input string in which to find the longest palindromic substring. Returns:...
evol_instruct_66k
43,630
Write a Python function to generate all possible permutations of pairs formed by elements from two given lists. Each pair should consist of one element from the first list and one element from the second list. The function should return a list of tuples, where each tuple represents a pair. 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 import itertools def generate_permutations(list1: List[int], list2: List[int]) -> List[Tuple[int, int]]: """ Generate all possible permutations of pairs formed by elements from two given lists. ...
evol_instruct_66k
43,634
Write a Python function to compute the total expenditure for a given quantity of merchandise, incorporating the application of a Value Added Tax (VAT) at a specified percentage. The function should take two parameters: the quantity of merchandise and the VAT percentage. The cost of each merchandise item is assumed to b...
Here is the Python code to solve the given problem in the markdown block: ```python def compute_total_expenditure(quantity: int, vat_percentage: int) -> float: """ Compute the total expenditure for a given quantity of merchandise, including VAT. Args: quantity (int): The quantity of merchandise. ...
evol_instruct_66k
43,643
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(X: str, Y: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def longest_common_subsequence(X: str, Y: str) -> int: """ Calculate the length of the longest common subsequence (LCS) between two strings. Args: X (str): The first string. Y (str): The second string. ...
evol_instruct_66k
43,648
Write a Python function to inspect and identify the datatype of each individual element within a given complex list. The function should return a list of tuples, where each tuple contains an element from the input list and its corresponding datatype. The code should start with: ```python from typing import List, Tuple...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def inspect_datatypes(lst: List) -> List[Tuple]: """ Inspects and identifies the datatype of each individual element within a given complex list. Args: lst (List): The complex list co...
evol_instruct_66k
43,654
Write a Python function to segregate a given array into `n` homogeneous sections without using built-in array division functions. Each section should be sorted in ascending order. The function should handle cases where the number of partitions is greater than the length of the array and ensure that the sections are as ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def segregate_and_sort(arr: List[int], num_partitions: int) -> List[List[int]]: """ Segregates a given array into `num_partitions` homogeneous sections, each sorted in ascending order. Args: ...
evol_instruct_66k
43,655
Write a Python function to create a dictionary with a single key-value pair, where the key is a given string and the value is a given integer. The function should return the dictionary. The code should start with: ```python def create_single_key_value_dict(key: str, value: int) -> dict: ```
Here is the Python code to solve the given problem in the markdown block: ```python def create_single_key_value_dict(key: str, value: int) -> dict: """ Creates a dictionary with a single key-value pair. Args: key (str): The key for the dictionary. value (int): The value corresponding to the...
evol_instruct_66k
43,674
Write a Python function to find the pair, triple, quadruple, and quintuple of integers from a given array that result in the minimum product. The function should handle cases where the array contains fewer than five integers by returning a message indicating that it's not possible to find the quintuple. The function sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Union def find_min_products(arr: List[int]) -> Union[str, Tuple[Tuple[int, int], Tuple[int, int, int], Tuple[int, int, int, int], Tuple[int, int, int, int, int]]]: """ Finds the pair, triple, qua...
evol_instruct_66k
43,677
Write a Python function to generate a random number within a specified range. The function should allow the user to specify a range within 1 to 100 from which the random number should be generated. The function should also handle any invalid range inputs by the user. The code should start with: ```python import random ...
Here is the Python code to solve the given problem in the markdown block: ```python import random def generate_random_number(range_start: int = 1, range_end: int = 100) -> int: """ Generates a random number within a specified range. Args: range_start (int): The start of the range (inclusive). Defa...
evol_instruct_66k
43,678
Write a Python function to calculate the sum of unique digits in a given string of integers. The function should handle input validation to ensure that the string contains only digits, and it should gracefully handle very long input strings (up to 1000 characters). The function should also ignore leading zeroes. The c...
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_unique_digits(input_string: str) -> int: """ Calculate the sum of unique digits in a given string of integers. Args: input_string (str): A string of integers (up to 1000 characters). Returns: ...
evol_instruct_66k
43,695
Write a Python function to determine if a given positive integer is an Armstrong number. An Armstrong number (also known as a narcissistic number) is a number that is the sum of its own digits each raised to the power of the number of digits. The code should start with: ```python def is_armstrong_number(n: int) -> boo...
Here is the Python code to solve the given problem in the markdown block: ```python def is_armstrong_number(n: int) -> bool: """ Determines if a given positive integer is an Armstrong number. An Armstrong number (or narcissistic number) is a number that is the sum of its own digits each raised to the p...
evol_instruct_66k
43,700
Write a Python function to flatten a nested list structure. The function should take a list that may contain other lists at any level of nesting and return a single list containing all the elements in a flat structure, without any nesting. The code should start with: ```python from typing import List, Any def flatten...
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 structure into a single list containing all elements in a flat structure. Args: nested_list (Lis...
evol_instruct_66k
43,716
Write a Python function to find all the words in a given list that start with a specified prefix. The function should return a list of words that match the prefix. The code should start with: ```python from typing import List def find_words_with_prefix(words: List[str], prefix: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_words_with_prefix(words: List[str], prefix: str) -> List[str]: """ Find all words in the given list that start with the specified prefix. Args: words (List[str]): The list of words ...
evol_instruct_66k
43,718
Write a Python function to transform a list of programming language names into a list of tuples where each tuple contains an index and the corresponding programming language name. The function should start with: ```python from typing import List, Tuple def transform_to_tuples(languages: List[str]) -> List[Tuple[int, s...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Tuple def transform_to_tuples(languages: List[str]) -> List[Tuple[int, str]]: """ Transforms a list of programming language names into a list of tuples where each tuple contains an index and the corre...
evol_instruct_66k
43,733
Write a Python function to implement the Bubble Sort algorithm, which sorts a list of integers in ascending order. The function should repeatedly step through the list, compare adjacent elements, and swap them if they are in the wrong order. The process should be repeated until the list is sorted. The code should start...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(numbers: List[int]) -> List[int]: """ Sorts a list of integers in ascending order using the Bubble Sort algorithm. Args: numbers (List[int]): The list of integers to be sorte...
evol_instruct_66k
43,771
Write a Python function to convert a given phrase into snake_case. The function should replace all spaces in the phrase with underscores and convert all characters to lowercase. The code should start with: ```python def convert_to_snake_case(phrase: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_snake_case(phrase: str) -> str: """ Converts a given phrase into snake_case by replacing spaces with underscores and converting all characters to lowercase. Args: phrase (str): The input phrase to be ...
evol_instruct_66k
43,777
Write a Python function to generate all possible permutations of a given list of strings. Each permutation should be a tuple of strings, and the function should return a list of all such permutations. The code should start with: ```python from typing import List, Tuple from itertools import permutations def generate_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple from itertools import permutations def generate_permutations(strings: List[str]) -> List[Tuple[str]]: """ Generate all possible permutations of a given list of strings. Args: strings ...
evol_instruct_66k
43,786
Write a Python function to calculate the sum of elements within a specified range in a given list. The function should take three parameters: the list of integers, the starting index (inclusive), and the ending index (exclusive). The function should return the sum of the elements in the list from the starting index to ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def range_sum(arr: List[int], start: int, end: int) -> int: """ Calculate the sum of elements in the list from the starting index (inclusive) to the ending index (exclusive). Args: arr (List...
evol_instruct_66k
43,797
Write a Python function to generate a list of n random numbers within a specified range [a, b]. The function should ensure that the generated numbers are unique and sorted in ascending order. The code should start with: ```python from typing import List import random def generate_unique_random_numbers(n: int, a: int, ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_unique_random_numbers(n: int, a: int, b: int) -> List[int]: """ Generates a list of n unique random numbers within the specified range [a, b] and returns them sorted in ascendi...
evol_instruct_66k
43,805
Write a Python function to perform a division operation and compute the resultant remainder. The function should print both the quotient and the remainder of the division operation. The code should start with: ```python def division_and_remainder(x: int, y: int) -> None: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def division_and_remainder(x: int, y: int) -> None: """ Perform a division operation and compute the resultant remainder. Print both the quotient and the remainder of the division operation. Args: x (int): The...
evol_instruct_66k
43,837
Write a Python function to identify and return the sentence that recurs with the highest frequency in a given list of sentences. If there are multiple sentences with the same highest frequency, return the first one encountered in the list. The function should handle the case where all sentences are unique by returning ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import Counter def most_frequent_sentence(sentences: List[str]) -> str: """ Identify and return the sentence that recurs with the highest frequency in a given list of sentences. If t...
evol_instruct_66k
43,874
Write a Python function to construct a secure Uniform Resource Locator (URL) by concatenating the given attributes in a specific format. The attributes include the secure data transfer method (e.g., "https"), subsection identifier (e.g., "mypage"), leading domain designation (e.g., "google"), and specific webpage pathw...
Here is the Python code to solve the given problem in the markdown block: ```python def construct_secure_url(secure_data_transfer_method: str, subsection_identifier: str, leading_domain_designation: str, specific_webpage_pathway: str) -> str: """ Constructs a secure URL by concatenating the given attributes in ...
evol_instruct_66k
43,877
Write a Python function to find the least common multiple (LCM) of two distinct whole numbers. The function should take two integers as input and return their LCM. The code should start with: ```python import math def least_common_multiple(a: int, b: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python import math def least_common_multiple(a: int, b: int) -> int: """ Calculate the least common multiple (LCM) of two distinct whole numbers. Args: a (int): The first whole number. b (int): The second whole nu...
evol_instruct_66k
43,882
Write a Python function to filter and print all odd numbers from a given list of integers. The function should also handle cases where the input is not a list, the list is empty, or the list contains non-integer items. If an invalid item is found, it should print a message indicating the invalid item. The function shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_odd_numbers(numbers: List[int]) -> None: """ Prints all odd numbers from the given list of integers. Handles cases where the input is not a list, the list is empty, or the list contains non...
evol_instruct_66k
43,896
Write a Python function to implement a multithreaded version of the given C++ code. The threads should print out "Hello World" in a synchronized manner such that they don't overlap with each other. Utilize suitable synchronization primitives to handle race conditions. The code should demonstrate correct thread creation...
Here is the Python code to solve the given problem in the markdown block: ```python import threading def synchronized_hello_world(num_threads: int): """ Creates a specified number of threads that print "Hello World" in a synchronized manner. Args: num_threads (int): The number of threads to create...
evol_instruct_66k
43,902
Write a Python function to visualize the individual entities within a given enumerated collection. The function should print each item in the collection on a new line. The collection can be a list, tuple, or any other iterable. The code should start with: ```python from typing import Iterable def visualize_collection(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Iterable def visualize_collection(collection: Iterable) -> None: """ Visualizes the individual entities within a given enumerated collection by printing each item on a new line. Args: collection ...
evol_instruct_66k
43,927
Write a Python function to calculate the highest common factor (HCF) of a given list of integers. The function should efficiently compute the HCF for any number of integers in the list. The code should start with: ```python from typing import List import math def highest_common_factor(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def highest_common_factor(numbers: List[int]) -> int: """ Calculate the highest common factor (HCF) of a list of integers. Args: numbers (List[int]): A list of integers for which...
evol_instruct_66k
43,930
Write a Python function to concatenate two strings with a space in between and then append an exclamation mark at the end using an f-string. The function should take two string inputs and return the resulting concatenated string with the exclamation mark. The code should start with: ```python def concatenate_and_excla...
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_and_exclaim(a: str, b: str) -> str: """ Concatenates two strings with a space in between and appends an exclamation mark at the end. Args: a (str): The first string to concatenate. b (str): T...
evol_instruct_66k
43,944
Write a Python function to find and return the unique elements in a singly-linked list. The singly-linked list is represented by a list of integers where each integer represents a node's value. The function should traverse the list and collect all unique values, maintaining their order of first appearance. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_unique_elements(linked_list: List[int]) -> List[int]: """ Finds and returns the unique elements in a singly-linked list represented by a list of integers. Args: linked_list (List[in...
evol_instruct_66k
43,945
Write a Python function to create a dictionary where each element of a given tuple acts as the key and its index as the value. The function should handle tuples of any length and return the resulting dictionary. The code should start with: ```python from typing import Tuple, Dict def tuple_to_index_dict(tuple_input: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Dict def tuple_to_index_dict(tuple_input: Tuple[int]) -> Dict[int, int]: """ Create a dictionary where each element of the given tuple acts as the key and its index as the value. Args: tup...
evol_instruct_66k
43,949
Write a Python function to sort a dictionary by its values, handling dictionaries with mixed data types as values. Numeric values should be sorted in ascending order, and string values should be sorted alphabetically. The function should return a new dictionary with the sorted key-value pairs. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Union def sort_dictionary_by_values(d: Dict[str, Union[int, float, str]]) -> Dict[str, Union[int, float, str]]: """ Sorts a dictionary by its values, handling mixed data types. Numeric values are sorted...
evol_instruct_66k
43,977
Write a Python function to detect if a given string matches a specific regular expression pattern. The pattern should detect strings that start with an uppercase 'M', end with a lowercase 'x', and contain at least one digit and one special character in between. The code should start with: ```python import re def dete...
Here is the Python code to solve the given problem in the markdown block: ```python import re def detect_sequence(string: str) -> bool: """ Detects if a given string matches the pattern: starts with 'M', ends with 'x', and contains at least one digit and one special character in between. Args: ...
evol_instruct_66k
43,978
Write a Python function to calculate the cumulative grade point average (CGPA) for a university undergraduate based on their list of subjects and corresponding grades. The function should handle different grading scales and ensure that the CGPA is calculated accurately. 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, Dict def calculate_cgpa(subjects: List[Dict[str, str]]) -> float: """ Calculate the cumulative grade point average (CGPA) for a university undergraduate. Args: subjects (List[Dict[str, st...
evol_instruct_66k
43,985
Write a Python function to determine the maximum profit that can be obtained by buying and selling a stock once, given a list of daily stock prices. The stock must be bought before it can be sold. The function should start with: ```python from typing import List def max_profit_single_transaction(stock_prices: List[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_profit_single_transaction(stock_prices: List[int]) -> int: """ Calculate the maximum profit that can be obtained by buying and selling a stock once. Args: stock_prices (List[int]): A...
evol_instruct_66k
43,989
Write a Python function to implement a linear search algorithm and find the index of a given element in a given array. If the element is not found, return -1. The code should start with: ```python from typing import List def linear_search(arr: List[int], target: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def linear_search(arr: List[int], target: int) -> int: """ Implements a linear search algorithm to find the index of a given element in an array. Args: arr (List[int]): The array in which ...
evol_instruct_66k
43,998
Write a Python function to determine the most efficient search method for finding a specific element within an array based on the array's characteristics. The function should return the index of the target element if found, or -1 if not found. The function should choose between linear search, binary search, and hash ta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_element(array: List[int], target: int, is_sorted: bool) -> int: """ Determines the most efficient search method based on the array's characteristics and returns the index of the target element. ...
evol_instruct_66k
44,006
Write a Python function to print the first n elements of a given list. If n is greater than the length of the list, print the entire list. The function should handle cases where n is negative or zero by printing an empty list. The code should start with: ```python from typing import List def print_first_n_elements(my...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_first_n_elements(mylist: List[int], n: int) -> None: """ Prints the first n elements of the given list. Args: mylist (List[int]): The list from which to print the first n elements....
evol_instruct_66k
44,014
Write a Python function to process each character in a given alphanumeric string and append them individually into a list. The function should return the resulting list. The code should start with: ```python from typing import List def process_characters(sequence: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def process_characters(sequence: str) -> List[str]: """ Processes each character in a given alphanumeric string and appends them individually into a list. Args: sequence (str): The alphanu...
evol_instruct_66k
44,034
Write a Python function to repeat each element in a given list of strings twice. The function should take a list of strings as input and return a new list where each string is repeated twice. The code should start with: ```python from typing import List def repeat_elements_twice(digits: List[str]) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def repeat_elements_twice(digits: List[str]) -> List[str]: """ Repeats each element in the given list of strings twice. Args: digits (List[str]): A list of strings where each string is to be...
evol_instruct_66k
44,073
Write a Python function to parse a string containing multiple key-value pairs separated by commas into a dictionary. The keys and values are separated by an "=" sign. The function should handle possible whitespace around the "=" sign and ensure that the parser can handle both integers and floating point numbers. The co...
Here is the Python code to solve the given problem in the markdown block: ```python import re def parse_string_to_dict(s: str) -> dict: """ Parses a string containing multiple key-value pairs separated by commas into a dictionary. The keys and values are separated by an "=" sign. The function handles possi...
evol_instruct_66k
44,090
Write a Python function to create a new list where each element is the result of multiplying the corresponding element in the input list by a given multiplication factor. The function should handle lists of integers and floating-point numbers. The code should start with: ```python from typing import List, Union def mu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def multiply_list_elements(input_list: List[Union[int, float]], factor: Union[int, float]) -> List[Union[int, float]]: """ Multiplies each element in the input list by the given factor and returns...
evol_instruct_66k
44,100
Write a Python function to determine the prime factors of a given number using a recursive approach with dynamic programming. The function should store intermediate results to avoid redundant calculations, thereby optimizing the performance. The code should start with: ```python from typing import List def prime_fact...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def prime_factors_recursive_dp(n: int, memo: dict = {}) -> List[int]: """ Determine the prime factors of a given number using a recursive approach with dynamic programming. Args: n (int): Th...
evol_instruct_66k
44,102
Write a Python function to generate an array of numbers ranging from a given start value to a given end value, with a specified step increment. The function should handle cases where the start value is greater than the end value and the step is negative. The function should also ensure that the generated array does not...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_array(start: int, end: int, step: int) -> List[int]: """ Generate an array of numbers ranging from start to end (inclusive) with a specified step. Args: start (int): The startin...
evol_instruct_66k
44,116
Write a Python function to calculate the average speed of a car given the distance traveled and the time taken. The function should return the average speed in the correct unit of measurement. The code should start with: ```python def calculate_average_speed(distance: float, time: float) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_average_speed(distance: float, time: float) -> str: """ Calculate the average speed of a car given the distance traveled and the time taken. Args: distance (float): The distance traveled by the car in ...
evol_instruct_66k
44,117
Write a Python function to convert a given temperature from Celsius to Fahrenheit. The function should handle invalid input gracefully by providing appropriate feedback to the user. Additionally, debug the provided faulty code that attempts to convert Celsius to Fahrenheit but contains logical errors. The function shou...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_fahrenheit(celsius: str) -> str: """ Converts a given temperature from Celsius to Fahrenheit. Args: celsius (str): The temperature in Celsius as a string. Returns: str: The temperature in...
evol_instruct_66k
44,127
Write a Python function to find the last non-zero digit in the factorial of a given number `n`. The function should efficiently handle large factorials by removing trailing zeros and limiting the size of the factorial to prevent overflow. The code should start with: ```python def last_non_zero_digit_in_factorial(n: int...
Here is the Python code to solve the given problem in the markdown block: ```python def last_non_zero_digit_in_factorial(n: int) -> int: """ Calculate the last non-zero digit in the factorial of a given number n. Args: n (int): The number for which to calculate the factorial. Returns: ...
evol_instruct_66k
44,136
Write a Python function to count the frequency of each letter in a given string and return the result as a dictionary. The keys of the dictionary should be the distinct alphabets present in the input string, and the corresponding values should represent the respective frequency of each letter. The function should ignor...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def letter_frequency(s: str) -> Dict[str, int]: """ Counts the frequency of each letter in the given string and returns the result as a dictionary. Args: s (str): The input string to analyze...
evol_instruct_66k
44,147
Write a Python function to convert a given list into a dictionary where the keys are the index positions of the elements in the list, and the values are the elements themselves. The function should handle lists of any length and ensure that the dictionary is correctly structured. 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, Dict def list_to_dict(arr: List[int]) -> Dict[int, int]: """ Converts a given list into a dictionary where the keys are the index positions of the elements in the list, and the values are the elemen...
evol_instruct_66k
44,148
Write a Python function to transpose a given square matrix in-place. The function should not allocate additional memory for the result. The matrix is guaranteed to be a square matrix (m == n). The code should start with: ```python from typing import List def transpose_matrix(matrix: List[List[int]]) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def transpose_matrix(matrix: List[List[int]]) -> None: """ Transposes a given square matrix in-place. Args: matrix (List[List[int]]): The square matrix to be transposed. Returns: ...
evol_instruct_66k
44,166
Write a Python function to calculate the sum of all elements in a given n x m 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, not just 3x3. The code should start with: ```python from typing import List def mat...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def matrix_sum(matrix: List[List[int]]) -> int: """ Calculate the sum of all elements in a given n x m matrix. Args: matrix (List[List[int]]): A list of lists representing the matrix. R...
evol_instruct_66k
44,168
Write a Python function to convert a given string to upper case without using built-in functions or string methods. Additionally, preserve the occurrence of any numeric characters in the input string. The function should start with: ```python def convert_to_upper_case(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_upper_case(s: str) -> str: """ Converts a given string to upper case without using built-in functions or string methods. Numeric characters in the input string are preserved. Args: s (str): The in...
evol_instruct_66k
44,179
Write a Python function to perform a circular rotation of numbers in a 3D matrix. The rotation should move the last 2D slice of the matrix to the front, and all other 2D slices should move one position backward. The function should take a 3D list (list of lists of lists) as input and return the rotated 3D list. The co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def circular_rotate_3d_matrix(matrix: List[List[List[int]]]) -> List[List[List[int]]]: """ Perform a circular rotation on a 3D matrix. The rotation moves the last 2D slice to the front, and all other...
evol_instruct_66k
44,180
Write a Python function to determine the length of the longest contiguous subset of identical characters within a given text string. The function should return the length of this subset. The code should start with: ```python def longest_contiguous_subset_length(input_string: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def longest_contiguous_subset_length(input_string: str) -> int: """ Determine the length of the longest contiguous subset of identical characters within the provided text string. Args: input_string (str): The input ...
evol_instruct_66k
44,200
Write a Python function to identify the least recurrent character in a given sentence. The function should ignore spaces and return the character that appears the fewest times in the sentence. If there are multiple characters with the same minimum frequency, return the first one encountered in the sentence. The code s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Optional from collections import Counter def least_recurrent_character(sentence: str) -> Optional[str]: """ Identify the least recurrent character in a given sentence, ignoring spaces. Args: sent...
evol_instruct_66k
44,205
Write a Python function to append a new element to the end of a given list of integers. The function should handle cases where the list is empty and ensure that the new element is added correctly. The code should start with: ```python from typing import List def append_to_list(items: List[int], new_item: int) -> List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def append_to_list(items: List[int], new_item: int) -> List[int]: """ Appends a new integer element to the end of a given list of integers. Args: items (List[int]): The list of integers to w...
evol_instruct_66k
44,208
Write a Python function to remove all blank spaces from a given string, transforming it into a continuous unbroken chain of alphanumeric characters. The function should handle strings with multiple spaces, leading spaces, trailing spaces, and spaces within the string. The code should start with: ```python def remove_s...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_spaces(input_string: str) -> str: """ Removes all blank spaces from the given string, transforming it into a continuous unbroken chain of alphanumeric characters. Args: input_string (str): The input strin...
evol_instruct_66k
44,213
Write a Python function to replace each letter in a given string with its immediate successor in the English alphabet. Non-alphabetic characters should remain unchanged. The function should handle both uppercase and lowercase letters, wrapping around from 'z' to 'a' and from 'Z' to 'A'. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python def replace_with_successor(string: str) -> str: """ Replace each letter in the given string with its immediate successor in the English alphabet. Non-alphabetic characters remain unchanged. Args: string (str): T...
evol_instruct_66k
44,231
Write a Python function to substitute each occurrence of the alphabetical figure '0' with the symbol 'x' in a given bi-dimensional lattice (2D list) of alphanumerical constituents. The function should modify the input array in place and return the modified array. The code should start with: ```python from typing impor...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def substitute_zeros(array: List[List[str]]) -> List[List[str]]: """ Substitutes each occurrence of the alphabetical figure '0' with the symbol 'x' in a given bi-dimensional lattice (2D list) of alphanum...
evol_instruct_66k
44,232
Write a Python function to generate a CSS text-decoration line style for an `h2` element. The function should create a segmented line under the text with specified colors and lengths. The segments should be defined by a list of tuples, where each tuple contains a color and a length in pixels. The function should return...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def generate_text_decoration(segments: List[Tuple[str, int]]) -> str: """ Generates a CSS text-decoration line style for an h2 element based on the given segments. Args: segments (Lis...
evol_instruct_66k
44,233
Write a Python function to parse a given URL and return the path, query parameters, and fragment identifier. The function should handle special characters and correctly decode the URL components. The code should start with: ```python from typing import Dict, Tuple from urllib.parse import urlparse, parse_qs, unquote d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Tuple from urllib.parse import urlparse, parse_qs, unquote def parse_url(url: str) -> Tuple[str, Dict[str, str], str]: """ Parses a given URL and returns the path, query parameters, and fragment identif...
evol_instruct_66k
44,272
Write a Python function to find the prime factors of a given positive integer using the fundamental theorem of arithmetic. The function should return a list of prime factors in ascending order. The code should start with: ```python from typing import List def prime_factors(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def prime_factors(n: int) -> List[int]: """ Returns the prime factors of a given positive integer in ascending order. Args: n (int): The positive integer to factorize. Returns: ...
evol_instruct_66k
44,275
Write a Python function to calculate the square root of a given number without using any predefined mathematical functions. The function should use the **Newton-Raphson method** to approximate the square root with a specified precision. The code should start with: ```python def find_square_root(number: float, precision...
Here is the Python code to solve the given problem in the markdown block: ```python def find_square_root(number: float, precision: float = 0.00001) -> float: """ Calculate the square root of a given number using the Newton-Raphson method. Args: number (float): The number for which to find the squar...
evol_instruct_66k
44,295
Write a Python function to encode a given input string using the ROT13 substitution cipher method. The ROT13 cipher shifts each letter in the alphabet by 13 positions, wrapping around if necessary. Non-alphabet characters should remain unchanged. The code should start with: ```python def rot13_encode(input_string: str)...
Here is the Python code to solve the given problem in the markdown block: ```python def rot13_encode(input_string: str) -> str: """ Encodes the given input string using the ROT13 substitution cipher method. Args: input_string (str): The string to be encoded. Returns: str: The encoded s...
evol_instruct_66k
44,317
Write a Python function to count the number of unique linguistic elements (words) in a given sentence. The function should handle sentences with varying punctuation and case sensitivity. The code should start with: ```python from typing import List def count_unique_words(sentence: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List import string def count_unique_words(sentence: str) -> int: """ Count the number of unique words in a given sentence, ignoring case and punctuation. Args: sentence (str): The sentence from...