source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_evol_110k
67,576
Write a Python function to process a list of tuples, where each tuple contains a name (string) and an age (integer). The function should return a dictionary where the keys are the names and the values are the ages. Additionally, the function should handle cases where the input list might be empty or contain invalid dat...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict, Union def process_tuples(tuples: List[Tuple[str, int]]) -> Dict[str, int]: """ Processes a list of tuples where each tuple contains a name (string) and an age (integer). Returns a dicti...
magic_evol_110k
67,580
Write a Python function to compute an aggregate of two integer inputs based on a specified aggregation type. The function should support three types of aggregation: sum, product, and minimum. The aggregation type should be passed as a string argument. The function should handle invalid aggregation types gracefully by r...
Here is the Python code to solve the given problem in the markdown block: ```python def compute_aggregate(variable1: int, variable2: int, aggregation_type: str) -> int: """ Computes an aggregate of two integers based on the specified aggregation type. Args: variable1 (int): The first integer input....
magic_evol_110k
67,585
Write a Python function to generate a list of prime numbers that are less than a given non-negative integer `n`. The function should be efficient and correctly handle edge cases such as `n` being 0 or 1. The code should start with: ```python from typing import List def generate_primes_up_to(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_primes_up_to(n: int) -> List[int]: """ Generate a list of prime numbers that are less than the given non-negative integer `n`. Args: n (int): The upper limit (exclusive) for gen...
magic_evol_110k
67,591
Write a Python function to compute the median value from a given list of integers. The median is the middle value in a sorted list of numbers. If the list has an even number of elements, the median is the average of the two middle numbers. The function should handle lists of any length, including empty lists. The code...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_median(sequence: List[int]) -> float: """ Compute the median value from a given list of integers. The median is the middle value in a sorted list of numbers. If the list has an even nu...
magic_evol_110k
67,596
Write a Python function to calculate the sum of all integers between two given integers, inclusive. The function should handle cases where the minimum value is greater than the maximum value by swapping them. The code should start with: ```python def sum_between_inclusive(min_val: int, max_val: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_between_inclusive(min_val: int, max_val: int) -> int: """ Calculate the sum of all integers between two given integers, inclusive. Args: min_val (int): The minimum value of the range. max_val (int): ...
magic_evol_110k
67,601
Write a Python function to initialize an array with exactly 10 integer elements, each set to a numeric zero value, and return the array. The function should also print the individual values of the array elements. The code should start with: ```python from typing import List def initialize_and_display_array() -> List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def initialize_and_display_array() -> List[int]: """ Initializes an array with exactly 10 integer elements, each set to zero, and prints the individual values of the array elements. Returns: ...
magic_evol_110k
67,602
Write a Python function to sort a given list of integers in descending order using the merge sort algorithm. The merge sort algorithm is a divide-and-conquer algorithm that recursively divides the list into halves, sorts each half, and then merges the sorted halves back together. The function should be efficient and ha...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort_descending(A: List[int]) -> List[int]: """ Sorts a list of integers in descending order using the merge sort algorithm. Args: A (List[int]): The list of integers to be sorted....
magic_evol_110k
67,604
Write a Python function to generate a list of pseudo-random numbers within the interval [0, 10]. The function should accept an integer `n` as input, which specifies the number of random numbers to generate. Ensure that the random number generator is seeded appropriately to produce different sequences of random numbers ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random import time def generate_random_numbers(n: int) -> List[int]: """ Generates a list of n pseudo-random numbers within the interval [0, 10]. Args: n (int): The number of random n...
magic_evol_110k
67,616
Write a Python function to compute the product of all elements in a given list of integers. The function should handle lists of any length, including empty lists, and return the correct product. The code should start with: ```python from typing import List def product_of_list(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def product_of_list(numbers: List[int]) -> int: """ Compute the product of all elements in a given list of integers. Args: numbers (List[int]): A list of integers whose product is to be comp...
magic_evol_110k
67,618
Write a Python function to determine if any number in a given list of integers is a perfect square. The function should return a list of boolean values, where each boolean value indicates whether the corresponding integer in the input list is a perfect square. 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 math def check_perfect_squares(num_array: List[int]) -> List[bool]: """ Determines if each number in the given list is a perfect square. Args: num_array (List[int]): A list of integer...
magic_evol_110k
67,619
Write a Python function to reverse the order of elements in a tuple containing only integers. The function should handle tuples of any length, including empty tuples. The code should start with: ```python from typing import Tuple def reverse_tuple(tup: Tuple[int, ...]) -> Tuple[int, ...]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def reverse_tuple(tup: Tuple[int, ...]) -> Tuple[int, ...]: """ Reverses the order of elements in a tuple containing only integers. Args: tup (Tuple[int, ...]): A tuple of integers. Re...
magic_evol_110k
67,630
Write a Python function to translate a given string into its equivalent hexadecimal representation and another function to translate the hexadecimal representation back to its original string form. The functions should not use built-in functions directly for the conversion but should implement the logic manually. The c...
Here is the Python code to solve the given problem in the markdown block: ```python def str_to_hex(input_string: str) -> str: """ Converts a given string into its equivalent hexadecimal representation. Args: input_string (str): The string to be converted to hexadecimal. Returns: str: A...
magic_evol_110k
67,631
Write a Python function to sort an array of strings in alphabetical order. The function should take a list of strings as input and return a new list with the strings sorted in ascending order. The original list should remain unchanged. The code should start with: ```python from typing import List def sort_strings_alp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_strings_alphabetically(strings: List[str]) -> List[str]: """ Sorts an array of strings in alphabetical order and returns the sorted list. The original list remains unchanged. Args: ...
magic_evol_110k
67,638
Write a Python function to find the first non-repeating character in a given string. If there are no non-repeating characters, the function should return `None`. The function should be efficient and handle various edge cases, such as an empty string or a string with all repeating characters. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python def find_first_non_repeating_char(string: str) -> str: """ Finds the first non-repeating character in the given string. Args: string (str): The input string to search for the first non-repeating character. Retu...
magic_evol_110k
67,640
Write a Python function to identify and extract the top three maximum and minimum numerical figures from a given collection of data that is in no discernible order. The function should return two lists: one containing the top three maximum numbers and the other containing the top three minimum numbers. The code should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_top_trio(nums: List[int]) -> Tuple[List[int], List[int]]: """ Identifies and extracts the top three maximum and minimum numerical figures from a given collection of data. Args: ...
magic_evol_110k
67,651
Write a Python function named `is_perfect_cube` that takes a number as an argument and returns `True` if the number is a perfect cube, else `False`. The function should handle non-numeric inputs and negative numbers by raising a `ValueError` with an appropriate message. The code should start with: ```python def is_per...
Here is the Python code to solve the given problem in the markdown block: ```python def is_perfect_cube(num: float) -> bool: """ Determines if a given number is a perfect cube. Args: num (float): The number to check. Returns: bool: True if the number is a perfect cube, False otherwise....
magic_evol_110k
67,657
Write a Python function to compute the average temperature of a given set of temperatures. The function should handle an empty list by returning `None` and should return the average temperature rounded to two decimal places for non-empty lists. The code should start with: ```python from typing import List, Optional d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def compute_average_temperature(temperatures: List[float]) -> Optional[float]: """ Compute the average temperature of a given set of temperatures. Args: temperatures (List[float]):...
magic_evol_110k
67,673
Write a Python function to generate a new list containing the rolling average of the given list with the specified window size. The rolling average is calculated as the average of the current and the previous `(window_size - 1)` values. If the window size is bigger than the list, return an error message. Additionally, ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def rolling_average(l: List[float], window_size: int) -> Union[List[float], str]: """ Generate a new list containing the rolling average of the given list with the specified window size. The r...
magic_evol_110k
67,674
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(str1: str, str2: str) -> bool: """ Determines if two given strings are anagrams of each other. Args: str1 (str): The first string to compare. str2 (str): The second string to compare. R...
magic_evol_110k
67,681
Write a Python function to create a dictionary that contains the elements from list `x` and their occurrence counts from both list `x` and list `y`. The function should return a dictionary where the keys are the elements from list `x` and the values are their total occurrence counts in both lists. The code should star...
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 count_elements_in_lists(x: List[int], y: List[int]) -> Dict[int, int]: """ Create a dictionary that contains the elements from list `x` and their occurrence coun...
magic_evol_110k
67,684
Write a Python function to find the minimum disparity achievable when subtracting the sum of any permutation of a given set of numerical values from a predefined target. The function should return both the minimum disparity and the corresponding permutation of the numerical values. The code should start with: ```pytho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple from itertools import permutations def find_min_disparity(target: int, num_array: List[int]) -> Tuple[int, Tuple[int]]: """ Finds the minimum disparity achievable when subtracting the sum of any p...
magic_evol_110k
67,699
Write a Python function to determine if a given number can be represented as the cube of an odd number. The function should handle edge cases and potential issues efficiently. The code should start with: ```python def is_cube_of_odd(n: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_cube_of_odd(n: int) -> bool: """ Determines if a given number can be represented as the cube of an odd number. Args: n (int): The number to check. Returns: bool: True if n is the cube of an odd n...
magic_evol_110k
67,714
Write a Python function to count the frequency of each word in a given list of words and return a dictionary where each word is a key and its frequency is the value. The function should handle lists of varying lengths and ensure that all words are counted accurately. The code should start with: ```python from typing i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def word_frequency(word_list: List[str]) -> Dict[str, int]: """ Counts the frequency of each word in a given list of words and returns a dictionary. Args: word_list (List[str]): A list...
magic_evol_110k
67,716
Write a Python function to sort a list of strings in alphabetical order, considering both case-sensitive and case-insensitive sorting. The function should return a tuple containing two lists: the first list sorted in a case-sensitive manner, and the second list sorted in a case-insensitive manner. The code should star...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def sort_strings(list_of_strings: List[str]) -> Tuple[List[str], List[str]]: """ Sorts a list of strings in both case-sensitive and case-insensitive manners. Args: list_of_strings (Li...
magic_evol_110k
67,725
Write a Python function to convert a given hexadecimal value to its equivalent binary and decimal values. The function should return a tuple containing the binary and decimal values. The hexadecimal value will be provided as a string prefixed with "0x". The function should also include a validation step to ensure the h...
Here is the Python code to solve the given problem in the markdown block: ```python def hex_to_bin_dec(hex_value: str) -> tuple: """ Converts a given hexadecimal value to its equivalent binary and decimal values. Args: hex_value (str): The hexadecimal value to convert, prefixed with "0x". Retu...
magic_evol_110k
67,728
Write a Python function to determine if there are two strings in a given list that differ by exactly one character at the same index. The function should handle lists where all strings are of the same length and also handle cases where strings are of different lengths. The function should return `True` if such a pair o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def strings_differ_by_one_character(dict: List[str]) -> bool: """ Determine if there are two strings in the given list that differ by exactly one character at the same index. Args: dict (Lis...
magic_evol_110k
67,733
Write a Python function to convert a given number into its word representation. The function should handle numbers up to 999,999. The code should start with: ```python def number_to_words(num: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def number_to_words(num: int) -> str: """ Convert a given number into its word representation. Args: num (int): The number to convert. Must be between 0 and 999,999. Returns: str: The word representatio...
magic_evol_110k
67,734
Write a Python function to create a complex payload for a server, including metadata and a binary file, using the `requests` library. The payload should be structured as a multipart form-data request, ensuring that both the metadata and the binary file are correctly sent to the server. The function should accept the fi...
Here is the Python code to solve the given problem in the markdown block: ```python import requests from typing import Optional def send_complex_payload(file_path: str, file_name: str, file_type: str, table_name: str, file_size: int, name: Optional[str] = None, description: Optional[str] = None) -> requests.Response: ...
magic_evol_110k
67,736
Write a Python function to determine if the cumulative result of a list of operations (which can be integers or string representations of integers) ever falls below zero or equals zero based on a `case_insensitive` flag. The function should return `True` if such a condition is met, otherwise `False`. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def operation_result(operations: List[Union[int, str]], case_insensitive: bool = False) -> bool: """ Determine if the cumulative result of a list of operations (integers or string representations ...
magic_evol_110k
67,739
Write a Python function to find the index of the last occurrence of a specific target integer within a given list of integers. If the target integer is not found in the list, the function should return `None`. The code should start with: ```python from typing import List, Optional def find_last_occurrence(nums: List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_last_occurrence(nums: List[int], target: int) -> Optional[int]: """ Find the index of the last occurrence of a specific target integer within a given list of integers. Args: ...
magic_evol_110k
67,743
Write a Python function to sort a list of mixed data types according to specific rules. The function should categorize elements by their type (int, float, str, and 'other'), sort each category separately, and then concatenate the sorted lists in a specific order. The sorting rules are as follows: - Integers should be s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def complex_sort(lst: List[Any]) -> List[Any]: """ Sorts a list of mixed data types according to specific rules and returns the sorted list. Args: lst (List[Any]): The list of mixed dat...
magic_evol_110k
67,744
Write a Python function to search for individuals in a list of dictionaries based on one or more criteria. Each dictionary represents an individual and contains keys such as `name`, `age`, `weight`, and `address`. The `address` key maps to another dictionary containing keys like `street`, `city`, `country`, and `postal...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def search_individuals(people: List[Dict[str, Any]], criteria: Dict[str, Any]) -> List[Dict[str, Any]]: """ Search for individuals in a list of dictionaries based on one or more criteria. ...
magic_evol_110k
67,748
Write a Python function to find the top `n` most frequent words in a given sentence, considering case insensitivity and ignoring punctuation. The function should return a list of tuples where each tuple contains a word and its frequency. The code should start with: ```python from typing import List, Tuple import strin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import string from collections import Counter def top_n_frequent_words(sentence: str, n: int) -> List[Tuple[str, int]]: """ Returns the top n most frequent words in the given sentence, considering...
magic_evol_110k
67,753
Write a Python function to generate the mirror image of a given character sequence. The function should reverse the order of characters in the sequence and return the reversed sequence. The code should start with: ```python def mirror_image(sequence: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def mirror_image(sequence: str) -> str: """ Generate the mirror image of a given character sequence by reversing the order of characters. Args: sequence (str): The input character sequence to be mirrored. Retur...
magic_evol_110k
67,755
Write a Python function to create a dictionary where the keys are prime numbers between 1 and 50, and the values are their respective natural logarithms. The function should use dictionary comprehension for efficiency. The code should start with: ```python import math def prime_logarithms_dict() -> dict: ```
Here is the Python code to solve the given problem in the markdown block: ```python import math def check_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. """ i...
magic_evol_110k
67,763
Write a Python function to determine if a list of unique integers can be sorted using the following operations: 1. Repeatedly reverse the order of any portion of the list. 2. Eliminate either one or two elements from the series. 3. Exchange any pair of elements a single time only. 4. Increment or decrement one digit by...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def advanced_sort(arr: List[int]) -> List[int]: """ Determine if a list of unique integers can be sorted using specific operations. Args: arr (List[int]): The list of unique integers to be s...
magic_evol_110k
67,766
Write a Python function that processes a list of elements using a provided callback function. The function should iterate through the list, apply the callback function to each element, and return a new list with the processed elements. If the callback function raises an exception for any element, the function should ha...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable def process_list_with_callback(elements: List, callback: Callable) -> List: """ Processes a list of elements using a provided callback function. If the callback function raises an exception...
magic_evol_110k
67,796
Write a Python function to find the length of the largest contiguous subset of alphabetic characters within a given string. The function should ignore any non-alphabetic characters and return the length of the longest sequence of consecutive alphabetic characters. The code should start with: ```python def largest_alph...
Here is the Python code to solve the given problem in the markdown block: ```python def largest_alpha_subset(text: str) -> int: """ Find the length of the largest contiguous subset of alphabetic characters in the given string. Args: text (str): The input string to analyze. Returns: int...
magic_evol_110k
67,797
Write a Python function to calculate the product of all numbers in a given list efficiently, with a time complexity of O(n). The function should handle both positive and negative numbers, as well as zero. The code should start with: ```python from typing import List def product_of_list(lst: 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_list(lst: List[int]) -> int: """ Calculate the product of all numbers in a given list efficiently. Args: lst (List[int]): The list of integers whose product is to be calculate...
magic_evol_110k
67,799
Write a Python function to determine the academic letter grade of an undergraduate scholar based on their arithmetic grade value using a ternary operator. The function should accept an integer representing the arithmetic grade value and return a string representing the corresponding letter grade. The grading scale is a...
Here is the Python code to solve the given problem in the markdown block: ```python def determine_letter_grade(arithmetic_grade_value: int) -> str: """ Determine the academic letter grade of an undergraduate scholar based on their arithmetic grade value. Args: arithmetic_grade_value (int): The arit...
magic_evol_110k
67,805
Write a Python function to find the second largest number in a given list without using built-in Python functions like `max()` or `sorted()`. Additionally, implement this function using a single pass through the list. The code should start with: ```python from typing import List, Optional def find_second_largest(myLi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_second_largest(myList: List[int]) -> Optional[int]: """ Find the second largest number in a given list without using built-in Python functions like max() or sorted(). The function ...
magic_evol_110k
67,816
Write a Python function to create a dictionary from two tuples of equal length. The first tuple contains keys, and the second tuple contains corresponding values. The function should ensure that the two tuples have the same length before creating the dictionary. If the lengths are not equal, the function should return ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Dict def create_dictionary_from_tuples(tuple1: Tuple[str], tuple2: Tuple[str]) -> Dict[str, str]: """ Creates a dictionary from two tuples of equal length. The first tuple contains keys, and the second...
magic_evol_110k
67,820
Write a Python function to shuffle the elements of a given list of integers randomly. The function should take a list of integers as input and return a new list with the same elements but in a random order. The original list should not be modified. The code should start with: ```python from typing import List import r...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def shuffle_list(numbers: List[int]) -> List[int]: """ Shuffles the elements of a given list of integers randomly. Args: numbers (List[int]): The list of integers to be shuffle...
magic_evol_110k
67,823
Write a Python function to recursively calculate the cumulative total of all numerical elements within a multi-dimensional array. The array may contain sub-arrays of various depths and configurations, and each sub-array may contain a mix of numerical elements and further sub-arrays. The function should handle edge case...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Union, List def recursive_sum(input_array: Union[List, int, float]) -> float: """ Recursively calculates the cumulative total of all numerical elements within a multi-dimensional array. Args: inp...
magic_evol_110k
67,824
Write a Python function to sort a list of dictionaries by the `public_id` in descending order and by the `name` in ascending order when the `public_id` values are the same. The function should handle the provided erroneous code and correct it to meet the new requirements. The code should start with: ```python from typ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def sort_data(data: List[Dict[str, any]]) -> List[Dict[str, any]]: """ Sorts a list of dictionaries by the 'public_id' in descending order and by the 'name' in ascending order when 'public_id' valu...
magic_evol_110k
67,832
Write a Python function to clean a given string by removing all whitespace characters and special characters (like punctuation marks and symbols). The function should return the cleaned string, which should only contain alphanumeric characters. The code should start with: ```python import re def clean_string(s: str) -...
Here is the Python code to solve the given problem in the markdown block: ```python import re def clean_string(s: str) -> str: """ Cleans a given string by removing all whitespace characters and special characters. Args: s (str): The input string to be cleaned. Returns: str: The clean...
magic_evol_110k
67,834
Write a Python function to validate and print a list and a dictionary, ensuring they are syntactically correct and handling any potential runtime errors gracefully. The function should accept a list and a dictionary as input, validate their syntax, and print them if they are valid. If any syntax errors or runtime error...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def validate_and_print_data(my_list: List, my_dict: Dict) -> None: """ Validates and prints a list and a dictionary, handling any potential runtime errors. Args: my_list (List): The li...
magic_evol_110k
67,845
Write a Python function to rotate the elements of an array to the right by a given number of steps. The rotation should be performed in-place, meaning the original array should be modified directly without using additional space (except for a constant amount of extra space). The code should start with: ```python from ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def rotate_array_in_place(arr: List[int], steps: int) -> None: """ Rotates the elements of the array to the right by the given number of steps in-place. Args: arr (List[int]): The array to b...
magic_evol_110k
67,846
Write a Python function to validate the Fundamental Theorem of Arithmetic for a given set of prime numbers and a composite number. The function should decompose the composite number into its prime factors using the provided set of prime numbers. The code should start with: ```python from typing import List, Tuple def ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def decompose_into_prime_factors(primes: Tuple[int], composite: int) -> List[int]: """ Decomposes a composite number into its prime factors using a given set of prime numbers. Args: p...
magic_evol_110k
67,858
Write a Python function to compute the transpose of a given two-dimensional matrix. The function should handle matrices of any size and ensure efficient memory usage. The code should start with: ```python from typing import List def transpose_matrix(matrix: List[List[int]]) -> List[List[int]]: ```
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]]: """ Compute the transpose of a given two-dimensional matrix. Args: matrix (List[List[int]]): The input matrix to be transpos...
magic_evol_110k
67,866
Write a Python function to calculate the sum of all integer elements in a given list, while ignoring any non-integer elements. The function should handle lists with mixed data types, including integers, strings, floats, and other types. The code should start with: ```python from typing import List, Union def sum_integ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def sum_integers_in_list(arr: List[Union[int, float, str, bool]]) -> int: """ Calculate the sum of all integer elements in a given list, ignoring non-integer elements. Args: arr (List...
magic_evol_110k
67,868
Write a Python function to find the most frequent element in a given list. If there are multiple elements with the same highest frequency, the function should return the first one encountered in the list. The function should be efficient and handle lists of various sizes. The code should start with: ```python from typ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional from collections import defaultdict def most_frequent_element(lst: List[int]) -> Optional[int]: """ Find the most frequent element in a given list. If there are multiple elements with the same ...
magic_evol_110k
67,878
Write a Python function to find the index of a given element in a sorted array using binary search. If the element is not found, return -1. The function should be efficient and leverage the sorted nature of the array. The code should start with: ```python from typing import List def find_element_index(array: List[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_element_index(array: List[int], element: int) -> int: """ Find the index of a given element in a sorted array using binary search. Args: array (List[int]): A sorted list of integers...
magic_evol_110k
67,880
Write a Python function to determine if any element from the second array exists in the first array. If at least one element from the second array is found in the first array, the function should return `True`. Otherwise, it should return `False`. The code should start with: ```python from typing import List def cont...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def contains_any_element(array1: List[int], array2: List[int]) -> bool: """ Determines if any element from the second array exists in the first array. Args: array1 (List[int]): The first arr...
magic_evol_110k
67,881
Write a Python function to count the frequency of each item in a given sorted list and return a list of tuples sorted by frequency in descending order. If two items have the same frequency, they should be sorted by their value in ascending order. The code should start with: ```python from typing import List, Tuple de...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def frequency_sort(lst: List[int]) -> List[Tuple[int, int]]: """ Counts the frequency of each item in a given sorted list and returns a list of tuples sorted by frequency in descending order. ...
magic_evol_110k
67,891
Write a Python function to compute the derivative of a given list of coefficients representing a complex exponential series. Each coefficient corresponds to an exponential term of the form \( a_i \cdot e^{x / i} \). The function should return a new list of coefficients representing the derivative of the series. The co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def compute_derivative(coefficients: List[float]) -> List[float]: """ Compute the derivative of a complex exponential series represented by a list of coefficients. Each coefficient a_i in the input ...
magic_evol_110k
67,895
Write a Python function to search for a given text string in a directory tree recursively. The function should be able to handle case-insensitive search, exclude certain file types, and limit the search within a certain file size range. The function should prompt the user for these inputs and also provide an option to ...
Here is the Python code to solve the given problem in the markdown block: ```python import os import fnmatch def search_text_in_directory(directory: str) -> None: """ Searches for a given text string in a directory tree recursively. Args: directory (str): The directory to start the search from. ...
magic_evol_110k
67,901
Write a Python function to extract the content from a string between two specified characters. The function should handle cases where the start or end character is not found, and should return an empty string in such cases. The function should also handle multiple occurrences of the start and end characters, extracting...
Here is the Python code to solve the given problem in the markdown block: ```python def extract_content(s: str, start_char: str, end_char: str) -> str: """ Extracts the content from a string between two specified characters. Args: s (str): The input string from which to extract the content. ...
magic_evol_110k
67,905
Write a Python function to calculate the least common multiple (LCM) of two given integers using the greatest common divisor (GCD) method. The function should return the LCM of the two numbers. The code should start with: ```python def lcm(a: int, b: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def gcd(a: int, b: int) -> int: """ Calculate the greatest common divisor (GCD) of two integers using the Euclidean algorithm. Args: a (int): The first integer. b (int): The second integer. Returns: ...
magic_evol_110k
67,911
Write a Python function to calculate the product of the sum of prime odd numbers at even indices and the count of odd numbers that are evenly divisible by 2 in a given list. The function should start with: ```python from typing import List def calculate_product(lst: 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 calculate_product(lst: List[int]) -> int: """ Calculate the product of the sum of prime odd numbers at even indices and the count of odd numbers that are evenly divisible by 2 in a given ...
magic_evol_110k
67,913
Write a Python function to randomly select an element from a given list of integers. The function should ensure that the selected element is within the specified range of 1 to 5, inclusive. If the list contains elements outside this range, they should be ignored. The function should return the randomly selected element...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def random_select_in_range(array: List[int]) -> int: """ Randomly selects an element from the given list that is within the range of 1 to 5, inclusive. Args: array (List[int]):...
magic_evol_110k
67,918
Write a Python function to find and return the maximum number in a given list of integers. The function should handle an empty list by returning `None`. The code should start with: ```python from typing import List, Optional def find_max_number(nums: 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 find_max_number(nums: List[int]) -> Optional[int]: """ Find and return the maximum number in a given list of integers. Args: nums (List[int]): The list of integers from which t...
magic_evol_110k
67,948
Write a Python function to find the age of the student who precedes the student with a specific second hobby in a given list of student data. The student data is provided as a list of dictionaries, where each dictionary contains the student's name, age, and a list of hobbies. The function should return the age of the s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Optional def get_preceding_student_age(student_data: List[Dict[str, any]], hobby: str) -> Optional[int]: """ Find the age of the student who precedes the student with a specific second hobby. ...
magic_evol_110k
67,951
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 as input and return the rotated 3D list. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List 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...
magic_evol_110k
67,970
Write a Python function to find the smallest prime number in a given list of integers. If no prime numbers are present in the list, the function should return `None`. The function should be efficient and handle edge cases such as an empty list or a list with no prime numbers. The code should start with: ```python from...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_min_prime(numbers: List[int]) -> Optional[int]: """ Find the smallest prime number in a given list of integers. Args: numbers (List[int]): A list of integers to search for...
magic_evol_110k
67,971
Write a Python function to calculate the cumulative sum of elements in a given list. The function should modify the input list in place and return the modified list. The code should start with: ```python from typing import List def cumulative_sum(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 cumulative_sum(arr: List[int]) -> List[int]: """ Calculate the cumulative sum of elements in the given list and return the modified list. Args: arr (List[int]): The list of integers fo...
magic_evol_110k
67,982
Write a Python function to identify and enumerate all lexemes (words) that start with the alphabetic character 'R' or 'r' within a given string. The function should return a list of tuples, where each tuple contains the index (starting from 1) and the corresponding word. The code should start with: ```python from typi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_r_words(input_string: str) -> List[Tuple[int, str]]: """ Identify and enumerate all lexemes that start with the alphabetic character 'R' or 'r' within a given string. Args: i...
magic_evol_110k
68,004
Write a Python function to convert the key-value pairs of a dictionary into a list of strings, where each string is formatted as "key: value". The function should handle dictionaries with various types of keys and values, ensuring that the output list is correctly formatted and adheres to good coding practices. The co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def dict_to_list_of_strings(dictionary: Dict[str, str]) -> List[str]: """ Converts the key-value pairs of a dictionary into a list of strings, where each string is formatted as "key: value". A...
magic_evol_110k
68,017
Write a Python function to calculate the least common multiple (LCM) of two positive integers. The function should use the greatest common divisor (GCD) to compute the LCM efficiently. The code should start with: ```python import math def lowest_common_multiple(x: int, y: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python import math def lowest_common_multiple(x: int, y: int) -> int: """ Calculate the least common multiple (LCM) of two positive integers. Args: x (int): The first positive integer. y (int): The second positive...
magic_evol_110k
68,018
Write a Python function to remove all occurrences of a specified character from a given string. The function should return the modified string. The code should start with: ```python def remove_char(input_str: str, char_to_remove: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def remove_char(input_str: str, char_to_remove: str) -> str: """ Removes all occurrences of a specified character from the given string. Args: input_str (str): The input string from which to remove the character. ...
magic_evol_110k
68,019
Write a Python function to generate the Fibonacci sequence up to a given number `n` and check if each number in the sequence is prime. The function should return a list of tuples where each tuple contains a Fibonacci number and a boolean indicating whether the number is prime. The code should start with: ```python fro...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def fibonacci_prime_check(n: int) -> List[Tuple[int, bool]]: """ Generate the Fibonacci sequence up to n terms and check if each number is prime. Args: n (int): The number of terms in...
magic_evol_110k
68,020
Write a Python function to calculate the maximum and minimum number of nodes in a binary tree given its height. The function should return a tuple containing the maximum and minimum number of nodes. The code should start with: ```python def calculate_nodes(height: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_nodes(height: int) -> tuple: """ Calculate the maximum and minimum number of nodes in a binary tree given its height. Args: height (int): The height of the binary tree. Returns: tuple: A t...
magic_evol_110k
68,029
Write a Python function to read a text file and return its content as a string, preserving all spaces and newline characters. The function should handle file reading errors gracefully by returning an empty string in case of any issues. The code should start with: ```python def read_file_preserve_format(file_path: str)...
Here is the Python code to solve the given problem in the markdown block: ```python def read_file_preserve_format(file_path: str) -> str: """ Reads the content of a text file and returns it as a string, preserving all spaces and newline characters. Args: file_path (str): The path to the text file t...
magic_evol_110k
68,030
Write a Python function to generate a radial treemap visualization of the given task force members and their connections with various departments. The treemap should display the role and cohort of each member, along with their connections to different departments. The strength of each connection should be represented v...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def generate_radial_treemap(task_force_members: Dict[str, Dict[str, str]], connection_strength: Dict[str, int]) -> Dict[str, Dict[str, Dict[str, int]]]: """ Generate a radial treemap visualization ...
magic_evol_110k
68,033
Write a Python function to calculate the power of a number raised to the nth power without using the power (**) operator or any in-built Python function like `pow()`. Additionally, handle edge cases like the power being negative or zero. The function should also handle exceptions like non-numeric inputs and return a su...
Here is the Python code to solve the given problem in the markdown block: ```python def power_of_number(base: float, exponent: int) -> float: """ Calculate the power of a number raised to the nth power without using the power (**) operator or any in-built Python function like pow(). Args: base (flo...
magic_evol_110k
68,039
Write a Python function to find the prime factors of a given integer `n`. 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 a list of prime factors of the given integer `n`. Args: n (int): The integer for which to find the prime factors. Returns: Li...
magic_evol_110k
68,042
Write a Python function to determine if there is a subset of a given set of non-negative integers that sums up to a given value. The function should return `True` if such a subset exists, otherwise `False`. The function should be efficient and handle the constraints provided. The code should start with: ```python from...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def has_subset_sum(nums: List[int], target_sum: int) -> bool: """ Determine if there is a subset of the given set of non-negative integers that sums up to the given target sum. Args: nums (L...
magic_evol_110k
68,048
Write a Python function to find the item that is positioned immediately before the very last element in a given tuple. The function should return the item as a string. The code should start with: ```python from typing import Tuple def find_item_before_last(fruits: Tuple[str]) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def find_item_before_last(fruits: Tuple[str]) -> str: """ Find the item that is positioned immediately before the very last element in a given tuple. Args: fruits (Tuple[str]): A tuple of s...
magic_evol_110k
68,052
Write a Python function to concatenate three given alphanumeric sequences (strings) into a single unique, linear sequence. The function should return the concatenated result. The code should start with: ```python def concatenate_strings(str1: str, str2: str, str3: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_strings(str1: str, str2: str, str3: str) -> str: """ Concatenates three given strings into a single unique, linear sequence. Args: str1 (str): The first alphanumeric sequence. str2 (str): The...
magic_evol_110k
68,056
Write a Python function to sort the strings within a mixed list of integers and strings in ascending alphabetical order while leaving the integers untouched. The function should handle lists with varying numbers of integers and strings. The code should start with: ```python from typing import List, Union def sort_mixe...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def sort_mixed_list(mixed_list: List[Union[int, str]]) -> List[Union[int, str]]: """ Sorts the strings within a mixed list of integers and strings in ascending alphabetical order while leaving the...
magic_evol_110k
68,067
Write a Python function to compute the least common multiple (LCM) of all prime numbers up to a given maximum threshold value. The function should first generate a list of all prime numbers up to the given threshold using the Sieve of Eratosthenes algorithm, and then calculate the LCM of these primes. The code should ...
Here is the Python code to solve the given problem in the markdown block: ```python def lcm_of_primes_up_to(n: int) -> int: """ Compute the least common multiple (LCM) of all prime numbers up to a given maximum threshold. Args: n (int): The maximum threshold value up to which prime numbers are cons...
magic_evol_110k
68,072
Write a Python function to create a 5x5 NumPy array containing randomly generated floating point numbers within the interval of -3.0 and 7.0. Then, find and replace all the negative values in the array with their absolute values using NumPy's masking capabilities. The function should return the modified array. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def replace_negatives_with_abs(arr: np.ndarray) -> np.ndarray: """ Replace all negative values in a 5x5 NumPy array with their absolute values. Args: arr (np.ndarray): A 5x5 NumPy array containin...
magic_evol_110k
68,073
Write a Python function to count the occurrences of a given number in a list efficiently. The function should use a dictionary to store the counts of each number in the list, and then return the count of the specified number. The code should start with: ```python from typing import List, Dict def count_occurrences(lst...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_occurrences(lst: List[int], num: int) -> int: """ Counts the occurrences of a given number in a list. Args: lst (List[int]): The list of integers in which to count occurrence...
magic_evol_110k
68,083
Write a Python function to sort a list of integer values in ascending numerical sequence. The function should handle lists of varying lengths, including empty lists, and should return the sorted list. The function should be efficient and should not modify the original list. The code should start with: ```python from t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_list(numbers: List[int]) -> List[int]: """ Sorts a list of integer values in ascending numerical sequence. Args: numbers (List[int]): The list of integers to be sorted. Returns...
magic_evol_110k
68,085
Write a Python function to convert each item in a given list to a float. The function should handle various types of inputs, including strings that represent integers and floating-point numbers, and should return a new list containing the float representations of the original list items. The function should also handle...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_list_to_float(input_list: List[str]) -> List[float]: """ Converts each item in the input list to a float. Args: input_list (List[str]): A list of strings where each string repres...
magic_evol_110k
68,090
Write a Python function to determine the least disparity between the maximum and minimum values in a numerical array `nums` after performing a maximum of three modifications. Each modification allows you to select a single element from `nums` and change it to any numerical value. 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 min_disparity_after_three_modifications(nums: List[int]) -> int: """ Calculate the least disparity between the maximum and minimum values in the array after performing a maximum of three modifica...
magic_evol_110k
68,095
Write a Python function to sort a list of integers using the bubble sort algorithm. The function should return the sorted list. The code should start with: ```python from typing import List def bubble_sort(arr: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the bubble sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: Li...
magic_evol_110k
68,102
Write a Python function to find the maximum value in a given list of integers. The function should return the maximum value found in the list. The code should start with: ```python from typing import List def find_max_value(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_value(numbers: List[int]) -> int: """ Find the maximum value in a given list of integers. Args: numbers (List[int]): The list of integers from which to find the maximum value. ...
magic_evol_110k
68,113
Write a Python function to determine if the sum of all elements in a list of integers falls within a specified range, inclusive of the bounds. The function should return `True` if the sum is within the range, and `False` otherwise. The code should start with: ```python from typing import List def sum_within_bounds(l: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_within_bounds(l: List[int], lower_bound: int, upper_bound: int) -> bool: """ Determines if the sum of all elements in the list `l` falls within the inclusive range [lower_bound, upper_bound]. ...
magic_evol_110k
68,115
Write a Python function to compute the factorial of a given non-negative integer `n` efficiently using an iterative approach. The function should handle very large input values and avoid potential exceptions such as exceeding the maximum recursion depth. Additionally, the function should include input validation to ens...
Here is the Python code to solve the given problem in the markdown block: ```python def factorial(n: int) -> int: """ Compute the factorial of a given non-negative integer `n` using an iterative approach. Args: n (int): The non-negative integer for which to compute the factorial. Returns: ...
magic_evol_110k
68,117
Write a Python function that takes a list of integers as input and returns a new list containing the squares of each integer in the original list. The function should utilize a single `while` loop to iterate through the list and compute the squares. The code should start with: ```python from typing import List def com...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def compute_squares(numbers: List[int]) -> List[int]: """ Computes the squares of each integer in the input list and returns a new list containing these squares. Args: numbers (List[int]): A...
magic_evol_110k
68,128
Write a Python function to create and populate a dictionary with key-value pairs where keys are names of ancient artifacts and values are their corresponding historical periods. The function should return the populated dictionary. The code should start with: ```python from typing import Dict def create_ancient_artifac...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def create_ancient_artifacts_dictionary() -> Dict[str, str]: """ Creates and populates a dictionary with ancient artifacts and their historical periods. Returns: Dict[str, str]: A dictionary...
magic_evol_110k
68,129
Write a Python function to apply a given transformation function to each element of a list and return a new list containing the transformed elements. The transformation function should be applied to each element in the list, and the result should be collected into a new list. The code should start with: ```python from ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable def transform_list(elements: List[any], transformation: Callable[[any], any]) -> List[any]: """ Applies a given transformation function to each element of a list and returns a new list with the...
magic_evol_110k
68,133
Write a Python function to determine if an array of integers can be partitioned into three non-empty parts with equal sums, and if so, ensure that the difference between the maximum and minimum sum of the three parts is minimized. The function should return `True` if such a partition exists, otherwise `False`. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def can_partition_three_parts_with_equal_sum(arr: List[int]) -> bool: """ Determine if an array can be partitioned into three non-empty parts with equal sums. Args: arr (List[int]): The arra...
magic_evol_110k
68,134
Write a Python function to extract specific information from a given dictionary and return it as a formatted string. The dictionary contains information about a celestial object, including its constellation, coordinates, and the period it is visible. The function should accept the dictionary and a list of keys as input...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def extract_info(dictionary: Dict[str, str], keys: List[str], delimiter: str = ' - ') -> str: """ Extracts specific information from a dictionary and returns it as a formatted string. Args: ...
magic_evol_110k
68,148
Write a Python function to dismantle a given character sequence by treating all non-alphanumeric characters (including hyphens) as delimiters. The function should handle cases where multiple non-alphanumeric characters are present consecutively. The function should return a list of words extracted from the sequence. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def dismantle_sequence(char_sequence: str) -> List[str]: """ Dismantles a given character sequence by treating all non-alphanumeric characters as delimiters. Handles cases where multiple no...
magic_evol_110k
68,149
Write a Python function to determine if a given sequence of hexadecimal characters exhibits cyclic symmetry, similar to an ambigram. A sequence is considered to have cyclic symmetry if it reads the same forwards and backwards. The function should be case-insensitive and should only consider valid hexadecimal characters...
Here is the Python code to solve the given problem in the markdown block: ```python def is_cyclic_symmetry(hex_seq: str) -> bool: """ Determines if a given sequence of hexadecimal characters exhibits cyclic symmetry. Args: hex_seq (str): The sequence of hexadecimal characters to check. Returns...
magic_evol_110k
68,152
Write a Python function to construct a regular expression pattern that exclusively matches the words "apple" and "match". The function should return the compiled regular expression pattern. The code should start with: ```python import re def construct_regex_pattern() -> re.Pattern: ```
Here is the Python code to solve the given problem in the markdown block: ```python import re def construct_regex_pattern() -> re.Pattern: """ Constructs a regular expression pattern that exclusively matches the words "apple" and "match". Returns: re.Pattern: A compiled regular expression pattern ...
magic_evol_110k
68,156
Write a Python function to count the total number of characters in a given string and to return the frequency distribution of each character. The function should consider case sensitivity, meaning 'A' and 'a' should be treated as different characters. The function should start with: ```python from typing import Dict, T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Tuple from collections import Counter def character_count_and_frequency(s: str) -> Tuple[int, Dict[str, int]]: """ Counts the total number of characters in a given string and returns the frequency distr...
magic_evol_110k
68,158
Write a Python function to calculate the product of all elements in a given list of integers. The function should handle an empty list by returning 1, as the multiplicative identity. The code should start with: ```python from typing import List def calculate_product(numbers: 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(numbers: List[int]) -> int: """ Calculate the product of all elements in a given list of integers. Args: numbers (List[int]): The list of integers whose product is to...