source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_evol_110k
70,535
Write a Python function to determine if a given number is both a prime number and a palindrome. The function should return `True` if the number meets both criteria, and `False` otherwise. The code should start with: ```python def is_palindromic_prime(n: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindromic_prime(n: int) -> bool: """ Determine if a given number is both a prime number and a palindrome. Args: n (int): The number to be checked. Returns: bool: True if the number is both prim...
magic_evol_110k
70,541
Write a Python function to generate a list of the squared values of the first 'n' odd prime numbers arranged in descending order. Additionally, implement an efficient algorithm to check if a number is prime. The function should start with: ```python from typing import List def squared_odd_primes(n: int) -> List[int]: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math 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, Fal...
magic_evol_110k
70,543
Write a Python function to perform a mathematical operation on two numbers based on a given operator. The function should handle all possible error scenarios, including invalid input types, invalid operators, and division by zero. The function should not use the built-in `eval` function. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python import operator def perform_operation(number1, number2, operation): """ Perform a mathematical operation on two numbers based on the given operator. Args: number1 (int or float): The first number. number2 (...
magic_evol_110k
70,550
Write a Python function to filter and log messages based on their levels. The function should accept a list of log messages and a list of log levels to filter out. It should return a list of log messages that do not contain any of the filtered log levels. The log messages are strings that contain the log level at the ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_logs(log_messages: List[str], filter_levels: List[str]) -> List[str]: """ Filters log messages based on the specified log levels to be filtered out. Args: log_messages (List[str])...
magic_evol_110k
70,568
Write a Python function to find the shared elements between two lists and return them in ascending order. The function must adhere to an O(nlogn) time complexity or better and should not use Python's intrinsic list methods for sorting or removing duplicates. The function 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 def shared_elements(list1: List[int], list2: List[int]) -> List[int]: """ Find the shared elements between two lists and return them in ascending order. This function uses set operations to efficien...
magic_evol_110k
70,579
Write a Python function to merge two sequences into one list, ensuring that the elements from the first sequence precede those from the second sequence. The function should handle nested sequences by flattening them before merging. The output should be a single list containing all the elements in their original order, ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def flatten(seq: List[Any]) -> List[Any]: """ Recursively flattens a nested list into a single list. Args: seq (List[Any]): The input list which may contain nested lists. Returns: ...
magic_evol_110k
70,589
Write a Python function to insert the string "Welcome to the party" at the end of a given list of strings, and then remove any duplicate elements while maintaining their original order. The function should start with: ```python from typing import List def insert_and_remove_duplicates(words: List[str]) -> List[str]: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def insert_and_remove_duplicates(words: List[str]) -> List[str]: """ Inserts the string "Welcome to the party" at the end of the provided list of strings, and removes any duplicate elements while mai...
magic_evol_110k
70,592
Write a Python function to determine if a given string is a palindrome. The function should ignore spaces, punctuation, and capitalization. The code should start with: ```python import re def is_palindrome(text: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_palindrome(text: str) -> bool: """ Determine if a given string is a palindrome, ignoring spaces, punctuation, and capitalization. Args: text (str): The input string to check. Returns: ...
magic_evol_110k
70,597
Write a Python function to construct a fully qualified URL using the provided subdomain, domain, and path fragment. The URL should use the HTTPS protocol and should be formatted correctly according to standard URL conventions. The function should handle the input parameters and return a properly formatted URL string. ...
Here is the Python code to solve the given problem in the markdown block: ```python def construct_url(subdomain: str, domain: str, path_fragment: str) -> str: """ Constructs a fully qualified URL using the provided subdomain, domain, and path fragment. Args: subdomain (str): The subdomain part of t...
magic_evol_110k
70,604
Write a Python function to calculate the product of the unique numbers from four given integers. The function should handle any integer inputs, including negative numbers and zeros. The code should start with: ```python from typing import List from functools import reduce def product_of_unique_numbers(numbers: List[in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from functools import reduce def product_of_unique_numbers(numbers: List[int]) -> int: """ Calculate the product of the unique numbers from a list of four integers. Args: numbers (List[int])...
magic_evol_110k
70,609
Write a Python function to remove consecutive duplicate characters from a given string. The function should return a new string where all consecutive duplicate characters are removed, leaving only the first occurrence of each character in a sequence of duplicates. The code should start with: ```python def remove_conse...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_consecutive_duplicates(s: str) -> str: """ Removes consecutive duplicate characters from the given string. Args: s (str): The input string from which consecutive duplicates are to be removed. Returns...
magic_evol_110k
70,614
Write a Python function to determine the number of double pandigital numbers that are divisible by 11. A double pandigital number is a positive integer that contains all the digits from 0 to 9 exactly twice, excluding any leading zero. The function should start with: ```python def count_double_pandigital_divisible_by_1...
Here is the Python code to solve the given problem in the markdown block: ```python from itertools import permutations def count_double_pandigital_divisible_by_11() -> int: """ Count the number of double pandigital numbers that are divisible by 11. A double pandigital number is a positive integer that con...
magic_evol_110k
70,622
Write a Python function to count the occurrences of each unique element in a given list and return the result as a dictionary. The function should handle any list of integers and return a dictionary where the keys are the unique elements from the list and the values are their respective counts. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_occurrences(arr: List[int]) -> Dict[int, int]: """ Counts the occurrences of each unique element in the given list. Args: arr (List[int]): The list of integers to count the o...
magic_evol_110k
70,631
Write a Python function to perform a vertical order traversal of a binary tree. The function should return a list of lists where each inner list contains the values of nodes at the same horizontal distance from the root. Nodes at the same horizontal distance should be grouped together from top to bottom, and if two nod...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import deque, defaultdict from typing import List, Optional class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def vertical...
magic_evol_110k
70,633
Write a Python function to implement the Bubble Sort algorithm to sort an array of integer values in ascending order. The function should handle arrays with duplicate integers. The code should start with: ```python from typing import List def bubble_sort(arr: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers in ascending order using the Bubble Sort algorithm. Args: arr (List[int]): The array of integers to be sorted. ...
magic_evol_110k
70,635
Write a Python function to implement a decrementing loop that starts from an integer value of 100 and stops if the current value is a prime number. The function should include a separate helper function to check if a number is prime. The loop should print the current value at each iteration and stop when a prime number...
Here is the Python code to solve the given problem in the markdown block: ```python 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. """ if n <= 1 o...
magic_evol_110k
70,643
Write a Python function to generate a new list of sole entities (values that appear only once) from a given unsorted list of integers, sorted in descending order. The function should have the following signature: ```python from typing import List def find_sole_entities(nums: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_sole_entities(nums: List[int]) -> List[int]: """ Generates a new list of sole entities (values that appear only once) from a given unsorted list of integers, sorted in descending order. Arg...
magic_evol_110k
70,649
Write a Python function to determine the number of rows and columns in a given two-dimensional array (2D array). The function should return a tuple containing the number of rows and columns. The code should start with: ```python from typing import List, Tuple def get_dimensions(array_2D: List[List[int]]) -> Tuple[int,...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def get_dimensions(array_2D: List[List[int]]) -> Tuple[int, int]: """ Determine the number of rows and columns in a given 2D array. Args: array_2D (List[List[int]]): A 2D array repres...
magic_evol_110k
70,650
Write a Python function to find the length of the longest valid (well-formed) parentheses substring from a given input string. The input string may contain parentheses `(` and `)`, special characters, and integers. The function should efficiently compute the result using a stack-based approach. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python def longest_valid_parentheses(s: str) -> int: """ Find the length of the longest valid (well-formed) parentheses substring in the given string. Args: s (str): The input string containing parentheses, special charact...
magic_evol_110k
70,655
Write a Python function to filter and return a new string containing only the characters from the input string that have a hexadecimal value within a specified range. The hexadecimal value range is from 0x00 to 0xFF. The function should also handle cases where the input string is empty or contains no characters within ...
Here is the Python code to solve the given problem in the markdown block: ```python def filter_hex_characters(input_str: str) -> str: """ Filters and returns a new string containing only the characters from the input string that have a hexadecimal value within the range 0x00 to 0xFF. Args: inpu...
magic_evol_110k
70,658
Write a Python function to find all prime numbers within a given list of integers. The function should return a list of prime numbers found in the input list. The code should start with: ```python from typing import List def find_prime_numbers(num_list: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def find_prime_numbers(num_list: List[int]) -> List[int]: """ Find all prime numbers within a given list of integers. Args: num_list (List[int]): A list of integers from which to...
magic_evol_110k
70,664
Write a Python function to sort an array of strings containing various names of fruits and generate a singular string output with the names of these fruits organized and neatly listed according to the rules of lexicographical sequence. The function should handle an empty list by returning an empty string. The code sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sorted_fruit_list(fruit_list: List[str]) -> str: """ Sorts a list of fruit names in lexicographical order and returns a single string with the names separated by commas. Args: fruit_list...
magic_evol_110k
70,678
Write a Python function to create a dictionary that stores information about a person's professional details. The dictionary should include the following keys: "Occupation", "Experience(Years)", and "Location". The function should accept three parameters corresponding to these keys and return the constructed dictionary...
Here is the Python code to solve the given problem in the markdown block: ```python def create_professional_details(occupation: str, experience_years: int, location: str) -> dict: """ Creates a dictionary containing professional details of a person. Args: occupation (str): The occupation of the per...
magic_evol_110k
70,688
Write a Python function to map each decimal in a given list to its corresponding reciprocal and return the results in a dictionary format. The reciprocal of a number \( x \) is \( \frac{1}{x} \). The function should handle cases where the input list may contain zero or negative numbers, returning `None` for such cases....
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Union from decimal import Decimal def reciprocal_mapping(decimals: List[Decimal]) -> Dict[Decimal, Union[Decimal, None]]: """ Maps each decimal in the given list to its corresponding reciprocal an...
magic_evol_110k
70,705
Write a Python function to find the longest word that can be formed using only the given set of alphabetical symbols. The function should take two inputs: a list of symbols and a list of words. The function should return the longest word that can be constructed using only the symbols provided. If no word can be formed,...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_longest_word(symbols: List[str], words: List[str]) -> str: """ Finds the longest word that can be formed using only the given set of alphabetical symbols. Args: symbols (List[str]):...
magic_evol_110k
70,719
Write a Python function to analyze a heterogeneous list containing integers, single-character strings, dictionaries, and nested lists. The function should separate and sort the integers and characters, count the number of dictionaries and their total items, and identify any other elements. The function should handle an...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple, Any def analyze_heterogeneous_list(input_list: List[Any]) -> Tuple[List[int], List[str], List[Dict[Any, Any]], List[Any]]: """ Analyze a heterogeneous list containing integers, single-chara...
magic_evol_110k
70,723
Write a Python function to find the index positions where a given string `y` occurs at least `z` times within a list of varying-length lists `info`. The function should return an array of tuples representing the (row, index) positions, sorted in ascending order. If `y` doesn't appear `z` times in any list, the function...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def get_indexes(info: List[List[str]], y: str, z: int) -> List[Tuple[int, int]]: """ Find the index positions where a given string `y` occurs at least `z` times within a list of varying-length lis...
magic_evol_110k
70,725
Write a Python function to filter and return a list of books published after a specified year from a given list of book dictionaries. Each book dictionary contains 'title' and 'year' keys. The function should start with: ```python from typing import List, Dict def filter_books_by_year(books: List[Dict[str, any]], year...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def filter_books_by_year(books: List[Dict[str, any]], year: int) -> List[Dict[str, any]]: """ Filters and returns a list of books published after a specified year. Args: books (List[Di...
magic_evol_110k
70,727
Write a Python function to determine if a given string of brackets is correctly balanced and nested according to the principles of correct syntax. The string can contain the following types of brackets: `<>`, `{}`, `[]`, and `()`. The function should return `True` if the brackets are correctly balanced and nested, and ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_correctly_bracketed(brackets: str) -> bool: """ Determines if the given string of brackets is correctly balanced and nested. Args: brackets (str): The string of brackets to be checked. Returns: b...
magic_evol_110k
70,735
Write a Python function to convert a JSON object representing an HTML structure into an HTML string. The JSON object is structured such that each element has a `tag` key, and may optionally have `text` and `childs` keys. The `childs` key is a list of nested JSON objects representing child elements. The function should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def json_to_html(json_obj: Dict[str, Any]) -> str: """ Converts a JSON object representing an HTML structure into an HTML string. Args: json_obj (Dict[str, Any]): A dictionary represent...
magic_evol_110k
70,736
Write a Python function to count the occurrences of a specific sequence of characters within a larger character string. The function should be case-sensitive and should handle overlapping occurrences correctly. The code should start with: ```python def count_occurrences(target: str, base_string: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_occurrences(target: str, base_string: str) -> int: """ Counts the occurrences of a specific sequence of characters within a larger character string. The function is case-sensitive and handles overlapping occurrence...
magic_evol_110k
70,739
Write a Python function to find the maximum numeric value from a given list of integers. The function should iterate through the list and update the maximum value found so far. The code should start with: ```python from typing import List def find_max_value(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_value(numbers: List[int]) -> int: """ Find the maximum numeric value from a given list of integers. Args: numbers (List[int]): A list of integers from which to find the maximum ...
magic_evol_110k
70,743
Write a Python function to implement a simplified version of the described API endpoint features using a list of dictionaries representing products. The function should handle pagination, sorting, and searching of the products. The function should return a list of products based on the provided query parameters. The c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Optional def query_products(products: List[Dict], page: int = 1, page_size: int = 10, sort_by: Optional[str] = None, search_term: Optional[str] = None) -> List[Dict]: """ Query and filter a list o...
magic_evol_110k
70,746
Write a Python function to extract elements found in even positions from a provided list, considering zero-based indexing. The function should return a new list containing only the elements from the even positions of the input list. The code should start with: ```python from typing import List def extract_even_positi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def extract_even_position_elements(lst: List[int]) -> List[int]: """ Extracts elements found in even positions from a provided list, considering zero-based indexing. Args: lst (List[int]): T...
magic_evol_110k
70,748
Write a Python function to construct an SQL query that retrieves the individual names of clients alongside the total count of unique orders per client from a table named 'orders'. Additionally, the query should account for cases where multiple orders are placed on the same day by a single client, treating them as a sin...
Here is the Python code to solve the given problem in the markdown block: ```python def construct_sql_query() -> str: """ Constructs an SQL query to retrieve the individual names of clients alongside the total count of unique orders per client from the 'orders' table. Additionally, the query accounts for mu...
magic_evol_110k
70,753
Write a Python function that processes a list of integers and returns a sorted list of unique elements without using Python's built-in `sort` function or `set` data structure. The function should remove duplicates and sort the list using a custom algorithm. 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 unique_sorted_list(lst: List[int]) -> List[int]: """ Returns a sorted list of unique elements from the input list without using Python's built-in sort function or set data structure. Args: ...
magic_evol_110k
70,758
Write a Python function to process two lists, `list_one` and `list_two`, sequentially using list comprehension. Each element in the resulting list should be the result of a mathematical operation applied on their corresponding items. Specifically, each item from `list_one` should be multiplied by two, then subtracted f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def process_lists(list_one: List[int], list_two: List[int]) -> List[int]: """ Processes two lists sequentially using list comprehension. Each element in the resulting list is the result of subtractin...
magic_evol_110k
70,761
Write a Python function to store a series of precisely 7 character long alphanumeric sequences in a list, ensuring they are unique and fall within the ASCII printable range (32-126). Implement functions to retrieve these sequences sorted lexicographically or by the frequency of a particular character. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def store_sequence(sequences: List[str], new_sequence: str) -> List[str]: """ Store a new 7-character alphanumeric sequence if it is unique and within the ASCII printable range. Args: sequen...
magic_evol_110k
70,766
Write a Python function to generate a sequence of numerical integers between a given start and end point, inclusive. The function should handle cases where the start point is greater than the end point by generating an empty list. Additionally, the function should be able to handle negative numbers and zero. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_sequence(start: int, end: int) -> List[int]: """ Generate a sequence of integers from the start point to the end point, inclusive. Args: start (int): The starting integer of the...
magic_evol_110k
70,767
Write a Python function to count the occurrences of each distinct character in a given string. The function should return a dictionary where the keys are the distinct characters and the values are their respective counts. The code should start with: ```python from typing import Dict def count_distinct_characters(strin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def count_distinct_characters(string: str) -> Dict[str, int]: """ Counts the occurrences of each distinct character in the given string. Args: string (str): The input string to count distinc...
magic_evol_110k
70,768
Write a Python function to filter out all null tuples from a given list of tuples. A null tuple is defined as a tuple with no elements (i.e., `()`). The function should return a new list containing only the non-null tuples. The code should start with: ```python from typing import List, Tuple def filter_null_tuples(tu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def filter_null_tuples(tuples_list: List[Tuple]) -> List[Tuple]: """ Filters out all null tuples from a given list of tuples. Args: tuples_list (List[Tuple]): A list of tuples from wh...
magic_evol_110k
70,770
Write a Python function to convert a list of floating-point numbers to a list of integers, handling any exceptions or errors that might occur during the conversion process. The function should return a list of integers if all conversions are successful, or an empty list if any conversion fails. 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 convert_float_list_to_int_list(float_list: List[float]) -> List[int]: """ Converts a list of floating-point numbers to a list of integers. If any conversion fails, returns an empty list. Arg...
magic_evol_110k
70,774
Create a Python function that validates user input from an HTML form. The form should include fields for the user's name, email, age, and favorite programming language. The function should validate the input fields and return a personalized message if all inputs are valid. If any input is invalid, the function should r...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Optional import re def validate_and_display_form(form_data: Dict[str, str]) -> Optional[str]: """ Validates the input fields from an HTML form and returns a personalized message if all inputs are valid....
magic_evol_110k
70,787
Write a Python function to flatten a nested list and then find the product of all elements contained within the flattened list. The function should handle any level of nested lists and should not use external libraries like `itertools` or `numpy`. The code should start with: ```python from typing import List def flatt...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def flatten_and_product(nested_list: List[List[int]]) -> int: """ Flatten a nested list into a single list and then find the product of all elements contained within the flattened list. Args: ...
magic_evol_110k
70,794
Write a Python function to create a new column in a DataFrame called `orc_4` that contains the value `1` if the value of the row in the `indictment_charges` column contains the substring `'2907.04'`, and `0` otherwise. The function should use the `pandas` library to manipulate the DataFrame. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python import pandas as pd def add_orc_4_column(df: pd.DataFrame) -> pd.DataFrame: """ Adds a new column 'orc_4' to the DataFrame. The column contains the value 1 if the value in the 'indictment_charges' column contains the substring ...
magic_evol_110k
70,814
Write a Python function to perform complex mathematical operations on a list of integers. The function should calculate the sum of squares of unique integers and the sum of absolute values of unique integers multiplied by the net product of signs for each unique number in the list. The signs are represented as 1 for po...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional, Tuple def complex_math_operations(arr: List[int]) -> Optional[Tuple[int, int]]: """ Given an array arr containing integers, this function calculates the sum of squares of unique integers a...
magic_evol_110k
70,826
Write a Python function to compute the sum of the maximum lengths of antichains of the set of factors for all integers in the range from 1 to a given integer `n`. An antichain is a subset of the set of factors where no element is divisible by any other element in the subset. The code should start with: ```python def su...
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_antichains(n: int) -> int: """ Compute the sum of the maximum lengths of antichains of the set of factors for all integers in the range from 1 to n. Args: n (int): The upper limit of the range. Retur...
magic_evol_110k
70,827
Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should start with: ```python from typing import List def unique_paths(m: int, n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def unique_paths(m: int, n: int) -> int: """ Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid. Args: m (int): The number of row...
magic_evol_110k
70,828
Write a Python function to replace all occurrences of a specified number in a given array with a new number. The function should return the updated array. The code should start with: ```python from typing import List def replace_number(input_array: List[int], origin_number: int, new_number: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def replace_number(input_array: List[int], origin_number: int, new_number: int) -> List[int]: """ Replaces all occurrences of a specified number in a given array with a new number. Args: inp...
magic_evol_110k
70,837
Write a Python function to reverse each word in a list of strings. The function should take a list of strings as input and return a new list where each word is reversed. The code should start with: ```python from typing import List def reverse_words(words: List[str]) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_words(words: List[str]) -> List[str]: """ Reverses each word in a list of strings. Args: words (List[str]): A list of strings where each string is a word. Returns: L...
magic_evol_110k
70,839
Write a Python function to convert an integer to its Roman numeral representation. The function should take an integer between 1 and 3999 (inclusive) and return a string representing the Roman numeral. The Roman numeral should be constructed using the standard symbols and rules for Roman numerals, including the special...
Here is the Python code to solve the given problem in the markdown block: ```python def int_to_roman(num: int) -> str: """ Convert an integer to its Roman numeral representation. Args: num (int): The integer to convert, between 1 and 3999 inclusive. Returns: str: The Roman numeral repr...
magic_evol_110k
70,842
Write a Python function to generate the first n Fibonacci numbers using a recursive approach. The function should include error checking to ensure that the input n is a positive integer and can handle cases where n is less than or equal to 1. Additionally, implement the solution in such a way that it efficiently handle...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_fibonacci(n: int) -> list: """ Generate the first n Fibonacci numbers using a recursive approach with memoization. Args: n (int): The number of Fibonacci numbers to generate. Returns: list:...
magic_evol_110k
70,845
Write a Python function to find the largest subset of distinct positive integers from a given list `nums` such that every pair of elements in the subset satisfies the condition: `answer[i] % answer[j] == 0` or `answer[j] % answer[i] == 0`. Additionally, the subset must contain the smallest and largest number from the o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def largest_divisible_subset(nums: List[int]) -> List[int]: """ Find the largest subset of distinct positive integers from a given list `nums` such that every pair of elements in the subset satisfies the...
magic_evol_110k
70,848
Write a Python function to identify and count the types of values found in a given dictionary. The function should return a dictionary where the keys are the names of the types (e.g., "str", "int", "bool", "list") and the values are the counts of how many times each type appears in the input dictionary. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def count_value_types(dictionary: Dict) -> Dict[str, int]: """ Counts the types of values in a given dictionary and returns a dictionary with the type names as keys and their counts as values. Args:...
magic_evol_110k
70,859
Write a Python function to check if all the items in a given list are of the same data type. Additionally, if the items are objects, ensure they are instances of the same class. The function should return `True` if all items are of the same type (and class, if applicable), and `False` otherwise. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def check_same_type(lst: List[Any]) -> bool: """ Check if all items in the given list are of the same data type. If the items are objects, ensure they are instances of the same class. Args:...
magic_evol_110k
70,878
Write a Python function to calculate the maximum disparity between the smallest and largest integer in each sub-matrix of a given bi-dimensional matrix. The function should return a list of these disparities for each sub-matrix. The code should start with: ```python from typing import List def find_disparities(matrix...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_disparities(matrix: List[List[int]]) -> List[int]: """ Calculate the maximum disparity between the smallest and largest integer in each sub-matrix of a given bi-dimensional matrix. Args: ...
magic_evol_110k
70,885
Write a Python function to filter a list of dictionaries representing persons, each containing the fields "name", "age", and "job". The function should return a new list containing only the persons whose 'job' field is 'developer'. Each dictionary in the returned list should only consist of the 'name' and 'age' fields....
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def get_developers(person_list: List[Dict[str, any]]) -> List[Dict[str, any]]: """ Filters a list of dictionaries representing persons and returns a new list containing only the persons whose '...
magic_evol_110k
70,886
Write a Python function to separate balanced groups of nested parentheses from a given string. Each group is balanced (every opening parenthesis has a corresponding closing parenthesis) and not embedded within another group. The function should disregard any spaces in the input string. The code should start with: ```p...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def separate_paren_groups(paren_string: str) -> List[str]: """ Separate balanced groups of nested parentheses from a given string. Args: paren_string (str): A string containing multiple sets...
magic_evol_110k
70,889
Write a Python function to swap the values of the `kth` node from the beginning and the `kth` node from the end in a singly linked list. The linked list is 1-indexed. The function should return the head of the modified linked list. The code should start with: ```python class ListNode: def __init__(self, val=0, nex...
Here is the Python code to solve the given problem in the markdown block: ```python class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def swap_kth_nodes(head: ListNode, k: int) -> ListNode: """ Swaps the values of the kth node from the beginning and the k...
magic_evol_110k
70,893
Write a Python function to find the common elements between two lists, considering both numbers and strings, and report their frequencies in each list. The comparison should be case-insensitive for strings. The results should be sorted in descending order based on the frequency of common elements in the second list. If...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_common_elements(list1: List[object], list2: List[object]) -> List[Tuple[str, int, int]]: """ Find common elements between two lists and report their frequencies in each list. The comp...
magic_evol_110k
70,895
Write a Python function to retrieve and print the value of a specific environment variable. If the environment variable does not exist, the function should print "NULL". The function should also print all environment variables along with their indices for debugging purposes. The code should start with: ```python impor...
Here is the Python code to solve the given problem in the markdown block: ```python import os def print_env_variable(env_var: str) -> None: """ Prints all environment variables along with their indices and retrieves the value of a specific environment variable. If the specified environment variable does no...
magic_evol_110k
70,896
Write a Python function to sort a list of dictionaries by the value of the "age" field in descending order. If two dictionaries have the same age, sort these entries based on the lexicographic order of their "name" field in ascending order. The code should start with: ```python from typing import List, Dict def sort_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def sort_by_age_and_name(data: List[Dict[str, any]]) -> List[Dict[str, any]]: """ Sorts a list of dictionaries by the "age" field in descending order. If two dictionaries have the same age, the...
magic_evol_110k
70,908
Write a Python function to merge two lists of emails and corresponding information based on the email. The lists may contain duplicates, and the duplicate entries should be resolved to a single entry chosen randomly from the duplicates. The merged result should be transformed into a dictionary where the keys are emails...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple import random def merge_email_lists(list1: List[Tuple[str, str, str]], list2: List[Tuple[str, str, str]]) -> Dict[str, Tuple[str, str, str]]: """ Merge two lists of emails and corresponding ...
magic_evol_110k
70,910
Write a Python function to count the frequency of each element in an n-sized matrix, where the matrix can contain nested lists and non-numerical elements. The function should return a dictionary where the keys are the elements and the values are their respective frequencies. The code should start with: ```python from ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any def count_frequency_in_matrix(matrix: List[List[Any]]) -> Dict[Any, int]: """ Counts the frequency of each element in an n-sized matrix, including nested lists and non-numerical elements. ...
magic_evol_110k
70,921
Write a Python function to generate a list of vowels present in a given string and count the occurrences of each vowel, considering both uppercase and lowercase letters. The function should return a dictionary where the keys are the vowels (in lowercase) and the values are the counts of those vowels in the string. The...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def count_vowels(s: str) -> Dict[str, int]: """ Counts the occurrences of each vowel in the given string, considering both uppercase and lowercase letters. Args: s (str): The input string to...
magic_evol_110k
70,922
Write a Python function that processes an array of integers and returns a dictionary containing specific information about the array. The function should: 1. Check if the array contains at least one positive integer. 2. Calculate the sum of all non-positive integers (i.e., negative integers and zeros) in the array. 3. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def analyze_array(arr: List[int]) -> Dict[str, any]: """ Analyzes an array of integers and returns a dictionary containing: - A boolean indicating if the array contains at least one positive in...
magic_evol_110k
70,946
Write a Python function to generate a list of prime numbers up to a given limit `n` using the Sieve of Eratosthenes algorithm. The function should return a list of all prime numbers less than `n`. The code should start with: ```python from typing import List def generate_primes(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_primes(n: int) -> List[int]: """ Generate a list of prime numbers up to a given limit `n` using the Sieve of Eratosthenes algorithm. Args: n (int): The upper limit for generatin...
magic_evol_110k
70,963
Write a Python function to transform a given string into uppercase and encrypt it using the Caesar cipher with a specified shift value. The Caesar cipher is a simple substitution cipher where each letter is replaced by another letter whose position in the alphabet is `shift` positions after the original letter. If it g...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher_encrypt(text: str, shift: int) -> str: """ Transforms the given string into uppercase and encrypts it using the Caesar cipher with the specified shift value. Args: text (str): The input string to b...
magic_evol_110k
70,968
Write a Python function to transform an array such that each element is replaced with the sum of all numeric elements before it. Additionally, implement error handling to exclude non-numeric elements from the sum and provide a reverse operation that can undo the array modifications. 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, Union def transform_array(array: List[Union[int, float, str]]) -> List[Union[int, float]]: """ Transforms the array such that each element is replaced with the sum of all numeric elements before it. ...
magic_evol_110k
70,970
Write a Python function to arrange the keys of a given dictionary in ascending order. The function should handle dictionaries with keys of mixed data types and return a relevant error message if the keys are not of the same type. The function should also return the dictionary with keys sorted in ascending order if all ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def order_keys(input_dict: Dict[Any, Any]) -> Dict[Any, Any] or str: """ Arrange the keys of a given dictionary in ascending order. If the keys are of mixed data types, return an error message. ...
magic_evol_110k
70,980
Write a Python function to create a shallow copy of a given list and demonstrate the behavior of shallow copying by modifying the original list and observing the changes in the copied list. The function should return a tuple containing the original list and the shallow copy. The code should start with: ```python from ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import copy def shallow_copy_demo(original_list: List) -> Tuple[List, List]: """ Creates a shallow copy of the given list and demonstrates the behavior of shallow copying. Args: origi...
magic_evol_110k
70,997
Write a Python function to calculate the length of a given string considering only alphabetic characters. Ignore spaces, punctuation, and numbers. The function should start with: ```python def get_alphabetic_length(string: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def get_alphabetic_length(string: str) -> int: """ Calculate the length of a given string considering only alphabetic characters. Ignore spaces, punctuation, and numbers. Args: string (str): The input string fro...
magic_evol_110k
71,006
Write a Python function to determine the frequency of a particular character in a given string. The function should be case-sensitive and should handle any string and character inputs. The code should start with: ```python def count_character_frequency(string: str, character: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_character_frequency(string: str, character: str) -> int: """ Counts the frequency of a particular character in a given string. Args: string (str): The string in which to count the character. charac...
magic_evol_110k
71,018
Write a Python function to find the smallest element in an array of size N efficiently. The function should iterate through the array only once to minimize the number of steps. The code should start with: ```python from typing import List def find_smallest_element(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_smallest_element(arr: List[int]) -> int: """ Finds the smallest element in an array of integers. Args: arr (List[int]): The array of integers from which to find the smallest element...
magic_evol_110k
71,022
Write a Python function to generate a string of exactly eight characters, consisting of a balanced mix of alphanumeric characters (letters and digits). The string should be generated such that half of the characters are digits and the other half are letters. The function should ensure that the resulting string is uniqu...
Here is the Python code to solve the given problem in the markdown block: ```python import random import string def generate_balanced_string() -> str: """ Generates a string of exactly eight characters, consisting of a balanced mix of alphanumeric characters (4 letters and 4 digits). The characters are sh...
magic_evol_110k
71,039
Write a Python function to filter and return a list of numbers that fall within a specified range from a given list of integers. The function should take three parameters: the list of integers, the lower bound (inclusive), and the upper bound (inclusive). The function should return a new list containing only the number...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_numbers_in_range(numbers: List[int], lower_bound: int, upper_bound: int) -> List[int]: """ Filters and returns a list of numbers that fall within the specified range [lower_bound, upper_bound]...
magic_evol_110k
71,042
Write a Python function to count the number of non-overlapping occurrences of a search sequence within a principal sequence. The function should handle cases where the search sequence is an empty string and should be efficient in terms of time complexity. The code should start with: ```python def count_occurrences(mai...
Here is the Python code to solve the given problem in the markdown block: ```python def count_occurrences(main_sequence: str, search_sequence: str) -> int: """ Counts the number of non-overlapping occurrences of a search sequence within a principal sequence. Args: main_sequence (str): The principal...
magic_evol_110k
71,043
Write a Python function to calculate the sum of all individual digits in a given integer. The function should handle both positive and negative integers. The code should start with: ```python def sum_of_digits(num: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_digits(num: int) -> int: """ Calculate the sum of all individual digits in a given integer. Args: num (int): The integer whose digits are to be summed. Returns: int: The sum of all individual...
magic_evol_110k
71,047
Write a Python function to compute the value of \( Q(n) \) as defined in the given code snippet. The function should calculate the sum of \( E(904961, i) \) for \( i \) from 1 to \( n \), where \( E(m, n) \) is the greatest integer \( k \) such that \( 2^k \) divides \( S((p_m\#)^n) \). Here, \( S(n) \) represents the ...
Here is the Python code to solve the given problem in the markdown block: ```python def compute_Q(n: int) -> int: """ Compute the value of Q(n) as defined in the problem statement. Args: n (int): The upper limit for the summation of E(904961, i) from 1 to n. Returns: int: The computed ...
magic_evol_110k
71,052
Write a Python function to reverse an alphanumeric string while preserving the positions of non-alphanumeric characters. The function should take an alphanumeric string as input and return the reversed string with non-alphanumeric characters in their original positions. The code should start with: ```python def revers...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_alphanumeric_string(input_string: str) -> str: """ Reverses the alphanumeric characters in the input string while preserving the positions of non-alphanumeric characters. Args: input_string (str): The in...
magic_evol_110k
71,069
Write a Python function to identify the official language of a given country from a dataset. The dataset is a dictionary where the keys are descriptive strings and the values are the corresponding data. The function should return the official language as a string. 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 Dict def get_official_language(dataset: Dict[str, str]) -> str: """ Identify and return the official language of a given country from a dataset. Args: dataset (Dict[str, str]): A dictionary conta...
magic_evol_110k
71,075
Write a Python function to generate a list of prime numbers up to a given number \( N \) efficiently using the Sieve of Eratosthenes algorithm. The function should also include comprehensive error handling to ensure that the input is a non-negative integer. The code should start with: ```python def generate_primes(n: i...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_primes(n: int) -> list: """ Generate a list of prime numbers up to a given number n using the Sieve of Eratosthenes algorithm. Args: n (int): The upper limit up to which prime numbers are to be generate...
magic_evol_110k
71,085
Write a Python function to instantiate a three-dimensional tensor filled with arbitrary whole numbers and then reshape it into a one-dimensional vector. The function should return the reshaped vector. The code should start with: ```python import numpy as np def reshape_tensor(size: int) -> np.ndarray: ```
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def reshape_tensor(size: int) -> np.ndarray: """ Instantiates a three-dimensional tensor filled with arbitrary whole numbers and reshapes it into a one-dimensional vector. Args: size (int): The s...
magic_evol_110k
71,114
Write a Python function to reverse a given string of ASCII characters and maintain a frequency count of each character. The frequency count should not differentiate between upper and lower-case characters. The function should return the reversed string and a dictionary containing the frequency count of each character. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Tuple def reverse_string_and_count_frequency(input_string: str) -> Tuple[str, Dict[str, int]]: """ Reverses the given string and counts the frequency of each character, ignoring case. Args: ...
magic_evol_110k
71,118
Write a Python function to find the smallest number in a given list of integers. The function should be efficient and handle various edge cases, such as an empty list or a list with all identical elements. The code should start with: ```python from typing import List def find_smallest_number(int_list: List[int]) -> in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_smallest_number(int_list: List[int]) -> int: """ Find the smallest number in a given list of integers. Args: int_list (List[int]): The list of integers to search through. Retur...
magic_evol_110k
71,122
Write a Python function to sort a list of floating point numbers in descending order. The function should be efficient and handle various edge cases, such as an empty list or a list with duplicate values. The code should start with: ```python from typing import List def sort_floats_descending(nums: List[float]) -> Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_floats_descending(nums: List[float]) -> List[float]: """ Sorts a list of floating point numbers in descending order. Args: nums (List[float]): The list of floating point numbers to ...
magic_evol_110k
71,124
Write a Python function to concatenate a list of dissociated alphabetic characters into a single, uninterrupted string. The function should handle lists of varying lengths and ensure that the characters are joined in the order they appear in the list. The code should start with: ```python from typing import List def c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def concatenate_characters(characters: List[str]) -> str: """ Concatenates a list of dissociated characters into a single, uninterrupted string. Args: characters (List[str]): A list of strin...
magic_evol_110k
71,125
Write a Python function to check whether two lists are equal in terms of their elements and their frequencies, even if the elements are not in the same order. The function should return `True` if the lists are equal and `False` otherwise. The code should start with: ```python from typing import List from collections im...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import Counter def are_lists_equal(lst1: List[int], lst2: List[int]) -> bool: """ Check whether two lists are equal in terms of their elements and their frequencies, even if the elem...
magic_evol_110k
71,130
Write a Python function to generate the Fibonacci sequence up to a specified number of terms. The function should handle invalid inputs gracefully by raising a `ValueError` for non-positive integers or non-integer inputs. The function should start with: ```python def generate_fibonacci(n: int) -> list: ```
Here is the Python code to solve the given problem in the markdown block: ```python def generate_fibonacci(n: int) -> list: """ Generate the Fibonacci sequence up to a specified number of terms. Args: n (int): The number of terms in the Fibonacci sequence to generate. Returns: list: A ...
magic_evol_110k
71,148
Write a Python function to sort an array of non-negative integral values in ascending order. The function should use a stable sorting algorithm to ensure that the relative order of equal elements is preserved. The code should start with: ```python from typing import List def sort_array(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 sort_array(array: List[int]) -> List[int]: """ Sorts an array of non-negative integral values in ascending order. Args: array (List[int]): The array of non-negative integers to be sort...
magic_evol_110k
71,151
Write a Python function to compute the summation of a specified numeric range present in a matrix of integer vectors. The function should be robust to handle different sizes of matrices and able to perform operations even when elements of the matrix are of different lengths. The code should start with: ```python from t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_sum_in_range(matrix: List[List[int]], lower: int, upper: int) -> int: """ Computes the summation of elements within a specified numeric range in a matrix of integer vectors. Args: ma...
magic_evol_110k
71,154
Write a Python function to find the last position of a target element in a sorted array. The array may contain duplicate elements and negative numbers. Implement this function without using built-in methods and with a time complexity better than O(n). The code should start with: ```python def find_last_position(nums: ...
Here is the Python code to solve the given problem in the markdown block: ```python def find_last_position(nums: list, target: int) -> int: """ Find the last position of a target element in a sorted array. Args: nums (list): A sorted list of integers which may contain duplicates and negative number...
magic_evol_110k
71,156
Write a Python function to compute the factorial of a given non-negative integer `n` using an iterative approach. The function should be optimized for performance and should handle large values of `n` efficiently. The code should start with: ```python def factorial(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def factorial(n: int) -> int: """ Compute the factorial of a given non-negative integer `n` using an iterative approach. Args: n (int): The non-negative integer for which to compute the factorial. Returns: ...
magic_evol_110k
71,160
Write a Python function to check if each element in a given list `list_to_check` exists in another list `list_of_numbers`. The function should return a list of boolean values where each boolean indicates whether the corresponding element in `list_to_check` is present in `list_of_numbers`. Additionally, the function sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def check_elements_in_list(list_of_numbers: List[int], list_to_check: List[int]) -> List[bool]: """ Check if each element in `list_to_check` exists in `list_of_numbers` and return a list of boolean value...
magic_evol_110k
71,176
Write a Python program that generates a list of prime numbers from 0 to 100 and stores them in a variable. Additionally, the program must have a function that checks if a provided number is in the list of prime numbers, returning a boolean value. The code should start with: ```python def generate_prime_numbers(limit: i...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_prime_numbers(limit: int) -> list: """ Generate a list of prime numbers from 0 to the given limit. Args: limit (int): The upper limit (inclusive) for generating prime numbers. Returns: list...
magic_evol_110k
71,179
Write a Python function to determine if a given number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding itself). The function should return `True` if the number is perfect and `False` otherwise. The code should start with: ```python def is_perfect_nu...
Here is the Python code to solve the given problem in the markdown block: ```python def is_perfect_number(n: int) -> bool: """ Determine if the given number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding itself). Args: n (...
magic_evol_110k
71,183
Write a Python function to determine if a person can attend all meetings in a given list of intervals without any overlap. Each interval is represented as a list `[start, end]`, where `start` is the start time and `end` is the end time of the meeting. The function should return `True` if all meetings can be attended wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def can_attend_all_meetings(intervals: List[List[int]]) -> bool: """ Determines if a person can attend all meetings without any overlap. Args: intervals (List[List[int]]): A list of interval...
magic_evol_110k
71,195
Write a Python function to perform a two-part mathematical calculation and return the resultant value. The function should first multiply two given numbers, then divide another given number by a fourth given number, and finally add the results of these two operations. The code should start with: ```python def combined...
Here is the Python code to solve the given problem in the markdown block: ```python def combined_calculation(num1: int, num2: int, num3: int, num4: int) -> float: """ Perform a two-part mathematical calculation and return the resultant value. The function first multiplies num1 by num2, then divides num3 by...
magic_evol_110k
71,198
Write a Python function to assess the congruence of two given dictionaries. The function should check if the two dictionaries have the same keys and corresponding values, regardless of the order in which they appear. The function should return `True` if the dictionaries are congruent, and `False` otherwise. The code s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def are_dictionaries_congruent(dict1: Dict[int, int], dict2: Dict[int, int]) -> bool: """ Assess the congruence of two given dictionaries. Args: dict1 (Dict[int, int]): The first dictionary ...
magic_evol_110k
71,217
Write a Python function to find the intersection of two given lists of integers. The intersection is defined as the set of elements that are present in both lists. The function should return a list of these common elements in ascending order. The code should start with: ```python from typing import List def find_inte...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_intersection(arr1: List[int], arr2: List[int]) -> List[int]: """ Find the intersection of two lists of integers and return the common elements in ascending order. Args: arr1 (List[i...