source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 94,991 | Write a Python function to determine the maximum value among three given integers using a multistage reasoning process. The function should compare the integers step by step and return the maximum value. The code should start with:
```python
def find_max_of_three(num1: int, num2: int, num3: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_max_of_three(num1: int, num2: int, num3: int) -> int:
"""
Determine the maximum value among three given integers using a multistage reasoning process.
Args:
num1 (int): The first integer.
num2 (int)... |
magic_evol_110k | 94,995 | Write a Python function to generate a list of tuples that encapsulates the rolling maximum and minimum values up to each position in a given list of integers, along with their respective indices. The function should return a list of tuples, where each tuple contains two sub-tuples: one for the maximum value and its ind... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def rolling_max_min_indices(numbers: List[int]) -> List[Tuple[Tuple[int, int], Tuple[int, int]]]:
"""
Generate a list of tuples that encapsulates the rolling maximum and minimum values up to each ... |
magic_evol_110k | 94,996 | Write a Python function to find the optimal division of a list of positive integers such that the result of the division is maximized. The function should return the division expression as a string with the optimal placement of parentheses to achieve the maximum result. The input list will have a length between 1 and 1... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def optimal_division(nums: List[int]) -> str:
"""
Returns the optimal division expression for a list of positive integers to maximize the result.
Args:
nums (List[int]): A list of positive i... |
magic_evol_110k | 95,016 | Write a Python function to determine if a given string matches the pattern where it starts with "dog", contains only uppercase letters in between, and ends with "X". The function should use regular expressions to perform this check. The code should start with:
```python
import re
def is_valid_pattern(s: str) -> bool:
... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_pattern(s: str) -> bool:
"""
Determines if the given string matches the pattern where it starts with "dog",
contains only uppercase letters in between, and ends with "X".
Args:
s (str): T... |
magic_evol_110k | 95,022 | Write a Python function to convert a given decimal number to its hexadecimal representation. The function should handle both positive and negative integers. The hexadecimal representation should be returned as a string without the '0x' prefix.
The code should start with:
```python
def decimal_to_hex(n: int) -> str:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def decimal_to_hex(n: int) -> str:
"""
Converts a given decimal number to its hexadecimal representation.
Args:
n (int): The decimal number to convert.
Returns:
str: The hexadecimal representation of th... |
magic_evol_110k | 95,025 | Create a Python function that takes a directory path as an argument and performs the following tasks:
1. Searches for files with the pattern `.gitconfig` in the given directory and its subdirectories.
2. For each `.gitconfig` file found, it should:
- Print the file path.
- Calculate and print the total number of ... | Here is the Python code to solve the given problem in the markdown block:
```python
import os
import hashlib
def process_gitconfig_files(directory: str):
"""
Searches for `.gitconfig` files in the given directory and its subdirectories,
and prints the file path, total number of lines, and MD5 hash of the f... |
magic_evol_110k | 95,045 | Write a Python function that converts a given list of integers into a list of their corresponding squares using a `while` loop. The function should start with:
```python
from typing import List
def list_of_squares(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 list_of_squares(arr: List[int]) -> List[int]:
"""
Converts a list of integers into a list of their corresponding squares using a while loop.
Args:
arr (List[int]): The list of integers... |
magic_evol_110k | 95,049 | Write a Python function to determine if a given number is present in a list using a binary search algorithm. The function should first sort the list if it is unsorted and then perform the binary search. The code should start with:
```python
from typing import List
def binary_search_in_list(data: List[int], search_num:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search_in_list(data: List[int], search_num: int) -> bool:
"""
Determines if a given number is present in a list using a binary search algorithm.
The list is sorted first if it is unsorted.... |
magic_evol_110k | 95,051 | Write a Python function to calculate the sum of squares of all numbers in a given list of integers. The function should take a list of integers as input and return the sum of their squares. The code should start with:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
"""
Calculate the sum of squares of all numbers in a given list of integers.
Args:
numbers (List[int]): A list of integers for which the sum of... |
magic_evol_110k | 95,076 | Write a Python function to concatenate a list of strings into a single string, minimizing the use of the "+" operator. The function should support different methods of string concatenation, including using the `join` method, `%` formatting, `str.format`, and f-strings. The function should accept a list of strings and a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def concatenate_strings(strings: List[str], method: str) -> str:
"""
Concatenates a list of strings into a single string using the specified method.
Args:
strings (List[str]): A list of stri... |
magic_evol_110k | 95,094 | Write a Python function to filter out all the odd integers from a given list of numerical values. The function should use a lambda function to perform the filtering. The code should start with:
```python
from typing import List
def filter_odd_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
def filter_odd_numbers(num_list: List[int]) -> List[int]:
"""
Filters out all the odd integers from the given list of numerical values.
Args:
num_list (List[int]): The list of integers to ... |
magic_evol_110k | 95,108 | Write a Python function to filter out non-Fibonacci numbers from a given list of integers. The function should return a new list containing only the numbers that are part of the Fibonacci sequence. The Fibonacci sequence is defined as a sequence where each number is the sum of the two preceding ones, starting from 0 an... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def is_Fibonacci(n: int) -> bool:
"""
Check if a given number is a Fibonacci number.
Args:
n (int): The number to check.
Returns:
bool: True if the number is a Fibon... |
magic_evol_110k | 95,118 | Write a Python function to identify the numbers with the least occurrences in a given list of floating point numbers. If there are multiple numbers with the same amount of minimum occurrences, return them in the order they appear in the list. The function should handle potential exceptions and edge cases, such as an em... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_least_occurrences(numbers: List[float]) -> List[float]:
"""
Identify the numbers with the least occurrences in a given list of floating point numbers.
If there are multiple numbers with the ... |
magic_evol_110k | 95,127 | Write a Python function to determine if the balance of an account ever drops below zero given a sequence of banking operations (credits and debits). The function should return `True` if the balance drops below zero at any point, and `False` otherwise. The initial balance is zero.
The code should start with:
```python
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def below_zero(operations: List[int]) -> bool:
"""
Determines if the account balance ever drops below zero given a sequence of banking operations.
Args:
operations (List[int]): A list of int... |
magic_evol_110k | 95,146 | Write a Python function to compare two numerical entities and generate a trinary output narrative. The function should return `0` if the two entities are identical, `-1` if the second entity is greater than the first, and `1` if the first entity is greater than the second. The function should handle any numerical input... | Here is the Python code to solve the given problem in the markdown block:
```python
def compare_numerical_entities(object1: float, object2: float) -> int:
"""
Compare two numerical entities and generate a trinary output narrative.
Args:
object1 (float): The first numerical entity to compare.
... |
magic_evol_110k | 95,165 | Write a Python function to convert a given two-dimensional matrix into a linear, one-dimensional array. The function should take a list of lists (matrix) as input and return a single list containing all the elements of the matrix in row-major order.
The code should start with:
```python
from typing import List
def fl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def flatten_matrix(matrix: List[List[int]]) -> List[int]:
"""
Converts a given two-dimensional matrix into a linear, one-dimensional array.
Args:
matrix (List[List[int]]): A list of lists re... |
magic_evol_110k | 95,174 | Write a Python function to generate a list of all possible line styles for a plotly scatter plot. The function should return a list of strings representing the different line styles that can be used with the `line` parameter in the `add_scatter` method of a plotly figure.
The code should start with:
```python
from typ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_plotly_line_styles() -> List[str]:
"""
Returns a list of all possible line styles for a plotly scatter plot.
These line styles can be used with the `line` parameter in the `add_scatter` meth... |
magic_evol_110k | 95,178 | Write a Python function to calculate the number of ways to reach the bottom-right corner of a grid from the top-left corner, moving only right or down, given the dimensions of the grid. The function should handle grids of any size, including those with a single row or column.
The code should start with:
```python
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_paths(m: int, n: int) -> int:
"""
Calculate the number of ways to reach the bottom-right corner of an m x n grid
from the top-left corner, moving only right or down.
Args:
m (int): The number of rows i... |
magic_evol_110k | 95,187 | Write a Python function to find the largest prime factor of a given integer `n`. The function should efficiently determine the largest prime factor using a sieve-like approach. The code should start with:
```python
def largest_prime_factor(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def largest_prime_factor(n: int) -> int:
"""
Find the largest prime factor of a given integer n.
Args:
n (int): The integer for which to find the largest prime factor.
Returns:
int: The largest prime fa... |
magic_evol_110k | 95,189 | Write a Python function to find the node with the smallest even value in a given list of nodes, considering the breadth-first traversal sequence. If two nodes have the same smallest even value, return the node that was last visited in the breadth-first traversal. If there are no even numbers or if the array is empty, r... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_smallest_even_node(nodes: List[int]) -> List[int]:
"""
Find the node with the smallest even value in a given list of nodes, considering the breadth-first traversal sequence.
If two nodes hav... |
magic_evol_110k | 95,192 | Write a Python function to identify and extract dates in the `DD/MM/YYYY` format from an array of sentences. The function should return a list of all dates found in the sentences.
The code should start with:
```python
from typing import List
import re
def extract_dates(sentences: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def extract_dates(sentences: List[str]) -> List[str]:
"""
Extracts all dates in the DD/MM/YYYY format from a list of sentences.
Args:
sentences (List[str]): A list of sentences to ... |
magic_evol_110k | 95,193 | Write a Python function to reverse the order of elements in a given list without using any built-in utility functions for reversing sequences (e.g., `reverse()`, `reversed()`, or slicing operations like `[::-1]`). The function should start with:
```python
from typing import List
def reverse_list(seq: List[int]) -> Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_list(seq: List[int]) -> List[int]:
"""
Reverses the order of elements in a given list without using built-in utility functions.
Args:
seq (List[int]): The list of integers to be ... |
magic_evol_110k | 95,204 | Write a Python function to calculate the Euclidean distance between two points in a three-dimensional Cartesian coordinate system. The function should handle potential errors for invalid points and provide meaningful, informative outputs in such cases. The code should start with:
```python
from typing import Tuple
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
import math
def euclidean_distance(point1: Tuple[float, float, float], point2: Tuple[float, float, float]) -> float:
"""
Calculate the Euclidean distance between two points in a three-dimensional Cartes... |
magic_evol_110k | 95,210 | Write a Python function that performs a multi-step reasoning process to determine if the sum of all integer elements in a given list falls within a specified range (inclusive). The function should:
1. Identify and sum all integer elements in the list.
2. Check if this sum falls within the given lower and upper bounds (... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_within_bounds(l: List[int], lower_bound: int, upper_bound: int) -> bool:
"""
Determines if the sum of all integer elements in the list falls within the specified range (inclusive).
Args:
... |
magic_evol_110k | 95,212 | Write a Python function to efficiently search for occurrences of specific keywords in a long string of text and return a dictionary where each key is a keyword and the value is a list of all indices where the keyword appears in the text. If a keyword does not exist in the text, the value should be `-1`. The function sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def find_keyword_indices(text: str, keywords: List[str]) -> Dict[str, List[int]]:
"""
Finds all occurrences of each keyword in the given text and returns a dictionary
where each key is a keywor... |
magic_evol_110k | 95,225 | Write a Python function to convert a given hexadecimal string into its corresponding ASCII string. The function should handle hexadecimal strings of even length and return the corresponding ASCII string. If the input hexadecimal string is of odd length, the function should return an empty string.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_ascii(hex_string: str) -> str:
"""
Converts a given hexadecimal string into its corresponding ASCII string.
Args:
hex_string (str): The hexadecimal string to be converted. Must be of even length.
Ret... |
magic_evol_110k | 95,228 | Write a Python function to rearrange the elements in a given tuple so that they are sorted in descending order, with all multiples of 5 placed at the beginning of the tuple. The function should return the rearranged tuple.
The code should start with:
```python
from typing import Tuple
def rearrange_tuple(tup: Tuple[i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def rearrange_tuple(tup: Tuple[int]) -> Tuple[int]:
"""
Rearranges the elements in the given tuple so that they are sorted in descending order,
with all multiples of 5 placed at the beginning of the... |
magic_evol_110k | 95,233 | Write a Python function to extract the first `n` pairs of elements from a given numeric sequence. Each pair should consist of two consecutive elements from the sequence. The function should return a list of tuples, where each tuple contains a pair of consecutive elements.
The code should start with:
```python
from typ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def get_first_n_pairs(sequence: List[int], n: int) -> List[Tuple[int, int]]:
"""
Extracts the first n pairs of consecutive elements from the given numeric sequence.
Args:
sequence (Li... |
magic_evol_110k | 95,236 | Write a Python function to find the largest prime factor of a given integer `n`, which can be positive or negative. The function should efficiently handle the input and identify the prime factors. The code should start with:
```python
def largest_prime_factor(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def largest_prime_factor(n: int) -> int:
"""
Return the largest prime factor of a positive or negative integer n.
Assume abs(n) > 1 and is not prime.
Args:
n (int): The integer for which to find the largest prim... |
magic_evol_110k | 95,244 | Write a Python function to calculate the sum of all integer elements in a given list. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def sum_of_elements(elements: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_elements(elements: List[int]) -> int:
"""
Calculate the sum of all integer elements in a given list.
Args:
elements (List[int]): A list of integers.
Returns:
int: The... |
magic_evol_110k | 95,245 | Write a Python function to perform a linear search on a given dataset to find all occurrences of a specified target value. The function should return a list of indices where the target value is found. If the target value is not found in the dataset, the function should return an empty list.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def linear_search_all(data: List[int], target: int) -> List[int]:
"""
Perform a linear search on the given dataset to find all occurrences of the target value.
Args:
data (List[int]): The da... |
magic_evol_110k | 95,256 | Write a Python function to find the minimum absolute value among a list of negative integers. The function should take a list of integers as input and return the smallest absolute value. The code should start with:
```python
from typing import List
def find_min_absolute_value(nums: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_min_absolute_value(nums: List[int]) -> int:
"""
Finds the minimum absolute value among a list of negative integers.
Args:
nums (List[int]): A list of negative integers.
Returns... |
magic_evol_110k | 95,260 | Write a Python function that returns the distinct elements that appear in both input lists, sorted in ascending order. The function should have a time complexity of O(nlogn) or better and should avoid using Python's built-in list functions to sort the result and remove duplicates. The function should start with:
```py... | 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]:
"""
Return a sorted list of unique elements that are present in both input lists.
The function sorts both input lists and uses a... |
magic_evol_110k | 95,262 | Write a Python function to generate an array of a specified length consisting exclusively of floating-point numbers chosen randomly. The function should ensure that each element in the array is a random floating-point number between 0 and 1. The code should start with:
```python
from typing import List
import random
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_random_float_array(length: int) -> List[float]:
"""
Generates an array of the specified length consisting exclusively of random floating-point numbers between 0 and 1.
Arg... |
magic_evol_110k | 95,284 | Write a Python function to generate an array of `n` random floating point numbers within a specified range `[min_value, max_value]`. The function should ensure that the generated numbers are uniformly distributed within the given range. The code should start with:
```python
from typing import List
import numpy as np
d... | 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_floats(n: int, min_value: float, max_value: float) -> List[float]:
"""
Generates an array of n random floating point numbers within the specified range [min_value, ... |
magic_evol_110k | 95,289 | Write a Python function to perform k-nearest neighbors (k-NN) classification on a given input instance using a training dataset. The function should calculate the distance between the input instance and each instance in the training dataset, sort the distances, select the k nearest neighbors, and return the majority cl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import math
def euclidean_distance(point1: List[float], point2: List[float]) -> float:
"""
Calculate the Euclidean distance between two points.
Args:
point1 (List[float]): The first p... |
magic_evol_110k | 95,295 | Write a Python function to generate a list of even Fibonacci numbers up to a given positive integer `N` (inclusive). The function should handle cases where `N` is not a positive integer by returning an error message. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the two preceding ... | Here is the Python code to solve the given problem in the markdown block:
```python
def even_fibonacci_numbers(N: int) -> list:
"""
Generate a list of even Fibonacci numbers up to a given positive integer N (inclusive).
Args:
N (int): The upper limit for the Fibonacci sequence.
Returns:
... |
magic_evol_110k | 95,307 | Write a Python function that handles each input greater than 100 and less than -100 recursively by reducing or increasing it by 100 respectively until it falls within the range [-100, 100]. The function should return -1 if the input is within the range (0, 100] and 1 if the input is within the range [-100, 0).
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
def handle_large_numbers(x: int) -> int:
"""
Handles each input greater than 100 and less than -100 recursively by reducing or increasing it by 100 respectively until it falls within the range [-100, 100].
Returns -1 if the ... |
magic_evol_110k | 95,311 | Write a Python function to generate a list of unique random alphanumeric strings of a specified length, sort the list, and provide a function to efficiently search for a particular string in this sorted list using binary search. The code should start with:
```python
import string
import random
from typing import List
... | Here is the Python code to solve the given problem in the markdown block:
```python
import string
import random
from typing import List
def generate_and_sort_unique_strings(n: int, length: int) -> List[str]:
"""
Generate a list of n unique random alphanumeric strings of the specified length, and sort them.
... |
magic_evol_110k | 95,316 | Write a Python function to sort an array of non-negative integers such that all even numbers appear before all odd numbers. The order of the even and odd numbers within their respective groups does not matter. The function should start with:
```python
from typing import List
def sort_array_by_parity(A: List[int]) -> L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_array_by_parity(A: List[int]) -> List[int]:
"""
Sorts an array of non-negative integers such that all even numbers appear before all odd numbers.
Args:
A (List[int]): The input arra... |
magic_evol_110k | 95,321 | Implement a function that performs an in-place bubble sort on a list of integers, counts the number of swaps made during the sorting process, and verifies if the list is sorted after the sorting is complete. The function should print "The list is sorted" if the list is sorted and "The list is not sorted" otherwise. The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort_with_verification(numbers: List[int]) -> None:
"""
Sorts the given list of integers in-place using the bubble sort algorithm,
counts the number of swaps made, and verifies if the list... |
magic_evol_110k | 95,336 | Write a Python function to determine if two integers are anagrams of each other. Two integers are considered anagrams if they contain the same digits in any order. The function should handle positive integers only.
The code should start with:
```python
def are_anagrams(num1: int, num2: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(num1: int, num2: int) -> bool:
"""
Determines if two integers are anagrams of each other.
Args:
num1 (int): The first integer to check.
num2 (int): The second integer to check.
Returns:... |
magic_evol_110k | 95,351 | Write a Python function to determine if each element in a given array of integers is a prime number. The function should return a new array where each element is `True` if the corresponding element in the input array is a prime number, and `False` otherwise. The function should be optimized for time complexity.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sieve_of_eratosthenes(n: int) -> List[int]:
"""
Generate a list of prime indicators using the Sieve of Eratosthenes algorithm.
Args:
n (int): The upper limit to generate prime indicators... |
magic_evol_110k | 95,352 | Write a Python function that repositions all numerical values to the end of a given string while preserving the order of non-numeric characters. Additionally, the function should return the count of distinct numerical values found in the string. The function should start with:
```python
def reposition_numbers_and_count... | Here is the Python code to solve the given problem in the markdown block:
```python
def reposition_numbers_and_count_unique(s: str) -> tuple:
"""
Repositions all numerical values to the end of the given string while preserving the order of non-numeric characters.
Additionally, returns the count of distinct ... |
magic_evol_110k | 95,366 | Write a Python function to calculate the lowest common multiple (LCM) of two given integer inputs, `x` and `y`. The function should use the greatest common divisor (GCD) to compute the LCM efficiently. The code should start with:
```python
import math
def lowest_common_multiple(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def lowest_common_multiple(x: int, y: int) -> int:
"""
Calculate the lowest common multiple (LCM) of two integers x and y.
The LCM is the smallest positive integer that is divisible by both x and y.
This fu... |
magic_evol_110k | 95,368 | Write a Python function to merge two numerical sequences by alternating elements from each list while maintaining the original order. If one list is longer than the other, append the remaining elements of the longer list at the end of the merged output. The function 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
from itertools import zip_longest
def merge_alternating_lists(list_1: List[int], list_2: List[int]) -> List[int]:
"""
Merges two numerical sequences by alternating elements from each list while maintaini... |
magic_evol_110k | 95,370 | Write a Python function to generate a tuple containing eight distinct numerical values, consisting of both integers and floating-point numbers. The function should ensure that each value in the tuple is unique and should return the tuple. The code should start with:
```python
def generate_distinct_numbers() -> tuple:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_distinct_numbers() -> tuple:
"""
Generates a tuple containing eight distinct numerical values, consisting of both integers and floating-point numbers.
Returns:
tuple: A tuple with eight distinct numeric... |
magic_evol_110k | 95,375 | Write a Python function to compute the number of unique digits and the sum of these unique digits from a given list of integers. The function should return a tuple containing the number of unique digits and the sum of these unique digits.
The code should start with:
```python
from typing import List, Tuple
def unique... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def unique_digits_and_sum(numbers_list: List[int]) -> Tuple[int, int]:
"""
Computes the number of unique digits and the sum of these unique digits from a given list of integers.
Args:
... |
magic_evol_110k | 95,381 | Write a Python function to calculate the frequency of occurrence and the positions (indexes) of specific elements within a given list. The function should handle lists with mixed types (integers, strings, floats, etc.) and should return the results in a well-structured, readable format. The function should take two inp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any, Dict
def find_elements_frequency_and_positions(my_list: List[Any], elements: List[Any]) -> Dict[Any, Dict[str, Any]]:
"""
Calculate the frequency of occurrence and the positions (indexes) of specif... |
magic_evol_110k | 95,387 | Write a Python function to efficiently recover the k-th smallest element from a bisynchronous list. A bisynchronous list is a data structure where elements are added in a way that maintains two levels of synchronization: one for the order of insertion and one for the order of values. The function should handle the case... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def recover_kth_smallest(bisync_list: List[int], k: int) -> Optional[int]:
"""
Recover the k-th smallest element from a bisynchronous list.
Args:
bisync_list (List[int]): The bisyn... |
magic_evol_110k | 95,390 | Write a Python function to reverse the order of words in a given sentence while maintaining the integrity of each word. The function should take a string as input and return a string with the words in reverse order. The code should start with:
```python
def reverse_words_order(sentence: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_words_order(sentence: str) -> str:
"""
Reverses the order of words in a given sentence while maintaining the integrity of each word.
Args:
sentence (str): The input sentence whose words are to be rever... |
magic_evol_110k | 95,395 | Write a Python function to calculate the sum of two inputs, ensuring that both inputs are converted to numbers if they are not already. If either input cannot be converted to a number, raise a `ValueError` with an appropriate message. The function should start with:
```python
def calculate_sum(a, b):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_sum(a, b):
"""
Calculate the sum of two inputs, ensuring both are converted to numbers if necessary.
Args:
a: The first input, which should be a number or a string that can be converted to a number.
... |
magic_evol_110k | 95,414 | Write a Python function to compute the sum of the primary diagonal elements in a given bidimensional array (2D list). The function should handle square matrices (where the number of rows equals the number of columns) and return the sum of the elements located at positions where the row index equals the column index.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_primary_diagonal(matrix: List[List[int]]) -> int:
"""
Compute the sum of the primary diagonal elements in a given square matrix.
Args:
matrix (List[List[int]]): A 2D list representin... |
magic_evol_110k | 95,419 | Write a Python function to transpose a given square matrix diagonally from top-left to bottom-right, swapping the elements at mirror image positions across the diagonal. The function should handle any N x N square matrix.
The code should start with:
```python
from typing import List
def transpose_diagonal(matrix: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def transpose_diagonal(matrix: List[List[int]]) -> List[List[int]]:
"""
Transposes a given square matrix diagonally from top-left to bottom-right, swapping the elements at mirror image positions across t... |
magic_evol_110k | 95,430 | Write a Python function to simulate a simplified version of a CPU's instruction execution process. The function should take a list of instructions and simulate the fetch, decode, execute, and write-back stages of a CPU pipeline. Each instruction is represented as a tuple where the first element is the operation (e.g., ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def simulate_cpu_pipeline(instructions: List[Tuple[str, List[int]]]) -> List[int]:
"""
Simulate a simplified CPU pipeline to execute a list of instructions.
Args:
instructions (List[T... |
magic_evol_110k | 95,442 | Write a Python function to optimize the parameters of a deep learning model by iteratively evaluating different sets of parameters and selecting the set that yields the best validation score. The function should start with:
```python
from typing import List, Any
def optimize_parameters(parameters: List[Any]) -> Any:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def optimize_parameters(parameters: List[Any]) -> Any:
"""
Optimizes the parameters of a deep learning model by iteratively evaluating different sets of parameters
and selecting the set that yie... |
magic_evol_110k | 95,465 | Write a Python function to construct a hierarchical dictionary from two given lists. The first list consists of strings, and the second list consists of integers. The second list may contain repeated values. The function should handle these repetitions by maintaining the hierarchical structure. If a key from the first ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
from collections import defaultdict
def construct_hierarchical_dict(l1: List[str], l2: List[int]) -> Dict[str, int | List[int]]:
"""
Constructs a hierarchical dictionary from two lists.
Args:
... |
magic_evol_110k | 95,469 | Write a Python function to determine if two given strings are isomorphic without using external libraries, recursive methods, or any inbuilt functions. Two strings are considered isomorphic if there is a one-to-one mapping between every character in the first string and every character in the second string. The functio... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_isomorphic(str1: str, str2: str) -> bool:
"""
Determines if two strings are isomorphic.
Args:
str1 (str): The first string to check.
str2 (str): The second string to check.
Returns:
bool:... |
magic_evol_110k | 95,485 | Write a Python function to find the intersection of two lists, i.e., the elements that are present in both lists. The function should return the intersection as a sorted list of unique elements. The code should start with:
```python
from typing import List
def list_intersection(l1: List[int], l2: List[int]) -> List[in... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def list_intersection(l1: List[int], l2: List[int]) -> List[int]:
"""
Find the intersection of two lists and return the result as a sorted list of unique elements.
Args:
l1 (List[int]): Th... |
magic_evol_110k | 95,486 | Write a Python function to manage rows in a tabular data structure represented by a list of dictionaries. The function should allow adding a new row to the table and removing a row based on a specified key-value pair. The code should start with:
```python
from typing import List, Dict, Any
def manage_table_rows(table:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Any
def manage_table_rows(table: List[Dict[str, Any]], action: str, row: Dict[str, Any] = None) -> List[Dict[str, Any]]:
"""
Manages rows in a tabular data structure represented by a list of dicti... |
magic_evol_110k | 95,500 | Write a Python function to find the largest sum from any two distinct numbers in a given array of integers. The function should ensure that the two numbers chosen are distinct, i.e., they should not be the same element in the array. The code should start with:
```python
from typing import List
def find_largest_distinc... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_largest_distinct_sum(arr: List[int]) -> int:
"""
Find the largest sum from any two distinct numbers in the given array.
Args:
arr (List[int]): The array of integers from which to fi... |
magic_evol_110k | 95,523 | Write a Python function to update a list of recorded coordinates for a simple snake game. The function should ensure that each coordinate is stored as a separate copy in the list, so that updating the original coordinate does not affect the previously recorded coordinates. The function should start with:
```python
from... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def record_coordinates(initial_coord: List[int], num_records: int) -> List[List[int]]:
"""
Records coordinates for a snake game, ensuring each coordinate is stored as a separate copy.
Args:
... |
magic_evol_110k | 95,528 | Write a Python function to find the unpaired numbers in each sub-array of a given 2D array. For each sub-array where an unpaired number is found, return the index of that sub-array along with the unpaired number. If no unpaired numbers are found in any sub-array, return an empty list. Each sub-array could have differen... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_unpaired_numbers(arr: List[List[int]]) -> List[Tuple[int, int]]:
"""
Find the unpaired numbers in each sub-array of a given 2D array.
Args:
arr (List[List[int]]): A 2D array ... |
magic_evol_110k | 95,533 | Write a Python function to retrieve the tertiary element (third element, index 2) from a given list. If the element at the third index does not exist or is not a number (integer or float), the function should return appropriate error messages. The function should handle exceptions gracefully without using try-except bl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union, Optional
def get_tertiary_element(my_list: List[Union[int, float, str]]) -> Optional[Union[int, float, str]]:
"""
Retrieves the tertiary element (third element, index 2) from a given list.
If... |
magic_evol_110k | 95,544 | Write a Python function to find and return the first `n` prime numbers. Additionally, include a helper function to check if a given number is prime. The main function should start with:
```python
from typing import List
def find_first_n_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 is_prime(num: int) -> bool:
"""
Check if a given number is prime.
Args:
num (int): The number to check for primality.
Returns:
bool: True if the number is prime, False other... |
magic_evol_110k | 95,556 | Write a Python function to replace the vowel characters in a given string with random alphabetic characters, ensuring that all letters of the alphabet have an approximately equal chance of replacing any given vowel. The string may contain alphanumeric and special characters. The code should start with:
```python
import... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
import string
def replace_vowels_with_random_letters(s: str) -> str:
"""
Replace the vowel characters in a given string with random alphabetic characters.
Args:
s (str): The input string containing al... |
magic_evol_110k | 95,559 | Write a Python class `Person` that represents a person with attributes `name`, `age`, `street`, `city`, `state`, and `zip_code`. Implement a method `populate_details` to set these attributes from a dictionary. Ensure proper data validation and error handling.
The starter code should be:
```python
class Person:
def... | Here is the Python code to solve the given problem in the markdown block:
```python
class Person:
def __init__(self, name, age, street, city, state, zip_code):
"""
Initialize a Person object with the given details.
Args:
name (str): The name of the person.
age (int):... |
magic_evol_110k | 95,569 | Write a Python function to remove duplicate elements from a given list while preserving the order of the first occurrence of each element. The function should be efficient and handle lists of various sizes. The code should start with:
```python
from typing import List
def remove_duplicates_preserve_order(values: List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_preserve_order(values: List[int]) -> List[int]:
"""
Removes duplicate elements from the given list while preserving the order of the first occurrence of each element.
Args:
... |
magic_evol_110k | 95,592 | Write a Python function to compute the union of two sets and return the resulting set. The function should handle sets of any size and ensure that the union operation is performed correctly. The code should start with:
```python
from typing import Set
def union_of_sets(set1: Set[int], set2: Set[int]) -> Set[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def union_of_sets(set1: Set[int], set2: Set[int]) -> Set[int]:
"""
Compute the union of two sets and return the resulting set.
Args:
set1 (Set[int]): The first set of integers.
set2 (... |
magic_evol_110k | 95,595 | Write a Python function to count the occurrences of each element in a given list efficiently, even for large lists. The function should avoid redundant computations and should be optimized for performance.
The code should start with:
```python
from typing import List, Dict
def count_elements(lst: List[int]) -> Dict[i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
from collections import Counter
def count_elements(lst: List[int]) -> Dict[int, int]:
"""
Counts the occurrences of each element in the given list efficiently.
Args:
lst (List[int]): T... |
magic_evol_110k | 95,606 | Write a Python function to merge two numerical sequences (lists) into a single list. The merged list should contain all elements from the first list followed by all elements from the second list. The function should handle lists of any length, including empty lists.
The code should start with:
```python
from typing im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_lists(list_1: List[int], list_2: List[int]) -> List[int]:
"""
Merges two lists into a single list. The merged list contains all elements from the first list followed by all elements from the se... |
magic_evol_110k | 95,610 | Write a Python function to generate the Fibonacci series for the first `n` numbers efficiently using memoization. The function should handle large numbers and ensure that the time complexity is reduced by storing previously computed Fibonacci numbers. The code should start with:
```python
def generate_fibonacci(n: int)... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the Fibonacci series for the first n numbers using memoization.
Args:
n (int): The number of Fibonacci numbers to generate.
Ret... |
magic_evol_110k | 95,612 | Write a Python function to find the highest value in a given list of integers without using the built-in `max` function. The function should handle edge cases such as an empty list by returning `None`. The code should start with:
```python
from typing import List, Optional
def find_highest_value(nums: List[int]) -> Op... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_highest_value(nums: List[int]) -> Optional[int]:
"""
Find the highest value in a given list of integers without using the built-in 'max' function.
Args:
nums (List[int]): ... |
magic_evol_110k | 95,613 | Write a Python function `get_last_element(array)` that takes an input array and efficiently returns the last element. The function should handle edge cases, including when the array is empty. The solution should have an O(1) time complexity.
The code should start with:
```python
from typing import List, Union
def get... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def get_last_element(array: List[int]) -> Union[int, str]:
"""
Returns the last element of the given array. If the array is empty, returns a message indicating so.
Args:
array (List[i... |
magic_evol_110k | 95,623 | Write a Python function to remove all dictionary keys that start with the string sequence "item", considering potential edge cases such as keys with leading or trailing spaces, or non-alphanumeric characters. The function should handle these cases by cleaning the keys before checking if they start with "item".
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def delete_items(data: Dict[str, str]) -> Dict[str, str]:
"""
Removes all dictionary keys that start with the string sequence "item",
considering potential edge cases such as keys with leading or tra... |
magic_evol_110k | 95,641 | Write a Python function to generate a 2x2 matrix with elements localized within the range of -0.5 to 0.5, ensuring that the elements are populated randomly. The function should return the generated matrix.
The code should start with:
```python
import numpy as np
def generate_random_matrix() -> np.ndarray:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def generate_random_matrix() -> np.ndarray:
"""
Generates a 2x2 matrix with elements localized within the range of -0.5 to 0.5.
Returns:
np.ndarray: A 2x2 matrix with random elements between -0.5... |
magic_evol_110k | 95,649 | Write a Python function to identify the longest palindromic substring within a given string. The function should return the longest palindromic substring found. If there are multiple palindromic substrings of the same maximum length, return the first one encountered.
The code should start with:
```python
def longest_p... | Here is the Python code to solve the given problem in the markdown block:
```python
def longest_palindromic_substring(s: str) -> str:
"""
Finds the longest palindromic substring within the given string.
Args:
s (str): The input string to search for the longest palindromic substring.
Returns:
... |
magic_evol_110k | 95,670 | Write a Python function to find the largest number in an array of integers using a recursive approach. The function should also check for any non-integer values in the array. If a non-integer value is found, the function should return an error message. The function should have a time complexity of O(n).
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_largest_recursive(arr: List[int]) -> Union[int, str]:
"""
Recursively finds the largest number in an array of integers.
If a non-integer value is found, returns an error message.
... |
magic_evol_110k | 95,672 | Write a Python function to evaluate division queries based on given equations and values. For each query, return the result of the division and the path of variables that led to the result. If a particular query cannot be evaluated, return `-1.0` and an empty array for the path.
The function should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
from collections import defaultdict, deque
def evaluate_division(equations: List[List[str]], values: List[float], queries: List[List[str]]) -> List[Tuple[float, List[str]]]:
"""
Evaluate division ... |
magic_evol_110k | 95,678 | Write a Python function to duplicate each element in a given array of integers while maintaining the original order of elements. The function should take a list of integers as input and return a new list where each element from the input list appears twice in the same order.
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
def duplicate_elements(array: List[int]) -> List[int]:
"""
Duplicates each element in the given array while maintaining the original order.
Args:
array (List[int]): The input array of intege... |
magic_evol_110k | 95,744 | Write a Python function to combine two strings into a single string by alternating characters from each input string, starting with the first string. If one string is longer than the other, append the remaining characters from the longer string to the end of the result.
The code should start with:
```python
def combin... | Here is the Python code to solve the given problem in the markdown block:
```python
def combine_strings(s1: str, s2: str) -> str:
"""
Combines two strings by alternating characters from each input string, starting with the first string.
If one string is longer than the other, append the remaining characters... |
magic_evol_110k | 95,746 | Write a Python function to create a dictionary that maps a list of integers to their corresponding English word representations. The function should take a list of integers as input and return a dictionary where each integer is a key and its corresponding English word representation is the value. If an integer is not b... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def map_numbers_to_words(numbers: List[int]) -> Dict[int, str]:
"""
Maps a list of integers to their corresponding English word representations.
Args:
numbers (List[int]): A list of in... |
magic_evol_110k | 95,777 | Write a Python function to validate and differentiate between short form (e.g., `#abc`) and long form (e.g., `#aabbcc`) hexadecimal color codes. The function should also ensure that the short form codes accurately correlate to their long form counterparts (e.g., `#abc` -> `#aabbcc`). Additionally, the function should v... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import Tuple
def validate_hex_color(code: str) -> Tuple[bool, str]:
"""
Validate and differentiate between short form and long form hexadecimal color codes.
Args:
code (str): The hexadecimal c... |
magic_evol_110k | 95,787 | 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 use dynamic programming to efficiently compute the result.
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 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 | 95,807 | Write a Python function to calculate the product of all numbers in a given list. The function should handle an empty list by returning 1, as the product of no numbers is defined as 1. The code should start with:
```python
from typing import List
from functools import reduce
import operator
def product_of_list(lst: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from functools import reduce
import operator
def product_of_list(lst: List[int]) -> int:
"""
Calculate the product of all numbers in a given list.
Args:
lst (List[int]): The list of integers... |
magic_evol_110k | 95,845 | Write a Python function to create a dictionary that maps each floating-point number in a given list to its multiplicative inverse. The multiplicative inverse of a number \( x \) is \( \frac{1}{x} \). The function should handle cases where the input list may contain zero, which has no multiplicative inverse. In such cas... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_inverse_mapping(numbers: List[float]) -> Dict[float, float]:
"""
Creates a dictionary that maps each floating-point number in the input list to its multiplicative inverse.
Args:
... |
magic_evol_110k | 95,866 | Write a Python function to search for a specific number in a given list of integers and return its position. If the list is empty or the number is not found, return appropriate error messages. Implement the function using a while loop and ensure it handles the errors correctly. The function should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_number(numbers: List[int], target: int) -> Union[int, str]:
"""
Searches for the target number in the given list of integers and returns its position.
If the list is empty or the targ... |
magic_evol_110k | 95,881 | Write a Python function to generate a list of random 3D shapes with specified properties. Each shape should be represented as a dictionary with keys 'type', 'color', and 'size'. The 'type' can be one of 'cube', 'sphere', or 'cylinder'. The 'color' should be a tuple of three integers representing RGB values (each betwee... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
import random
def generate_random_shapes(num_shapes: int) -> List[Dict[str, object]]:
"""
Generates a list of random 3D shapes with specified properties.
Args:
num_shapes (int):... |
magic_evol_110k | 95,886 | Write a Python function to compute the greatest common divisor (GCD) of two non-negative integers. The function should handle edge cases such as zero values and ensure that both inputs are non-negative integers. The code should start with:
```python
def highest_common_factor(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def highest_common_factor(a: int, b: int) -> int:
"""
Compute the greatest common divisor (GCD) of two non-negative integers.
Args:
a (int): The first non-negative integer.
b (int): The second non-negative i... |
magic_evol_110k | 95,887 | Write a Python function to print the contents of a given dictionary in a formatted way. The function should accept a dictionary as input and print each key-value pair in the format "Key: <key>, Value: <value>". The function should handle dictionaries with any type of keys and values.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def print_dictionary_contents(dictionary: Dict) -> None:
"""
Prints the contents of a given dictionary in the format "Key: <key>, Value: <value>".
Args:
dictionary (Dict): The dictionary who... |
magic_evol_110k | 95,890 | Write a Python function to perform element-wise addition of two lists. The function should take two lists of integers as input and return a new list where each element is the sum of the corresponding elements from the input lists. If the lists are of different lengths, the function should raise a `ValueError`.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def element_wise_addition(list1: List[int], list2: List[int]) -> List[int]:
"""
Perform element-wise addition of two lists.
Args:
list1 (List[int]): The first list of integers.
list2... |
magic_evol_110k | 95,899 | Write a Python function to reverse the elements of an array within a specified index range in-place. The function should modify the input array directly without creating additional data structures for the reversed elements. The function should start with:
```python
from typing import List
def reverse_elements_in_range... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_elements_in_range(arr: List[int], start_index: int, end_index: int) -> None:
"""
Reverses the elements of the array within the specified index range in-place.
Args:
arr (List[int... |
magic_evol_110k | 95,916 | Write a Python function to print a given array of bytes in a two-column format, where the first column is the byte number and the second column is the byte value. If the byte value is a printable ASCII character (between 0x20 and 0x7F), print it as a character; otherwise, print it as a hexadecimal escape sequence.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_bytes_in_columns(byte_array: bytes):
"""
Prints a given array of bytes in a two-column format, where the first column is the byte number
and the second column is the byte value. Printable ASCII characters are print... |
magic_evol_110k | 95,923 | Write a Python function to find the minimum value and its index in a given list of integers. The function should also validate the list to ensure it is not empty and contains only integers. If the list is empty, return "Empty list". If the list contains non-integer elements, return "Invalid list". The function should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union, Tuple
def find_min_and_index(lst: List[int]) -> Union[Tuple[int, int], str]:
"""
Finds the minimum value and its index in a given list of integers.
Args:
lst (List[int]): The list of... |
magic_evol_110k | 95,927 | Write a Python function to implement the Cocktail Sort algorithm, which is a variant of the Bubble Sort algorithm that sorts in both directions (bidirectional). Additionally, optimize the algorithm to skip unnecessary iterations by keeping track of the last swapped index. The function should start with:
```python
from ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cocktail_sort(arr: List[int]) -> List[int]:
"""
Sorts the given list using the Cocktail Sort algorithm, which is a bidirectional variant of Bubble Sort.
The algorithm is optimized to skip unneces... |
magic_evol_110k | 95,939 | Write a Python function to calculate the remaining amount of money after multiple purchases from an initial combined total. The function should take the initial amount and a list of purchase amounts as inputs and return the remaining amount rounded to two decimal places.
The code should start with:
```python
from typi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_remaining_amount(initial_amount: float, purchase_amounts: List[float]) -> float:
"""
Calculate the remaining amount of money after multiple purchases from an initial combined total.
Ar... |
magic_evol_110k | 95,942 | Write a Python function to determine if each number within a list is within a specified range. The function should return `True` if all numbers in the list are within the inclusive range `[lower_limit, upper_limit]`, and `False` otherwise. The function should handle edge cases such as empty lists and invalid range limi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def within_range(lst: List[int], lower_limit: int, upper_limit: int) -> bool:
"""
Determine if each number in the list is within the specified inclusive range [lower_limit, upper_limit].
Args:
... |
magic_evol_110k | 95,951 | Write a Python function to find a target word or its reversed version in a list of words. The function should return the word if found, otherwise return `None`. The code should start with:
```python
from typing import List, Optional
def find_word_or_reverse(words: List[str], target: str) -> Optional[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_word_or_reverse(words: List[str], target: str) -> Optional[str]:
"""
Find a target word or its reversed version in a list of words.
Args:
words (List[str]): A list of word... |
magic_evol_110k | 95,957 | Write a Python function to determine the parity (even or odd) of each number in a given list of integers. The function should return a list of message strings, each stating whether the corresponding number is even or odd. The function should be efficient and avoid excessive recursive calls, which can lead to exceeding ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def check_parity(numbers: List[int]) -> List[str]:
"""
Determines the parity (even or odd) of each number in the given list and returns a list of message strings.
Args:
numbers (List[int]): ... |
magic_evol_110k | 95,959 | Write a Python function to find the highest and lowest values within a list of integers without using the built-in `min()` and `max()` functions, while maintaining the original list's order. The function should return a tuple containing the highest and lowest values.
The code should start with:
```python
from typing i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_extremes(lst: List[int]) -> Tuple[int, int]:
"""
Find the highest and lowest values within a list of integers without using the built-in min() and max() functions.
Args:
lst ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.