source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_evol_110k
99,039
Write a Python function to sort an array containing only 0s and 1s, such that all the 0s come before all the 1s. The function should use an efficient in-place sorting algorithm. The code should start with: ```python from typing import List def sort_binary_array(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 sort_binary_array(arr: List[int]) -> List[int]: """ Sorts an array containing only 0s and 1s such that all 0s come before all 1s. Args: arr (List[int]): The array to be sorted, containin...
magic_evol_110k
99,050
Write a Python function to enumerate and output the collection of arguments provided to it upon execution. The function should accept a variable number of arguments and return a list of tuples, where each tuple contains the index of the argument (starting from 1) and the argument itself. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def enumerate_arguments(*args) -> List[Tuple[int, any]]: """ Enumerates and outputs the collection of arguments provided to the function. Args: *args: A variable number of arguments. ...
magic_evol_110k
99,051
Write a Python function to determine if a given string `s` is "magic" or "mundane" based on the following criteria: 1. The string `s` must be a palindrome. 2. The string `s` must not contain any consecutive repeated characters. 3. The sum of the positions of each character in the alphabet (where 'a' is 1, 'b' is 2, ......
Here is the Python code to solve the given problem in the markdown block: ```python def magic_or_mundane(s: str, t: int) -> bool: """ Determine if a given string `s` is "magic" or "mundane" based on the following criteria: 1. The string `s` must be a palindrome. 2. The string `s` must not contain any co...
magic_evol_110k
99,059
Write a Python function to convert a given hexadecimal string to its corresponding decimal (base-10) value. 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 given hexadecimal string to its corresponding decimal (base-10) value. Args: hex_string (str): The hexadecimal string to be converted. It can contain charac...
magic_evol_110k
99,063
Create a Python function to encrypt and decrypt a given message using a simple Caesar cipher. The Caesar cipher shifts each letter in the message by a fixed number of positions in the alphabet. The function should handle both uppercase and lowercase letters, while leaving non-alphabetic characters unchanged. The code s...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher(message: str, shift: int, encrypt: bool) -> str: """ Encrypts or decrypts a message using the Caesar cipher. Args: message (str): The message to be encrypted or decrypted. shift (int): The ...
magic_evol_110k
99,070
Write a Python function to organize a dictionary of linguistic terms and their definitions into a new dictionary, where the terms are grouped by their first letters and sorted alphabetically within each group. The function should start with: ```python from typing import Dict, List, Tuple def organize_linguistic_terms(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def organize_linguistic_terms(words: Dict[str, str]) -> Dict[str, List[Tuple[str, str]]]: """ Organizes a dictionary of linguistic terms and their definitions into a new dictionary, wher...
magic_evol_110k
99,097
Write a Python function to generate a random number within a specified interval, ensuring that the number is uniformly distributed within the given range. The function should also allow for the option to generate a random integer instead of a floating-point number. The code should start with: ```python import random d...
Here is the Python code to solve the given problem in the markdown block: ```python import random def generate_random_number(lower_limit: float, upper_limit: float, is_integer: bool = False) -> float: """ Generates a random number within the specified interval. Args: lower_limit (float): The lower...
magic_evol_110k
99,125
Write a Python function to reverse a string while preserving the case sensitivity of each character. The function should not use any built-in functions or methods for string manipulation, except for basic operations like string concatenation. Additionally, the function should handle special characters and white spaces ...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string_preserve_case(input_string: str) -> str: """ Reverses the input string while preserving the case sensitivity of each character. Args: input_string (str): The string to be reversed. Returns: ...
magic_evol_110k
99,128
Write a Python function to calculate the average price of items in a list of dictionaries, where each dictionary contains the keys 'name' and 'price'. The function should handle cases where the list might be empty and return `None` in such cases. The function should also round the average price to two decimal places. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Optional def calculate_average_price(items: List[Dict[str, float]]) -> Optional[float]: """ Calculate the average price of items in a list of dictionaries. Args: items (List[Dict[str,...
magic_evol_110k
99,137
Write a Python function to merge two lists of the same length into a dictionary where one list acts as the keys and the other as the corresponding values. If the lists are of different lengths, the function should disregard the additional elements in the longer list. Additionally, the function should handle the edge ca...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def merge_lists_to_dict(keys: List[str], values: List[int]) -> Dict[str, int]: """ Merges two lists into a dictionary where the first list acts as the keys and the second list acts as the values. ...
magic_evol_110k
99,144
Write a Python function to process an input string by changing the case of each letter (upper to lower and vice versa) while keeping non-letter characters the same. If the input string contains no letters, reverse the string order before returning the result. The code should start with: ```python def solve(s: str) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python def solve(s: str) -> str: """ Processes the input string by changing the case of each letter (upper to lower and vice versa) while keeping non-letter characters the same. If there are no letters, reverse the string order ...
magic_evol_110k
99,155
Write a Python function to correctly calculate the area of a triangle given the length of a side and the corresponding height. The function should return the area using the correct formula. The code should start with: ```python def triangle_area(a: float, h: float) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def triangle_area(a: float, h: float) -> float: """ Calculate the area of a triangle given the length of a side (base) and the corresponding height. Args: a (float): The length of the side of the triangle (base). ...
magic_evol_110k
99,157
Write a Python function that removes the last element from a given list and returns the modified list. The function should use the `pop()` method to achieve this. The function should handle lists of any length, including empty lists. The code should start with: ```python from typing import List def remove_last_element...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_last_element(lst: List[any]) -> List[any]: """ Removes the last element from the given list and returns the modified list. Args: lst (List[any]): The list from which the last elem...
magic_evol_110k
99,164
Write a Python function to generate a social media post with a title, content, and a list of tags. The function should return a dictionary representing the post. The dictionary should have the following keys: 'title', 'content', and 'tags'. The 'tags' value should be a list of strings. The function should also validate...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional, Dict def create_social_media_post(title: str, content: str, tags: List[str]) -> Optional[Dict[str, object]]: """ Create a social media post with a title, content, and a list of tags. Args...
magic_evol_110k
99,180
Write a Python function to perform arithmetic operations on two given inputs, ensuring that the inputs are of compatible types before performing the operation. The function should handle addition, subtraction, multiplication, and division. If the inputs are not compatible for a given operation, the function should retu...
Here is the Python code to solve the given problem in the markdown block: ```python def perform_arithmetic_operations(x, y): """ Perform arithmetic operations on two given inputs, ensuring compatibility of types. Args: x (int or float or str): The first input. y (int or float or str): The s...
magic_evol_110k
99,182
Write a Python function to compute the number of non-repeating, distinct numerical elements present in both given arrays and return these distinct numbers in sorted order. The function should be efficient and minimize the time complexity. The code should start with: ```python from typing import List, Tuple def find_d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_distinct_elements(array1: List[int], array2: List[int]) -> Tuple[int, List[int]]: """ Computes the number of non-repeating, distinct numerical elements present in both given arrays an...
magic_evol_110k
99,187
Write a Python function to modify a given sorted list in place by doubling each element and ensuring the resulting list remains sorted. The function should not create a new list but modify the existing one directly. The code should start with: ```python from typing import List def double_and_sort_in_place(lst: List[i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import bisect def double_and_sort_in_place(lst: List[int]) -> None: """ Modifies the given sorted list in place by doubling each element and ensuring the resulting list remains sorted. Args: ...
magic_evol_110k
99,191
Write a Python function to create an array of length `n` that contains the numbers from `0` to `n-1` in random order. The function should ensure that the array is shuffled randomly each time it is called. The code should start with: ```python from typing import List import numpy as np def create_random_array(n: int) ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import numpy as np def create_random_array(n: int) -> List[int]: """ Creates an array of length n containing numbers from 0 to n-1 in random order. Args: n (int): The length of the array to ...
magic_evol_110k
99,192
Write a Python function to perform a binary XOR operation on three distinct strings comprised solely of '1's and '0's. The function should first XOR the first two strings and then XOR the result with the third string. The final result should be returned as a string. The code should start with: ```python from typing im...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def string_xor_advanced(a: str, b: str, c: str) -> str: """ Perform a binary XOR operation on three distinct strings comprised solely of '1's and '0's. The function first XORs the first two strings a...
magic_evol_110k
99,198
Write a Python function to reverse the characters in a given string without using Python's built-in slicing or any library functions that directly reverse strings. The function should use a loop to manually swap characters to achieve the reversed order. The code should start with: ```python def reverse_string(s: str) ...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses the characters in a given string without using built-in slicing or library functions. Args: s (str): The input string to be reversed. Returns: str: The re...
magic_evol_110k
99,201
Write a Python function to calculate the sum of all prime numbers in a given multidimensional array (matrix) of integers. The function should be able to handle matrices of any size and depth. The code should start with: ```python from typing import List def sum_of_primes_in_matrix(matrix: List[List[int]]) -> int: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a given number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise...
magic_evol_110k
99,214
Write a Python function to merge multiple dictionaries into a single dictionary. The function should take a variable number of dictionaries as input and return a new dictionary that contains all the key-value pairs from the input dictionaries. If there are duplicate keys, the value from the last dictionary in the input...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def merge_dictionaries(*dicts: Dict[str, Any]) -> Dict[str, Any]: """ Merge multiple dictionaries into a single dictionary. Args: *dicts: A variable number of dictionaries to be merged....
magic_evol_110k
99,215
Write a Python function to create a new list that contains only even numbers and is in reverse order of their appearance in the original list. The function should take a list of integers as input and return a new list of integers. The code should start with: ```python from typing import List def reverse_even_numbers(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_even_numbers(orig_list: List[int]) -> List[int]: """ Create a new list that contains only even numbers and is in reverse order of their appearance in the original list. Args: ori...
magic_evol_110k
99,244
Write a Python function to determine if a given integer is a prime number. The function should return `True` if the integer is prime and `False` otherwise. Enhance the function to include optimizations for better performance, such as checking divisibility only up to the square root of the number and skipping even numbe...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n: int) -> bool: """ Determines if a given integer is a prime number. Args: n (int): The integer to check for primality. Returns: bool: True if the integer is prime, False otherwise. ""...
magic_evol_110k
99,296
Write a Python function to determine if a given number is a prime number. The function should efficiently check for primality by leveraging mathematical properties of prime 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: """ Determines if a given number is a prime number. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. """ ...
magic_evol_110k
99,305
Write a Python function to swap the values of two variables using bitwise XOR operations. The function should take two integers as input and return a tuple containing the swapped values. The code should start with: ```python def swap_using_xor(a: int, b: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def swap_using_xor(a: int, b: int) -> tuple: """ Swaps the values of two integers using bitwise XOR operations. Args: a (int): The first integer. b (int): The second integer. Returns: tuple: A t...
magic_evol_110k
99,310
Write a Python function to reorganize an array of non-negative integers based on the length of their binary representations. The array should be sorted first by the length of the binary representation of each number, and if two numbers have the same binary length, they should be sorted by their decimal value. The funct...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_by_binary_length(arr: List[int]) -> List[int]: """ Reorganizes an array of non-negative integers based on the length of their binary representations. Numbers are sorted first by the length o...
magic_evol_110k
99,320
Write a Python function to detect and correct common indexing errors in a list. The function should take a list and an index as input, and return the corrected list. If the index is out of bounds, the function should append the value to the end of the list instead of attempting to assign it to an invalid index. The fun...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def correct_list_indexing(lst: List[int], index: int, value: int) -> List[int]: """ Corrects common indexing errors in a list by appending the value to the end of the list if the index is out of bounds. ...
magic_evol_110k
99,333
Write a Python function to filter out all numbers from a given list that are both even and prime. The function should return a new list containing only these numbers. The code should start with: ```python from typing import List def filter_even_prime_numbers(numbers: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. ...
magic_evol_110k
99,351
Write a Python function to calculate the product of all elements in a given matrix of numeric integers, considering the position, sequence, and potential duplication of elements. The function should handle matrices of any size, including empty matrices. The code should start with: ```python from typing import List de...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def matrix_product(matrix: List[List[int]]) -> int: """ Calculate the product of all elements in a given matrix of numeric integers. Args: matrix (List[List[int]]): A 2D list representing th...
magic_evol_110k
99,353
Write a Python function to count the frequency of each character in a multi-dimensional array. The function should return a dictionary where the keys are characters and the values are their respective counts. The multi-dimensional array can have varying dimensions, and the characters can be any valid string characters....
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_character_frequencies(multi_array: List[List[str]]) -> Dict[str, int]: """ Counts the frequency of each character in a multi-dimensional array. Args: multi_array (List[List[s...
magic_evol_110k
99,360
Write a Python function to merge two sorted arrays without using any additional memory or built-in functions for merging/sorting. The function should preserve the original arrays and return a new merged array sorted in ascending order. The code should start with: ```python from typing import List def merge_sorted_arra...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]: """ Merge two sorted arrays into a single sorted array without using additional memory or built-in functions. Args: ar...
magic_evol_110k
99,364
Write a Python function to generate the first `n` Fibonacci numbers. The function should return a list of the first `n` Fibonacci numbers. The code should start with: ```python from typing import List def generate_fibonacci(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(n: int) -> List[int]: """ Generate the first n Fibonacci numbers. Args: n (int): The number of Fibonacci numbers to generate. Returns: List[int]: A list...
magic_evol_110k
99,365
Write a Python function to find the k lowest even numbers from a given dataset efficiently. The dataset is a list of integers. The function should use an efficient sorting algorithm to achieve this. Additionally, provide a piece of faulty code where a simple sorting mechanism is incorrectly applied leading to wrong out...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import heapq def find_k_lowest_even_numbers(nums: List[int], k: int) -> List[int]: """ Finds the k lowest even numbers from the given dataset efficiently. Args: nums (List[int]): The dataset...
magic_evol_110k
99,376
Write a Python function to generate the first `n` terms of the Fibonacci sequence, where `n` is a positive integer. The function should return a list containing the first `n` terms of the Fibonacci sequence. If `n` is less than or equal to 0, the function should return an empty list. 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 generate_fibonacci(n: int) -> List[int]: """ Generate the first n terms of the Fibonacci sequence. Args: n (int): The number of terms to generate. Returns: List[int]: A list...
magic_evol_110k
99,382
Write a Python function to convert a given non-negative integer to its binary representation. The function should return the binary representation as a string. Additionally, identify and correct the issue in the given erroneous code. The code should start with: ```python def convert_to_binary(number: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_binary(number: int) -> str: """ Converts a non-negative integer to its binary representation. Args: number (int): The non-negative integer to convert. Returns: str: The binary representat...
magic_evol_110k
99,394
Write a Python function to interpret a given textual input and yield an array of lexemes. The function should handle various delimiters such as spaces, commas, and semicolons. Additionally, it should be able to handle multiple consecutive delimiters and ignore empty lexemes. The function should start with: ```python fr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def interpret_text(input_text: str) -> List[str]: """ Interpret the given textual input and yield an array of lexemes. The function handles various delimiters such as spaces, commas, and s...
magic_evol_110k
99,402
Write a Python function to transform a list of integers into a single string where each integer is represented as a string and separated by commas. The function should handle an empty list by returning an empty string. The code should start with: ```python from typing import List def integers_to_comma_separated_strin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def integers_to_comma_separated_string(integer_list: List[int]) -> str: """ Transforms a list of integers into a single string where each integer is represented as a string and separated by commas. ...
magic_evol_110k
99,409
Write a Python function to calculate the total sum of all the elements in a multidimensional list (i.e., a list of lists). The list may contain integers as well as string representations of integers. The function should handle these situations and should not crash due to unhandled exceptions. If a string cannot be pars...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calc_total(nested_list: List[List[str | int]]) -> int: """ Calculate the total sum of all elements in a multidimensional list. The list may contain integers as well as string representations of i...
magic_evol_110k
99,417
Write a Python function to generate an HTML hyperlink with optional attributes. The function should allow specifying the URL, the link text, and an optional parameter to open the link in a new tab. The function should return a string containing the HTML hyperlink. The code should start with: ```python def generate_hyp...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_hyperlink(url: str, text: str, new_tab: bool = False) -> str: """ Generates an HTML hyperlink with optional attributes. Args: url (str): The URL to which the hyperlink points. text (str): The te...
magic_evol_110k
99,431
Write a Python function to generate a two-dimensional array with random integers from 0 to 100. Each sub-array should have a random length between 1 and 10. The function should then calculate and print the sum of all elements in each sub-array, the total sum of all elements in the array, and identify and print the sub-...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random import numpy as np def analyze_2d_array(num_subarrays: int) -> None: """ Generates a two-dimensional array with random integers from 0 to 100. Each sub-array has a random length between...
magic_evol_110k
99,441
Write a Python function that accepts a list of fruit names and a list of priority categories. The function should return a single string containing the fruit names sorted by their respective priority first and then in alphabetical order within each priority group. Each fruit name will be paired with a priority category...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_fruits_by_priority(fruits: List[str], priorities: List[int]) -> str: """ Sorts a list of fruit names by their respective priority categories and then alphabetically within each priority group. ...
magic_evol_110k
99,448
Write a Python function to efficiently merge two pre-sorted lists into a single sorted list. The function should avoid using the built-in `sort()` method and instead use a two-pointer technique to achieve the merge. The code should start with: ```python from typing import List def merge_sorted_lists(lst1: List[int], l...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_lists(lst1: List[int], lst2: List[int]) -> List[int]: """ Merges two pre-sorted lists into a single sorted list using a two-pointer technique. Args: lst1 (List[int]): The fi...
magic_evol_110k
99,461
Write a Python function to process a list of items in a basket, distinguishing between fruits and non-fruit items, and apply a multiplier to the fruit quantities if the items were gathered on an odd day. The function should also validate the multiplier and ensure the total number of items does not exceed the given capa...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple def advanced_fruit_distribution(s: int, n: int, fruits: List[str], non_fruit_items: List[str], multiplier: float) -> Tuple[Dict[str, int], Dict[str, int]]: """ Process the basket items, dist...
magic_evol_110k
99,464
Write a Python function to merge two dictionaries into a new dictionary, prioritizing the values from the second dictionary in case of matching keys. The resulting dictionary should be sorted by its keys. The code should start with: ```python from typing import Dict def merge_and_sort_dictionaries(dict1: Dict[str, in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def merge_and_sort_dictionaries(dict1: Dict[str, int], dict2: Dict[str, int]) -> Dict[str, int]: """ Merges two dictionaries into a new dictionary, prioritizing values from the second dictionary in case ...
magic_evol_110k
99,475
Write a Python function to find the smallest missing positive integer in an unsorted integer array `nums`. The array may contain duplicate values. The function should run in `O(n)` time and use constant extra space. The code should start with: ```python from typing import List def first_missing_positive(nums: List[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def first_missing_positive(nums: List[int]) -> int: """ Find the smallest missing positive integer in an unsorted integer array. Args: nums (List[int]): The unsorted integer array. Retu...
magic_evol_110k
99,478
Write a Python function to merge two distinct sets, ensuring that the resulting set contains no recurring elements. The function should accept two sets as input and return a new set that is the union of the two input sets. The code should start with: ```python def merge_sets(set1: set, set2: set) -> set: ```
Here is the Python code to solve the given problem in the markdown block: ```python def merge_sets(set1: set, set2: set) -> set: """ Merges two distinct sets, ensuring that the resulting set contains no recurring elements. Args: set1 (set): The first set to merge. set2 (set): The second set...
magic_evol_110k
99,484
Write a Python function to group subjects by their terms and return a dictionary where the keys are the terms and the values are tuples of subjects associated with each term. The function should handle a pandas DataFrame as input. The code should start with: ```python import pandas as pd from typing import Dict, Tuple...
Here is the Python code to solve the given problem in the markdown block: ```python import pandas as pd from typing import Dict, Tuple def group_subjects_by_term(df: pd.DataFrame) -> Dict[str, Tuple[str]]: """ Groups subjects by their terms and returns a dictionary where the keys are the terms and the valu...
magic_evol_110k
99,487
Write a Python function to check if the elements of a given list are monotonically increasing or decreasing, considering a strictness criterion. If `strict` is `True`, consecutive items must be unique; if `False`, they can be the same. The function should have a time complexity of O(n) or less. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_monotonic(lst: List[int], strict: bool = False) -> bool: """ Check if the elements of the list are monotonically increasing or decreasing, considering the strictness criterion. Args: ...
magic_evol_110k
99,489
Write a Python function to convert a time string in the format 'hh:mm:ss' into the equivalent time in seconds. The function should handle input validation to ensure the time string is in the correct format and that the hours, minutes, and seconds are within valid ranges. The code should start with: ```python def time_...
Here is the Python code to solve the given problem in the markdown block: ```python import re def time_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 in 'hh:mm:ss' format. Ret...
magic_evol_110k
99,492
Write a Python function to create a dictionary where the keys are sequential integers from 1 to `n` (inclusive), and each key is mapped to its square root. The function should use dictionary comprehension for efficiency. The code should start with: ```python from typing import Dict import math def generate_square_roo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict import math def generate_square_roots_dict(n: int) -> Dict[int, float]: """ Generates a dictionary where the keys are sequential integers from 1 to n (inclusive), and each key is mapped to its square...
magic_evol_110k
99,497
Write a Python function to calculate the maximum sum of a contiguous sub-array within a given array of integers. The function should handle both positive and negative integers. The code should start with: ```python from typing import List def max_sum_subarray(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_sum_subarray(arr: List[int]) -> int: """ Calculate the maximum sum of a contiguous sub-array within the given array. Args: arr (List[int]): The array of integers from which to find t...
magic_evol_110k
99,507
Write a Python function to concatenate two given alphanumeric strings with a space in between and return the resulting string. The function should handle any combination of alphanumeric characters in the input strings. The code should start with: ```python def concatenate_strings_with_space(str1: str, str2: str) -> st...
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_strings_with_space(str1: str, str2: str) -> str: """ Concatenates two given strings with a space in between and returns the resulting string. Args: str1 (str): The first string to concatenate. ...
magic_evol_110k
99,525
Write a Python function to sort a list of tuples according to the specified criteria. Each tuple contains two integers and a single string. The list should be sorted primarily by the first integer in ascending order, then by the second integer in descending order, and finally by the length of the string in descending o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def custom_sort(tuples_list: List[Tuple[int, int, str]]) -> List[Tuple[int, int, str]]: """ Sorts a list of tuples according to the specified criteria: 1. Primarily by the first integer in asc...
magic_evol_110k
99,536
Write a Python function to find the intersection of two sets without using Python's built-in set operations. The function should return the intersection elements in ascending order. The function should start with: ```python from typing import Set, List def set_intersection(s1: Set[int], s2: Set[int]) -> List[int]: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set, List def set_intersection(s1: Set[int], s2: Set[int]) -> List[int]: """ Calculate the intersection of two sets and return the result in ascending order. Args: s1 (Set[int]): The first set. ...
magic_evol_110k
99,556
Write a Python function to calculate the Least Common Multiple (LCM) of a set of two positive whole numbers, and optionally a third number. The function should handle the case where the third number is not provided. The code should start with: ```python def get_lcm_of_numbers(a: int, b: int, c: int = None) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def gcd(x: int, y: int) -> int: """Computes the Greatest Common Divisor (GCD) of two numbers. Args: x (int): The first number. y (int): The second number. Returns: int: The GCD of x and y. """ ...
magic_evol_110k
99,559
Write a Python function to remove all elements below a specified limit from a given list of integers. The function should return a new list containing only the elements that are greater than or equal to the specified limit. The code should start with: ```python from typing import List def filter_elements_above_limit(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_elements_above_limit(num_array: List[int], limit: int) -> List[int]: """ Filters the elements of the given list to include only those that are greater than or equal to the specified limit. ...
magic_evol_110k
99,594
Write a Python function to find the longest string in a given list of strings. If there are multiple strings with the same maximum length, return the first one encountered in the list. If the list is empty, return `None`. The function should be efficient and handle edge cases gracefully. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_longest_string(strings: List[str]) -> Optional[str]: """ Finds the longest string in a given list of strings. If multiple strings have the same maximum length, the function return...
magic_evol_110k
99,604
Write a Python function that uses a ternary operation to determine if a given number is negative or positive. The function should return the string "negative" if the number is less than 0, and "positive" if the number is greater than or equal to 0. The function should handle edge cases such as zero correctly. The code...
Here is the Python code to solve the given problem in the markdown block: ```python def check_number_sign(number: int) -> str: """ Determines if a given number is negative or positive using a ternary operation. Args: number (int): The number to check. Returns: str: "negative" if the nu...
magic_evol_110k
99,622
Write a Python function to calculate the square of a given number. The function should return the square of the number as an integer. The code should start with: ```python def square_number(num: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def square_number(num: int) -> int: """ Calculate the square of a given number. Args: num (int): The number to be squared. Returns: int: The square of the given number. """ # Calculate the squar...
magic_evol_110k
99,661
Write a Python function to partition a list of integers into a pair of nested lists, where the first list contains all even numbers and the second list contains all odd numbers. The function should handle an empty list and return a pair of empty lists in that case. The code should start with: ```python from typing impo...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Tuple def partition_list(lst: List[int]) -> Tuple[List[int], List[int]]: """ Partition a list of integers into a pair of nested lists, where the first list contains all even numbers and the second...
magic_evol_110k
99,662
Write a Python function to determine if two given words 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 handle case-insensitive comparisons and ignore spaces and punctua...
Here is the Python code to solve the given problem in the markdown block: ```python def is_anagram(word1: str, word2: str) -> bool: """ Determine if two given words are anagrams of each other. Args: word1 (str): The first word to check. word2 (str): The second word to check. Returns: ...
magic_evol_110k
99,667
Write a Python function to calculate the divergence between two discrete numerical entities, specifically the integral values of `x` and `y`. The divergence should be defined as the absolute difference between the two values. The function should handle any integer inputs and return the absolute difference. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_divergence(x: int, y: int) -> int: """ Calculate the absolute difference (divergence) between two integers x and y. Args: x (int): The first integer. y (int): The second integer. Returns: ...
magic_evol_110k
99,668
Write a Python function to convert each alphabetical character in a given string to its corresponding lowercase rendition. The function should ignore non-alphabetical characters and return the modified string. The code should start with: ```python def convert_to_lowercase(input_string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_lowercase(input_string: str) -> str: """ Converts each alphabetical character in the input string to its corresponding lowercase rendition. Args: input_string (str): The input string to be converted. ...
magic_evol_110k
99,684
Write a Python function to shuffle a given list of integers using the Fisher-Yates algorithm. The Fisher-Yates algorithm is an efficient way to shuffle a list in-place with a time complexity of O(n). The function should take a list of integers as input and return the shuffled list. 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 import random def fisher_yates_shuffle(arr: List[int]) -> List[int]: """ Shuffles a list of integers using the Fisher-Yates algorithm. The Fisher-Yates algorithm shuffles the list in-place by iterat...
magic_evol_110k
99,685
Write a Python function to calculate the sum of elements in an array of any length. The function should handle both positive and negative integers, as well as an empty array. The code should start with: ```python from typing import List def sum_array(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_array(arr: List[int]) -> int: """ Calculate the sum of elements in an array of any length. Args: arr (List[int]): The array of integers whose sum needs to be calculated. Returns...
magic_evol_110k
99,687
Write a Python function to merge two sorted lists into a single sorted list efficiently. The function should use O(N) time complexity and O(1) additional space complexity, where N is the total number of elements in the two lists. The code should start with: ```python from typing import List def merge_sorted_lists(l1: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_lists(l1: List[int], l2: List[int]) -> List[int]: """ Merge two sorted lists into a single sorted list. Args: l1 (List[int]): The first sorted list. l2 (List[int]): ...
magic_evol_110k
99,692
Write a Python function to sort the negative integers in a given list of integers while keeping the positive integers in their original positions. The function should return the modified list with the negative integers sorted in ascending order. The code should start with: ```python from typing import List def sort_n...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_negatives_in_list(num_list: List[int]) -> List[int]: """ Sorts the negative integers in the given list while keeping the positive integers in their original positions. Args: num_lis...
magic_evol_110k
99,712
Write a Python function to convert a hexadecimal input (string) to its binary representation (string). The function should handle both uppercase and lowercase hexadecimal digits and should return the binary representation without leading zeros. The code should start with: ```python def hex_to_binary(x: str) -> str: ``...
Here is the Python code to solve the given problem in the markdown block: ```python def hex_to_binary(x: str) -> str: """ Convert a hexadecimal input (string) to its binary representation (string). Args: x (str): The hexadecimal input string to be converted. Returns: str: The binary re...
magic_evol_110k
99,728
Write a Python function to reverse the order of characters in a given string. The function should handle strings of any length, including empty strings. The code should start with: ```python def reverse_string(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses the order of characters in the given string. Args: s (str): The input string to be reversed. Returns: str: The reversed string. """ # Use slicing ...
magic_evol_110k
99,730
Write a Python function to analyze a list of integers by determining whether each number is even or odd, and then identifying whether it is a prime number. The function should return a list of tuples, where each tuple contains the original number, a string indicating whether the number is "even" or "odd", and another s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def is_prime(n: int) -> bool: """Return whether a number is a prime number or not.""" if n < 2: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: re...
magic_evol_110k
99,738
Write a Python function to calculate the maximum sum of a subarray of a given array using Kadane's Algorithm. The function should return the maximum sum of the subarray. The code should start with: ```python from typing import List def max_subarray_sum(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_subarray_sum(arr: List[int]) -> int: """ Calculate the maximum sum of a subarray using Kadane's Algorithm. Args: arr (List[int]): The input array of integers. Returns: i...
magic_evol_110k
99,741
Write a Python function to calculate the sum of magnitudes of unique non-zero integers in an array, multiplied by the product of all signs of each unique number in the array. The function should return `None` for an empty array or an array containing only zeros. The code should start with: ```python from typing import ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def prod_signs(arr: List[int]) -> Optional[int]: """ Calculate the sum of magnitudes of unique non-zero integers in the array, multiplied by the product of all signs of each unique number i...
magic_evol_110k
99,742
Write a Python function to combine two given strings, reverse the order of the characters, and capitalize the resulting letters. Additionally, calculate the length of the final string and return it along with the transformed string. The function should start with: ```python def transform_strings(s1: str, s2: str) -> tu...
Here is the Python code to solve the given problem in the markdown block: ```python def transform_strings(s1: str, s2: str) -> tuple: """ Combines two strings, reverses the order of characters, capitalizes the letters, and returns the transformed string along with its length. Args: s1 (str): Th...
magic_evol_110k
99,744
Write a Python function to locate and replace all occurrences of a string `x` with another string `y` in a 2D list of strings, and return the coordinates of the replaced strings. The function should also print the updated 2D list. The code should start with: ```python from typing import List, Tuple def locate_and_rep...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def locate_and_replace(data: List[List[str]], x: str, y: str) -> List[Tuple[int, int]]: """ Locate and replace all occurrences of a string `x` with another string `y` in a 2D list of strings, ...
magic_evol_110k
99,748
Write a Python function to compute the rolling maximum of a list of positive integers. The function should return a new list where each element from index 0 to n is the maximum element from the original list from index 0 to n. If the input list contains any negative numbers, the function should return an empty list. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def rolling_max(arr: List[int]) -> List[int]: """ Compute the rolling maximum of a list of positive integers. This function takes a list of positive integers and returns a new list where each elemen...
magic_evol_110k
99,758
Write a Python function to flatten a given two-dimensional array into a one-dimensional array. The function should handle any level of nested arrays, not just a single level of nesting. The code should start with: ```python from typing import List, Any def flatten_array(nested_array: List[Any]) -> List[Any]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def flatten_array(nested_array: List[Any]) -> List[Any]: """ Flattens a nested array into a one-dimensional array. Args: nested_array (List[Any]): The nested array to be flattened. ...
magic_evol_110k
99,760
Write a Python function that takes in two parameters: a list of numerical values and a list of predefined mathematical operations. The function should perform these operations on the numerical values in the order they were given, add them to a list, and then return the list with the values rearranged in a random order....
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def perform_operations_and_shuffle(nums: List[int], ops: List[str]) -> List[int] or str: """ Perform a series of predefined mathematical operations on a list of numerical values and then sh...
magic_evol_110k
99,764
Write a Python function to segregate alphanumeric and non-alphanumeric characters from a given string. The function should return two lists: one containing all alphanumeric characters and the other containing all non-alphanumeric characters. The function should handle any string input, including empty strings. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import re def segregate_characters(text: str) -> Tuple[List[str], List[str]]: """ Segregates alphanumeric and non-alphanumeric characters from a given string. Args: text (str): The in...
magic_evol_110k
99,770
Write a Python function to find the largest even number within a given inclusive range `[x, y]` that is divisible by a specified integer `z`. If no such number exists, the function should return `-1`. The code should start with: ```python def superior_parallel_dividend(x: int, y: int, z: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def superior_parallel_dividend(x: int, y: int, z: int) -> int: """ Find the largest even number within the inclusive range [x, y] that is divisible by z. Args: x (int): The lower bound of the range (inclusive). ...
magic_evol_110k
99,773
Write a Python function to output positional arguments passed to it and handle improper usage of positional parameters by displaying an appropriate error message. The function should be efficient and capable of handling a large number of parameters. The code should start with: ```python from typing import List def out...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def output_positional_arguments(args: List[str]) -> None: """ Outputs each positional argument with its position and handles improper usage by displaying an error message. Args: args (List[s...
magic_evol_110k
99,783
Write a Python function to calculate the cumulative sum of all numerical values contained within a provided list of tuples. The function should be capable of navigating nested tuple structures and disregarding any non-numeric entities. Additionally, the function should handle complex numbers, extracting their real part...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Union def cumulative_sum_of_tuples(tuples: List[Union[Tuple, int, float, complex]]) -> float: """ Calculate the cumulative sum of all numerical values contained within a provided list of tuples. ...
magic_evol_110k
99,792
Write a Python function to filter and return a list of Fibonacci numbers from a given list of integers. The function should efficiently determine if each number in the list is a Fibonacci number and return only those numbers that are. The code should start with: ```python from typing import List def filter_fibonacci_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def is_fibonacci(n: int) -> bool: """ Check if a given number is a Fibonacci number. Args: n (int): The number to check. Returns: bool: True if the number is a Fibon...
magic_evol_110k
99,796
Write a Python function to extract all odd numbers from a given list of integers. The function should iterate over the list and return a new list containing only the odd numbers. The code should start with: ```python from typing import List def extract_odd_numbers(input_array: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def extract_odd_numbers(input_array: List[int]) -> List[int]: """ Extracts all odd numbers from a given list of integers. Args: input_array (List[int]): The list of integers from which to ex...
magic_evol_110k
99,833
Write a Python function to harmonize two distinct numerical entities into a uniform format under specific conditions. The first numerical entity is a list of integers in string representation, and the second numerical entity is a floating point number in string representation. The output should be in floating point rep...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def harmonize_numerical_entities(list_entity: List[str], float_entity: str) -> List[float]: """ Harmonizes two distinct numerical entities into a uniform format. Args: list_entity (List[str]...
magic_evol_110k
99,837
Write a Python function to find the first integer in a given sequence that appears with a unique occurrence rate. The sequence is a list of integers. The function should return the first integer that appears exactly once in the sequence. If no such integer exists, the function should return `None`. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional from collections import Counter def find_first_unique_occurrence(arr: List[int]) -> Optional[int]: """ Finds the first integer in the given sequence that appears exactly once. Args: ...
magic_evol_110k
99,851
Write a Python function to count the total number of vowel characters in a given text string. The function should be case-insensitive, meaning both uppercase and lowercase vowels should be counted. The code should start with: ```python def count_vowels(text: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_vowels(text: str) -> int: """ Count the total number of vowel characters in a given text string. Args: text (str): The input text string in which to count the vowels. Returns: int: The total n...
magic_evol_110k
99,865
Write a Python function to delete the last element from a given list and return the modified list. The function should handle cases where the list is empty or has only one element. The code should start with: ```python from typing import List def remove_last_element(lst: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_last_element(lst: List[int]) -> List[int]: """ Deletes the last element from the given list and returns the modified list. Args: lst (List[int]): The list from which the last elem...
magic_evol_110k
99,886
Write a Python function to remove an element from a given tuple by its value. The function should return a new tuple with the specified element removed. If the element is not found in the tuple, the function should return the original tuple. The code should start with: ```python from typing import Tuple def remove_el...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def remove_element_from_tuple(t: Tuple[int], element: int) -> Tuple[int]: """ Removes an element from a given tuple by its value and returns a new tuple. If the element is not found, the original tu...
magic_evol_110k
99,891
Write a Python function to find the smallest and the largest elements in a given list of integers with a time complexity of O(n). You are not allowed to use built-in sorting or max/min functions. The function should return a tuple containing the smallest and the largest elements. 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, Tuple def find_smallest_largest(nums: List[int]) -> Tuple[int, int]: """ Finds the smallest and the largest elements in a list of integers with a time complexity of O(n). Args: nums (List[i...
magic_evol_110k
99,895
Write a Python function to merge two lists of positive integers and sort the combined list in descending order. Ensure that no digit appears more than twice in the sorted list. If a digit appears more than twice, keep the two largest occurrences and remove the rest. The code should start with: ```python from typing im...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_and_sort_lists(list1: List[int], list2: List[int]) -> List[int]: """ Merges two lists of positive integers, sorts the combined list in descending order, and ensures that no digit appears mo...
magic_evol_110k
99,906
Write a Python function to analyze a dictionary of events attended by different people. The function should output the number of events each person attended, the unique events they attended that no one else did, and the count of such unique events. The dictionary `events` is structured such that each key is a person's...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List from collections import Counter def analyze_events(events: Dict[str, List[str]]) -> None: """ Analyzes the events attended by different people and prints the number of events each person attended, ...
magic_evol_110k
99,917
Write a Python function to perform basic arithmetic operations on two floating-point numbers. The function should support addition, subtraction, multiplication, division, and square root operations. The function should return the result of the operation as a floating-point number. The function should handle division by...
Here is the Python code to solve the given problem in the markdown block: ```python def basic_calculator(operation: str, num1: float, num2: float = None) -> float: """ Perform basic arithmetic operations on two floating-point numbers. Args: operation (str): The operation to perform. Supported opera...
magic_evol_110k
99,924
Write a Python function to count the number of vowels in a given string. The function should be case-insensitive, meaning it should count both uppercase and lowercase vowels. The code should start with: ```python def count_vowels(word: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_vowels(word: str) -> int: """ Counts the number of vowels in a given string. Args: word (str): The input string to count vowels in. Returns: int: The number of vowels in the input string. ...
magic_evol_110k
99,930
Write a Python function to reverse a given string without using any built-in reverse methods or functions. The function should handle alphanumeric sequences, special characters, and Unicode inputs. The function should start with: ```python def reverse_string(input_string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(input_string: str) -> str: """ Reverses a given string without using any built-in reverse methods or functions. Args: input_string (str): The string to be reversed. Returns: str: The ...
magic_evol_110k
99,937
Write a Python function to convert a given string into uppercase letters without changing other aspects of the text (e.g., punctuation, numbers). The function should handle both single words and sentences or paragraphs. The code should start with: ```python def convert_to_uppercase(text: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_uppercase(text: str) -> str: """ Converts all lowercase letters in the given text to uppercase while preserving other characters. Args: text (str): The input string to be converted. Returns: ...
magic_evol_110k
99,938
Write a Python function to validate an email address based on the following criteria: 1. The email address must contain only lowercase letters and digits. 2. The email address must contain exactly one '@' symbol. 3. The domain part of the email address must be one of the specified valid domains. 4. The email address mu...
Here is the Python code to solve the given problem in the markdown block: ```python import re from typing import List def validate_email(email: str, valid_domains: List[str]) -> bool: """ Validates an email address based on the following criteria: 1. The email address must contain only lowercase letters an...
magic_evol_110k
99,946
Write a Python function to eliminate all instances of multiple consecutive spaces in a given text and replace them with a single space. The function should handle any number of consecutive spaces, not just dual spaces. The code should start with: ```python def eliminate_multiple_spaces(text: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def eliminate_multiple_spaces(text: str) -> str: """ Eliminates all instances of multiple consecutive spaces in the given text and replaces them with a single space. Args: text (str): The input text string containin...
magic_evol_110k
99,978
Write a Python function to construct a Universal Resource Locator (URL) using the secure Hypertext Transfer Protocol Secure (HTTPS). The function should take three parameters: a subdomain, a domain, and a path fragment. The function should return the complete URL string. The code should start with: ```python def constr...
Here is the Python code to solve the given problem in the markdown block: ```python def construct_url(subdomain: str, domain: str, path: str) -> str: """ Constructs a URL using the secure Hypertext Transfer Protocol Secure (HTTPS). Args: subdomain (str): The subdomain part of the URL. domai...
magic_evol_110k
99,998
Write a Python function to divide a given string into equal segments by slicing it at every nth character. The function should accept two arguments: the string to be sliced and the integer n, which represents the interval at which the string should be sliced. The function should return a list of slices. If the string d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Union, List def slice_string(string: str, n: int) -> Union[List[str], str]: """ Divides a given string into equal segments by slicing it at every nth character. Args: string (str): The string to ...