source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_evol_110k
68,997
Write a Python function to convert a given percentage to its decimal representation. The function should take an integer representing the percentage and return a float representing the decimal equivalent. The code should start with: ```python def convert_percentage_to_decimal(percent: int) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def convert_percentage_to_decimal(percent: int) -> float: """ Converts a given percentage to its decimal representation. Args: percent (int): The percentage value to be converted. Returns: float: The de...
magic_evol_110k
69,033
Write a Python function to count the occurrences of each punctuation symbol in a given English statement and return a dictionary where the keys are the punctuation symbols and the values are their respective counts. The function should handle any string input, including those with no punctuation symbols. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict import string def count_punctuation_occurrences(statement: str) -> Dict[str, int]: """ Counts the occurrences of each punctuation symbol in a given English statement. Args: statement (str): ...
magic_evol_110k
69,039
Write a Python function to determine if the balance goes below zero during a series of financial transactions. Each transaction is represented by a tuple containing an operation (either "deposit" or "withdrawal") and a value. The function should handle case insensitivity for the operation type and ensure that all input...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def below_zero(operations: List[Tuple[str, int]], case_insensitive: bool = False) -> bool: """ Determine if the balance goes below zero during a series of financial transactions. Args: ...
magic_evol_110k
69,042
Write a Python function to create a shallow copy of a given list. The function should handle lists of any length and any type of elements. The function should return the shallow copy of the list. The code should start with: ```python from typing import List def shallow_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 def shallow_copy_list(original_list: List) -> List: """ Creates a shallow copy of a given list. Args: original_list (List): The original list to be copied. Returns: List: A shal...
magic_evol_110k
69,061
Write a Python function to calculate the exponentiation of a base number `n` raised to a specified power `m`. The function should handle both positive and negative integer values for `m`. The code should start with: ```python def exponentiate(n: int, m: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def exponentiate(n: int, m: int) -> int: """ Calculate the exponentiation of a base number `n` raised to a specified power `m`. Args: n (int): The base number. m (int): The exponent. Returns: in...
magic_evol_110k
69,084
Write a Python function to merge two sorted lists into a single sorted list without using any built-in Python list functions or set operations. The function should be implemented using recursion and functional programming concepts. The function should not modify the original lists and should handle edge cases such as e...
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 without using built-in Python list functions or set operations. Args: ...
magic_evol_110k
69,089
Write a Python function to determine the current phase of the moon based on the current date. The function should fetch the moon phase information from an external API and return a string describing the current phase of the moon. The code should start with: ```python import requests from datetime import datetime def ...
Here is the Python code to solve the given problem in the markdown block: ```python import requests from datetime import datetime def get_current_moon_phase() -> str: """ Fetches and returns the current phase of the moon based on the current date. Returns: str: A string describing the current phas...
magic_evol_110k
69,105
Write a Python function to determine if the second string is a transformed version of the first string, allowing for rotations, reversals, and sorting of characters. The function should take two strings and their respective lengths as input and return a boolean value indicating whether the second string is a valid tran...
Here is the Python code to solve the given problem in the markdown block: ```python def is_transformed_string(str1: str, len1: int, str2: str, len2: int) -> bool: """ Determines if the second string is a transformed version of the first string, allowing for rotations, reversals, and sorting of characters. ...
magic_evol_110k
69,106
Write a Python function to convert an array of strings to an array of integers. Each string in the array represents a valid integer. The function should handle an empty array by returning an empty array. The code should start with: ```python from typing import List def convert_to_integers(str_array: List[str]) -> List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_to_integers(str_array: List[str]) -> List[int]: """ Converts an array of strings, where each string represents a valid integer, to an array of integers. Args: str_array (List[str...
magic_evol_110k
69,109
Write a Python function to generate a list of composed strings by integrating information from multiple lists and conditionally formatting the strings based on specified criteria. The function should skip certain combinations as specified. The code should start with: ```python from typing import List def generate_com...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_composed_strings(names: List[str], blanks: List[str]) -> List[str]: """ Generates a list of composed strings by integrating information from multiple lists and conditionally formatting the s...
magic_evol_110k
69,111
Write a Python function to find the sum of the two largest numbers in a given list of integers. The function should be efficient and handle edge cases such as an empty list or a list with fewer than two elements. The code should start with: ```python from typing import List def sum_of_two_largest(numbers: List[int]) -...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import heapq def sum_of_two_largest(numbers: List[int]) -> int: """ Calculate the sum of the two largest numbers in a given list of integers. Args: numbers (List[int]): The list of integers ...
magic_evol_110k
69,117
Write a Python function that appends a specified string at the end of every unique word in a given paragraph. The function should tokenize the paragraph into words, map each unique word to itself plus the specified string, and then replace the words in the original paragraph with their transformed versions. The functio...
Here is the Python code to solve the given problem in the markdown block: ```python import re def append_string_to_unique_words(paragraph: str, string_to_append: str) -> str: """ Appends a specified string at the end of every unique word in a given paragraph. Args: paragraph (str): The paragraph t...
magic_evol_110k
69,130
Write a Python function to find the top `n` most frequent elements in a given list of integers. The function should return a list of tuples where each tuple contains an element and its frequency in descending order of frequency. If two elements have the same frequency, they should be ordered by their value in ascending...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple from collections import Counter def top_n_frequent_elements(nums: List[int], n: int) -> List[Tuple[int, int]]: """ Returns the top n most frequent elements in the given list of integers. Args...
magic_evol_110k
69,132
Write a Python function to rotate a given list by `n` elements to the right. The function should handle cases where `n` is greater than the length of the list by taking the modulus of `n` with the length of the list. The function should start with: ```python from typing import List def rotate_list_right(arr: List[int]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def rotate_list_right(arr: List[int], n: int) -> List[int]: """ Rotates a given list to the right by n elements. Args: arr (List[int]): The list to be rotated. n (int): The number of...
magic_evol_110k
69,149
Write a Python function to identify and count all palindrome substrings within a given string. The function should return the count of such substrings. The code should start with: ```python def count_palindrome_substrings(s: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_palindrome_substrings(s: str) -> int: """ Counts all palindrome substrings within a given string. Args: s (str): The input string to search for palindrome substrings. Returns: int: The count o...
magic_evol_110k
69,150
Write a Python function to find the longest common prefix among a list of strings. The function should return the longest initial sequence that is common to all strings in the list. If there is no common prefix, the function should return an empty string. 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 longest_common_prefix(strs: List[str]) -> str: """ Find the longest common prefix string amongst a list of strings. Args: strs (List[str]): A list of strings to find the longest common p...
magic_evol_110k
69,156
Write a Python function to filter out and return a list of prime numbers from a given list of integers. The function should use a helper function to determine if a number is prime. The code should start with: ```python from typing import List def filter_primes(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
69,158
Write a Python function to manipulate a given list such that each element becomes divisible by 3 by adding the minimum positive integer to each element if it is not already divisible by 3. The function should return the modified list. The code should start with: ```python from typing import List def make_divisible_by...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def make_divisible_by_3(arr: List[int]) -> List[int]: """ Manipulate the given list such that each element becomes divisible by 3. Args: arr (List[int]): The list of integers to be modified....
magic_evol_110k
69,159
Write a Python function to calculate the product of all prime numbers in a given list. The function should take a list of integers as input and return the product of all prime numbers in the list. The function should start with: ```python from typing import List def product_of_primes(num_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 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
69,166
Write a Python function to determine if it is possible to make two strings `s1` and `s2` equal by performing at most one string swap on exactly one of the strings. Additionally, check if a third string `s3` can also be made equal to `s1` and `s2` with at most one swap. If it is possible, return `true`; otherwise, retur...
Here is the Python code to solve the given problem in the markdown block: ```python def can_strings_be_equal_with_one_swap(s1: str, s2: str, s3: str) -> bool: """ Determine if it is possible to make two strings `s1` and `s2` equal by performing at most one string swap on exactly one of the strings. Addition...
magic_evol_110k
69,169
Write a Python function to count the number of unique elements in a given array of integers. The function should efficiently handle arrays of varying sizes and ensure that duplicate elements are not counted multiple times. The code should start with: ```python from typing import List def count_unique_elements(arr: Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_unique_elements(arr: List[int]) -> int: """ Counts the number of unique elements in a given array of integers. Args: arr (List[int]): The array of integers from which to count uniq...
magic_evol_110k
69,174
Write a Python function to replace multiple consecutive occurrences of a specific character in a string with a single replacement character. The function should handle any string and any characters for the target and replacement. The code should start with: ```python def replace_multiple_consecutive(string: str, targe...
Here is the Python code to solve the given problem in the markdown block: ```python def replace_multiple_consecutive(string: str, target: str, replacement: str) -> str: """ Replaces multiple consecutive occurrences of a specific character in a string with a single replacement character. Args: strin...
magic_evol_110k
69,175
Write a Python function to generate a list of the first `n` cube numbers using list comprehensions. The function should efficiently compute the cube of each integer from 1 to `n` and return the resulting list. The code should start with: ```python def generate_cubed_numbers(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_cubed_numbers(n: int) -> List[int]: """ Generate a list of the first n cube numbers using list comprehensions. Args: n (int): The number of cube numbers to generate. Return...
magic_evol_110k
69,219
Write a Python function to generate a Fibonacci sequence that terminates at a user-provided numerical value `y`. The function should return a list of Fibonacci numbers that do not exceed `y`. The code should start with: ```python from typing import List def generate_fibonacci_sequence(y: 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(y: int) -> List[int]: """ Generate a Fibonacci sequence that terminates at a given value `y`. Args: y (int): The maximum value for the last number in the Fibo...
magic_evol_110k
69,232
Write a Python function to compute the area of a complex geometric shape, such as a non-rectangular polygon, given its vertices' coordinates. The function should be robust and capable of handling a variety of irregular polygon shapes. The code should start with: ```python from typing import List, Tuple def polygon_are...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def polygon_area(coordinates: List[Tuple[float, float]]) -> float: """ Calculate the area of a polygon given its vertices' coordinates. This function uses Gauss's Area Formula (Shoelace Theor...
magic_evol_110k
69,239
Write a Python function to extract the first five distinct characters from a given text string and return them as a list. If the text string has fewer than five distinct characters, return all distinct characters found. The function should start with: ```python from typing import List def extract_first_five_distinct_c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def extract_first_five_distinct_characters(text: str) -> List[str]: """ Extracts the first five distinct characters from the given text string and returns them as a list. Args: text (str): T...
magic_evol_110k
69,245
Write a Python function to check if a given input string is a case-insensitive palindrome, ignoring special characters and whitespaces. The function should not use the `reversed()` built-in function or string slicing. The code should start with: ```python def is_palindrome_ignore_case_and_special(s: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome_ignore_case_and_special(s: str) -> bool: """ Check if the given string is a case-insensitive palindrome, ignoring special characters and whitespaces. Args: s (str): The input string to check. ...
magic_evol_110k
69,248
Write a Python function to determine if two given strings are anagrams of each other, ignoring case sensitivity. The function should return `True` if the strings are anagrams, and `False` otherwise. The code should start with: ```python def are_anagrams(string1: str, string2: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(string1: str, string2: str) -> bool: """ Determines if two given strings are anagrams of each other, ignoring case sensitivity. Args: string1 (str): The first string to compare. string2 (str...
magic_evol_110k
69,253
Write a Python function to find and return the quintet of strings with the highest frequency in a given list of strings. The function should return a list of tuples, where each tuple contains a string and its frequency. The code should start with: ```python from typing import List, Tuple from collections import Counte...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple from collections import Counter def find_top_five_strings(strings: List[str]) -> List[Tuple[str, int]]: """ Find and return the quintet of strings with the highest frequency in the given list. ...
magic_evol_110k
69,266
Write a Python function to generate a unique, unguessable secret code of a specified length. The secret code should include a mix of capital and small alphabetic symbols, numerical digits, and non-alphanumeric special symbols. The function should ensure that the generated code is unique by checking against a list of pr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import string import random def generate_unique_secret_code(length: int, existing_codes: List[str]) -> str: """ Generates a unique, unguessable secret code of the specified length. The secret code i...
magic_evol_110k
69,270
Write a Python function to validate if a given string is a valid ISBN-10 number according to the standard ISBN-10 validation rules. The function should use a regular expression to ensure the format is correct and then calculate the checksum to verify the validity of the ISBN-10 number. The code should start with: ```p...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_isbn10(isbn: str) -> bool: """ Validate if a given string is a valid ISBN-10 number. Args: isbn (str): The ISBN-10 number to validate. Returns: bool: True if the ISBN-10 number i...
magic_evol_110k
69,284
Write a Python function to reorder a given collection of integers into a descending sequence pattern. The function should take a list of integers as input and return a new list with the integers sorted in descending order. The original list should not be modified. 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 def reorder_descending(numbers: List[int]) -> List[int]: """ Reorders a given collection of integers into a descending sequence pattern. Args: numbers (List[int]): The collection of integers...
magic_evol_110k
69,292
Write a Python function to check if a given string of brackets is correctly balanced. The string can contain three types of brackets: round brackets `()`, square brackets `[]`, and curly brackets `{}`. The function should ensure that every opening bracket has a corresponding closing bracket and that the brackets are pr...
Here is the Python code to solve the given problem in the markdown block: ```python def is_balanced_brackets(s: str) -> bool: """ Check if the given string of brackets is correctly balanced. Args: s (str): The string containing the brackets to be checked. Returns: bool: True if the bra...
magic_evol_110k
69,339
Write a Python function to sort an array of unique numerical entities using the insertion sort algorithm. The function should be able to handle any array of unique integers and return the sorted array. The code should start with: ```python from typing import List def insertion_sort(arr: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def insertion_sort(arr: List[int]) -> List[int]: """ Sorts an array of unique integers using the insertion sort algorithm. Args: arr (List[int]): The array of unique integers to be sorted. ...
magic_evol_110k
69,346
Write a Python function to combine two given lists and remove any duplicate elements, returning the result as a new list. The function should handle lists of integers and ensure that the final list contains only unique elements in the order they first appear. The code should start with: ```python from typing import Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def combine_and_remove_duplicates(list1: List[int], list2: List[int]) -> List[int]: """ Combines two lists of integers and removes any duplicate elements, returning a new list with unique elements in the...
magic_evol_110k
69,352
Write a Python function to calculate the cumulative sum of a given list of numbers. The function should take a list of integers as input and return the cumulative sum of these integers. The function should handle an empty list by returning 0. The code should start with: ```python from typing import List def cumulativ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def cumulative_sum(numbers: List[int]) -> int: """ Calculate the cumulative sum of a given list of integers. Args: numbers (List[int]): A list of integers for which the cumulative sum is to ...
magic_evol_110k
69,355
Write a Python function to shuffle the elements of a given dictionary such that each key-value pair is displayed in a random order, ensuring no pair is repeated in subsequent runs. Additionally, ensure that each data type ('fruit', 'vegetable', 'meat', 'drink', 'grain') appears only once before repeating. The function ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple import random def balanced_shuffle_dict(input_dict: Dict[str, str]) -> Dict[str, str]: """ Shuffles the elements of a given dictionary such that each key-value pair is displayed in a random ...
magic_evol_110k
69,356
Write a Python function to return all elements of an `m x n` matrix in a spiral order. The matrix is a list of lists where each inner list represents a row of the matrix. The function should start with: ```python from typing import List def spiral_order(matrix: List[List[int]]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def spiral_order(matrix: List[List[int]]) -> List[int]: """ Returns all elements of the given matrix in a spiral order. Args: matrix (List[List[int]]): A 2D list representing the matrix. ...
magic_evol_110k
69,377
Write a Python function to determine the frequency of a particular value within a given array, check for duplicate values, and return the count of duplicates and their respective frequencies in the array. The function should start with: ```python from typing import List, Dict, Tuple def count_value_and_duplicates(valu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple from collections import Counter def count_value_and_duplicates(values: List[int], target_value: int) -> Tuple[int, Dict[int, int], int]: """ Counts the frequency of a particular value and id...
magic_evol_110k
69,378
Write a Python function that converts a tuple of two floats into a complex number. The function should include type hinting for the function arguments and return value, following Python's best practices. The function should correctly handle the conversion and return the expected complex number. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def tuple_to_complex(numbers: Tuple[float, float]) -> complex: """ Converts a tuple of two floats into a complex number. Args: numbers (Tuple[float, float]): A tuple containing two floats, ...
magic_evol_110k
69,388
Write a Python function to validate an email address according to the rules defined in the RFC5322 technical standard. The function should ensure that the email address is syntactically correct, adhering to the format specified in the standard. The function should return `True` if the email address is valid and `False`...
Here is the Python code to solve the given problem in the markdown block: ```python import re def validate_email(email: str) -> bool: """ Validates an email address according to the RFC5322 standard. Args: email (str): The email address to validate. Returns: bool: True if the email ad...
magic_evol_110k
69,404
Write a Python function to extract the value associated with a specified key from a multi-layered dictionary. The function should be able to handle dictionaries with an arbitrary depth of nesting. If the key is not found in the dictionary, the function should return `None`. 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 Any, Dict, Optional def extract_nested_value(dictionary: Dict[str, Any], key: str) -> Optional[Any]: """ Extracts the value associated with a specified key from a multi-layered dictionary. Args: ...
magic_evol_110k
69,406
Write a Python function to determine whether a given sequence of characters qualifies as a palindrome. A sequence is considered a palindrome if its inverted sequence mirrors its original arrangement identically, ignoring case sensitivity and spaces. The code should start with: ```python def is_palindrome(s: str) -> bo...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(s: str) -> bool: """ Determine whether the given sequence of characters is a palindrome. A sequence is considered a palindrome if its inverted sequence mirrors its original arrangement identically, ign...
magic_evol_110k
69,418
Write a Python function to calculate the sum of all elements in a given list of integers. The function should iterate through the list and accumulate the sum of its elements. The code should start with: ```python from typing import List def sum_of_list(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_list(numbers: List[int]) -> int: """ Calculate the sum of all elements in a given list of integers. Args: numbers (List[int]): A list of integers whose sum needs to be calculated....
magic_evol_110k
69,420
Write a Python function to find the longest word in a given list of words, considering only lowercase alphabetic characters. Words containing special characters or digits should be excluded. The function should start with: ```python from typing import List def find_longest_word(words: List[str]) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def find_longest_word(words: List[str]) -> str: """ Finds the longest word in a given list of words, considering only lowercase alphabetic characters. Words containing special characters or...
magic_evol_110k
69,422
Write a Python function to compute the nth heptagonal figure number using a recursive algorithm fortified with dynamic programming techniques. The function should handle various input scenarios, including single integers, ranges of integers, and arrays of integers or ranges. It should also compute the cumulative sum an...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union # Initialize memoization arrays for heptagonal numbers, cumulative sum, and product heptagonal_memo = [0] * 2005 cumulative_sum = [0] * 2005 cumulative_product = [1] * 2005 def heptagonal_number(n: Union...
magic_evol_110k
69,425
Write a Python function to generate a randomized alphanumeric string of a specified length, ensuring that the string contains at least one uppercase letter, one lowercase letter, and one digit. The function should start with: ```python from typing import List def generate_secure_random_string(length: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List import random import string def generate_secure_random_string(length: int) -> str: """ Generates a randomized alphanumeric string of the specified length, ensuring it contains at least one uppercase le...
magic_evol_110k
69,427
Write a Python function to merge two given arrays and sort the resulting array in descending order without using any built-in sorting functions. The function should start with: ```python from typing import List def merge_and_sort_descending(arr1: List[int], arr2: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_and_sort_descending(arr1: List[int], arr2: List[int]) -> List[int]: """ Merges two arrays and sorts the resulting array in descending order without using built-in sorting functions. Args: ...
magic_evol_110k
69,428
Write a Python function to perform an interpolative search in a sorted list, ensuring the procedure handles duplicates and missing numbers efficiently. The function should return the index of the first occurrence of the target element if it exists in the list, otherwise return -1. The code should start with: ```python...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def interpolation_search(arr: List[int], x: int) -> int: """ Perform an interpolative search in a sorted list to find the index of the first occurrence of the target element. Args: arr (List...
magic_evol_110k
69,429
Write a Python function to calculate the sum and product of elements in a given list. The function should handle the common errors found in the provided code snippet and ensure that the sum and product are calculated correctly. The code should start with: ```python from typing import List def calculate_sum_and_product...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_sum_and_product(my_list: List[int]) -> (int, int): """ Calculate the sum and product of elements in a given list. Args: my_list (List[int]): The list of integers for which to c...
magic_evol_110k
69,431
Write a Python function to simulate the process of sending data from one site (x) to another site (y) using a simplified HTTP POST request. The function should take a dictionary of data to be sent and a URL endpoint as input, and it should return the response from the server. The function should handle the conversion o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any import requests import json def send_data_to_site(data: Dict[str, Any], url: str) -> requests.Response: """ Sends data from one site (x) to another site (y) using an HTTP POST request. Args: ...
magic_evol_110k
69,449
Write a Python function to reverse a given string sequence in an inverse or reversed manner. The function should handle strings of varying lengths, including empty strings. The code 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 the given string sequence. Args: input_string (str): The string to be reversed. Returns: str: The reversed string. """ # Use slicing to...
magic_evol_110k
69,456
Write a Python function to convert an alphanumeric string into its corresponding hexadecimal representation. Each character in the string should be converted to its hexadecimal equivalent using its ASCII value. The function should return a single concatenated string of all hexadecimal values. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python def string_to_hex(input_string: str) -> str: """ Converts an alphanumeric string into its corresponding hexadecimal representation. Args: input_string (str): The input string to be converted. Returns: s...
magic_evol_110k
69,466
Write a Python function to concatenate three given strings in reverse order, with each string itself reversed before concatenation. The function should return the final concatenated string. The code should start with: ```python def reverse_and_concatenate(str1: str, str2: str, str3: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_and_concatenate(str1: str, str2: str, str3: str) -> str: """ Reverses each of the three input strings and concatenates them in reverse order. Args: str1 (str): The first string to be reversed and concate...
magic_evol_110k
69,469
Write a Python function to compare the magnitudes of two variables `x` and `y`. If `x` is greater than `y`, the function should return the string `"x is greater than y"`. Otherwise, it should return the string `"x is not greater than y"`. The function should handle any numeric inputs for `x` and `y`. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_magnitudes(x: float, y: float) -> str: """ Compares the magnitudes of two variables x and y. Args: x (float): The first variable to compare. y (float): The second variable to compare. Return...
magic_evol_110k
69,474
Write a Python function to find all strings in a list that contain a given substring efficiently. The function should return a list of strings that include the substring. The code should start with: ```python from typing import List def find_strings_with_substring(listStr: List[str], s: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def find_strings_with_substring(listStr: List[str], s: str) -> List[str]: """ Find all strings in a list that contain a given substring. Args: listStr (List[str]): The list of strings to s...
magic_evol_110k
69,479
Write a Python function to reverse a given string using a non-slicing approach. The function should iterate through the string and build the reversed string character by character. 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 a given string using a non-slicing approach. Args: s (str): The input string to be reversed. Returns: str: The reversed string. """ # Initialize a...
magic_evol_110k
69,493
Write a Python function to perform a ternary search on a sorted array to find the index of a given key. The ternary search algorithm should divide the array into three parts and recursively search for the key in the appropriate segment. If the key is found, return its index; otherwise, return -1. The code should start...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def ternary_search(arr: List[int], key: int) -> int: """ Perform a ternary search on a sorted array to find the index of a given key. Args: arr (List[int]): A sorted list of integers. ...
magic_evol_110k
69,495
Write a Python function to generate a list of square numbers for all integers from 1 up to a given number `n`. The function should return a list containing the squares of these integers. The code should start with: ```python from typing import List def generate_square_numbers(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_square_numbers(n: int) -> List[int]: """ Generate a list of square numbers for all integers from 1 up to a given number n. Args: n (int): The upper limit (inclusive) for generat...
magic_evol_110k
69,502
Write a Python function to create a dictionary from a list of words where each key is a unique word (stripped of special characters and case insensitive), and each value is a list containing the total occurrences of the word and the number of letters in the word. The code should start with: ```python from typing impor...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict import re import string def word_count_dictionary(word_list: List[str]) -> Dict[str, List[int]]: """ Create a dictionary from a list of words where each key is a unique word (stripped of special ch...
magic_evol_110k
69,506
Write a Python function to calculate the total cost of buying a specified number of lemons, given the cost of a bag containing a certain number of lemons. The function should handle cases where the number of lemons requested is not a multiple of the number of lemons in a bag. The code should start with: ```python def c...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_total_cost(lemons_wanted: int, lemons_in_bag: int, cost_of_bag: float) -> float: """ Calculate the total cost of buying a specified number of lemons. Args: lemons_wanted (int): The number of lemons the...
magic_evol_110k
69,508
Write a Python function to compute the nth Catalan number using memoization to optimize performance. The function should handle invalid inputs and boundary conditions by raising appropriate exceptions. The code should start with: ```python def catalan_number(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def catalan_number(n: int) -> int: """ Compute the nth Catalan number using memoization. Args: n (int): The ordinal integer to compute the Catalan number. Returns: int: The nth Catalan number. Rais...
magic_evol_110k
69,509
Write a Python function to calculate the product of all elements in a given list of numbers. The function should handle lists of any length, 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 calculate_product(numb...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_product(numbers: List[int]) -> int: """ Calculate the product of all elements in a given list of integers. Args: numbers (List[int]): A list of integers for which the product i...
magic_evol_110k
69,511
Write a Python function to verify whether two given strings contain the identical set of words along with identical frequencies, disregarding word duplicity and case sensitivity. The function should return `True` if the two strings have the same set of words with the same frequencies, and `False` otherwise. The code s...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import Counter def verify_same_word_sets_freqs(phrase1: str, phrase2: str) -> bool: """ Verifies whether two given strings contain the identical set of words along with identical frequencies, disregarding w...
magic_evol_110k
69,515
Write a Python function to find the longest common subsequence (LCS) between two given strings. The function should return the length of the LCS. The code should start with: ```python def longest_common_subsequence(str1: str, str2: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def longest_common_subsequence(str1: str, str2: str) -> int: """ Calculate the length of the longest common subsequence (LCS) between two strings. Args: str1 (str): The first string. str2 (str): The second...
magic_evol_110k
69,517
Write a Python function to calculate the total cost of a shopping trip, including the state sales tax and a processing fee. The function should take three parameters: `purchase_price`, `state_tax`, and `processing_fee_percentage`. The function should return the total cost, which is the sum of the purchase price, the st...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_total_cost(purchase_price: float, state_tax: float, processing_fee_percentage: float) -> float: """ Calculate the total cost of a shopping trip, including the state sales tax and a processing fee. Args: ...
magic_evol_110k
69,534
Write a Python function to count the occurrences of each unique word in a given sentence, excluding specified words, and ignoring punctuation. The function should return a dictionary where the keys are the unique words (excluding the specified words) and the values are their respective counts. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict import string def count_unique_words(sentence: str, excluded_words: List[str]) -> Dict[str, int]: """ Counts the occurrences of each unique word in a sentence, excluding specified words and ignorin...
magic_evol_110k
69,538
Write a Python function to organize a list of integers into sublists, each containing exactly 3 elements. If the last sublist has fewer than 3 elements, it should still be included in the result. The code should start with: ```python from typing import List def organize_into_sublists(arr: List[int]) -> List[List[int]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def organize_into_sublists(arr: List[int]) -> List[List[int]]: """ Organizes a list of integers into sublists, each containing exactly 3 elements. If the last sublist has fewer than 3 elements, it is...
magic_evol_110k
69,545
Create a Python function to implement a novel encryption algorithm specifically optimized for handling and safeguarding historical document data. The algorithm should be based on a modified Caesar cipher that handles both uppercase and lowercase letters, digits, and punctuation. The function should also include a decry...
Here is the Python code to solve the given problem in the markdown block: ```python import string def encrypt_historical_document(text: str, shift: int) -> str: """ Encrypts a historical document text using a modified Caesar cipher. Args: text (str): The text to be encrypted. shift (int): ...
magic_evol_110k
69,552
Write a Python function to replace missing values in a given dataset with a specified replacement value. The dataset is represented as a list of dictionaries, where each dictionary corresponds to a post on Facebook. Each post dictionary contains keys such as `'type'` (either 'video' or 'photo') and `'view_count'` (the ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union import numpy as np def replace_missing_views(posts: List[dict], replacement: Union[int, float]) -> List[dict]: """ Replaces missing 'view_count' values in a list of post dictionaries with a specif...
magic_evol_110k
69,570
Write a Python function to count the number of circular primes below a given threshold. A circular prime is a prime number where all rotations of its digits are also prime numbers. For example, 197 is a circular prime because 197, 971, and 719 are all prime numbers. The code should start with: ```python def count_circ...
Here is the Python code to solve the given problem in the markdown block: ```python def count_circular_primes(threshold: int) -> int: """ Count the number of circular primes below a given threshold. A circular prime is a prime number where all rotations of its digits are also prime numbers. Args: ...
magic_evol_110k
69,576
Write a Python function to find the top `k` numbers from a given list of integers efficiently. The function should return a list containing the top `k` numbers in descending order. If `k` is greater than the length of the list, the function should return the entire list sorted in descending order. The code should star...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import heapq def get_top_k_numbers(arr: List[int], k: int) -> List[int]: """ Returns the top k numbers from the given list of integers in descending order. Args: arr (List[int]): The list of...
magic_evol_110k
69,594
Write a Python function to print each element of a given list of strings, one element per line. The function should accept a list of strings as its input and print each string in the list using a for loop. The code should start with: ```python from typing import List def print_each_element(elements: List[str]) -> None...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_each_element(elements: List[str]) -> None: """ Prints each element of the given list of strings, one element per line. Args: elements (List[str]): A list of strings to be printed. ...
magic_evol_110k
69,596
Write a Python function to count the number of times a given character appears in a sentence, considering both uppercase and lowercase versions of the character as the same. The function should be case-insensitive. The code should start with: ```python def count_char_occurrences(sentence: str, character: str) -> int: ...
Here is the Python code to solve the given problem in the markdown block: ```python def count_char_occurrences(sentence: str, character: str) -> int: """ Counts the number of times a given character appears in a sentence, ignoring case differences. Args: sentence (str): The sentence in which to cou...
magic_evol_110k
69,597
Write a Python function to select and isolate specific columns from a given DataFrame using pandas. The function should handle various selection methods including single column selection, multiple column selection, and column range selection using both label-based (`loc`) and integer-based (`iloc`) indexing. Additional...
Here is the Python code to solve the given problem in the markdown block: ```python import pandas as pd from typing import List, Union def select_columns(df: pd.DataFrame, columns: Union[str, List[str], slice], drop: bool = False) -> pd.DataFrame: """ Selects or drops specific columns from a DataFrame using va...
magic_evol_110k
69,608
Write a Python function to generate a dataset that follows a multinomial distribution based on given parameters. The function should take the number of samples, the number of categories, and the parameters for generating the probabilities for each category. The probabilities should be generated using a logistic functio...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def generate_multinomial_data(num_samples: int, num_categories: int, beta_values: np.ndarray) -> np.ndarray: """ Generate a dataset that follows a multinomial distribution based on given parameters. Args...
magic_evol_110k
69,632
Write a Python function to combine two lists into a single list of tuples. If the lists have different lengths, the function should combine elements up to the length of the shorter list and ignore the remaining elements in the longer list. The code should start with: ```python from typing import List, Tuple def combin...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Tuple def combine_lists(list1: List[any], list2: List[any]) -> List[Tuple[any, any]]: """ Combines two lists into a single list of tuples. Args: list1 (List[any]): The first list to combi...
magic_evol_110k
69,639
Write a Python function to extract and return all domestic and international telephone numbers present in a given passage. The function should be able to identify numbers in common formats such as those with parentheses for area codes and dashes for number separation. The function should also handle international forma...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def extract_phone_numbers(passage: str) -> List[str]: """ Extracts and returns all domestic and international telephone numbers present in the provided passage. Args: passage (str)...
magic_evol_110k
69,649
Write a Python function to filter an array of string elements based on a provided string. The function should identify and return the elements that are substrings of the given string. For example, if the provided string is "hello world", and the array is ["hello", "world"], the function should return ["hello", "world"]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_array_by_substring(match_string: str, arr: List[str]) -> List[str]: """ Filters an array of string elements based on a provided string. Returns the elements that are substrings of the give...
magic_evol_110k
69,653
Write a Python function that generates a list of prime numbers up to a given input limit. The function should include an optional parameter to print either the square or the cube of each prime number in the list, depending on the user's choice. The function should also return the list of identified prime numbers. You a...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_primes(limit: int, to_print: str = 'square') -> list: """ Generates a list of prime numbers up to a given limit and optionally prints their squares or cubes. Args: limit (int): The upper limit for gener...
magic_evol_110k
69,657
Write a Python function to convert a date string in the format 'day-month-year' (e.g., '01 Jan 2018') into a tuple containing the day, the full month name, and the year. The function should handle the conversion and dissection of the date string efficiently. The code should start with: ```python from datetime import d...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime def convert_and_dissect_date(date_string: str) -> tuple: """ Converts a date string in the format 'day-month-year' (e.g., '01 Jan 2018') into a tuple containing the day, full month name, and year. ...
magic_evol_110k
69,658
Write a Python function to generate a unique URL for a virtual retail platform. The URL should be constructed by appending a random string to a given base URL and path. The random string should consist of alphanumeric characters and should be of a specified length. The function should ensure that the generated URL adhe...
Here is the Python code to solve the given problem in the markdown block: ```python import string import random def generate_unique_url(base_url: str, path: str, random_string_length: int = 10) -> str: """ Generates a unique URL for a virtual retail platform by appending a random string to a given base URL and...
magic_evol_110k
69,663
Write a Python function to create a 3D NumPy array with dimensions 4x3x3, where all elements are initially zero. Then, replace all border elements of this 3D array with ones. The function should return the modified 3D array. The code should start with: ```python import numpy as np def create_and_modify_3d_array() -> ...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def create_and_modify_3d_array() -> np.ndarray: """ Creates a 3D NumPy array with dimensions 4x3x3, initialized with zeros. Replaces all border elements of this 3D array with ones. Returns: n...
magic_evol_110k
69,667
Write a Python function to compute the sum of all integer values within a specified range for each integer in a given list. The function should accept a list of integers, where each integer represents the upper limit (exclusive) of a range, and return a list of sums corresponding to each range. 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 compute_sums_of_ranges(num_list: List[int]) -> List[int]: """ Computes the sum of all integer values within a specified range for each integer in the given list. Args: num_list (List[int...
magic_evol_110k
69,671
Write a Python function to generate and return a list of septuple integers (multiples of 7) spanning from zero up to a given limit `n`. The function should ensure that the limit `n` is non-negative and adjust the range accordingly if `n` is less than 7. The code should start with: ```python from typing import List def...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_septuples(n: int) -> List[int]: """ Generates a list of septuple integers (multiples of 7) from 0 up to a given limit n. Args: n (int): The upper limit for the septuples. R...
magic_evol_110k
69,674
Write a Python function to convert an input number, represented as a string, of a specified base (integer) into its binary equivalent as a string. The base can be either 8 (indicating octal), 10 (indicating decimal), or 16 (for hexadecimal). The function should handle the conversion efficiently and return the binary re...
Here is the Python code to solve the given problem in the markdown block: ```python def number_to_binary(x: str, base: int) -> str: """ Convert an input number, represented as a string, of a specified base (integer) into its binary equivalent as a string. Args: x (str): The input number as a string...
magic_evol_110k
69,678
Write a Python function to generate and initialize two vacant array lists, and then fill them with random integers within a specified range. The function should also return the sum of the elements in each array. The code should start with: ```python from typing import List import random def initialize_and_sum_arrays(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def initialize_and_sum_arrays(size: int, lower_bound: int, upper_bound: int) -> List[int]: """ Generates and initializes two vacant array lists, fills them with random integers within a spe...
magic_evol_110k
69,684
Write a Python function to concatenate two strings with a specified delimiter and return the resulting unified string. The function should handle cases where the delimiter is an empty string or one of the input strings is empty. The code should start with: ```python def concatenate_strings(string1: str, string2: str, ...
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_strings(string1: str, string2: str, delimiter: str) -> str: """ Concatenates two strings with a specified delimiter and returns the resulting unified string. Args: string1 (str): The first string to ...
magic_evol_110k
69,710
Write a Python function to search for multiple regular expression patterns within a given string and return the start and end indices of all matches, including overlapping and nested patterns. The function should handle the complexity of the patterns efficiently and return a list of dictionaries, each containing the pa...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict import re def search_patterns(string: str, patterns: List[str]) -> List[Dict[str, any]]: """ Searches for multiple regular expression patterns within a given string and returns the start and end in...
magic_evol_110k
69,714
Write a Python function to determine if it is possible to construct a palindrome by partitioning two given strings `a` and `b` at the same index and concatenating the resulting prefixes and suffixes in a specific manner. The function should return `True` if such a palindrome can be formed, otherwise `False`. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python def can_form_palindrome(a: str, b: str) -> bool: """ Determine if it is possible to construct a palindrome by partitioning two strings `a` and `b` at the same index and concatenating the resulting prefixes and suffixes in a ...
magic_evol_110k
69,721
Write a Python function to filter and count the fruits from a given two-dimensional list. The function should return a list of fruits and the total count of fruits. The function should handle cases where the inner lists may contain non-fruit items. The code should start with: ```python from typing import List, Tuple ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def filter_and_count_fruits(items: List[List[str]]) -> Tuple[List[str], int]: """ Filters and counts the fruits from a given two-dimensional list. Args: items (List[List[str]]): A two...
magic_evol_110k
69,727
Write a Python function to manage a collection of animal names, keeping track of the count of each animal type. The function should allow adding more animals, removing an animal type, and getting the count of a specific animal by name. The function should be efficient in terms of both time and space complexity. The co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def animal_counter() -> Dict[str, int]: """ Returns a dictionary to manage animal counts. Returns: Dict[str, int]: A dictionary with initial animal counts set to zero. """ return {"c...
magic_evol_110k
69,732
Write a Python function to create a nested dictionary for three primary colors: red, blue, and green. Each primary color key should correspond to a dictionary containing two second-level keys: 'Hexadecimal' and 'RGB'. 'Hexadecimal' should contain the hexadecimal color code, and 'RGB' should contain a tuple of RGB value...
Here is the Python code to solve the given problem in the markdown block: ```python def create_color_dictionary() -> dict: """ Creates a nested dictionary for three primary colors: red, blue, and green. Each primary color key corresponds to a dictionary containing two keys: 'Hexadecimal' and 'RGB'. 'Hex...
magic_evol_110k
69,733
Write a Python function to generate a basic HTML page with a functional form that includes validation logic. The form should have fields for a user's name and email, and it should validate that the name is not empty and the email is in a valid format. The function should return the complete HTML string. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_html_form() -> str: """ Generates a basic HTML page with a functional form that includes validation logic. The form has fields for a user's name and email, and it validates that the name is not empty and the em...
magic_evol_110k
69,738
Write a Python function to merge two given lists, remove duplicates, and sort the final list in ascending order without using the built-in `sort` function. The function should start with: ```python from typing import List def merge_remove_duplicates_sort(a: List[int], b: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_remove_duplicates_sort(a: List[int], b: List[int]) -> List[int]: """ Merge two lists, remove duplicates, and sort the final list in ascending order. Args: a (List[int]): The first ...
magic_evol_110k
69,744
Write a Python function to reverse a given list of integers and return the reversed list. The function should handle lists of any length, including empty lists. The code should start with: ```python from typing import List def reverse_list(input_list: 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(input_list: List[int]) -> List[int]: """ Reverses the given list of integers and returns the reversed list. Args: input_list (List[int]): The list of integers to be reversed...
magic_evol_110k
69,759
Write a Python function to extract the name and age of the second item from a given dictionary. The dictionary contains multiple entries, each with a name, age, and city. The function should be dynamic and work for any dictionary with a similar structure but an arbitrary number of records. The function should not extra...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def extract_second_item_info(data: Dict[str, Dict[str, Any]]) -> Dict[str, Any]: """ Extracts the name and age of the second item from a given dictionary. Args: data (Dict[str, Dict[str...
magic_evol_110k
69,764
Write a Python function to transform a given list of integers into a tuple after performing a series of computational steps. The steps involve filtering out even numbers, squaring the remaining odd numbers, and then sorting the squared values in descending order. The final result should be a tuple containing these sort...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def transform_list(input_list: List[int]) -> Tuple[int]: """ Transforms a given list of integers into a tuple after performing a series of computational steps. The steps involve: 1. Filte...
magic_evol_110k
69,773
Write a Python function that takes a list of discrete alphabetic characters and consolidates them into a single, uninterrupted text string. The function should be implemented using higher-order functions to enhance readability and maintainability. The code should start with: ```python from typing import List def conso...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def consolidate_chars(chars: List[str]) -> str: """ Consolidates a list of discrete alphabetic characters into a single, uninterrupted text string. Args: chars (List[str]): A list of discret...
magic_evol_110k
69,777
Write a Python function to search for a given element in a 2D array and return its position as a tuple `(row, column)`. If the element is not found, the function should return `-1`. The function should handle any rectangular 2D array, not just square matrices. The code should start with: ```python from typing import Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Union def find_element_in_2d_array(array: List[List[int]], element: int) -> Union[Tuple[int, int], int]: """ Searches for a given element in a 2D array and returns its position as a tuple (row, c...