source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_evol_110k
84,592
Write a Python function to determine if all elements in a given list are even numbers. The function should return `True` if all elements are even, and `False` otherwise. The code should start with: ```python from typing import List def all_even(arr: List[int]) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def all_even(arr: List[int]) -> bool: """ Determine if all elements in the given list are even numbers. Args: arr (List[int]): The list of integers to check. Returns: bool: True...
magic_evol_110k
84,594
Write a Python function to create a dictionary that maps each month of the year to its average temperature in a given city. The function should take a list of tuples as input, where each tuple contains a month and its corresponding average temperature. The function should return a dictionary with unique keys representi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def create_temperature_dict(temperatures: List[Tuple[str, int]]) -> Dict[str, int]: """ Creates a dictionary that maps each month of the year to its average temperature. Args: t...
magic_evol_110k
84,597
Write a Python function to find and list all prime numbers up to a given number `n` without using the Sieve of Eratosthenes algorithm. Additionally, for each prime number found, calculate the number of prime numbers less than that prime number. The function should be efficient in terms of processing time and should han...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import math def is_prime(num: int) -> bool: """ Check if a number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime...
magic_evol_110k
84,599
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
84,616
Write a Python function to convert a matrix of hexadecimal strings to a matrix of their corresponding decimal values. The matrix is represented as a list of strings, where each string is a hexadecimal number prefixed with '0x'. The function should return a list of integers representing the decimal values of the hexadec...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def hex_to_dec_matrix(matrix_data: List[str]) -> List[int]: """ Converts a matrix of hexadecimal strings to a matrix of their corresponding decimal values. Args: matrix_data (List[str]): A l...
magic_evol_110k
84,619
Write a Python function to find the largest negative integer and the smallest positive integer in a given list of integers. If there are no negative or positive integers, the function should return `None` for those respective values. The function should be efficient and handle edge cases such as empty lists or lists wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def largest_smallest_integers(lst: List[int]) -> List[Optional[int]]: """ Find the largest negative integer and the smallest positive integer in a given list of integers. Args: lst...
magic_evol_110k
84,638
Write a Python function to compute the product of corresponding elements from two given arrays. The function should handle arrays of equal length and ensure that the product is calculated correctly without any mismatches. Additionally, provide a piece of erroneous code that beginners often write, which creates a mismat...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def elementwise_product(array1: List[int], array2: List[int]) -> List[int]: """ Compute the product of corresponding elements from two given arrays. Args: array1 (List[int]): The first array...
magic_evol_110k
84,645
Write a Python function to generate unique external identifiers for a given list of product records based on their categories. Each product record has a unique ID and belongs to a category. The function should ensure that the generated identifiers are unique and follow a specific format. The format for the identifier i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def generate_unique_identifiers(products: List[Dict[str, str]], category: str = 'nuts') -> List[str]: """ Generates unique external identifiers for product records belonging to a specified category...
magic_evol_110k
84,682
Write a Python function to rotate the elements of a given list to the right by a specified number of steps. The rotation should be done in-place, meaning the original list should be modified. The function should handle cases where the number of steps is greater than the length of the list by taking the modulo of the st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def rotate_right_in_place(array: List[int], steps: int) -> None: """ Rotates the elements of the given list to the right by the specified number of steps in-place. Args: array (List[int]): T...
magic_evol_110k
84,698
Write a Python function to create a deep copy of a given list. The function should handle nested lists and ensure that the copied list is completely independent of the original list. The code should start with: ```python from typing import List import copy def deep_copy_list(original_list: List) -> List: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import copy def deep_copy_list(original_list: List) -> List: """ Creates a deep copy of the given list, including all nested lists. Args: original_list (List): The list to be deep copied. ...
magic_evol_110k
84,700
Write a Python function to calculate a more complex operation involving three parameters: `x`, `y`, and `z`. The function should first compute the sum of `x` and `y`, then divide this sum by `z`, and finally round up the division result to the nearest integer. The function should handle cases where `z` is zero by retur...
Here is the Python code to solve the given problem in the markdown block: ```python import math def calculate_complicated_sum(x: int, y: int, z: int) -> int: """ Calculate the sum of x and y, divide it by z, and round up the division result to the nearest integer. Args: x (int): The first integer....
magic_evol_110k
84,704
Write a Python function to create a regular expression pattern that matches strings consisting solely of uppercase English alphabets and numerical digits. The function should return the correct pattern and demonstrate its functionality by checking if a given string matches the pattern. The code should start with: ```py...
Here is the Python code to solve the given problem in the markdown block: ```python import re def create_regex_pattern() -> str: """ Creates a regular expression pattern that matches strings consisting solely of uppercase English alphabets and numerical digits. Returns: str: The regular expre...
magic_evol_110k
84,708
Write a Python function that initializes multiple variables of different data types (integer, string, list, dictionary, tuple) and returns a dictionary where the keys are the variable names and the values are the corresponding data types. The integer variable should have a value of 15. The function should also handle p...
Here is the Python code to solve the given problem in the markdown block: ```python def get_variable_types() -> dict: """ Initializes multiple variables of different data types and returns a dictionary where the keys are the variable names and the values are the corresponding data types. The integer var...
magic_evol_110k
84,722
Write a Python function that accepts two dictionaries as input. The first dictionary contains string keys and string values, and the second one contains string keys and lists of strings as values. The function should replace all instances of the string keys in the first dictionary with their corresponding lists of stri...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Union def replace_strings_with_lists(dict1: Dict[str, str], dict2: Dict[str, List[str]]) -> Dict[str, Union[str, List[str]]]: """ Replace string values in the first dictionary with lists of string...
magic_evol_110k
84,732
Write a Python function to multiply each element in a given list of integers by 2 efficiently. The list can contain up to \(10^6\) elements. The function should use a lambda function and list comprehension to achieve this. The code should start with: ```python from typing import List def multiply_array_by_2(array: Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def multiply_array_by_2(array: List[int]) -> List[int]: """ Multiplies each element in the given list of integers by 2. Args: array (List[int]): The list of integers to be multiplied. R...
magic_evol_110k
84,734
Write a Python function to split a given colloquial expression into an assortment of individual words. The function should handle expressions with varying punctuation and spacing. The code should start with: ```python from typing import List def split_expression(expression: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def split_expression(expression: str) -> List[str]: """ Splits a given colloquial expression into an assortment of individual words. Args: expression (str): The colloquial expression to be s...
magic_evol_110k
84,739
Write a Python function to perform element-wise modulo operation on two lists of tuples. The function should handle various error cases such as: - Lists of different lengths. - Tuples of different lengths. - Non-tuple elements in the lists. - Non-integer elements in the tuples. - Division by zero. The function should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Union def element_wise_modulo(list1: List[Tuple[int, ...]], list2: List[Tuple[int, ...]]) -> Union[List[Tuple[int, ...]], str]: """ Perform element-wise modulo operation on two lists of tuples. ...
magic_evol_110k
84,742
Write a Python function to remove all strings from a given list that contain a specified pattern, regardless of the case (case-insensitive). The function should return a new list with the filtered strings. The code should start with: ```python from typing import List def remove_strings_with_pattern(array: List[str], ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_strings_with_pattern(array: List[str], pattern: str) -> List[str]: """ Removes all strings from the given list that contain the specified pattern, regardless of case. Args: array ...
magic_evol_110k
84,746
Write a Python function to determine the interaction type between two users based on a given interaction dictionary. The function should return a string indicating the type of interaction (e.g., "like", "block", "follow", "unfollow") and the direction of the interaction (e.g., "user_1 likes user_2", "user_2 blocks user...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def determine_interaction(interaction: Dict[str, str]) -> str: """ Determines the type and direction of the interaction between two users. Args: interaction (Dict[str, str]): A dictionary co...
magic_evol_110k
84,753
Write a Python function to generate a random number within a specified range. The function should take two parameters: `start` (the lower bound of the range, inclusive) and `end` (the upper bound of the range, inclusive). The function should return a random integer within this range. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python import random def generate_random_number(start: int, end: int) -> int: """ Generates a random integer within the specified range [start, end]. Args: start (int): The lower bound of the range (inclusive). en...
magic_evol_110k
84,792
Write a Python function to perform a binary search in a sorted list of integers to find the starting and ending indexes of all occurrences of a target value. If the target value is not found, the function should return a message stating "The target value is not found in the list". The function should achieve O(log n) t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Union def find_target_range(mylist: List[int], target: int) -> Union[Tuple[int, int], str]: """ Perform a binary search to find the starting and ending indexes of all occurrences of a target valu...
magic_evol_110k
84,793
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 handle edge cases such as a 0x0 grid or a grid with only one row or column. The code should start with: ```python from typing ...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def 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
84,796
Write a Python function to initialize a 2D array (matrix) with given dimensions and initial values. The function should take the number of rows, number of columns, and an initial value as inputs, and return the initialized 2D array. The code should start with: ```python from typing import List def initialize_2d_array(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def initialize_2d_array(rows: int, cols: int, initial_value: int) -> List[List[int]]: """ Initializes a 2D array (matrix) with the given number of rows and columns, and sets each element to the initial v...
magic_evol_110k
84,803
Write a Python function to reverse the elements of a given list without using any built-in functions or methods that directly reverse a list. The function should start with: ```python from typing import List def reverse_list(nums: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_list(nums: List[int]) -> List[int]: """ Reverses the elements of a given list without using any built-in functions or methods. Args: nums (List[int]): The list of integers to be ...
magic_evol_110k
84,811
Write a Python function that checks if two sentences have the same set of words with identical frequencies, while ignoring case sensitivity and word duplicity. The function should return `True` if the two sentences have the same words with the same frequencies, and `False` otherwise. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python def verify_same_word_sets_freqs(phrase1: str, phrase2: str) -> bool: """ Confirm if two phrases share exactly the same words with identical frequencies, regardless of word duplicity and case sensitivity. Args: phras...
magic_evol_110k
84,834
Write a Python function to create and populate a dictionary with exactly five key-value pairs, where each key represents a type of vehicle and each value represents a brand associated with that vehicle type. The function should return the populated dictionary. The code should start with: ```python from typing import D...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def create_vehicle_dictionary() -> Dict[str, str]: """ Creates and populates a dictionary with exactly five key-value pairs, where each key represents a type of vehicle and each value represents ...
magic_evol_110k
84,843
Write a Python function to generate a list of prime numbers that are less than or equal to a given number `n`. The function should efficiently determine whether each number in the range is prime and collect all prime numbers into a list. The code should start with: ```python from typing import List def generate_prime...
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(n: int) -> List[int]: """ Generate a list of prime numbers that are less than or equal to the given number n. Args: n (int): The upper limit for generating prime ...
magic_evol_110k
84,877
Write a Python function to find the longest common subsequence (LCS) among four given strings. The function should handle special characters, numerical values, Unicode characters, and emojis. It should also be optimized to have a time complexity better than O(n^3). Additionally, the function should handle erroneous inp...
Here is the Python code to solve the given problem in the markdown block: ```python def longest_common_subsequence(s1: str, s2: str, s3: str, s4: str) -> int: """ Find the length of the longest common subsequence among four given strings. Args: s1 (str): The first string. s2 (str): The seco...
magic_evol_110k
84,880
Write a Python function to count the number of even and odd digits in a given integer, regardless of whether the integer is positive or negative. The function should return a tuple containing the counts of even and odd digits. The code should start with: ```python def even_odd_count(num: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def even_odd_count(num: int) -> tuple: """ Counts the number of even and odd digits in a given integer. Args: num (int): The integer to analyze. Returns: tuple: A tuple containing the count of even digi...
magic_evol_110k
84,883
Write a Python function to detect and list all collisions between vehicles on a linear highway. Each vehicle is represented by its starting position and time to reach the center of the highway. The function should return a list of tuples, each containing the collision time, the index of the leftward-moving vehicle, and...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def car_race_collision(n: int, left_cars: List[Tuple[float, float]], right_cars: List[Tuple[float, float]]) -> List[Tuple[float, int, int]]: """ Detect and list all collisions between vehicles on ...
magic_evol_110k
84,885
Write a Python function to convert a given duration in milliseconds into hours, with control over the decimal precision. The function should allow the user to specify the number of decimal places to round the result to. The code should start with: ```python def convert_milliseconds_to_hours(milliseconds: int, decimal_...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_milliseconds_to_hours(milliseconds: int, decimal_places: int = 3) -> float: """ Converts a given duration in milliseconds to hours, with control over the decimal precision. Args: milliseconds (int): The ...
magic_evol_110k
84,896
Write a Python function to convert a list of numerical ASCII codes into their corresponding characters and return the concatenated string. The function should handle a list of integers where each integer represents an ASCII code. The code should start with: ```python from typing import List def convert_ascii_codes_to...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_ascii_codes_to_string(codes: List[int]) -> str: """ Converts a list of numerical ASCII codes into their corresponding characters and returns the concatenated string. Args: codes ...
magic_evol_110k
84,901
Write a Python function to verify the primality of a given integer, returning `True` for prime numbers and `False` otherwise. The function should be optimized for efficiency, especially for larger numbers. 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: """ Verifies the primality of a given integer. Args: n (int): The integer to check for primality. Returns: bool: True if the integer is prime, False otherwise. """ ...
magic_evol_110k
84,905
Write a Python function to process a 2D array of size N (where N <= 10) and return a list of unique numbers sorted in descending order. The function should handle any 2D array input and ensure that the output is a list of unique numbers in descending order. 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 process_2d_array(arr: List[List[int]]) -> List[int]: """ Processes a 2D array of size N (where N <= 10) and returns a list of unique numbers sorted in descending order. Args: arr (List[L...
magic_evol_110k
84,914
Write a Python function to generate the Fibonacci sequence up to the nth term. The function should handle invalid inputs by raising appropriate exceptions. The code should start with: ```python from typing import List def generate_fibonacci_sequence(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_fibonacci_sequence(n: int) -> List[int]: """ Generate the Fibonacci sequence up to the nth term. Args: n (int): The number of terms in the Fibonacci sequence to generate. R...
magic_evol_110k
84,916
Write a Python function that accepts two lists as input and returns a new list with the element-wise product of the input lists. Additionally, the function should return the sum of the elements in the product list. If the input lists are not of the same size, the function should return a message indicating that the lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def elementwise_product_and_sum(lst1: List[int], lst2: List[int]) -> Tuple[List[int], int] or str: """ Computes the element-wise product of two lists and the sum of the resulting product list. ...
magic_evol_110k
84,921
Write a Python function to perform a shallow copy of a dictionary. The function should take a dictionary as input and return a new dictionary that is a shallow copy of the input dictionary. The shallow copy should duplicate the dictionary itself, but the values within the dictionary should remain references to the same...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def shallow_copy_dict(original_dict: Dict) -> Dict: """ Creates a shallow copy of the given dictionary. Args: original_dict (Dict): The original dictionary to be copied. Returns: ...
magic_evol_110k
84,933
Write a Python function to implement the XOR cipher methodology for encrypting and decrypting textual messages. The function should adhere to the following requirements: 1. Accept only 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' as a valid key. For any other key, raise a `ValueError` with an appropriate error message. 2. Handle not o...
Here is the Python code to solve the given problem in the markdown block: ```python def xor_encrypt(text: str, key: str) -> str: """ Encrypts the given text using the XOR cipher with the provided key. Args: text (str): The text to be encrypted. key (str): The encryption key, which must be '...
magic_evol_110k
84,939
Write a Python function to calculate the product of all numbers in a given list. The function should handle exceptions for empty lists and non-numeric values. If the list is empty, return a specific error message. If the list contains non-numeric values, return a different specific error message. The function should st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def product_of_list(lst: List[Union[int, float]]) -> Union[int, float, str]: """ Calculate the product of all numbers in a given list. Args: lst (List[Union[int, float]]): The list of...
magic_evol_110k
84,948
Write a Python function to generate all prime numbers between 1 and a given number `n` using an optimized algorithm, and then calculate and return the sum of these prime numbers. The function should be efficient in terms of both time and space complexity. The code should start with: ```python def generate_and_sum_prim...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_and_sum_primes(n: int) -> int: """ Generate all prime numbers up to a given number n using the Sieve of Eratosthenes algorithm, and return the sum of these prime numbers. Args: n (int): The upper li...
magic_evol_110k
84,958
Write a Python function to calculate the length of a given string excluding whitespace and punctuation marks. The string may contain lowercase letters, whitespace, and punctuation marks. The function should return the length of the string after removing all non-alphabetic characters. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python def length_of_string_excluding_non_alpha(s: str) -> int: """ Calculate the length of a string excluding whitespace and punctuation marks. Args: s (str): The input string which may contain lowercase letters, whitespa...
magic_evol_110k
84,981
Write a Python function to add two numbers represented by linked lists. Each node in the linked list contains a single digit, and the digits are stored in reverse order. The function should return the sum as a linked list in the same reverse order format. The starter code should include the `ListNode` class definition...
Here is the Python code to solve the given problem in the markdown block: ```python class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def add_two_numbers(l1: ListNode, l2: ListNode) -> ListNode: """ Adds two numbers represented by linked lists and returns...
magic_evol_110k
85,019
Write a Python function to convert a hexadecimal string into its corresponding ASCII string. The function should handle hexadecimal strings of even length and return the decoded ASCII string. If the input hexadecimal string is of odd length, the function should raise a `ValueError`. The code should start with: ```pyth...
Here is the Python code to solve the given problem in the markdown block: ```python def hex_to_ascii(hex_str: str) -> str: """ Converts a hexadecimal string into its corresponding ASCII string. Args: hex_str (str): The hexadecimal string to be converted. Must be of even length. Returns: ...
magic_evol_110k
85,024
Write a Python function to print all prime numbers between 0 and 25 that are situated at prime indexes. The function should use nested loops to iterate through the range and check for prime numbers and prime indexes. The code should start with: ```python def print_primes_at_prime_indexes(): ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n): """ 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 <= 1: return False if n == ...
magic_evol_110k
85,038
Write a Python function to identify the first and last occurrence of a given string within a list of strings. If the string is not found in the list, both the first and last occurrence indices should be returned as -1. The function should be efficient and handle edge cases such as an empty list or a string that does no...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_occurrences(lst: List[str], target: str) -> List[int]: """ Identifies the first and last occurrence of a given string within a list of strings. Args: lst (List[str]): The list of st...
magic_evol_110k
85,045
Write a Python function to reverse each sub-array in a given two-dimensional array, and then reverse the entire two-dimensional array. The function should return the modified two-dimensional array. The code should start with: ```python from typing import List def reverse_2d_array(array: List[List[int]]) -> List[List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_2d_array(array: List[List[int]]) -> List[List[int]]: """ Reverses each sub-array in a given two-dimensional array and then reverses the entire two-dimensional array. Args: array ...
magic_evol_110k
85,054
Write a Python function to generate a list of multiples of a given number `k` within a specified range `[start, end]`. The function should return a list of these multiples. The code should start with: ```python from typing import List def multiples_in_range(k: int, start: int, end: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def multiples_in_range(k: int, start: int, end: int) -> List[int]: """ Returns a list of multiples of `k` within the specified range `[start, end]`. Args: k (int): The number whose multiples...
magic_evol_110k
85,076
Write a Python function to find all prime numbers less than a given integer `n` efficiently using the Sieve of Eratosthenes algorithm. The function should return a list of all prime numbers less than `n`. The code should start with: ```python from typing import List def primes_less_than(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def primes_less_than(n: int) -> List[int]: """ Returns a list of all prime numbers less than the given integer n using the Sieve of Eratosthenes algorithm. Args: n (int): The upper limit to ...
magic_evol_110k
85,082
Write a Python function to evaluate a mathematical expression given as a string. The function should handle basic arithmetic operations including addition, subtraction, multiplication, and division. The function should also handle parentheses to enforce the correct order of operations. The code should start with: ```py...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def evaluate_expression(expression: str) -> float: """ Evaluates a mathematical expression given as a string. Args: expression (str): The mathematical expression to evaluate. ...
magic_evol_110k
85,113
Write a Python function to calculate the nth Fibonacci number using an iterative approach. The function should return the nth Fibonacci number, where the Fibonacci sequence starts with 0 and 1. The code should start with: ```python def fibonacci(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci(n: int) -> int: """ Calculate the nth Fibonacci number using an iterative approach. Args: n (int): The position in the Fibonacci sequence to calculate. Returns: int: The nth Fibonacci numb...
magic_evol_110k
85,118
Write a Python function to rearrange the elements in a given list such that every prime number is followed by the next non-prime number. If the number of primes is greater than the number of non-primes, the remaining primes should be placed at the end of the list. Conversely, if the number of non-primes is greater than...
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.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 whil...
magic_evol_110k
85,129
Write a Python function to separate odd and even numbers from a given array and return a list of two different arrays. The even numbers should be sorted in ascending order, and the odd numbers should be sorted in descending order. The solution must be implemented using only one loop. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def separate_and_sort_numbers(arr: List[int]) -> List[List[int]]: """ Separates the odd and even numbers from the given array and returns them sorted. Even numbers are sorted in ascending order, and ...
magic_evol_110k
85,141
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. It can be in uppercase or lowercase. Retu...
magic_evol_110k
85,150
Write a Python function to validate if a given string is a valid IP address and classify it into one of the following categories: Class A, B, C, D, or E for IPv4 addresses, and IPv6 for IPv6 addresses. The function should handle both IPv4 and IPv6 addresses. The code should start with: ```python def validate_and_classi...
Here is the Python code to solve the given problem in the markdown block: ```python import socket def validate_and_classify_ip_address(ip: str) -> str: """ Validates if a given string is a valid IP address and classifies it into one of the following categories: Class A, B, C, D, or E for IPv4 addresses, an...
magic_evol_110k
85,165
Write a Python function that determines whether a given number is even or odd and checks if it is a prime number. The function should return a tuple with the first element indicating whether the number is 'Even' or 'Odd' and the second element indicating whether the number is 'Prime' or 'Not Prime'. The code should st...
Here is the Python code to solve the given problem in the markdown block: ```python def check_number_properties(n: int) -> tuple: """ Determines whether a given number is even or odd and checks if it is a prime number. Args: n (int): The number to be checked. Returns: tuple: A tuple wi...
magic_evol_110k
85,170
Write a Python function to dynamically adjust the font size of a message based on its color. If the color is 'red', the font size should increase by 20%. The function should validate the input parameters and return the adjusted font size. The code should start with: ```python def adjust_font_size(message: str, color: ...
Here is the Python code to solve the given problem in the markdown block: ```python def adjust_font_size(message: str, color: str, font_size: int) -> int: """ Adjusts the font size of a message based on its color. If the color is 'red', the font size increases by 20%. Args: message (str): The messa...
magic_evol_110k
85,172
Write a Python function to calculate the cumulative count of characters in a given string. The function should return a dictionary where the keys are characters from the string and the values are the counts of those characters. The code should start with: ```python from typing import Dict def cumulative_character_cou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def cumulative_character_count(string: str) -> Dict[str, int]: """ Calculate the cumulative count of characters in a given string. Args: string (str): The input string for which to calculate...
magic_evol_110k
85,174
Write a Python function to create a dictionary where the keys are the individual characters from a given phrase, and the values are the ASCII values of those characters. The function should handle any string input, including spaces, punctuation, and special characters. The code should start with: ```python def create_a...
Here is the Python code to solve the given problem in the markdown block: ```python def create_ascii_dict(phrase: str) -> dict: """ Creates a dictionary where the keys are the individual characters from the given phrase, and the values are the ASCII values of those characters. Args: phrase (str...
magic_evol_110k
85,180
Write a Python function to convert a given binary number represented as a string to its decimal (base-10) equivalent. The function should handle binary numbers of any length and should return the decimal value as an integer. The code should start with: ```python def binary_to_decimal(binary: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def binary_to_decimal(binary: str) -> int: """ Converts a given binary number represented as a string to its decimal (base-10) equivalent. Args: binary (str): The binary number to be converted, represented as a stri...
magic_evol_110k
85,195
Write a Python function to flatten a nested list of integers, strings, and other nested lists, while removing any duplicate elements, and preserving the order of the elements. The function should be scalable and performance-efficient, considering potential growth and increased data volume. The code should start with: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def flatten_and_uniq(arr: List[Any]) -> List[Any]: """ Flattens a nested list of integers, strings, and other nested lists, removes any duplicate elements, and preserves the order of the element...
magic_evol_110k
85,202
Write a Python function to find the median of two sorted sequences efficiently without merging them. The function should handle both even and odd lengths of the combined sequences. The code should start with: ```python from typing import List def find_median_of_two_sorted_sequences(sequence1: List[int], sequence2: Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_median_of_two_sorted_sequences(sequence1: List[int], sequence2: List[int]) -> float: """ Find the median of two sorted sequences efficiently without merging them. Args: sequence1 (L...
magic_evol_110k
85,207
Write a Python function to calculate the mean value of a collection of integers. The function should handle any discrepancies in the input collection, such as non-integer values or missing elements, and ensure the collection size is not predetermined and could contain up to 1,000,000 elements. The mean should be return...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def calculate_mean(collection: List[Union[int, float]]) -> float: """ Calculate the mean value of a collection of integers, handling discrepancies such as non-integer values or missing elements. ...
magic_evol_110k
85,215
Write a Python function to calculate the arithmetic average of a list of ages. The function should handle any list of integers representing ages and return the average as a float. The code should start with: ```python from typing import List def calculate_average_age(ages: List[int]) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_average_age(ages: List[int]) -> float: """ Calculate the arithmetic average of a list of ages. Args: ages (List[int]): A list of integers representing the ages. Returns: ...
magic_evol_110k
85,217
Write a Python function to process a list of numbers according to the following rules: 1. Sort the list in descending order. 2. Filter out the positive numbers greater than 2. 3. Calculate the sum of these filtered positive numbers. 4. If the sum exceeds 100, return an empty list. Otherwise, return the filtered list of...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_positive_numbers(numbers: List[float]) -> List[float]: """ Processes a list of numbers according to the following rules: 1. Sort the list in descending order. 2. Filter out the positive n...
magic_evol_110k
85,256
Write a Python function to reverse a given string. The function should take a string as input and return the reversed string. The function should handle any string, including empty strings and strings with special characters. The code should start with: ```python def reverse_string(input_str: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(input_str: str) -> str: """ Reverses the given string. Args: input_str (str): The string to be reversed. Returns: str: The reversed string. """ # Ensure the input is a string ...
magic_evol_110k
85,263
Write a Python function to manually sort an array in ascending numerical order using the Bubble Sort algorithm. Additionally, implement a validation function that checks if the array is sorted correctly. The validation function should return `True` if the array is sorted in ascending order, and `False` otherwise. The c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(array: List[int]) -> List[int]: """ Sorts the input array in ascending order using the Bubble Sort algorithm. Args: array: A list of integers to be sorted. Returns: ...
magic_evol_110k
85,271
Write a Python function to determine if a given string is a valid MongoDB ObjectId. A valid MongoDB ObjectId is a 24-character hexadecimal string. The function should return `True` if the string is a valid ObjectId, and `False` otherwise. The code should start with: ```python def is_valid_objectid(s: str) -> bool: ```...
Here is the Python code to solve the given problem in the markdown block: ```python def is_valid_objectid(s: str) -> bool: """ Determines if a given string is a valid MongoDB ObjectId. Args: s (str): The string to be checked. Returns: bool: True if the string is a valid MongoDB ObjectI...
magic_evol_110k
85,279
Write a Python function to categorize an array of hexadecimal numbers into three distinct categories: zeros, odd numbers, and even numbers. The function should return a dictionary with keys 'zeros', 'odds', and 'evens', each containing the corresponding hexadecimal numbers. 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, Dict def categorize_hex_numbers(hex_list: List[int]) -> Dict[str, List[int]]: """ Categorizes an array of hexadecimal numbers into zeros, odd numbers, and even numbers. Args: hex_list (List...
magic_evol_110k
85,300
Write a Python function to create and populate a one-dimensional array (list) with sequential integer values in a monotonically ascending sequence starting from 1 and ending at a specified number `n`. The function should ensure that the array can hold exactly `n` elements. The code should start with: ```python from ty...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def create_sequential_array(n: int) -> List[int]: """ Creates and populates a one-dimensional array with sequential integer values from 1 to n. Args: n (int): The upper limit of the sequence...
magic_evol_110k
85,302
Write a Python function to generate a list of prime numbers between two given numbers \( A \) and \( B \) (both inclusive) using the Sieve of Eratosthenes algorithm. The function should be optimized for performance and should handle large values of \( A \) and \( B \). The code should start with: ```python from typing...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_primes_between(A: int, B: int) -> List[int]: """ Generate a list of prime numbers between two given numbers A and B (both inclusive) using the Sieve of Eratosthenes algorithm. Args:...
magic_evol_110k
85,310
Write a Python function to sort a multidimensional list using the merge sort algorithm. Each sublist in the multidimensional list should be sorted individually, and the function should return the sorted multidimensional list. The function should handle lists of varying dimensions and lengths. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_multi_dimensional_list(multi_list: List[List[int]]) -> List[List[int]]: """ Sorts each sublist in a multidimensional list using the merge sort algorithm. Args: multi_list (List[List...
magic_evol_110k
85,332
Write a Python function to perform integer division of two integers, `X` and `Y`, where `X` is always greater than `Y`. The function should handle the case where `Y` is zero by returning an error message. The function should be implemented using a lambda function. The code should start with: ```python def integer_divi...
Here is the Python code to solve the given problem in the markdown block: ```python def integer_division(X: int, Y: int) -> int or str: """ Perform integer division of X by Y, with error handling for division by zero. Args: X (int): The dividend, always greater than Y. Y (int): The divisor....
magic_evol_110k
85,371
Write a Python function to determine if a given input is divisible by both 5 and 8. The function should handle both numerical values and strings that can be converted to numerical values. If the input is a string that cannot be converted to a number, the function should return `False`. The function should be optimized ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_5_and_8(x): """ Determines if a given input is divisible by both 5 and 8. Args: x (int or str): The input to be checked. If it's a string, it should be convertible to an integer. Returns: ...
magic_evol_110k
85,400
Write a Python function to group a list of numbers into even and odd numbers. The function should return two lists: one containing all even numbers and the other containing all odd numbers. The code should start with: ```python from typing import List, Tuple def group_even_odd(numbers: List[int]) -> Tuple[List[int], L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def group_even_odd(numbers: List[int]) -> Tuple[List[int], List[int]]: """ Groups a list of numbers into even and odd numbers. Args: numbers (List[int]): A list of integers to be grou...
magic_evol_110k
85,404
Write a Python function to determine if two given integers are equal or not. The function should return `True` if the integers are equal, and `False` otherwise. The function should handle invalid inputs gracefully by returning `None` for non-integer inputs. The code should start with: ```python def are_integers_equal(...
Here is the Python code to solve the given problem in the markdown block: ```python def are_integers_equal(a: int, b: int) -> bool: """ Determines if two given integers are equal. Args: a (int): The first integer to compare. b (int): The second integer to compare. Returns: bool...
magic_evol_110k
85,419
Write a Python function to find the k largest elements from a given dataset efficiently. The dataset is a list of integers. The function should return a list of the k largest elements in descending order. The code should start with: ```python from typing import List def get_k_largest_items(dataset: List[int], k: int) ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import heapq def get_k_largest_items(dataset: List[int], k: int) -> List[int]: """ Returns the k largest items from the given dataset in descending order. Args: dataset (list): The dataset f...
magic_evol_110k
85,428
Write a Python function to determine whether the provided input is a boolean value or an array data structure. The function should handle various types of inputs, including nested arrays, and return a string indicating the type of the input. If the input is neither a boolean nor an array, the function should return "Un...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Union, List, Any def determine_type(input_data: Union[bool, List[Any]]) -> str: """ Determine whether the provided input is a boolean value or an array data structure. Args: input_data (Union[boo...
magic_evol_110k
85,437
Write a Python function to determine if a given integer `n` can be represented as the sum of distinct powers of three and two. The powers of three and two used in the sum must be distinct, meaning you cannot use the same power of three or two more than once. The code should start with: ```python def can_represent_as_s...
Here is the Python code to solve the given problem in the markdown block: ```python def can_represent_as_sum_of_powers(n: int) -> bool: """ Determine if a given integer `n` can be represented as the sum of distinct powers of three and two. Args: n (int): The integer to check. Returns: ...
magic_evol_110k
85,440
Write a Python function to calculate the sum of the squares of the elements in a given list of integers. The function should handle lists of any length, including empty lists. The code should start with: ```python from typing import List def sum_of_squares(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_squares(arr: List[int]) -> int: """ Calculate the sum of the squares of the elements in a given list of integers. Args: arr (List[int]): The list of integers for which to calculat...
magic_evol_110k
85,448
Write a Python function to determine the positional index of a given character within a predefined array of letters. The array "letters" is a list of lowercase English alphabet letters from 'a' to 'z'. The function should return the index of the specified character if it exists in the array, otherwise return -1. The c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_character_index(letters: List[str], character: str) -> int: """ Determine the positional index of a given character within a predefined array of letters. Args: letters (List[str]): ...
magic_evol_110k
85,468
Write a Python function to compute the product of all elements in a given list of integers. The function should handle lists of any size, including empty lists. If the list is empty, the function should return 1 as the product. The code should start with: ```python from typing import List def product_of_elements(arr: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def product_of_elements(arr: List[int]) -> int: """ Compute the product of all elements in a given list of integers. Args: arr (List[int]): The list of integers whose product is to be comput...
magic_evol_110k
85,470
Write a Python function to analyze multiple alphanumeric sequences and identify all distinct alphabetical elements present in these sequences. The function should also count the frequencies of each distinct alphabetical element and track their locations/indices in the sequences. The function should return a dictionary ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple def analyze_sequences(sequences: List[str]) -> Dict[str, Dict[str, int or List[Tuple[int, int]]]]: """ Analyze multiple alphanumeric sequences to identify all distinct alphabetical elements,...
magic_evol_110k
85,474
Write a Python function to find the statistical mode of a given dataset. The dataset is a list of integers. The mode is the number that appears most frequently in the dataset. If there are multiple numbers with the same highest frequency, return the smallest number among them. 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 from collections import defaultdict def find_mode(dataset: List[int]) -> int: """ Find the statistical mode of a given dataset. The mode is the number that appears most frequently. If there are multi...
magic_evol_110k
85,477
Write a Python function to convert a time string in the format "hh:mm:ss" to the equivalent time in seconds. The function should handle input validation to ensure the time string is in the correct format and that the values for hours, minutes, and seconds are within their respective valid ranges. The code should start...
Here is the Python code to solve the given problem in the markdown block: ```python import re def time_string_to_seconds(time_string: str) -> int: """ Converts a time string in the format "hh:mm:ss" to the equivalent time in seconds. Args: time_string (str): The time string to convert, in the form...
magic_evol_110k
85,498
Write a Python function to compute the nth Fibonacci number using an iterative approach. The function should efficiently calculate the Fibonacci number by storing intermediate results in a list to avoid redundant calculations, which is a common technique in dynamic programming. The code should start with: ```python de...
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci(n: int) -> int: """ Compute the nth Fibonacci number using an iterative approach. Args: n (int): The position in the Fibonacci sequence to compute. Returns: int: The nth Fibonacci number. ...
magic_evol_110k
85,505
Write a Python function to count the total number of characters in a given string, including spaces, punctuation, and special characters. Additionally, the function should return the frequency of each character in the string. The function should be case-sensitive, meaning 'H' and 'h' should be considered as different c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Dict def character_count_and_frequency(s: str) -> Tuple[int, Dict[str, int]]: """ Counts the total number of characters in the given string and returns the frequency of each character. Args: ...
magic_evol_110k
85,509
Write a Python function to add a new item at a specific index in a list. The function should handle potential errors such as when an invalid index is given. The function should return the modified list if the insertion is successful, or `None` if the index is out of range. The code should start with: ```python from ty...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def add_item_at_index(item_list: List[str], index: int, item: str) -> Optional[List[str]]: """ Adds a new item at a specific index in the list. If the index is out of range, prints an error mes...
magic_evol_110k
85,514
Write a Python function to construct a URL based on the given dictionary of URL components. The dictionary contains keys for the protocol, subdomain, primary domain, and path. The function should return the constructed URL as a string. The code should start with: ```python from typing import Dict def construct_url(ur...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def construct_url(url_parts: Dict[str, str]) -> str: """ Constructs a URL from the given dictionary of URL components. Args: url_parts (Dict[str, str]): A dictionary containing the following...
magic_evol_110k
85,524
Write a Python function to find the first available unique order ID from a list of open trades. The function should loop through a predefined set of order IDs (from 1 to 5) and check if each ID is already in use in the list of open trades. If an ID is not in use, it should be returned as the available ID. The function ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_available_order_id(open_trades: List[int]) -> Optional[int]: """ Finds the first available unique order ID from a predefined set of IDs (1 to 5) that is not in the list of open trades....
magic_evol_110k
85,549
Write a Python function to determine the time complexity of a linear search algorithm in terms of Big O notation. The function should analyze the given linear search function and return the Big O notation as a string. The code should start with: ```python def linear_search_time_complexity() -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def linear_search_time_complexity() -> str: """ Determines the time complexity of the linear search algorithm in terms of Big O notation. Returns: str: The Big O notation representing the time complexity of the line...
magic_evol_110k
85,562
Write a Python function to create a 2-dimensional array from a given sequence of integers, ensuring that the sequence is filled row by row. The function should take the sequence of integers, the number of rows, and the number of columns as inputs and return the 2-dimensional array. 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 def create_2d_array(numbers: List[int], rows: int, cols: int) -> List[List[int]]: """ Creates a 2-dimensional array from a given sequence of integers, filled row by row. Args: numbers (List[...
magic_evol_110k
85,572
Create a Python function that converts a dictionary with keys in snake_case to a dictionary with keys in camelCase. The function should handle nested dictionaries and lists of dictionaries as well. The code should start with: ```python from typing import Any, Dict, List, Union def convert_snake_to_camel_case(data: Un...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Dict, List, Union def convert_snake_to_camel_case(data: Union[Dict[str, Any], List[Dict[str, Any]]]) -> Union[Dict[str, Any], List[Dict[str, Any]]]: """ Converts a dictionary or a list of dictionaries wi...
magic_evol_110k
85,598
Write a Python function to filter an array of objects based on the following criteria: 1. Extract only those objects which have the property `type` as `'string'`. 2. From the extracted objects, pick out only those objects with the property `value` greater than 5. 3. From the resulting objects, identify those whose `val...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def triple_filter(data: List[Dict[str, any]]) -> List[Dict[str, any]]: """ Filters an array of objects based on the following criteria: 1. Extract only those objects which have the property 'ty...
magic_evol_110k
85,601
Write a Python function to determine if two dictionaries are equal in terms of both keys and values, regardless of the order in which the key-value pairs were inserted. The function should return a boolean value (`True` if the dictionaries are equal, `False` otherwise). The code should start with: ```python from typin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def are_dictionaries_equal(dict1: Dict, dict2: Dict) -> bool: """ Determines if two dictionaries are equal in terms of both keys and values, regardless of the order of insertion. Args: dict1...
magic_evol_110k
85,616
Write a Python function to find the intersection of two arrays, ensuring the result is sorted regardless of the input arrays' order. The function should be optimized for efficiency, even for larger array sizes. The code should start with: ```python from typing import List def sorted_intersection(arr1: List[int], arr2:...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sorted_intersection(arr1: List[int], arr2: List[int]) -> List[int]: """ Finds the intersection of two arrays and returns the result in sorted order. Args: arr1 (List[int]): The first arr...
magic_evol_110k
85,665
Write a Python function to find the second smallest numerical value from a given list of integers. The function should handle any nuances associated with repetition, negative values, or an unordered dataset. The code should start with: ```python from typing import List def find_second_smallest(numbers: List[int]) -> i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_second_smallest(numbers: List[int]) -> int: """ Find the second smallest numerical value from a given list of integers. Args: numbers (List[int]): A list of integers from which to f...
magic_evol_110k
85,717
Write a Python function to filter a dictionary based on a list of keys or values. The function should handle cases where some keys in the list might not be present in the dictionary and vice versa. Additionally, the function should allow filtering by either keys or values, with the method of filtering specified by an a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Union def filter_dictionary(dict_to_filter: Dict[str, str], keys_or_values: List[str], filter_by: str = 'keys') -> Dict[str, str]: """ Filters a dictionary based on a list of keys or values. ...
magic_evol_110k
85,727
Write a Python function to find the second smallest number in a given list of integers without using any built-in functions or sorting algorithms. Assume all numbers in the list are unique. The code should start with: ```python from typing import List def find_second_smallest(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_second_smallest(numbers: List[int]) -> int: """ Find the second smallest number in a list of unique integers without using any built-in functions or sorting algorithms. Args: number...
magic_evol_110k
85,731
Write a Python function to separate and alphabetize a predetermined list of book titles and author names represented as strings. The list alternates between book titles and author names. The function should return two lists: one sorted list of book titles and one sorted list of author names. 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 separate_and_sort_books_and_authors(list_of_strings: List[str]) -> (List[str], List[str]): """ Separates and alphabetizes a predetermined list of book titles and author names. Args: list...
magic_evol_110k
85,745
Write a Python function to accurately compute the sum of a list of numbers. The function should handle various edge cases, such as an empty list, a list with negative numbers, and a list with floating-point numbers. The function should also be able to handle lists with non-numeric elements, returning `None` in such cas...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def calculate_sum(numbers: List[Union[int, float]]) -> Union[int, float, None]: """ Calculate the sum of a list of numbers. Args: numbers (List[Union[int, float]]): A list of numbers ...