source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_evol_110k
73,328
Write a Python function to create a dictionary that maps each number in a given list to its square. The function should take a list of integers as input and return a dictionary where each key is an integer from the list and the corresponding value is the square of that integer. The code should start with: ```python fr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def create_square_dict(numbers: List[int]) -> Dict[int, int]: """ Creates a dictionary where each key is an integer from the input list and the corresponding value is the square of that integer. ...
magic_evol_110k
73,329
Write a Python function to evaluate a given mathematical expression string and return the result. The expression string will contain only non-negative integers and the following operators: `+`, `-`, `*`, `/`, `**` (exponentiation), and parentheses `()`. The function should handle basic arithmetic operations and respect...
Here is the Python code to solve the given problem in the markdown block: ```python def evaluate_expression(expression: str) -> float: """ Evaluates a given mathematical expression string and returns the result. Args: expression (str): A string containing a mathematical expression with non-negative...
magic_evol_110k
73,338
Write a Python function to find the kth largest element in a given list of integers efficiently. The function should handle edge cases such as an empty list or a k value that exceeds the length of the list. The code should start with: ```python from typing import List def find_kth_largest(arr: List[int], k: int) -> in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import heapq def find_kth_largest(arr: List[int], k: int) -> int: """ Find the kth largest element in a given list of integers. Args: arr (List[int]): The list of integers from which to find...
magic_evol_110k
73,345
Write a Python function to sort an array of integers using the Merge Sort algorithm. The function should recursively divide the array into halves until each subarray contains one or zero elements, and then merge the sorted subarrays back together. The code should start with: ```python from typing import List def merge...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers using the Merge Sort algorithm. Args: arr (List[int]): The array of integers to be sorted. Returns: L...
magic_evol_110k
73,358
Write a Python function to generate a sequence of 20 unique prime numbers within the range of 100 to 200. The function should ensure that each number in the sequence is a prime number and falls within the specified range. The code should start with: ```python from typing import List def generate_prime_sequence(lower_b...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if n <...
magic_evol_110k
73,359
Write a Python function to print even numbers from 0 to a given limit (inclusive) using a loop and conditional statements. The function should use a loop to iterate through the numbers and a conditional statement to check if the number exceeds the limit. The function should also be able to be converted to a do-while lo...
Here is the Python code to solve the given problem in the markdown block: ```python def print_even_numbers(limit: int) -> None: """ Prints even numbers from 0 to the given limit (inclusive). Args: limit (int): The upper limit for the even numbers to be printed. Returns: None """ ...
magic_evol_110k
73,364
Write a Python function to iteratively calculate the factorial of each element in a given numerical sequence represented as a Python list and return the last calculated factorial. The factorial of a non-negative integer `n` is the product of all positive integers less than or equal to `n`. The function should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_last_factorial(sequence: List[int]) -> int: """ Iteratively calculates the factorial of each element in the given sequence and returns the last calculated factorial. Args: sequ...
magic_evol_110k
73,367
Write a Python function to segment a provided textual string into its individual character components. The function should return a list of characters, including spaces and punctuation marks. The code should start with: ```python from typing import List def segment_string(sentence: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def segment_string(sentence: str) -> List[str]: """ Segments a provided textual string into its individual character components. Args: sentence (str): The input string to be segmented. ...
magic_evol_110k
73,368
Write a Python function to determine if a given number `y` surpasses another number `x` and if a third number `z` is not equal to `y`. If both conditions are met, the function should return the result of `y` raised to the power of `z`. Otherwise, it should return `None`. The code should start with: ```python def check...
Here is the Python code to solve the given problem in the markdown block: ```python def check_conditions_and_compute(x: int, y: int, z: int) -> int: """ Check if y surpasses x and if z is not equal to y. If both conditions are met, return the result of y raised to the power of z. Otherwise, return None. ...
magic_evol_110k
73,369
Write a Python function to swap the keys and values of a given dictionary. The function should return a new dictionary with the keys and values swapped. If the original dictionary contains duplicate values, the function should handle this by ensuring that the new dictionary only contains unique keys. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def swap_keys_and_values(dictionary: Dict[int, str]) -> Dict[str, int]: """ Swaps the keys and values of a given dictionary. Args: dictionary (Dict[int, str]): The original dictionary with i...
magic_evol_110k
73,377
Write a Python function to determine if a given string is a palindrome, considering only alphanumeric characters and ignoring case. The function should return `True` if the string is a palindrome and `False` otherwise. An empty string should be considered a palindrome. The code should start with: ```python def is_pali...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(s: str) -> bool: """ Determine if a given string is a palindrome, considering only alphanumeric characters and ignoring case. Args: s (str): The input string to check. Returns: bool: T...
magic_evol_110k
73,379
Write a Python function to simulate a file upload service that accepts a file and returns a confirmation message. The function should validate the file type and size before processing it. If the file type is not allowed or the file size exceeds the limit, the function should return an appropriate error message. The fun...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Union def file_upload_service(file: Dict[str, Union[str, int]]) -> str: """ Simulates a file upload service that validates the file type and size before processing it. Args: file (dict): A ...
magic_evol_110k
73,387
Write a Python function to mimic the behavior of the JavaScript `map()` function with the additional challenge of handling errors elegantly. The function should take a list as input, perform a calculation on each item (adding 3 to each item), and return a new list of successfully processed items. If an item throws a `T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def map_with_error_handling(input_list: List[any]) -> Tuple[List[int], List[any]]: """ Mimics the behavior of the JavaScript map() function with error handling. This function takes a list as ...
magic_evol_110k
73,391
Write a Python function to validate an email address using a regular expression pattern that adheres to formal email standards. The function should accurately verify the validity of the email address, including multi-level domains and special characters criteria. The function should return `True` if the email is valid ...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_email(email: str) -> bool: """ Validates an email address using a regular expression pattern that adheres to formal email standards. Args: email (str): The email address to validate. Ret...
magic_evol_110k
73,398
Write a Python function to simplify a given fraction to its lowest terms and return the result as a tuple containing the numerator and the denominator. The function should handle both positive and negative fractions. The code should start with: ```python from typing import Tuple def simplify_fraction(numerator: int, ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple from fractions import Fraction def simplify_fraction(numerator: int, denominator: int) -> Tuple[int, int]: """ Simplifies a given fraction to its lowest terms and returns the result as a tuple (numerato...
magic_evol_110k
73,405
Write a Python function to generate an Elasticsearch query that searches for all entries in a database where the "location" attribute has the exact value "Los Angeles". The function should return a dictionary representing the Elasticsearch query. The code should start with: ```python def generate_elasticsearch_query()...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_elasticsearch_query() -> dict: """ Generates an Elasticsearch query to search for all entries where the "location" attribute is exactly "Los Angeles". Returns: dict: A dictionary representing the Elasti...
magic_evol_110k
73,410
Write a Python function that accepts a list of integers, including negative and positive values, as well as decimal numbers. The function should return the highest positive integer after handling possible errors or irregularities such as non-integer inputs in the list. The function should also handle decimal numbers by...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def highest_positive_integer(arr: List[Union[int, float, str]]) -> int: """ Find the highest positive integer from a list of integers, floats, and strings. Non-integer inputs and decimal numbe...
magic_evol_110k
73,419
Write a Python function to calculate the total cumulative rainfall for a given list of monthly rainfall measurements, rounded to the nearest whole number. The function should accept a list of floating-point numbers representing the rainfall measurements for each month and return the total cumulative rainfall rounded to...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_total_rainfall(rainfall_measures: List[float]) -> int: """ Calculate the total cumulative rainfall from a list of monthly rainfall measurements, rounded to the nearest whole number. ...
magic_evol_110k
73,424
Write a Python function that generates a lambda function from a given string and applies it to a list of integers. The generated lambda function should be based on the string input, which specifies a condition for filtering the list. The function should return the filtered list. The code 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 filter_list_by_condition(condition: str, lst: List[int]) -> List[int]: """ Filters a list of integers based on a condition specified by a string. Args: condition (str): A string represen...
magic_evol_110k
73,430
Write a Python function to retrieve and display the HTTP header information for a given URL. The function should handle the HTTP request, retrieve the headers, and print them in a formatted manner. The code should start with: ```python import requests def display_http_headers(url: str) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python import requests def display_http_headers(url: str) -> None: """ Retrieves and displays the HTTP header information for a given URL. Args: url (str): The URL for which to retrieve the HTTP headers. Returns: ...
magic_evol_110k
73,439
Write a Python function to find the maximum value in a given list of numbers without using the built-in `max()` function. The function should iterate through the list and keep track of the maximum value encountered. The code should start with: ```python from typing import List def find_max_value(num_list: List[int]) ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_value(num_list: List[int]) -> int: """ Find the maximum value in a given list of numbers without using the built-in max() function. Args: num_list (List[int]): A list of integer...
magic_evol_110k
73,443
Write a Python function to create a detailed dictionary structure for a scholar, including nominal data, years alive, academic scores, and the anticipated year of leaving academia. The function should handle cases where some information is unknown by setting the corresponding values to `None`. The function should also ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def create_scholar_profile( first_name: str, last_name: str, birth_year: int, death_year: Optional[int], academic_scores: List[int], year_leaving_academia: Optional[int] ) -> di...
magic_evol_110k
73,445
Write a Python function to determine whether a provided input belongs to the boolean category. If the input does not belong to the boolean category, further investigate if it is a list. The function should return a string indicating the category of the input: "boolean", "list", or "other". The code should start with: ...
Here is the Python code to solve the given problem in the markdown block: ```python def verify_input(input_data): """ Determine the category of the provided input data. Args: input_data: The input data to be categorized. Returns: str: A string indicating the category of the input data:...
magic_evol_110k
73,463
Write a Python function that performs multiple logical and computational steps to reverse and concatenate integers, maintaining certain conditions. Your function should take in two lists of equal length as inputs, where each list contains integer values. The function should perform the following steps: 1. Compare the ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_concatenate_max(l1: List[int], l2: List[int]) -> str: """ Performs multiple logical and computational steps to reverse and concatenate integers. Args: l1 (List[int]): The first l...
magic_evol_110k
73,464
Write a Python function to flip a given 2D numpy array diagonally from the top-left to the bottom-right. The function should take a 2D numpy array as input and return the flipped array. The code should start with: ```python import numpy as np def flip_array_diagonally(arr: np.ndarray) -> np.ndarray: ```
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def flip_array_diagonally(arr: np.ndarray) -> np.ndarray: """ Flips a given 2D numpy array diagonally from the top-left to the bottom-right. Args: arr (np.ndarray): A 2D numpy array to be flipped...
magic_evol_110k
73,475
Write a Python function to evaluate a given expression in postfix notation. The expression will be represented as a string containing integers and operators (`+`, `-`, `*`, `/`, `^`), where `^` denotes exponentiation. The function should return the computed result of the expression. The expression is assumed to be vali...
Here is the Python code to solve the given problem in the markdown block: ```python def evaluate_postfix(expression: str) -> float: """ Evaluates a given expression in postfix notation and returns the computed result. Args: expression (str): A string representing the postfix expression to be evalua...
magic_evol_110k
73,476
Write a Python function to determine the maximum and minimum of two given integers. The function should return a tuple containing the maximum value followed by the minimum value. The code should start with: ```python def find_max_min(num1: int, num2: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def find_max_min(num1: int, num2: int) -> tuple: """ Determine the maximum and minimum of two given integers. Args: num1 (int): The first integer. num2 (int): The second integer. Returns: tuple:...
magic_evol_110k
73,487
Write a Python function to process a two-dimensional list of integers and check for specific conditions using nested if statements within a loop structure. If a number is divisible by both 3 and 5, log a message. Implement error handling to catch any exceptions that occur during the process. 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 process_two_dim_list(two_dim_list: List[List[int]]) -> None: """ Process a two-dimensional list of integers and check for specific conditions. If a number is divisible by both 3 and 5, log a mess...
magic_evol_110k
73,502
Write a Python function to calculate the new average score after adding an additional score to a list of original scores. The function should take two parameters: a list of original scores and an additional score. The function should return the new average score after including the additional score. The code should st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_new_average(original_scores: List[int], additional_score: int) -> float: """ Calculate the new average score after adding an additional score to a list of original scores. Args: ...
magic_evol_110k
73,503
Write a Python function to find and return the three smallest elements from a given list of integers. The function should handle cases where the list has fewer than three elements by returning as many smallest elements as possible. The function should also handle cases where the list is empty by returning an empty list...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_three_smallest(arr: List[int]) -> List[int]: """ Finds and returns the three smallest elements from a given list of integers. Args: arr (List[int]): The list of integers from which ...
magic_evol_110k
73,507
Write a Python function to convert an angle measurement from gradians to degrees. The function should take a single argument representing the angle in gradians and return the equivalent angle in degrees. The conversion factor from gradians to degrees is 180/200. The code should start with: ```python def convert_gradia...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_gradians_to_degrees(gradians: float) -> float: """ Converts an angle measurement from gradians to degrees. Args: gradians (float): The angle measurement in gradians. Returns: float: The equi...
magic_evol_110k
73,513
Write a Python function to calculate the sum of all odd integers from 1 up to a given positive integer `n` inclusively. The function should use a for loop and conditionals to determine which numbers are odd and then aggregate them. The code should start with: ```python def sum_of_odd_integers(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_odd_integers(n: int) -> int: """ Calculate the sum of all odd integers from 1 up to a given positive integer `n` inclusively. Args: n (int): The upper limit of the range (inclusive) for which to calculate...
magic_evol_110k
73,514
Write a Python function to find the least frequently occurring element in a given list, which is considered the 'rarest' element. If there are multiple elements with the same minimum frequency, return the smallest element among them. The function should handle lists with both positive and negative integers. The code s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import Counter def find_rarest_element(elements: List[int]) -> int: """ Find the least frequently occurring element in the given list. If there are multiple elements with the same mi...
magic_evol_110k
73,516
Write a Python function to determine the minimum number of pigs required to identify the poisonous bucket within the given time frame. The function should take three parameters: `buckets`, `minutesToDie`, and `minutesToTest`. The function should return the minimum number of pigs needed to identify the poisonous bucket....
Here is the Python code to solve the given problem in the markdown block: ```python import math def min_pigs_to_identify_poison(buckets: int, minutesToDie: int, minutesToTest: int) -> int: """ Calculate the minimum number of pigs required to identify the poisonous bucket within the given time frame. Args:...
magic_evol_110k
73,532
Write a Python function to find the three smallest elements in a given list of integers efficiently. The function should handle cases where the list has fewer than three elements by returning all available elements in ascending order. The code should start with: ```python from typing import List def find_three_smalles...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List import heapq def find_three_smallest(B: List[int]) -> List[int]: """ Finds the three smallest elements in the given list of integers. Args: B (List[int]): The list of integers from which t...
magic_evol_110k
73,539
Write a Python function to generate two arrays: one containing the numbers between 1 and 1000 that are divisible by both 5 and 7, and another containing the numbers that are divisible by 5 or 7 individually. Implement this without using built-in functions for array manipulation or filtering. Also, calculate the sum of ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, List def generate_divisible_arrays() -> Tuple[List[int], List[int], int, int]: """ Generate two arrays: one containing the numbers between 1 and 1000 that are divisible by both 5 and 7, and another...
magic_evol_110k
73,540
Write a Python function to construct a comprehensive HTTPS internet network location, including a precise subdomain and a domain, up to and including a detailed web path. The function should take four parameters: the protocol (defaulting to "https://"), the subdomain, the domain, and the path. The function should retur...
Here is the Python code to solve the given problem in the markdown block: ```python def construct_url(subdomain: str, domain: str, path: str, protocol: str = "https://") -> str: """ Constructs a comprehensive HTTPS internet network location. Args: subdomain (str): The subdomain of the URL. ...
magic_evol_110k
73,548
Write a Python function to calculate the number of ways to climb a staircase with `n` steps, where a person can take either 1 or 2 steps at a time. The function should use dynamic programming to efficiently compute the result. The code should start with: ```python def climb_stairs(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def climb_stairs(n: int) -> int: """ Calculate the number of ways to climb a staircase with n steps, where a person can take either 1 or 2 steps at a time. Args: n (int): The number of steps in the staircase. R...
magic_evol_110k
73,556
Write a Python function to replace all instances of the character '0' with the character 'x' in a given two-dimensional grid of alphanumeric entities. The grid is represented as a list of lists, where each inner list represents a row in the grid. The function should modify the grid in place and return the modified grid...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def replace_zeros_with_x(grid: List[List[str]]) -> List[List[str]]: """ Replace all instances of the character '0' with the character 'x' in a given two-dimensional grid. Args: grid (List[Li...
magic_evol_110k
73,557
Write a Python function to determine if a given string `s` is a subsequence of another string `t`. A subsequence is a string derived from the original string by selectively removing some characters (possibly none), while maintaining the relative order of the remaining characters. The function should be efficient and ha...
Here is the Python code to solve the given problem in the markdown block: ```python def is_subsequence(s: str, t: str) -> bool: """ Determines if the string `s` is a subsequence of the string `t`. Args: s (str): The subsequence candidate. t (str): The string to check against. Returns: ...
magic_evol_110k
73,564
Write a Python function to count the occurrence of each alphabet character in a list of lexemes, ignoring case differences and excluding non-alphabetic symbols and numerals. The function should handle the provided faulty code by correcting the logic to ensure accurate counting. The code should start with: ```python fr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_alphabets(lexemes: List[str]) -> Dict[str, int]: """ Count the occurrence of each alphabet character in a list of lexemes, ignoring case differences and excluding non-alphabetic symbols a...
magic_evol_110k
73,565
Write a Python function to extract all unique values from a given nested dictionary, considering values that are lists or other dictionary types. If a value is a list, the function should return a tuple of unique values from this list. If a value is another dictionary, it should return a tuple of unique values from thi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any, Tuple def get_unique_values(input_dict: Dict[str, Any]) -> Tuple[Any, ...]: """ Extracts all unique values from a given nested dictionary, considering values that are lists or other dictionary type...
magic_evol_110k
73,572
Write a Python function to safely access an element in a list by providing a default value if the index is out of range. The function should take a list, an index, and a default value as parameters. If the index is within the bounds of the list, the function should return the element at that index. Otherwise, it should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, List def safe_list_access(lst: List[Any], index: int, default: Any) -> Any: """ Safely access an element in a list by providing a default value if the index is out of range. Args: lst (List[...
magic_evol_110k
73,583
Write a Python function to calculate the total cost of purchasing a specified number of items, each priced at a given amount, while also breaking down the cost into the tens and units place. The function should return the total cost, the cost contributed by the tens place, and the cost contributed by the units place. ...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_total_cost(price: int, num_items: int) -> tuple: """ Calculate the total cost of purchasing a specified number of items, each priced at a given amount, while also breaking down the cost into the tens and units ...
magic_evol_110k
73,592
Write a Python function to debug and correct the given code snippet. The function should calculate a "strange sum" based on the following criteria: 1. Filter the list `y` to include only elements that are greater than or equal to `x`. 2. Calculate the average of these filtered elements. 3. Compute the "strange sum" as ...
Here is the Python code to solve the given problem in the markdown block: ```python def strange_sum(x: int, y: list) -> int: """ Calculate a "strange sum" based on the given criteria. Args: x (int): The threshold value to filter the list. y (list): The list of integers to process. Retu...
magic_evol_110k
73,593
Write a Python function to determine if an object (dictionary) in a list of objects has a specific property (key) and count the occurrences of that property in the list. Additionally, the function should return a list of objects containing the specific property. The code should start with: ```python from typing import...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def find_property_in_objects(array_of_obj: List[Dict[str, Any]], property_name: str) -> Dict[str, Any]: """ Determines if an object in a list of objects has a specific property and counts the ...
magic_evol_110k
73,598
Write a Python function to display elements within a specific numerical array in a formatted manner. The function should take a list of integers as input and print each element followed by a newline character. The function should also handle cases where the input list is empty or contains non-integer elements. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def display_elements(arr: List[int]) -> None: """ Displays each element of the given list of integers followed by a newline character. Args: arr (List[int]): The list of integers to be displ...
magic_evol_110k
73,616
Write a Python function to construct a dictionary from two tuples of equal length, where the first tuple contains keys and the second tuple contains corresponding values. The function should ensure that the tuples are of equal length before constructing the dictionary. If the tuples are not of equal length, the functio...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Dict def construct_dictionary(tuple1: Tuple[str], tuple2: Tuple[str]) -> Dict[str, str]: """ Constructs a dictionary from two tuples of equal length. Args: tuple1 (Tuple[str]): A tuple con...
magic_evol_110k
73,628
Write a Python function to generate a rolling list of the greatest integers from two distinct input lists, comparing sequential elements up to the given moment. The function should compare elements from both lists at each step and keep track of the maximum value encountered so far. The function should handle lists of d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from itertools import zip_longest def rolling_max(numbers1: List[int], numbers2: List[int]) -> List[int]: """ Generate a rolling list of the greatest integers from two distinct input lists. Args: ...
magic_evol_110k
73,632
Write a Python function to determine the lowest prime number in a given list of integers. If there are no prime numbers in the list, the function should return `None`. The code should start with: ```python from typing import List, Optional def lowest_prime_number(numbers: List[int]) -> Optional[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def lowest_prime_number(numbers: List[int]) -> Optional[int]: """ Determine the lowest prime number in a given list of integers. Args: numbers (List[int]): A list of integers from ...
magic_evol_110k
73,645
Write a Python function to determine if the first array contains at least one element from the second array. The function should return `True` if there is at least one common element, and `False` otherwise. The code should start with: ```python from typing import List def contains_common_element(array1: List[int], arr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def contains_common_element(array1: List[int], array2: List[int]) -> bool: """ Determines if the first array contains at least one element from the second array. Args: array1 (List[int]): Th...
magic_evol_110k
73,646
Write a Python function to find the product of all numerical values in a nested list. The list may contain other lists as elements, and those lists may also contain lists as elements, and so on. The function should be able to handle this nesting and return the product of all numerical values. The function should ignore...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def product_of_nested_list(nested_list: List[Union[int, float, List]]) -> Union[int, float]: """ Calculate the product of all numerical values in a nested list. Args: nested_list (Lis...
magic_evol_110k
73,664
Write a Python function to convert a given integer to its English name. The function should handle integers from 0 to 999,999,999,999 (one trillion minus one). The function should return the English name as a string. The code should start with: ```python def int_to_english(n: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def int_to_english(n: int) -> str: """ Convert an integer to its English name. Args: n (int): The integer to convert, must be between 0 and 999,999,999,999 (inclusive). Returns: str: The English name of...
magic_evol_110k
73,675
Write a Python function to concatenate a list of textual elements into a single string with a custom delimiter between each element. The function should handle cases where the list is empty or contains only one element. The code should start with: ```python from typing import List def concatenate_with_delimiter(elemen...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def concatenate_with_delimiter(elements: List[str], delimiter: str) -> str: """ Concatenates a list of textual elements into a single string with a custom delimiter between each element. Args: ...
magic_evol_110k
73,682
Write a Python function that implements the Binary Search algorithm to find the index of a target element in a sorted array. The function should return the index of the target element if it exists in the array, otherwise it should return -1. The function should handle edge cases such as an empty array or a target eleme...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search(arr: List[int], x: int) -> int: """ Perform a binary search to find the index of the target element in a sorted array. Args: arr (List[int]): A sorted list of integers. ...
magic_evol_110k
73,697
Write a Python function to simulate the growth of a plant based on varying environmental conditions such as temperature and rainfall. The function should take the initial characteristics of the plant (type, lifespan, native environment) and the environmental conditions (temperature, rainfall) as inputs. The function sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Union def simulate_plant_growth(plant_info: Dict[str, Union[str, int]], temperature: int, rainfall: int) -> str: """ Simulate the growth of a plant based on environmental conditions. Args: ...
magic_evol_110k
73,703
Write a Python function to compute the element-wise product of two given matrices. The function should take two matrices as input and return a new matrix where each element is the product of the corresponding elements from the input matrices. The code should start with: ```python from typing import List def element_wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def element_wise_product(A: List[List[int]], B: List[List[int]]) -> List[List[int]]: """ Compute the element-wise product of two matrices. Args: A (List[List[int]]): The first matrix. ...
magic_evol_110k
73,708
Write a Python function to insert an element at the initial position of a given tuple. Since tuples are immutable, the function should create a new tuple with the inserted element. The function should be efficient in terms of both time and space complexity. The code should start with: ```python from typing import Tupl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def insert_at_initial_position(original_tuple: Tuple[int], element: int) -> Tuple[int]: """ Inserts an element at the initial position of a given tuple and returns the new tuple. Args: orig...
magic_evol_110k
73,710
Write a Python function to filter out items from a list of dictionaries where the 'cost' value is greater than or equal to a given threshold. The function should return a new list containing only the items that do not meet this condition. The code should start with: ```python from typing import List, Dict def filter_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def filter_items_by_cost(inventory: List[Dict[str, any]], threshold: int) -> List[Dict[str, any]]: """ Filters out items from the inventory where the 'cost' value is greater than or equal to the gi...
magic_evol_110k
73,717
Write a Python function to find the most competitive subsequence of a given integer array `nums` of size `k`. The most competitive subsequence is defined as the subsequence that is the smallest possible lexicographical order among all possible subsequences of the same length. 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 most_competitive_subsequence(nums: List[int], k: int) -> List[int]: """ Find the most competitive subsequence of a given integer array `nums` of size `k`. Args: nums (List[int]): The inp...
magic_evol_110k
73,718
Write a Python function that generates a sequence of alternating even and odd integers from 1 to 100 using multithreading. The sequence should start with an odd integer and ensure that the sequence alternates correctly between even and odd numbers. The function should be optimized for performance and thread safety, and...
Here is the Python code to solve the given problem in the markdown block: ```python import threading def generate_alternating_sequence(): """ Generates a sequence of alternating even and odd integers from 1 to 100 using multithreading. The sequence starts with an odd integer and ensures correct alternation...
magic_evol_110k
73,729
Write a Python function to increment a specified element of a numerical array by a given value. The function should include error checking for invalid inputs such as non-existent indices or non-numerical increment values. The function should return the modified array if the operation is successful, or an error message ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def increment_array_element(arr: List[Union[int, float]], index: int, increment_value: Union[int, float]) -> Union[List[Union[int, float]], str]: """ Increments the element at the specified index ...
magic_evol_110k
73,738
Write a Python function that takes in three arguments: `x`, `y`, and `num`. The function should use a ternary operator (conditional expression) to determine the result based on the comparison of `x` and `y`. If `x` is greater than `y`, the function should return the sum of `x` and `num`. If `y` is greater than or equal...
Here is the Python code to solve the given problem in the markdown block: ```python def arithmetic_operation(x: int, y: int, num: int) -> int: """ Perform a conditional arithmetic operation based on the comparison of x and y. Args: x (int): The first integer to compare. y (int): The second ...
magic_evol_110k
73,743
Write a Python function to convert a given tuple of strings into a list and then extract the second element from the list. The function should handle the conversion and extraction in a single step. The code should start with: ```python from typing import Tuple, List def extract_second_element(animals: Tuple[str, ...])...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, List def extract_second_element(animals: Tuple[str, ...]) -> str: """ Converts a tuple of strings into a list and extracts the second element. Args: animals (Tuple[str, ...]): A tuple of s...
magic_evol_110k
73,745
Write a Python function to reduce a given 3-dimensional NumPy array into a 2-dimensional matrix. The function should take a 3-dimensional array and a target shape for the resulting 2-dimensional array as input. The target shape must be compatible with the total number of elements in the original 3-dimensional array. Th...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np from typing import Tuple def reduce_3d_to_2d(three_dim_array: np.ndarray, target_shape: Tuple[int, int]) -> np.ndarray: """ Reduces a given 3-dimensional NumPy array into a 2-dimensional matrix with the speci...
magic_evol_110k
73,776
Write a Python function to remove the first occurrence of the string "Pineapple" from each tuple in a list of tuples containing fruit names. If a tuple does not contain "Pineapple", it should remain unchanged. The function should return a new list of tuples with the modifications. The function should be case-sensitive,...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def remove_first_pineapple(fruit_tuples: List[Tuple[str]]) -> List[Tuple[str]]: """ Removes the first occurrence of the string "Pineapple" from each tuple in a list of tuples. If a tuple does ...
magic_evol_110k
73,777
Write a Python function that accepts three parameters: a text string, a delimiter, and a collection in the form of a list. The function should return a new ordered dictionary. Each key-value pair of the dictionary should be generated using the constituent elements of the given list and an incrementing integer, starting...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import OrderedDict def create_ordered_dict(text: str, delimiter: str, collection: list) -> OrderedDict: """ Creates an ordered dictionary where each key-value pair is generated using the elements of the given l...
magic_evol_110k
73,789
Write a Python function to find the shared elements between two lists and return them sorted in ascending order. The function should use set operations to find the common elements and then implement a simple Bubble Sort algorithm to sort the resulting list. The code should start with: ```python from typing import List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def shared_elements(list1: List[int], list2: List[int]) -> List[int]: """ Find the shared elements between two lists and return them sorted in ascending order. Args: list1 (List[int]): The f...
magic_evol_110k
73,805
Write a Python function to create and manipulate a multi-dimensional array using Python's standard library and commonly used packages. The function should allow creating a 2D array, accessing elements, and performing basic operations like summing all elements. 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 import numpy as np def multi_dimensional_array_operations(data: List[List[int]]) -> int: """ Create a 2D array from the input data, access elements, and return the sum of all elements. Args: ...
magic_evol_110k
73,825
Write a Python function to find the largest prime factor of a given integer. The function should efficiently determine and return the most significant prime divisor of the input number. The code should start with: ```python def largest_prime_factor(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def largest_prime_factor(n: int) -> int: """ Find the largest prime factor of a given integer. Args: n (int): The integer for which to find the largest prime factor. Returns: int: The largest prime fact...
magic_evol_110k
73,827
Write a Python function to sort a list containing both integer and string elements in ascending order. The function should handle the sorting of integers and strings separately and then combine the sorted results. The code should start with: ```python from typing import List, Union def sort_mixed_list(arr: List[Union[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def sort_mixed_list(arr: List[Union[int, str]]) -> List[Union[int, str]]: """ Sorts a list containing both integer and string elements in ascending order. Args: arr (List[Union[int, s...
magic_evol_110k
73,830
Write a Python function to find the minimum value among five distinct numerical elements. The function should accept five arguments and return the smallest number. The code should start with: ```python def find_minimum(num1: int, num2: int, num3: int, num4: int, num5: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def find_minimum(num1: int, num2: int, num3: int, num4: int, num5: int) -> int: """ Find the minimum value among five distinct numerical elements. Args: num1 (int): The first numerical element. num2 (int): T...
magic_evol_110k
73,834
Write a Python function to convert an octal number (represented as a string) to its hexadecimal representation (also represented as a string). The function should handle any valid octal input and return the corresponding hexadecimal string in uppercase. The code should start with: ```python def octal_to_hex(o: str) ->...
Here is the Python code to solve the given problem in the markdown block: ```python def octal_to_hex(o: str) -> str: """ Convert an octal input (string) to its hexadecimal representation (string). Args: o (str): The octal number to be converted, represented as a string. Returns: str: T...
magic_evol_110k
73,848
Write a Python function to transpose a given matrix using recursion. The function should validate the input to ensure it is a 2-dimensional array containing only integer values. If the input is invalid, the function should raise a `ValueError`. The function should start with: ```python from typing import List def tran...
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]]) -> List[List[int]]: """ Transposes a given matrix using recursion. Args: matrix (List[List[int]]): The matrix to be transposed. Returns: ...
magic_evol_110k
73,858
Write a Python function to safely convert a given number to a specified type, handling potential pitfalls such as loss of precision or invalid type conversions. The function should accept a number and a target type (either 'int' or 'float'), and return the converted number. If the conversion is not possible or would re...
Here is the Python code to solve the given problem in the markdown block: ```python def safe_type_conversion(number, target_type): """ Safely converts a given number to a specified type ('int' or 'float'), handling potential pitfalls. Args: number (int or float): The number to be converted. ...
magic_evol_110k
73,867
Write a Python function to perform a linear search on an unordered array to find a target value. The function should return the index of the target value if found, otherwise return -1. The code should start with: ```python from typing import List def linear_search(arr: List[int], target_value: 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_value: int) -> int: """ Perform a linear search on the given unordered array to find the target value. Args: arr (List[int]): The unordered array to ...
magic_evol_110k
73,887
Write a Python function to find and return the smallest prime number in a given list of integers. If there are no prime numbers in the list, the function should return `None`. The code should start with: ```python from typing import List, Optional def find_smallest_prime(numbers: List[int]) -> Optional[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def is_prime(num: int) -> bool: """ Check if a number is prime. Args: num (int): The number to check. Returns: bool: True if the number is prime, False otherwise. ...
magic_evol_110k
73,894
Write a Python function to perform matrix exponentiation on a given square matrix using NumPy. The function should take a square matrix and an integer exponent as inputs and return the matrix raised to the power of the exponent. The code should start with: ```python import numpy as np from typing import List def matri...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np from typing import List def matrix_exponentiation(matrix: List[List[int]], exponent: int) -> np.ndarray: """ Perform matrix exponentiation on a given square matrix. Args: matrix (List[List[int]])...
magic_evol_110k
73,901
Write a Python function to remove duplicate characters from a given string and return a new string with only unique characters. The order of characters in the new string should be the same as their first occurrence in the input string. The code should start with: ```python def remove_duplicates(input_string: str) -> s...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_duplicates(input_string: str) -> str: """ Removes duplicate characters from the input string and returns a new string with only unique characters. The order of characters in the new string is the same as their fir...
magic_evol_110k
73,903
Write a Python function to generate a greeting message that includes a user's name and age. The function should ensure that the `user_name` is of type `str` and the `user_age` is of type `int`. The function should return a string formatted as "Hello, my name is [user_name] and I am [user_age] years old." The function s...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_greeting(user_name: str, user_age: int) -> str: """ Generates a greeting message that includes the user's name and age. Args: user_name (str): The name of the user. user_age (int): The age of th...
magic_evol_110k
73,905
Write a Python function to compute the Euclidean distance between two points in a two-dimensional Euclidean space. The function should take two lists as input, each containing the x and y coordinates of a point. The function should return the Euclidean distance between these two points. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def euclidean_distance(point1: List[float], point2: List[float]) -> float: """ Computes the Euclidean distance between two points in a two-dimensional Euclidean space. Args: poin...
magic_evol_110k
73,908
Write a Python function that accepts a list of strings as input, removes strings without vowels or containing special characters, and returns the sorted list based on the following criteria: - The list will solely have strings, not arrays. - Duplicates are permitted. - Rank the items by the word length in ascending man...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def custom_string_list(lst: List[str], reverse: bool = False) -> List[str]: """ Filters a list of strings to remove those without vowels or containing special characters, and sorts the remaining stri...
magic_evol_110k
73,917
Write a Python function to calculate the power of a given base raised to a given exponent using an iterative approach. The function should handle both positive and negative exponents. The code should start with: ```python def power(base: int, exponent: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def power(base: int, exponent: int) -> int: """ Calculate the power of a given base raised to a given exponent using an iterative approach. Args: base (int): The base number. exponent (int): The exponent to ...
magic_evol_110k
73,933
Write a Python function to fuse two sets of integers together, ensuring that the resulting set does not contain any recurring entities. The function should return the fused set. The code should start with: ```python from typing import Set def fuse_sets(set1: Set[int], set2: Set[int]) -> Set[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set def fuse_sets(set1: Set[int], set2: Set[int]) -> Set[int]: """ Fuses two sets of integers together, ensuring the resulting set does not contain any recurring entities. Args: set1 (Set[int]): ...
magic_evol_110k
73,946
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...
magic_evol_110k
73,956
Write a Python function to generate a list of all prime numbers between 0 and 99, where the sum of the individual digits of the prime number is also a prime number. The function should return the list of such prime numbers. The code should start with: ```python from typing import List def generate_primes_with_prime_d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if n <...
magic_evol_110k
73,958
Write a Python function to convert a string of space-separated decimal values into a list of precise floating-point numbers. The input string will contain one or more decimal values separated by spaces. The function should handle any valid decimal values and return a list of corresponding float values. The code should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def string_to_float_list(s: str) -> List[float]: """ Converts a string of space-separated decimal values into a list of floating-point numbers. Args: s (str): A string containing one or more...
magic_evol_110k
73,959
Write a Python function to count the number of unique words in a given string, considering punctuation and differing cases (uppercase/lowercase). The function should normalize the string by removing punctuation and converting all characters to lowercase before counting the unique words. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import string from collections import Counter def count_unique_words(s: str) -> int: """ Counts the number of unique words in a given string, considering punctuation and differing cases. Args: ...
magic_evol_110k
73,969
Write a Python function to traverse a given matrix (2D list) of integers and return the sum of all elements in the matrix. The function should handle matrices of any size, including empty matrices. The code should start with: ```python from typing import List def sum_matrix_elements(matrix: List[List[int]]) -> int: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_matrix_elements(matrix: List[List[int]]) -> int: """ Calculate the sum of all elements in a given matrix. Args: matrix (List[List[int]]): A 2D list of integers representing the matri...
magic_evol_110k
73,980
Write a Python function that generates a list of even numbers within a specified range using a generator expression. The function should take two parameters: `start` and `end`, which define the range of numbers to consider. The function should return a list of even numbers within this range, inclusive of the `start` an...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_even_numbers(start: int, end: int) -> List[int]: """ Generates a list of even numbers within the specified range [start, end]. Args: start (int): The starting value of the range...
magic_evol_110k
73,997
Write a Python function to perform a multi-step analysis to determine if each integer in a given list is greater than a particular predefined limit. The function should return a list of boolean values, where each boolean value indicates whether the corresponding integer in the list is greater than the limit. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def analyze_above_limit(l: List[int], lim: int) -> List[bool]: """ Analyzes each integer in the list to determine if it is greater than the predefined limit. Args: l (List[int]): The list of...
magic_evol_110k
74,006
Write a Python function to filter and return a list of web development frameworks that are developed in a specified programming language. The function should take a list of dictionaries, where each dictionary represents a web development framework, and a string representing the programming language. The function should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def filter_frameworks_by_language(frameworks: List[Dict[str, str]], language: str) -> List[Dict[str, str]]: """ Filters a list of web development frameworks by the specified programming language. ...
magic_evol_110k
74,008
Write a Python function to accurately determine if a given integer is a prime number using an optimized method. The function should return `True` if the number is prime and `False` otherwise. The optimization method should involve checking divisibility only up to the integer square root of `n` and using a more efficien...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime(n: int) -> bool: """ Determines if a given integer is a prime number. Args: n (int): The integer to check for primality. Returns: bool: True if the integer is prime, False othe...
magic_evol_110k
74,009
Write a Python function to calculate the number of times Pat would bounce a basketball over a given interval of time, given a consistent bounce rate. The function should take two parameters: the bounce rate (in bounces per second) and the total time (in seconds). The function should return the approximate number of bou...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_bounces(bounce_rate: float, time: int) -> int: """ Calculate the approximate number of bounces of a basketball over a given time interval. Args: bounce_rate (float): The rate at which the basketball is...
magic_evol_110k
74,010
Write a Python function to determine if a given integer is a prime number. The function should be optimized for performance and correctness. The function should handle edge cases such as 1 and negative numbers correctly. The code should start with: ```python def is_prime(n: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n: int) -> bool: """ Determines if a given integer is a prime number. Args: n (int): The integer to check for primality. Returns: bool: True if the integer is prime, False otherwise. ""...
magic_evol_110k
74,012
Write a Python function to efficiently merge two already sorted lists into a single sorted list. The function should use an optimal approach to merge the lists without relying on Python's built-in sorting functions. The code should start with: ```python from typing import List def merge_sorted_lists(lst1: List[int], l...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_lists(lst1: List[int], lst2: List[int]) -> List[int]: """ Merges two already sorted lists into a single sorted list. Args: lst1 (List[int]): The first sorted list. l...
magic_evol_110k
74,015
Write a Python function to convert a hexadecimal string to its decimal equivalent. The function should handle both uppercase and lowercase hexadecimal characters and should return the decimal value as an integer. The code should start with: ```python def hex_to_decimal(hex_string: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def hex_to_decimal(hex_string: str) -> int: """ Converts a hexadecimal string to its decimal equivalent. Args: hex_string (str): The hexadecimal string to be converted. Returns: int: The decimal equival...
magic_evol_110k
74,019
Write a Python function to extract the last three elements from a given list of integers. The function should handle lists of any length, including cases where the list has fewer than three elements. The code should start with: ```python from typing import List def get_last_triad(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 get_last_triad(arr: List[int]) -> List[int]: """ Extracts the last three elements from a given list of integers. Args: arr (List[int]): The list of integers from which to extract the las...
magic_evol_110k
74,038
Write a Python function to merge two sets of integers and return the resulting set. The function should handle sets of arbitrary size and ensure that the resulting set contains only unique elements. The code should start with: ```python def merge_sets(set1: set, set2: set) -> set: ```
Here is the Python code to solve the given problem in the markdown block: ```python def merge_sets(set1: set, set2: set) -> set: """ Merges two sets of integers and returns the resulting set containing all unique elements. Args: set1 (set): The first set of integers. set2 (set): The second ...
magic_evol_110k
74,065
Write a Python function to determine if a given string is a palindrome, considering only alphanumeric characters and ignoring case and special characters. The function should return `True` if the string is a palindrome and `False` otherwise. The code should start with: ```python def is_palindrome(s: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(s: str) -> bool: """ Determines if a given string is a palindrome, considering only alphanumeric characters and ignoring case and special characters. Args: s (str): The input string to be checked f...