source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
magic_evol_110k
71,898
Write a Python function to count the number of distinct islands in a given two-dimensional binary grid. An island is defined as a contiguous landmass formed by horizontally or vertically adjacent land cells ('1'), and is entirely surrounded by water ('0'). The grid is assumed to be surrounded by water on all sides. Th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_islands(grid: List[List[str]]) -> int: """ Count the number of distinct islands in a given 2D binary grid. Args: grid (List[List[str]]): A 2D list representing the binary grid wher...
magic_evol_110k
71,910
Write a Python function to convert an adjacency matrix representation of an undirected graph into its corresponding adjacency list representation. The adjacency matrix is a 2D list where `matrix[i][j]` is 1 if there is an edge between vertex `i` and vertex `j`, and 0 otherwise. The adjacency list should be a dictionary...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def adjacency_matrix_to_list(matrix: List[List[int]]) -> Dict[int, List[int]]: """ Converts an adjacency matrix representation of an undirected graph into an adjacency list representation. Arg...
magic_evol_110k
71,911
Write a Python function to check if a target element is present in a given dataset efficiently. The dataset is a list of integers. The function should use a more efficient data structure to improve the performance of the search operation. The code should start with: ```python from typing import List def is_target_in_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_target_in_dataset(dataset: List[int], target: int) -> bool: """ Checks if the target element is present in the given dataset efficiently. Args: dataset (List[int]): The dataset in whi...
magic_evol_110k
71,916
Write a Python function to calculate the average of three numbers using hardware optimization for better performance. The function should leverage vectorized operations provided by the NumPy library to achieve this. The code should start with: ```python import numpy as np def optimized_average_of_three(num1: float, nu...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def optimized_average_of_three(num1: float, num2: float, num3: float) -> float: """ Calculate the average of three numbers using hardware-optimized vectorized operations. Args: num1 (float): The ...
magic_evol_110k
71,919
Write a Python function to reverse a given list and return a new list where each element is repeated twice. The function should start with: ```python from typing import List def reverse_and_double(nums: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def reverse_and_double(nums: List[int]) -> List[int]: """ Reverses the given list and returns a new list where each element is repeated twice. Args: nums (List[int]): The list of integers ...
magic_evol_110k
71,920
Write a Python function to calculate the Greatest Common Divisor (GCD) for four number inputs (a, b, c, and d) efficiently. The function should be optimized for computational effectiveness and should handle the constraints where 1 ≤ a, b, c, d ≤ 10^9. The function should start with: ```python def gcd_four_numbers(a: in...
Here is the Python code to solve the given problem in the markdown block: ```python def gcd(a: int, b: int) -> int: """ Standard Euclid's GCD calculation method for a and b. Args: a (int): The first integer. b (int): The second integer. Returns: int: The greatest common divisor...
magic_evol_110k
71,929
Write a Python function to extract all numerical figures from a given text string. The function should return a list of integers found in the text. The code should start with: ```python from typing import List import re def extract_numbers(text: str) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def extract_numbers(text: str) -> List[int]: """ Extracts all numerical figures from the given text string and returns them as a list of integers. Args: text (str): The input text ...
magic_evol_110k
71,931
Write a Python function to calculate the factorial of a given non-negative integer using a recursive approach. The function should handle the base case and the recursive case appropriately. Additionally, ensure that the function is designed to handle large inputs by setting an appropriate recursion limit. The code sho...
Here is the Python code to solve the given problem in the markdown block: ```python import sys sys.setrecursionlimit(10000) def factorial_recursive(n: int) -> int: """ Calculate the factorial of a given non-negative integer using a recursive approach. Args: n (int): The non-negative integer for wh...
magic_evol_110k
71,937
Write a Python function to calculate the minimum balance encountered during a series of deposit and withdrawal operations on a bank account. The function should return the smallest balance experienced. If the balance never goes below zero, the function should return 0. The code should start with: ```python from typing...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def minimum_balance(operations: List[int]) -> int: """ Calculate the minimum balance encountered during a series of deposit and withdrawal operations. Args: operations (List[int]): A list of...
magic_evol_110k
71,942
Write a Python function to compute the cumulative average for each row in a DataFrame, ignoring any instances where the value is zero. The DataFrame contains a 'Name' column and several year columns (e.g., '2001', '2002', etc.). The function should return a DataFrame with the same structure, but with cumulative average...
Here is the Python code to solve the given problem in the markdown block: ```python import pandas as pd import numpy as np def cumulative_average_with_zeros_ignored(df: pd.DataFrame) -> pd.DataFrame: """ Compute the cumulative average for each row in a DataFrame, ignoring zeros. Args: df (pd.DataF...
magic_evol_110k
71,950
Write a Python function to remove duplicate text entities from a given input sequence while preserving the order of their first occurrence. The input sequence is a list of strings. The function should return a new list containing only the unique text entities in the order they first appeared in the input sequence. The...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_preserve_order(input_sequence: List[str]) -> List[str]: """ Removes duplicate text entities from the input sequence while preserving the order of their first occurrence. Args: ...
magic_evol_110k
71,951
Write a Python function to calculate the minimum amount of money required to guarantee a win in the Guessing Game with a twist. In this game, you pick a number between `1` and `n`, and the player guesses a number. If the guess is wrong, the player pays the amount of the guessed number in dollars. After each wrong guess...
Here is the Python code to solve the given problem in the markdown block: ```python def get_minimum_cost_to_win(n: int) -> int: """ Calculate the minimum amount of money required to guarantee a win in the Guessing Game with a twist. Args: n (int): The upper limit of the range of numbers to guess fr...
magic_evol_110k
71,956
Write a Python function to detect if the balance of a bank account dips below zero at any point during a series of deposit and withdrawal operations. The operations can be integers, strings representing integers, or tuples containing both. If a tuple is encountered, the operation should be performed multiple times, usi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union, Tuple def below_zero(operations: List[Union[Tuple[int, str], int]], case_insensitive: bool = False) -> bool: """ Detect if the balance of a bank account dips below zero at any point during a seri...
magic_evol_110k
71,963
Write a Python function to compute the least common multiple (LCM) of two given integers. The function should be able to handle any positive integers and return the correct LCM. The code should start with: ```python import math def least_common_multiple(a: int, b: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python import math def least_common_multiple(a: int, b: int) -> int: """ Compute the least common multiple (LCM) of two integers. Args: a (int): The first integer. b (int): The second integer. Returns: ...
magic_evol_110k
71,967
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 segments in two specific ways: `aprefix + bsuffix` or `bprefix + asuffix`. The function should return `True` if either concatenation results in...
Here is the Python code to solve the given problem in the markdown block: ```python def can_form_palindrome(a: str, b: str) -> bool: """ Determines if it is possible to construct a palindrome by partitioning two strings `a` and `b` at the same index and concatenating the resulting segments in two specific w...
magic_evol_110k
71,968
Write a Python function to reconstruct a permutation `perm` of `n + 1` integers from a given string `s` of length `n` where: - `s[i] == 'I'` if `perm[i] < perm[i + 1]`, and - `s[i] == 'D'` if `perm[i] > perm[i + 1]`. Additionally, return the number of possible permutations that can be formed from the given string `s`....
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def di_string_match(s: str) -> Tuple[List[int], int]: """ Reconstructs a permutation `perm` of `n + 1` integers from a given string `s` of length `n` and returns the number of possible permuta...
magic_evol_110k
71,971
Write a Python function to generate a numeric table or matrix with an incremental sequence starting from a given number, encompassing a predefined dimension structure of breadth and length, denoted by `m` and `n`. The function should return the generated matrix. The code should start with: ```python from typing import...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_incremental_matrix(start: int, m: int, n: int) -> List[List[int]]: """ Generates a numeric matrix with an incremental sequence starting from a given number. Args: start (int): T...
magic_evol_110k
71,980
Write a Python function to extract entries from a dictionary whose keys start with a specified alphabetic character. The function should use dictionary comprehension to achieve this. The code should start with: ```python from typing import Dict def extract_entries_by_prefix(dictionary: Dict[str, int], prefix: str) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def extract_entries_by_prefix(dictionary: Dict[str, int], prefix: str) -> Dict[str, int]: """ Extracts entries from a dictionary whose keys start with a specified prefix. Args: dictionary (D...
magic_evol_110k
71,982
Write a Python function to implement an optimized bubble sort algorithm that can sort both a list of integers and a list of dictionaries based on a specified key. The function should stop early if the list is already sorted to improve efficiency. The code should start with: ```python from typing import List, Union def...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def optimized_bubble_sort(arr: Union[List[int], List[dict]], sort_key: str = None) -> Union[List[int], List[dict]]: """ Sorts a list of integers or a list of dictionaries using an optimized bubble...
magic_evol_110k
71,987
Write a Python function to count the number of vowels in a given string, considering both uppercase and lowercase vowels. The function should iterate through each character in the string and increment a counter whenever a vowel is encountered. The function should return the total count of vowels. The code should start...
Here is the Python code to solve the given problem in the markdown block: ```python def count_vowels(input_string: str) -> int: """ Counts the number of vowels in the given input string. Args: input_string (str): The string in which to count the vowels. Returns: int: The total number o...
magic_evol_110k
72,002
Write a Python function to replicate each word in a given text a specified number of times. The function should accept a string and an integer as input and return a new string where each word from the original text is repeated according to the specified integer. The code should start with: ```python def replicate_word...
Here is the Python code to solve the given problem in the markdown block: ```python def replicate_words(text: str, number: int) -> str: """ Replicates each word in the given text a specified number of times. Args: text (str): The input text containing words to be replicated. number (int): T...
magic_evol_110k
72,003
Write a Python function to calculate the nth Fibonacci number using memoization to optimize the computation. The function should take an integer `n` as input and return the nth Fibonacci number. The memoization technique should be used to store previously computed Fibonacci numbers to avoid redundant calculations and i...
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci_memoized(n: int) -> int: """ Calculate the nth Fibonacci number using memoization to optimize the computation. Args: n (int): The position in the Fibonacci sequence to compute. Returns: in...
magic_evol_110k
72,019
Write a Python function to classify a list of integers as prime or not prime, and optimize it for searching large datasets. The function should return two lists: one containing prime numbers and the other containing non-prime numbers. The code should start with: ```python from typing import List, Tuple import math def...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import math def classify_primes(numbers: List[int]) -> Tuple[List[int], List[int]]: """ Classify a list of integers as prime or not prime. Args: numbers (List[int]): A list of integer...
magic_evol_110k
72,021
Write a Python function to filter and extract hourly rainfall data from a given dataset where the rainfall values exceed a specified threshold. The dataset is represented as a list of dictionaries, where each dictionary contains 'hour' and 'rainfall' keys. The function should return a list of dictionaries containing on...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def filter_high_rainfall(rainfall_data: List[Dict[str, int]], threshold: int) -> List[Dict[str, int]]: """ Filters and extracts hourly rainfall data where the rainfall values exceed a specified thr...
magic_evol_110k
72,028
Write a Python function to convert a string of digits to the corresponding integer value without using built-in functions like `int()` or `atoi()`. Additionally, handle potential edge cases such as invalid characters in the string. The function should raise a `ValueError` if any character in the string is not a digit. ...
Here is the Python code to solve the given problem in the markdown block: ```python def string_to_int(string: str) -> int: """ Converts a string of digits to the corresponding integer value without using built-in functions like int() or atoi(). Raises a ValueError if any character in the string is not a dig...
magic_evol_110k
72,031
Write a Python function that prints the product of the current values of an outer loop variable, an inner loop variable, and the index of the inner loop variable. The outer loop should iterate over a list of numbers from 1 to 3, and the inner loop should also iterate over a list of numbers from 1 to 3. The function sho...
Here is the Python code to solve the given problem in the markdown block: ```python def print_products(): """ Prints the product of the current values of an outer loop variable, an inner loop variable, and the index of the inner loop variable. Both loops iterate over a list of numbers from 1 to 3. Args...
magic_evol_110k
72,034
Write a Python function to generate an Elasticsearch query that limits the number of search results for a given keyword. The function should accept three parameters: the field name to search in, the keyword to search for, and the maximum number of results to return. The function should return a dictionary representing ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def generate_search_query(field_name: str, keyword: str, max_results: int) -> Dict: """ Generates an Elasticsearch query to limit the number of search results for a given keyword. Args: fiel...
magic_evol_110k
72,043
Write a Python function to decompose a given sentence into its constituent words and return them in a list. Additionally, provide a function to analyze the frequency of each word in the sentence. The code should start with: ```python from typing import List, Dict def decompose_sentence(sentence: str) -> List[str]: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def decompose_sentence(sentence: str) -> List[str]: """ Decomposes a given sentence into its constituent words. Args: sentence (str): The sentence to be decomposed. Returns: ...
magic_evol_110k
72,051
Write a Python function to calculate the Least Common Multiple (LCM) of four given integers. The function should be able to handle any quartet of positive integers and return their LCM. The code should start with: ```python from typing import List from math import gcd def lcm_of_four(a: int, b: int, c: int, d: int) ->...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from math import gcd def lcm(a: int, b: int) -> int: """ Calculate the Least Common Multiple (LCM) of two integers. Args: a (int): The first integer. b (int): The second integer. ...
magic_evol_110k
72,064
Write a Python function to find the index of a specified term in a given text sequence. The function should return the index of the first occurrence of the term if it exists, otherwise return -1. The text sequence can contain multiple words separated by spaces. The code should start with: ```python from typing import ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_term_index(text_sequence: str, search_term: str) -> int: """ Finds the index of the first occurrence of a specified term in a given text sequence. Args: text_sequence (str): The tex...
magic_evol_110k
72,070
Write a Python function to replace each item in a given list with a random integer within a specified range. The function should modify the list in place and return the modified list. The code should start with: ```python from typing import List import random def replace_with_random(my_list: List[int], lower_bound: in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def replace_with_random(my_list: List[int], lower_bound: int, upper_bound: int) -> List[int]: """ Replaces each item in the given list with a random integer within the specified range. ...
magic_evol_110k
72,083
Write a Python function to sort a collection of real numbers, expressed in floating point notation, in descending order. The function should handle any list of floating-point numbers and return the sorted list in descending order. The code should start with: ```python from typing import List def sort_descending(collec...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def sort_descending(collection: List[float]) -> List[float]: """ Sorts a collection of real numbers in descending order. Args: collection (List[float]): The collection of floating-point nu...
magic_evol_110k
72,084
Write a Python function to create a dictionary where the keys are the elements of a given tuple and the values are their corresponding indices in the tuple. The function should handle tuples of any length and return the resulting dictionary. The code should start with: ```python from typing import Tuple, Dict def tup...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Dict def tuple_to_indexed_dict(my_tuple: Tuple[int]) -> Dict[int, int]: """ Creates a dictionary from a tuple where each element of the tuple becomes a key and its index becomes the corresponding value...
magic_evol_110k
72,089
Write a Python function to generate a unique geometric sequence of numbers. The sequence must be increasing, at least 10 elements long, and cannot include any negative numbers or fractions. The function should validate the input parameters and ensure that the sequence adheres to the specified constraints. The code sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_geometric_sequence(start: float, ratio: float, length: int) -> List[float]: """ Generates a unique geometric sequence of numbers. The sequence is increasing, at least 10 elements long, a...
magic_evol_110k
72,094
Write a Python function to determine if the cumulative sum of all elements at even indices in a given list of integers is within a specified range. The list must have an even number of non-empty elements. The function should return `True` if the cumulative sum is within the specified range (inclusive), and `False` othe...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_evenid_within_bounds(l: List[int], lower_limit: int, upper_limit: int) -> bool: """ Determines if the cumulative sum of all integers at even indices in the list `l` is within the range [lower...
magic_evol_110k
72,108
Write a Python function to solve a given linear equation of the form `a - b + c = d` for the variable `c`, where `a`, `b`, and `d` are constants. The function should return the value of `c` that satisfies the equation. The code should start with: ```python def solve_for_c(a: int, b: int, d: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def solve_for_c(a: int, b: int, d: int) -> int: """ Solves the linear equation a - b + c = d for the variable c. Args: a (int): The first constant in the equation. b (int): The second constant in the equatio...
magic_evol_110k
72,122
Write a Python function to split a given sentence into individual words and return them as a list. The function should handle sentences with varying numbers of spaces between words and should not include empty strings in the result. The code should start with: ```python from typing import List def split_sentence_into_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def split_sentence_into_words(sentence: str) -> List[str]: """ Splits a given sentence into individual words and returns them as a list. Args: sentence (str): The sentence to be split into w...
magic_evol_110k
72,139
Write a Python function to find the longest common continuous subarray between two given arrays of integers. The function should return the subarray and its length. The code should start with: ```python from typing import List, Tuple def longest_common_continuous_subarray(arr1: List[int], arr2: List[int]) -> Tuple[Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def longest_common_continuous_subarray(arr1: List[int], arr2: List[int]) -> Tuple[List[int], int]: """ Finds the longest common continuous subarray between two given arrays of integers. Args:...
magic_evol_110k
72,150
Write a Python function to generate a 3-dimensional tensor (a 3D array) of given dimensions `x`, `y`, and `z`, where each element in the tensor is a random integer from a predefined list of integers ranging from 0 to 20. The function should return the generated tensor. The code should start with: ```python from typing...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import numpy as np def generate_random_tensor(x: int, y: int, z: int) -> np.ndarray: """ Generates a 3-dimensional tensor of dimensions x, y, and z, where each element is a random integer from a predefin...
magic_evol_110k
72,154
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
72,181
Write a Python function to determine if two character sequences can be made congruent by performing exactly one of the following modifications on the first sequence: inserting a character, removing a character, or replacing a character. The sequences should only include lowercase letters and must match exactly after th...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_congruent_after_one_modification(string1: str, string2: str) -> bool: """ Determines if two character sequences can be made congruent by performing exactly one of the following modifications on the first sequen...
magic_evol_110k
72,192
Write a Python function to convert a list of monetary values from their originating currencies to their target currencies using predefined exchange rates. The function should handle multiple conversions simultaneously and include error checking for invalid currencies or mismatched list lengths. 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 convert_currency(monetary_values: List[float], originating_currencies: List[str], target_currencies: List[str], exchange_rates: Dict[str, Dict[str, float]]) -> List[float]: """ Converts a list ...
magic_evol_110k
72,200
Write a Python function to perform a parallel binary search on a sorted list of integers to find the index of a specified value. The function should be efficient and capable of handling very large sequences with more than 1,000,000 integers. The function should utilize Python's `concurrent.futures` module to achieve pa...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional from concurrent.futures import ThreadPoolExecutor, as_completed def binary_search(sequence: List[int], target: int, low: int, high: int) -> Optional[int]: """ Perform a binary search on a sorte...
magic_evol_110k
72,216
Write a Python function to check if a string `b` can be found in string `a` after cyclically rotating `b` any number of times. A cyclic rotation of a string involves moving its last character to the front. For example, the string "abc" cyclically rotated once becomes "cab". The function should return `True` if `b` can...
Here is the Python code to solve the given problem in the markdown block: ```python def cyc_pattern_check(a: str, b: str) -> bool: """ Check if string `b` can be found in string `a` after any number of cyclic rotations. Args: a (str): The main string in which to search for `b`. b (str): The...
magic_evol_110k
72,218
Write a Python function to transform an Entity-Relationship (ER) model into a Relational model and generate SQLite3 table creation SQL statements. The ER model is represented as a dictionary where keys are entity names and values are lists of attributes. The relationships between entities are represented as tuples of e...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def generate_sql_from_er_model(er_model: Dict[str, List[str]], relationships: List[Tuple[str, str]]) -> List[str]: """ Generates SQLite3 table creation SQL statements from an ER model. ...
magic_evol_110k
72,230
Write a Python function to calculate the sum of all elements in two lists `A` and `B`, and also find the cross sum of elements at the same index position in both lists. The function should handle potential overflow errors by using Python's arbitrary-precision integers. The code should start with: ```python from typing ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_sums(A: List[int], B: List[int]) -> (int, int): """ Calculate the sum of all elements in two lists A and B, and the cross sum of elements at the same index position. Args: A (L...
magic_evol_110k
72,233
Write a Python function to recursively search for a specific value `k` within deeply nested tuples and dictionaries, and count its frequency. The function should handle invalid inputs appropriately and return a string indicating invalid input if the input is neither a tuple nor a dictionary. The function should be opti...
Here is the Python code to solve the given problem in the markdown block: ```python def find_frequency(data, to_find='k') -> int or str: """ Recursively searches for a specific value 'k' within deeply nested tuples and dictionaries, and counts its frequency. Returns "Invalid input!" if the input is neither ...
magic_evol_110k
72,243
Write a Python function to convert any given string into snake case notation. Snake case notation is a string format where all letters are in lowercase and words are separated by underscores. The input string may contain uppercase letters, lowercase letters, and spaces. The function should handle multiple consecutive s...
Here is the Python code to solve the given problem in the markdown block: ```python def to_snake_case(s: str) -> str: """ Converts a given string into snake case notation. Snake case notation is a string format where all letters are in lowercase and words are separated by underscores. The input string ...
magic_evol_110k
72,267
Write a Python function to count the number of adjacent elements in a given list that have identical values. The function should iterate through the list and count pairs of adjacent elements that are the same. The code should start with: ```python from typing import List def count_identical_adjacent_elements(arr: List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_identical_adjacent_elements(arr: List[int]) -> int: """ Counts the number of adjacent elements in a list that have identical values. Args: arr (List[int]): The list of integers to ...
magic_evol_110k
72,268
Write a Python function to generate a list of integers starting from 1 up to a given number `n`, with each successive number having an interval of 10 between them. The function should handle cases where `n` is less than 1 by returning an empty list. The code should start with: ```python from typing import List def ge...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_interval_list(n: int) -> List[int]: """ Generate a list of integers starting from 1 up to n with an interval of 10 between each successive number. Args: n (int): The upper limit...
magic_evol_110k
72,273
Write a Python function to find the Greatest Common Divisor (GCD) of two given integers using the Euclidean algorithm. The function should handle erroneous inputs and raise appropriate exceptions. Additionally, provide a piece of erroneous code related to the task and explain why the code is incorrect and how to fix it...
Here is the Python code to solve the given problem in the markdown block: ```python def gcd(a: int, b: int) -> int: """ Compute the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm. Args: a (int): The first integer. b (int): The second integer. Returns: ...
magic_evol_110k
72,275
Write a Python function to filter out all odd integers from a given list of numerical values that are not multiples of 5. The function should return a list of these filtered integers. The code should start with: ```python from typing import List def filter_odd_non_multiples_of_5(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 filter_odd_non_multiples_of_5(numbers: List[int]) -> List[int]: """ Filters out all odd integers from the given list that are not multiples of 5. Args: numbers (List[int]): The list of n...
magic_evol_110k
72,278
Write a Python function to create a dictionary representing a Firebase document with the given parameters. The function should accept three parameters: `name`, `age`, and `occupation`. The dictionary should have keys `name`, `age`, and `occupation` corresponding to the provided parameters. The function should return th...
Here is the Python code to solve the given problem in the markdown block: ```python def create_firebase_document(name: str, age: int, occupation: str) -> dict: """ Creates a dictionary representing a Firebase document with the given parameters. Args: name (str): The name of the person. age ...
magic_evol_110k
72,282
Write a Python function to remove duplicates from a list while preserving the original order, considering only case-insensitive alphanumeric characters. The function should handle a list containing strings and integers. The code should start with: ```python from typing import List, Union def remove_duplicates_preserv...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def remove_duplicates_preserve_order(arr: List[Union[str, int]]) -> List[Union[str, int]]: """ Removes duplicates from a list while preserving the original order, considering only case-insensitive...
magic_evol_110k
72,285
Write a Python function to save a given NumPy array to a binary file with the `.npy` extension and then load it back to ensure it retains its original form. The function should take a NumPy array and a file path as input, save the array to the specified file, and then load and return the array from the file. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np from typing import List def save_and_load_array(array: np.ndarray, file_path: str) -> np.ndarray: """ Saves a given NumPy array to a binary file with the .npy extension and then loads it back. Args: ...
magic_evol_110k
72,291
Write a Python function to convert a list of tuples, where each tuple contains a full name and a unique numerical ID, into a dictionary. The dictionary should use the unique numerical IDs as keys and the full names as values. The code should start with: ```python from typing import List, Tuple, Dict def convert_list_t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def convert_list_to_dict(data: List[Tuple[str, str]]) -> Dict[str, str]: """ Converts a list of tuples into a dictionary where each tuple contains a full name and a unique numerical ID. ...
magic_evol_110k
72,307
Write a Python function to calculate the frequency of each distinct word in a given sentence. The function should perform preprocessing steps such as converting all words to lowercase and removing punctuation before mapping the frequency. The code should start with: ```python from typing import Dict def word_frequency...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict import string from collections import defaultdict def word_frequency(sentence: str) -> Dict[str, int]: """ Calculate the frequency of each distinct word in the given sentence. Args: sentence...
magic_evol_110k
72,313
Write a Python function to create a dictionary mapping student IDs to their corresponding grades. The function should handle possible input errors, such as mismatched lengths of the lists or non-numeric values in either list. The function should return an error message if any of these conditions are met. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def create_student_dict(student_ids: List[int], grades: List[Union[int, float]]) -> Union[dict, str]: """ Create a dictionary mapping student IDs to their corresponding grades. Args: ...
magic_evol_110k
72,330
Write a Python function to return an array containing the unique elements from a given array of integers in ascending order. The function should handle any size of input array and ensure that the output array contains only unique elements sorted in ascending order. 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 unique_sorted_elements(arr: List[int]) -> List[int]: """ Returns a list of unique elements from the given array in ascending order. Args: arr (List[int]): The input array of integers. ...
magic_evol_110k
72,331
Write a Python function to perform a quadrille swap of four integers. The quadrille swap involves swapping the values of four variables in a cyclic manner. Specifically, the function should swap the values of the variables such that: - The first variable takes the value of the third variable. - The second variable take...
Here is the Python code to solve the given problem in the markdown block: ```python def quadrille_swap(a: int, b: int, c: int, d: int) -> tuple: """ Perform a quadrille swap of four integers. The quadrille swap involves swapping the values of four variables in a cyclic manner: - The first variable take...
magic_evol_110k
72,336
Write a Python function to count the occurrences of vowels, consonants, digits, special characters, and white spaces in a given string. The function should be efficient and handle large strings without performance degradation. The code should start with: ```python def count_characters(s: str) -> dict: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_characters(s: str) -> dict: """ Counts the occurrences of vowels, consonants, digits, special characters, and white spaces in a given string. Args: s (str): The input string to analyze. Returns: ...
magic_evol_110k
72,345
Write a Python function to calculate the multiplicative product of three given integral parameters `x`, `y`, and `z`. The function should return the resulting multiplication. Additionally, provide a starter code that initializes the parameters `x`, `y`, and `z` with specific values and calls the function to print the r...
Here is the Python code to solve the given problem in the markdown block: ```python def multiply(x: int, y: int, z: int) -> int: """ Calculate the multiplicative product of three integral parameters x, y, and z. Args: x (int): The first integral parameter. y (int): The second integral param...
magic_evol_110k
72,347
Write a Python function to calculate the sum of a list of numbers, ensuring the function is efficient, readable, and adheres to Python's best practices. The function should handle edge cases such as an empty list and should be optimized for performance. 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 calculate_sum_of_list(numbers: List[int]) -> int: """ Calculate the sum of a list of integers. This function uses Python's built-in `sum` function to efficiently compute the sum of the provided ...
magic_evol_110k
72,360
Write a Python function to create a dictionary with three unique key-value pairs, where each key is a string and each value is an integer. The function should return the dictionary. The code should start with: ```python from typing import Dict def create_unique_dict() -> Dict[str, int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def create_unique_dict() -> Dict[str, int]: """ Creates a dictionary with three unique key-value pairs, where each key is a string and each value is an integer. Returns: Dict[str, int]: A di...
magic_evol_110k
72,364
Write a Python function to process a sequence of consecutive numerical values. The function should identify prime numbers in the sequence and replace them with their respective cubed equivalents. The function should return the modified sequence. The code should start with: ```python from typing import List def proces...
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
72,367
Write a Python function to initialize a list with a specified number of elements, each set to a given value. The function should handle cases where the number of elements is zero or negative by returning an empty list. The code should start with: ```python from typing import List def initialize_list(value: int, num_el...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def initialize_list(value: int, num_elements: int) -> List[int]: """ Initializes a list with a specified number of elements, each set to a given value. Args: value (int): The value to set ea...
magic_evol_110k
72,376
Write a Python function to identify the smallest repeating unit of a given string and return the number of times this unit is repeated. If no repeating unit is found, return 'None'. Additionally, include error handling for non-string inputs. The function should start with: ```python def find_smallest_rep_unit(s: str) -...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Union, Tuple def find_smallest_rep_unit(s: str) -> Union[Tuple[str, int], str]: """ Identify the smallest repeating unit of a given string and return the number of times this unit is repeated. If no repea...
magic_evol_110k
72,380
Write a Python function to convert a nested list into its stringified version while maintaining the structure of the nested list. Each entry in the list should be separated by a comma and enclosed in brackets `[]`. The function should handle integers, floating point numbers, and strings. If the function encounters a da...
Here is the Python code to solve the given problem in the markdown block: ```python def stringify_nested_list(input_list): """ Convert a nested list into its stringified version while maintaining the structure of the nested list. Args: input_list (list): The nested list to be stringified. Retu...
magic_evol_110k
72,393
Write a Python function to construct a dictionary that records the frequency of each character in a given ASCII text string. The dictionary should have each character as a key and the frequency of its occurrence as the corresponding value. The function should be efficient in terms of counting. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def character_frequency(string: str) -> Dict[str, int]: """ Constructs a dictionary that records the frequency of each character in a given ASCII text string. Args: string (str): The input s...
magic_evol_110k
72,399
Write a Python function to detect duplicates in a tuple and return a dictionary with the elements that have duplicates as keys and their respective counts as values. The function should handle tuples containing both string and integer elements. The code should start with: ```python from typing import Tuple, Dict, Union...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Dict, Union def detect_duplicates(T: Tuple[Union[int, str], ...]) -> Dict[Union[int, str], int]: """ Detects duplicates in a tuple and returns a dictionary with elements that have duplicates as keys an...
magic_evol_110k
72,410
Write a Python function to calculate the cumulative product of elements in a three-dimensional numeric array. The function should take a three-dimensional list of integers as input and return a list of integers representing the cumulative product of each element in the array. 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 import numpy as np def cumulative_product_3d(data: List[List[List[int]]]) -> List[int]: """ Calculate the cumulative product of elements in a three-dimensional numeric array. Args: data (Lis...
magic_evol_110k
72,416
Write a Python function to randomly swap two distinct elements of a given list without using the built-in swap method. The function should handle edge cases where the list has less than two elements or contains duplicate elements. The function should return the modified list. The code should start with: ```python from...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def swap_random_elements(arr: List[int]) -> List[int]: """ Randomly swaps two distinct elements of a given list without using the built-in swap method. Args: arr (List[int]): T...
magic_evol_110k
72,425
Write a Python function to check if any two elements in a given list have potentially different data types and values. Additionally, if any elements are dictionaries, the function should compare the key-value pairs for equality. The function should return `True` if any such differences are found, otherwise `False`. Th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def check_for_differences(lst: List[Any]) -> bool: """ Checks if any two elements in the given list have potentially different data types and values. Additionally, if any elements are dictionari...
magic_evol_110k
72,426
Write a Python function to identify and extract all the odd numerals from a given numerical string, and then compute their cumulative sum. The function should return the cumulative sum of the odd numerals. The code should start with: ```python def cumulative_sum_of_odd_numerals(numerical_string: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def cumulative_sum_of_odd_numerals(numerical_string: str) -> int: """ Identifies and extracts all the odd numerals from a given numerical string and computes their cumulative sum. Args: numerical_string (str): A str...
magic_evol_110k
72,427
Write a Python function to identify and print any sequences of four or more consecutive identical characters that are present in both given strings. The function should also print the count of these sequences in both strings. The comparison should be case-insensitive and should consider whitespace and special character...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple import re def find_matching_sequences(str1: str, str2: str) -> None: """ Identifies and prints any sequences of four or more consecutive identical characters that are present in both given strings. ...
magic_evol_110k
72,442
Write a Python function to perform a binary search on a sorted list of integers. The function should return the index of the target element if it exists in the list, otherwise it should return -1. The function should be efficient in terms of time complexity, and you should analyze and explain the time and space complex...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search(arr: List[int], target: int) -> int: """ Perform a binary search on a sorted list of integers to find the index of the target element. Args: arr (List[int]): A sorted list ...
magic_evol_110k
72,447
Write a Python function to replace all occurrences of a specified item in a given list with a new item, while preserving the original structure of the list. The function should handle nested lists and tuples, ensuring that the replacement is done recursively. 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 replace_item_in_structure(original_structure: Union[List, Tuple], old_item, new_item) -> Union[List, Tuple]: """ Replace all occurrences of a specified item in a given list or tuple str...
magic_evol_110k
72,449
Write a Python function to sort a list of strings in alphabetical order. The function should handle lists of varying lengths and should return the sorted list. The code should start with: ```python from typing import List def sort_lexical_items(items: List[str]) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_lexical_items(items: List[str]) -> List[str]: """ Sorts a list of strings in alphabetical order. Args: items (List[str]): The list of strings to be sorted. Returns: Lis...
magic_evol_110k
72,452
Write a Python function to find all the prime factors of a given integer `n`. The function should return a list of prime factors, including their multiplicities. The code should start with: ```python from typing import List def prime_factors(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def prime_factors(n: int) -> List[int]: """ Find all the prime factors of a given integer `n`, including their multiplicities. Args: n (int): The integer for which to find the prime factor...
magic_evol_110k
72,457
Write a Python function to calculate the average grade for each subject in a classroom. The function should take a list of students, where each student is represented as a dictionary with keys 'name' and 'grades'. The 'grades' key maps to another dictionary where the keys are subject names and the values are the grades...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def calculate_average_grades(students: List[Dict[str, Dict[str, int]]]) -> Dict[str, float]: """ Calculate the average grade for each subject in a classroom. Args: students (List[Dict[...
magic_evol_110k
72,460
Write a Python function to extract the first n lexical items (words) from a given text string. The function should handle cases where n is greater than the number of words in the text, and it should return an empty list if n is less than or equal to 0. The function should also handle text strings that may contain multi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def extract_first_n_words(text: str, n: int) -> List[str]: """ Extracts the first n words from a given text string. Args: text (str): The text string from which to extract the words. ...
magic_evol_110k
72,469
Write a Python function to implement the bubble sort algorithm on a given list of unique whole numbers. The function should sort the list in ascending order. The code should start with: ```python from typing import List def bubble_sort(sequence: 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(sequence: List[int]) -> List[int]: """ Sorts a list of unique whole numbers in ascending order using the bubble sort algorithm. Args: sequence (List[int]): The list of unique...
magic_evol_110k
72,488
Write a Python function to calculate the product of three given integers using the associative property of multiplication. The function should return the product and should be able to handle both positive and negative integers. The code should start with: ```python def calculate_product(num1: int, num2: int, num3: int)...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_product(num1: int, num2: int, num3: int) -> int: """ Calculate the product of three integers using the associative property of multiplication. Args: num1 (int): The first integer. num2 (int): T...
magic_evol_110k
72,489
Write a Python function to perform a clockwise rotation of elements within a two-dimensional square array. The number of rotation steps should be determined by the user's input. The function should preserve the original matrix structure and handle any valid integer input for the number of rotations. The code should st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def rotate_square_matrix(matrix: List[List[int]], rotations: int) -> List[List[int]]: """ Rotates a two-dimensional square matrix clockwise by the specified number of rotations. Args: matrix...
magic_evol_110k
72,493
Write a Python function to sort the elements of a given array in descending order. The function should take a list of integers as input and return a new list with the elements sorted in descending order. The original list should not be modified. The code should start with: ```python from typing import List def sort_a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_array_descending(array: List[int]) -> List[int]: """ Sorts the elements of a given array in descending order. Args: array (List[int]): The list of integers to be sorted. Return...
magic_evol_110k
72,496
Write a Python function to generate a randomized matrix of given dimensions `m x n`, where the elements range between `low` and `high`. The function should use the `numpy` library to achieve this. The code should start with: ```python import numpy as np def generate_random_matrix(m: int, n: int, low: float, high: floa...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def generate_random_matrix(m: int, n: int, low: float, high: float) -> np.ndarray: """ Generate a randomized matrix of dimensions m x n with elements uniformly distributed between low and high. Args: ...
magic_evol_110k
72,498
Write a Python function to count the number of distinct words in a given text fragment. The function should be case-insensitive and should handle punctuation by stripping it from the words. The code should start with: ```python from typing import List def count_distinct_words(text: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import string def count_distinct_words(text: str) -> int: """ Counts the number of distinct words in a given text fragment. Args: text (str): The text fragment from which to count distinct w...
magic_evol_110k
72,502
Write a Python function to merge two given lists, remove any duplicates from the merged list, and then sum all the unique elements in the merged list. The function should start with: ```python from typing import List def merge_and_sum_unique(arr1: List[int], arr2: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_and_sum_unique(arr1: List[int], arr2: List[int]) -> int: """ Merges two lists, removes duplicates, and returns the sum of the unique elements. Args: arr1 (List[int]): The first lis...
magic_evol_110k
72,505
Write a Python function to partition a list of floating-point numbers into three categories: positive, negative, and zero, and then sort each category in ascending order. The function should return a single list that combines the sorted categories in the order of negative, zero, and positive numbers. The operation shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def partition_and_sort_numbers(numbers: List[float]) -> List[float]: """ Partitions a list of floating-point numbers into three categories: negative, zero, and positive, and then sorts each category ...
magic_evol_110k
72,530
Write a Python function to determine if a given database supports Multiversion Concurrency Control (MVCC). The function should take a database name as input and return a boolean indicating whether the database supports MVCC. The list of databases that support MVCC is predefined in the function. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python def supports_mvcc(database_name: str) -> bool: """ Determines if a given database supports Multiversion Concurrency Control (MVCC). Args: database_name (str): The name of the database to check. Returns: ...
magic_evol_110k
72,534
Write a Python function that accepts a text input, an integer `n`, and a replacement symbol. The function should substitute all occurrences of the nth letter in the English alphabet that are not alphanumeric with the supplied replacement symbol. The function should handle both uppercase and lowercase letters. The code...
Here is the Python code to solve the given problem in the markdown block: ```python def substitute_nth_letter(text: str, n: int, replacement: str) -> str: """ Substitutes all occurrences of the nth letter in the English alphabet that are not alphanumeric with the supplied replacement symbol. Args: ...
magic_evol_110k
72,536
Write a Python function to calculate the Least Common Multiple (LCM) of three numbers (x, y, and z) using an optimized algorithm. The function should be resource-efficient and handle the constraints where the input numbers are within the range 1 to 10^9. The function should start with: ```python def lcm_of_three(x: int...
Here is the Python code to solve the given problem in the markdown block: ```python def gcd(a: int, b: int) -> int: """ Compute the greatest common divisor of two numbers using the Euclidean algorithm. Args: a (int): The first number. b (int): The second number. Returns: int: T...
magic_evol_110k
72,542
Write a Python function to count the number of occurrences of a given element in a list or nested list, supporting various data types such as integers, strings, tuples, and sets. The function should be able to handle both flat and nested lists efficiently, even with large datasets. The code should start with: ```pytho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Union, List, Tuple, Set def count_occurrences(element: Union[int, str], data: Union[List, Tuple, Set]) -> int: """ Counts the number of occurrences of a given element in a list or nested list, supporting vari...
magic_evol_110k
72,545
Write a Python function to rearrange the subsequent alphabets in alphabetical order without utilizing any built-in sorting methods. The function should use the Bubble Sort algorithm to achieve this. The code should start with: ```python from typing import List def bubble_sort_alphabets(alphabets: List[str]) -> List[st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort_alphabets(alphabets: List[str]) -> List[str]: """ Sorts a list of alphabets in alphabetical order using the Bubble Sort algorithm. Args: alphabets (List[str]): The list of al...
magic_evol_110k
72,547
Write a Python function to compute the aggregate count of vowels from a specified list of words, but only after eliminating words that commence with a consonant and disregarding any words that incorporate non-alphabetic characters. The function should be robust and efficient, avoiding the pitfalls of the provided decep...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_vowels_in_words(words: List[str]) -> int: """ Computes the aggregate count of vowels from a specified list of words, but only after eliminating words that commence with a consonant and ...
magic_evol_110k
72,551
Write a Python function to encrypt a given message using the Caesar cipher technique. The function should take a string `message` and an integer `key` as input, and return the encrypted message. The Caesar cipher shifts each letter in the message by `key` positions in the alphabet. Non-alphabet characters should remain...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher_encrypt(message: str, key: int) -> str: """ Encrypts the given message using the Caesar cipher technique. Args: message (str): The message to be encrypted. key (int): The number of position...
magic_evol_110k
72,566
Write a Python function to implement the quicksort algorithm for sorting an array. The function should be able to handle lists of integers and return a sorted list. The code should start with: ```python from typing import List def quicksort(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 quicksort(arr: List[int]) -> List[int]: """ Sorts an array of integers using the quicksort algorithm. Args: arr (List[int]): The array of integers to be sorted. Returns: L...
magic_evol_110k
72,574
Write a Python function to find the complex number with the smallest magnitude from a given list of complex numbers. The function should return the complex number itself, not just its magnitude. The code should start with: ```python from typing import List def find_smallest_magnitude(complex_numbers: List[complex]) ->...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_smallest_magnitude(complex_numbers: List[complex]) -> complex: """ Finds the complex number with the smallest magnitude from a given list of complex numbers. Args: complex_numbers (...
magic_evol_110k
72,576
Write a Python function to determine the minimum number of non-overlapping intervals needed to cover the entire range of a given set of intervals. The intervals can include fractional numbers and can have the same start and end points. The function should handle an empty list of intervals by returning 0. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def min_non_overlapping_intervals(intervals: List[List[float]]) -> int: """ Determine the minimum number of non-overlapping intervals needed to cover the entire range of a given set of intervals. Ar...
magic_evol_110k
72,584
Write a Python function to find the smallest even integer in a given list of integers. The function should return the smallest even integer if found, otherwise return `None`. The code should start with: ```python from typing import List, Optional def find_smallest_even(arr: List[int]) -> Optional[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_smallest_even(arr: List[int]) -> Optional[int]: """ Finds the smallest even integer in a given list of integers. Args: arr (List[int]): The list of integers to search thro...