source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 26,028 | Write a Python function to calculate and return the prime factors of a given integer `n`. The function should return a list of prime factors in ascending order. 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]:
"""
Calculate the prime factors of a given integer `n`.
Args:
n (int): The integer for which to find the prime factors.
Returns:
List[int... |
evol_instruct_66k | 26,030 | Write a Python function to perform element-wise multiplication on two input lists and return a new list containing the results. The function should handle lists of different lengths by truncating the longer list to match the length of the shorter list. 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 element_wise_multiply(list1: List[int], list2: List[int]) -> List[int]:
"""
Perform element-wise multiplication on two input lists and return a new list containing the results.
If the lists are o... |
evol_instruct_66k | 26,041 | 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 floating point notation in descending order.
Args:
collection (List[float]): The coll... |
evol_instruct_66k | 26,053 | Write a Python function to determine if two given lists of integers are equivalent in terms of their element-wise sums. The function should return `True` if the sums of the corresponding elements in both lists are equal, and `False` otherwise. If the lists are of different lengths, the function should return `False`.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def are_lists_equivalent(list1: List[int], list2: List[int]) -> bool:
"""
Determines if two lists of integers are equivalent in terms of their element-wise sums.
Args:
list1 (List[int]): The... |
evol_instruct_66k | 26,074 | Write a Python function to calculate the median of a given list of integers without using built-in statistical functions. The function should validate if the list is not empty and handle both even and odd lengths of the list. The code should start with:
```python
from typing import List
def calculate_median(data: List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_median(data: List[int]) -> float:
"""
Calculate the median of a given list of integers without using built-in statistical functions.
Args:
data (List[int]): The list of integer... |
evol_instruct_66k | 26,080 | Write a Python function to sort a given list of numerical values in ascending order using the selection sort algorithm. The function should not use any pre-existing sorting techniques or libraries. The code should start with:
```python
from typing import List
def selection_sort(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def selection_sort(arr: List[int]) -> List[int]:
"""
Sorts a given list of numerical values in ascending order using the selection sort algorithm.
Args:
arr (List[int]): The list of numerica... |
evol_instruct_66k | 26,082 | Write a Python function to create a multidimensional array of zeros with a specified number of rows and columns. The function should return the initialized array. The code should start with:
```python
from typing import List
def create_zero_array(rows: int, cols: int) -> List[List[int]]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_zero_array(rows: int, cols: int) -> List[List[int]]:
"""
Create a multidimensional array of zeros with the specified number of rows and columns.
Args:
rows (int): The number of ro... |
evol_instruct_66k | 26,087 | Write a Python function to sort a given numerical sequence in an increasingly progressive fashion without using the built-in `sorted` function or any other built-in sorting functions. The function should implement a simple sorting algorithm such as Bubble Sort, Selection Sort, or Insertion Sort.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_sequence(sequence: List[int]) -> List[int]:
"""
Sorts a given numerical sequence in an increasingly progressive fashion using Insertion Sort.
Args:
sequence (List[int]): The numeric... |
evol_instruct_66k | 26,091 | Write a Python function to shuffle an array of numbers without using any built-in shuffle or random functions. The function should ensure that the execution time does not exceed O(N log N). The function should use a custom pseudo-random number generator to determine the positions for shuffling.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def pseudo_random(number: int) -> float:
"""
Generate a pseudo-random number between 0 and 1 based on the input number.
Args:
number (int): The input number to generate the pseudo-random num... |
evol_instruct_66k | 26,092 | Write a Python function to concatenate the elements of two tuple lists into a single dictionary structure. The function should take two lists of tuples as input, where each tuple in the first list represents a key and each tuple in the second list represents a value. The function should return a dictionary where each k... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def concatenate_tuples_to_dict(tuple_list1: List[Tuple], tuple_list2: List[Tuple]) -> Dict:
"""
Concatenate the elements of two tuple lists into a single dictionary structure.
Args:
... |
evol_instruct_66k | 26,106 | Write a Python function to identify and categorize the datatype of a given input parameter. The function should return a string that represents the category of the datatype. The categories include 'Integer', 'Float', 'String', 'Boolean', 'Tuple', 'List', 'Dictionary', 'Set', 'None', and 'Unknown' for any other types.
... | Here is the Python code to solve the given problem in the markdown block:
```python
def identify_datatype(value) -> str:
"""
Identifies and categorizes the datatype of a given input parameter.
Args:
value: The input parameter whose datatype needs to be identified.
Returns:
str: A strin... |
evol_instruct_66k | 26,120 | Write a Python function to generate a symmetric matrix from a given vector `y`. Each element in the vector should be used to create a 2D array where each unique pair combination of elements forms a symmetric matrix. The first element of the pair should act as the row index, and the second element should act as the colu... | 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_symmetric_matrix(vector: List[int]) -> np.ndarray:
"""
Generates a symmetric matrix from a given vector where each element in the vector
is used to create a 2D array. ... |
evol_instruct_66k | 26,131 | Write a Python function to output the distinct elements of a list of strings, using recursion instead of a simple loop. Each distinct element should be appended with its respective index in the list for clarity. The function should handle potential exceptions efficiently and effectively.
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 distinct_elements_with_indices(strings: List[str]) -> List[str]:
"""
Returns a list of distinct elements from the input list of strings, each appended with its respective index.
Args:
st... |
evol_instruct_66k | 26,135 | Write a Python function to remove all elements with a value of zero from a given list. The function should return a new list containing only the non-zero elements. The code should start with:
```python
from typing import List
def remove_zeros(my_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 remove_zeros(my_list: List[int]) -> List[int]:
"""
Removes all elements with a value of zero from the given list.
Args:
my_list (List[int]): The list from which to remove zero elements.
... |
evol_instruct_66k | 26,173 | Write a Python function to determine if a given integer `x` is a prime number. The function should return `True` if `x` is a prime number and `False` otherwise. The function should handle edge cases such as `x` being less than 2, which are not prime numbers.
The code should start with:
```python
def is_prime(x: int) -... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(x: int) -> bool:
"""
Determine if a given integer `x` is a prime number.
Args:
x (int): The integer to check for primality.
Returns:
bool: True if `x` is a prime number, False otherwise.
... |
evol_instruct_66k | 26,200 | Write a Python function to find the middle-most element in a given list of integers. If the list has an even number of elements, return the element at the index just before the middle. The function should handle lists of any length, including empty lists.
The code should start with:
```python
from typing import List
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_middle_element(arr: List[int]) -> int:
"""
Find the middle-most element in a given list of integers.
If the list has an even number of elements, return the element at the index just before t... |
evol_instruct_66k | 26,203 | Write a Python function to determine if one string (`str_1`) is a contiguous subsequence of another string (`str_2`). The function should return a boolean value indicating whether `str_1` can be found as a contiguous sequence of characters within `str_2`.
The code should start with:
```python
def is_contiguous_subsequ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_contiguous_subsequence(str_1: str, str_2: str) -> bool:
"""
Determines if `str_1` is a contiguous subsequence of `str_2`.
Args:
str_1 (str): The string to check for as a contiguous subsequence.
str_2 ... |
evol_instruct_66k | 26,208 | Write a Python function to check if a given group of elements (group1) is a subset of another group of elements (group2) without any repetition. The check should be case-insensitive and should also account for white spaces. The function should return `True` if all elements in group1 can be found in group2 in a case-ins... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_subset_case_insensitive(group1: List[str], group2: List[str]) -> bool:
"""
Checks if all elements in group1 are present in group2 in a case-insensitive and whitespace-insensitive manner.
Args... |
evol_instruct_66k | 26,211 | Write a Python function to sort a list of whole and mixed numbers in ascending order efficiently. The function should use an optimized sorting algorithm and handle any potential bugs in the provided code. The code should start with:
```python
from typing import List
def sort_mixed_numbers(arr: List[float]) -> List[flo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_mixed_numbers(arr: List[float]) -> List[float]:
"""
Sorts a list of whole and mixed numbers in ascending order efficiently.
Args:
arr (List[float]): The list of numbers to be sorted... |
evol_instruct_66k | 26,224 | Write a Python function to calculate the power of a number using both iterative and recursive methods. The function should handle positive, negative, and fractional exponents. If the base or exponent is not a number, an appropriate error message should be displayed. The function should return the result of the power ca... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def power_calculation(base: float, exponent: float) -> float:
"""
Calculate the power of a number using both iterative and recursive methods.
Args:
base (float): The base number.
exponent (float... |
evol_instruct_66k | 26,231 | Write a Python function to merge two given character sequences and reverse the resulting sequence. The function should take two strings as input and return the merged and reversed string. The code should start with:
```python
def merge_and_reverse(sequence1: str, sequence2: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def merge_and_reverse(sequence1: str, sequence2: str) -> str:
"""
Merges two given character sequences and reverses the resulting sequence.
Args:
sequence1 (str): The first character sequence.
sequence2 (s... |
evol_instruct_66k | 26,237 | Write a Python function to identify the lone integer in a given non-empty list of integers, where every integer appears twice except for one unique integer. The function should operate with a linear runtime complexity and without using additional memory (i.e., constant space complexity).
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 find_lone_integer(nums: List[int]) -> int:
"""
Identifies the lone integer in a list where every other integer appears twice.
Args:
nums (List[int]): A non-empty list of integers where e... |
evol_instruct_66k | 26,244 | Write a Python function to sort a list of unique non-decimal whole numbers in descending order. The function should ensure that only whole numbers are accepted and sorted. The code should start with:
```python
from typing import List
def sort_unique_whole_numbers_descending(numbers: List[float]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def sort_unique_whole_numbers_descending(numbers: List[float]) -> List[int]:
"""
Sorts a list of unique non-decimal whole numbers in descending order.
Args:
numbers (List[float])... |
evol_instruct_66k | 26,248 | Write a Python function that uses asynchronous generators to compute the cube of each element in a given list of numbers. The function should return a list of these cubed values. The code should start with:
```python
from typing import List
import asyncio
async def async_cubed_generator(numbers: List[int]):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import asyncio
async def async_cubed_generator(numbers: List[int]):
"""
Asynchronous generator that yields the cube of each number in the input list.
Args:
numbers (List[int]): A list of int... |
evol_instruct_66k | 26,249 | Write a Python function to print out the elements in a given list along with their corresponding indices, but only for the even numbers in the list. The function should start with:
```python
from typing import List
def print_even_numbers_with_indices(nums: List[int]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_even_numbers_with_indices(nums: List[int]) -> None:
"""
Prints the indices and values of even numbers in the given list.
Args:
nums (List[int]): The list of integers to process.
... |
evol_instruct_66k | 26,250 | Write a Python function to invert the case of every character in a given string. The function should handle both uppercase and lowercase letters, and any non-alphabetic characters should remain unchanged. The code should start with:
```python
def invert_case(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def invert_case(s: str) -> str:
"""
Inverts the case of every character in the given string.
Args:
s (str): The input string whose characters' cases are to be inverted.
Returns:
str: A new string with a... |
evol_instruct_66k | 26,304 | Write a Python function to calculate the arithmetic mean of a given list of non-decimal integers. The function should handle edge cases such as an empty list by returning 0.0. The code should start with:
```python
from typing import List
def arithmetic_mean(numbers: List[int]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def arithmetic_mean(numbers: List[int]) -> float:
"""
Calculate the arithmetic mean of a list of non-decimal integers.
Args:
numbers (List[int]): A list of non-decimal integers.
Retur... |
evol_instruct_66k | 26,306 | Write a Python function to add two numbers and return the result. The function should be reusable and should handle any two integers or floating-point numbers. The code should start with:
```python
def add_two_numbers(num1: float, num2: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def add_two_numbers(num1: float, num2: float) -> float:
"""
Adds two numbers and returns the result.
Args:
num1 (float): The first number to be added.
num2 (float): The second number to be added.
Return... |
evol_instruct_66k | 26,315 | Write a Python function to calculate the sum of the first n natural numbers efficiently. The function should take an integer `n` as input and return the sum of all integers from 1 to `n`. The function should be optimized for performance and readability.
The code should start with:
```python
def sum_of_first_n(n: int) ... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_first_n(n: int) -> int:
"""
Calculate the sum of the first n natural numbers.
Args:
n (int): The number up to which the sum is to be calculated.
Returns:
int: The sum of the first n natural n... |
evol_instruct_66k | 26,334 | Write a Python function to calculate the frequency distribution of each distinct word in a given text string. The function should return a dictionary where the keys are the distinct words and the values are their respective frequencies.
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
def word_frequency(text: str) -> Dict[str, int]:
"""
Calculate the frequency distribution of each distinct word in a given text string.
Args:
text (str): The input text string from which to ... |
evol_instruct_66k | 26,357 | Write a Python function to determine if a given number is divisible by 5. The function should return a boolean value (`True` if the number is divisible by 5, and `False` otherwise). The function should handle both positive and negative integers, as well as zero.
The code should start with:
```python
def is_divisible_b... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_divisible_by_5(num: int) -> bool:
"""
Determine if a given number is divisible by 5.
Args:
num (int): The number to check for divisibility by 5.
Returns:
bool: True if the number is divisible by ... |
evol_instruct_66k | 26,361 | Write a Python function to generate the first `n` numbers of the Fibonacci series. The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. The function should handle edge cases such as `n` being 0 or 1.
The code should start with:
```python
f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the first n numbers of the Fibonacci series.
Args:
n (int): The number of Fibonacci numbers to generate.
Returns:
List[... |
evol_instruct_66k | 26,383 | Write a Python function to calculate the power of a given base raised to a given exponent, ensuring the result is returned as a float. Additionally, handle the case where the base is provided as a string representation of an integer. The function should raise a ValueError if the base is not a valid integer string.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
def power_as_float(base: str, exponent: int) -> float:
"""
Calculate the power of a given base raised to a given exponent and return the result as a float.
Args:
base (str): The base as a string representation of an... |
evol_instruct_66k | 26,390 | Write a Python function to find the prime factors of a given number `n` as efficiently as possible, considering both time and space complexity. The function should handle large inputs and edge cases effectively. The code should start with:
```python
def prime_factors(n: int) -> list:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def prime_factors(n: int) -> list:
"""
Find the prime factors of a given number n.
Args:
n (int): The number for which to find the prime factors.
Returns:
list: A list of prime factors of n.
"""
... |
evol_instruct_66k | 26,400 | Write a Python function to determine if a specific element `k` is present within a given tuple or nested tuple, and count the number of occurrences of `k`. The function should return a tuple containing a boolean indicating the presence of `k` and an integer representing the count of `k`.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Any
def find_and_count_k(tuple_input: Tuple[Any, ...], k: Any) -> Tuple[bool, int]:
"""
Determines if the element `k` is present in the given tuple or nested tuple, and counts its occurrences.
Arg... |
evol_instruct_66k | 26,409 | Write a Python function to compute the arithmetic average of a list of integers. The function should handle the case where the list is empty by returning 0. The code should start with:
```python
from typing import List
def compute_average(nums: List[int]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def compute_average(nums: List[int]) -> float:
"""
Computes the arithmetic average of a list of integers.
Args:
nums (List[int]): A list of integers for which the average is to be computed... |
evol_instruct_66k | 26,418 | Write a Python function to find the k-th smallest element in a given array efficiently. The function should handle edge cases such as an empty array or k being out of bounds. The code should start with:
```python
from typing import List
def find_kth_smallest(arr: List[int], k: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import heapq
def find_kth_smallest(arr: List[int], k: int) -> int:
"""
Finds the k-th smallest element in the given array.
Args:
arr (List[int]): The array from which to find the k-th smal... |
evol_instruct_66k | 26,419 | Write a Python function to find the common elements between a given list and a predefined list. The function should return a new list containing only the elements that are present in both lists. The code should start with:
```python
from typing import List
def find_common_elements(my_list: List[int], pre_defined_list:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_common_elements(my_list: List[int], pre_defined_list: List[int]) -> List[int]:
"""
Find the common elements between a given list and a predefined list.
Args:
my_list (List[int]): Th... |
evol_instruct_66k | 26,426 | Write a Python function to reverse a given sequence of characters. The function should return the reversed sequence, starting from the last character and moving to the first. The function should handle both strings and lists of characters.
The code should start with:
```python
from typing import Union, List
def rever... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union, List
def reverse_sequence(seq: Union[str, List[str]]) -> Union[str, List[str]]:
"""
Reverses a given sequence of characters.
Args:
seq (Union[str, List[str]]): The sequence to be reversed.... |
evol_instruct_66k | 26,458 | Write a Python function to generate the first n Fibonacci numbers. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the previous two. The function should return a list containing the first n Fibonacci numbers.
The code should start with:
```python
from typing import List
def genera... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the first n Fibonacci numbers.
Args:
n (int): The number of Fibonacci numbers to generate.
Returns:
List[int]: A list c... |
evol_instruct_66k | 26,468 | Write a Python function to generate the first `n` numbers in the Fibonacci sequence, where `n` is a positive integer. The function should return a list containing the first `n` Fibonacci numbers. If `n` is less than or equal to 0, the function should return an empty list.
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 generate_fibonacci(n: int) -> List[int]:
"""
Generate the first n numbers in the Fibonacci sequence.
Args:
n (int): The number of Fibonacci numbers to generate.
Returns:
Lis... |
evol_instruct_66k | 26,472 | Write a Python function to construct a dictionary where each key-value pair represents a unique word from a given list and its corresponding character length. The function should handle lists of varying lengths and ensure that each word is unique in the dictionary.
The code should start with:
```python
from typing imp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_word_length_dict(word_list: List[str]) -> Dict[str, int]:
"""
Constructs a dictionary where each key-value pair represents a unique word from the provided list and its corresponding char... |
evol_instruct_66k | 26,474 | Write a Python function to perform a generalized multi-partition search technique, specifically a quinary search, within a sorted sequence of integers. The sequence may contain missing integers and errors in sequential order. The function should handle the scenario when the array isn't properly sorted or doesn't follow... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def quinary_search(arr: List[int], x: int) -> Union[int, str]:
"""
Perform a quinary search on a sorted array to find the index of the element `x`.
Args:
arr (List[int]): The array to... |
evol_instruct_66k | 26,478 | Write a Python function to identify the smallest number in a given list and its index positions. If the list contains multiple instances of the same smallest number, the function should return all index positions. The function should not use built-in functions such as `min()` or `index()`. Instead, it should implement ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_smallest_number_and_indices(lst: List[int]) -> Tuple[int, List[int]]:
"""
Finds the smallest number in a given list and returns its value along with all its index positions.
Args:
... |
evol_instruct_66k | 26,482 | Write a Python function to retrieve the element at a specific ordinal position from a given numerical series. The ordinal position is defined as the position in the series multiplied by a given factor. The function should handle cases where the calculated position exceeds the length of the series by returning the last ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_element_at_ordinal_position(series: List[int], position_factor: int, ordinal_position: int) -> int:
"""
Retrieves the element at a specific ordinal position from a given numerical series.
Th... |
evol_instruct_66k | 26,488 | Write a Python function to create a personalized, warm, and engaging greeting salutation for a patron identified by their name and the current date/time. The salutation should also include an appreciation message based on the patron's tenure. The function should start with:
```python
import datetime
def create_greetin... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def create_greeting(name: str, tenure: str) -> str:
"""
Create a personalized, warm, and engaging greeting salutation for a patron.
Args:
name (str): The name of the patron.
tenure (str): Th... |
evol_instruct_66k | 26,492 | Write a Python function to determine whether a given square matrix is a reflection of itself, meaning that all elements that are symmetrical along the diagonal are equal. The function should return `True` if the matrix is a reflection, and `False` otherwise. The code should start with:
```python
from typing import List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_reflection_matrix(matrix: List[List[int]]) -> bool:
"""
Determines whether a given square matrix is a reflection of itself.
Args:
matrix (List[List[int]]): A square matrix represented... |
evol_instruct_66k | 26,494 | Write a Python function to safely perform arithmetic operations on two integers and handle potential exceptions. The function should take two integers as input, perform addition, multiplication, and division operations, and return the results of these operations in a tuple. If any operation results in an error, the fun... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_arithmetic_operations(x: int, y: int) -> tuple:
"""
Safely performs addition, multiplication, and division on two integers and handles potential exceptions.
Args:
x (int): The first integer.
y (int)... |
evol_instruct_66k | 26,506 | Write a Python function to calculate the total revenue generated by a retail application based on the given database schema. The function should take a list of orders and a list of products as input and return the total revenue. Each order contains a `ProductID` and a `Quantity`, and each product contains a `ProductID`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def calculate_total_revenue(orders: List[Tuple[int, int]], products: List[Tuple[int, float]]) -> float:
"""
Calculate the total revenue generated by a retail application based on the given orders ... |
evol_instruct_66k | 26,507 | Write a Python function to create a new matrix by applying a defined mathematical operation to each element of the original matrix. The function should accept a matrix and a lambda function representing the operation. The code should start with:
```python
from typing import List, Callable
def apply_operation_to_matrix... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable
def apply_operation_to_matrix(matrix: List[List[int]], operation: Callable[[int], int]) -> List[List[int]]:
"""
Create a new matrix by applying a defined mathematical operation to each element ... |
evol_instruct_66k | 26,536 | Write a Python function to calculate the average of a given list of numbers. The function should handle lists of any length, including empty lists, and return `None` for an empty list. The code should start with:
```python
from typing import List, Optional
def calculate_average(numbers: List[int]) -> Optional[float]:
... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Optional
def calculate_average(numbers: List[int]) -> Optional[float]:
"""
Calculate the average of a given list of numbers.
Args:
numbers (List[int]): The list of numbers to calculate th... |
evol_instruct_66k | 26,546 | Write a Python function to calculate the frequency of each unique character in a given sentence, including spaces and punctuation. The function should return a dictionary where the keys are characters and the values are their respective frequencies.
The code should start with:
```python
from typing import Dict
def ch... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def character_frequency(sentence: str) -> Dict[str, int]:
"""
Calculate the frequency of each unique character in a given sentence.
Args:
sentence (str): The input sentence for which to calc... |
evol_instruct_66k | 26,552 | Write a Python function to calculate the Least Common Multiple (LCM) of four numbers (w, x, y, and z) using an optimized approach under specific constraints. The function should be efficient and handle large numbers within the range of 1 to \(10^9\). The code should start with:
```python
def lcm_of_four(w: int, x: int,... | Here is the Python code to solve the given problem in the markdown block:
```python
def lcm_of_four(w: int, x: int, y: int, z: int) -> int:
"""
Calculate the Least Common Multiple (LCM) of four numbers (w, x, y, and z) using an optimized approach.
Args:
w (int): The first number.
x (int): T... |
evol_instruct_66k | 26,554 | Write a Python function to flatten a two-dimensional matrix of integers and sort the resultant array in ascending order without using built-in sort functions. The function should start with:
```python
from typing import List
def flatten_and_sort_matrix(matrix: List[List[int]]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def flatten_and_sort_matrix(matrix: List[List[int]]) -> List[int]:
"""
Flattens a two-dimensional matrix of integers and sorts the resultant array in ascending order without using built-in sort functions... |
evol_instruct_66k | 26,563 | Write a Python function to construct a dictionary where the keys are the hexadecimal representations of the first five non-negative integers (0 to 4) and the corresponding values are their binary equivalents. The function should return the constructed dictionary.
The code should start with:
```python
def create_hex_bi... | Here is the Python code to solve the given problem in the markdown block:
```python
def create_hex_bin_dict() -> dict:
"""
Constructs a dictionary where the keys are the hexadecimal representations of the first five non-negative integers (0 to 4)
and the corresponding values are their binary equivalents.
... |
evol_instruct_66k | 26,579 | Write a Python function to determine the Greatest Common Divisor (GCD) of two integers `a` and `b` using the Euclidean algorithm. The function should be optimized for speed and handle the constraints where `1 <= a, b <= 10^9`. The code should start with:
```python
def gcd(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def gcd(a: int, b: int) -> int:
"""
Determine the Greatest Common Divisor (GCD) of two integers `a` and `b` using the Euclidean algorithm.
Args:
a (int): The first integer, with the constraint 1 <= a <= 10^9.
... |
evol_instruct_66k | 26,581 | 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
def lcm_of_four(a: int, b: int, c: int, d: int) -> 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.
... |
evol_instruct_66k | 26,584 | Write a Python function to generate a sequence of numbers from a given start number to a given end number, inclusive. The function should return a list of these numbers. The code should start with:
```python
from typing import List
def generate_sequence(start: int, end: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def generate_sequence(start: int, end: int) -> List[int]:
"""
Generate a sequence of numbers from the start number to the end number, inclusive.
Args:
start (int): The starting number of t... |
evol_instruct_66k | 26,593 | Write a Python function to determine the allocation of $300 across two accounts with different interest rates, given that the total interest earned after one year is $9. The first account offers a yearly interest rate of 4%, and the second account offers a yearly interest rate of 2%. The function should return the amou... | Here is the Python code to solve the given problem in the markdown block:
```python
def allocate_funds(total_amount: float, total_interest: float, interest_rate1: float, interest_rate2: float) -> tuple:
"""
Determine the allocation of funds across two accounts with different interest rates,
given the total ... |
evol_instruct_66k | 26,603 | Write a Python function to rearrange a given array in maximum-minimum form. The rearranged array should start with the largest element, followed by the smallest, then the second largest, followed by the second smallest, and so on. The code should start with:
```python
from typing import List
def rearrange_max_min(arr:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def rearrange_max_min(arr: List[int]) -> List[int]:
"""
Rearranges the given array in maximum-minimum form.
Args:
arr (List[int]): The input array to be rearranged.
Returns:
Lis... |
evol_instruct_66k | 26,615 | Write a Python function to remove all elements from a given list that are divisible by a specified divisor without a remainder. The function should return the modified list. The code should start with:
```python
from typing import List
def remove_divisible_elements(numbers: List[int], divisor: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def remove_divisible_elements(numbers: List[int], divisor: int) -> List[int]:
"""
Removes all elements from the given list that are divisible by the specified divisor without a remainder.
Args:
... |
evol_instruct_66k | 26,616 | Write a Python function to print all elements of a given array and compute the sum of the array elements using a while loop. The function should handle any exceptions that may arise during the execution. The code should start with:
```python
from typing import List
def print_and_sum_array(arr: List[int]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_and_sum_array(arr: List[int]) -> None:
"""
Prints all elements of the given array and computes the sum of the array elements using a while loop.
Handles any exceptions that may arise during... |
evol_instruct_66k | 26,628 | Write a Python function to compute a new list where each element is the product of all elements of the original list except for the element at the same position. The solution must not use the division operation and should have a linear time complexity.
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 product_of_all_except_self(lst: List[int]) -> List[int]:
"""
Compute a new list where each element is the product of all elements of the original list except for the element at the same position.
... |
evol_instruct_66k | 26,663 | Write a Python function to perform a binary search for a specific string in a sorted list of strings. The function should return the index of the string if it is found in the list, otherwise it should return -1. The solution should not exceed a time complexity of O(log n) and a space complexity of O(1). Handle all poss... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search_string(arr: List[str], target: str) -> int:
"""
Perform a binary search to find the index of a target string in a sorted list of strings.
Args:
arr (List[str]): A sorted li... |
evol_instruct_66k | 26,665 | Write a Python function to find the nth digit from the unending sequence of integers `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...]`. The function should efficiently determine the nth digit by leveraging mathematical properties of number sequences.
The code should start with:
```python
def find_nth_digit(n: int) -> int:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_nth_digit(n: int) -> int:
"""
Finds the nth digit in the sequence of natural numbers [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...].
Args:
n (int): The position of the digit to find.
Returns:
int: Th... |
evol_instruct_66k | 26,667 | Write a Python function to generate a list of numbers within a specified range, inclusive of both the start and end values. The function should handle cases where the start value is greater than the end value by reversing the order of the numbers in the list. The function should also handle cases where the start and en... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_numeric_range(start: int, end: int) -> List[int]:
"""
Generate a list of numbers within a specified range, inclusive of both the start and end values.
If the start value is greater than ... |
evol_instruct_66k | 26,690 | Write a Python function to replace all punctuation in a given string with a specific sequence of characters while preserving the original spacing between words. Additionally, write a mechanism to recover the original string from the modified one. The code should start with:
```python
import re
def replace_punctuation(... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def replace_punctuation(input_string: str, rep_sequence: str) -> str:
"""
Replace all punctuation in the input string with a specified sequence of characters,
while preserving the original spacing between words.
... |
evol_instruct_66k | 26,693 | Write a Python function to construct a novel array by selecting specific food items from multiple tables. Each table is represented as a list of strings, where each string is a food item. The function should take a list of tables (each table being a list of strings) and a list of indices (each index corresponding to a ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def construct_novel_array(tables: List[List[str]], indices: List[int]) -> List[str]:
"""
Constructs a novel array by selecting specific food items from multiple tables.
Args:
tables (List[Li... |
evol_instruct_66k | 26,705 | Write a Python function to calculate the maximum discrepancy between any two distinct numerical values within a given array of integers. The array contains random integers ranging from 1 to 100, and it may include repeated values. The function should handle edge cases where the array contains fewer than two distinct va... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_max_discrepancy(array: List[int]) -> int:
"""
Calculate the maximum discrepancy between any two distinct numerical values within a given array.
Args:
array (List[int]): The array of... |
evol_instruct_66k | 26,718 | Write a Python function to compute the sum of elements in a given list of integers. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def compute_sum(x: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def compute_sum(x: List[int]) -> int:
"""
Computes the sum of all elements in the given list of integers.
Args:
x (List[int]): The list of integers whose sum needs to be computed.
Retur... |
evol_instruct_66k | 26,720 | Write a Python function to calculate the sum of all elements in a given square matrix. A square matrix is a matrix where the number of rows is equal to the number of columns. The function should handle matrices of any size, including 0x0 matrices.
The code should start with:
```python
from typing import List
def sum_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_matrix_elements(matrix: List[List[int]]) -> int:
"""
Calculate the sum of all elements in a given square matrix.
Args:
matrix (List[List[int]]): A square matrix represented as a l... |
evol_instruct_66k | 26,724 | Write a Python function to calculate the average score of a student given a list of scores. The function should handle invalid inputs gracefully by raising an appropriate exception. The function should start with:
```python
from typing import List
def calculate_average_score(scores: List[int]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_average_score(scores: List[int]) -> float:
"""
Calculate the average score of a student given a list of scores.
Args:
scores (List[int]): A list of integer scores.
Returns... |
evol_instruct_66k | 26,728 | Write a Python function to check if a given phrase contains any abusive or vulgar words. The function should be case-insensitive and should return `True` if any of the specified abusive words are found in the phrase, otherwise `False`.
The code should start with:
```python
def check_profanity(input_text: str) -> bool:... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_profanity(input_text: str) -> bool:
"""
Check if the given phrase contains any abusive or vulgar words.
Args:
input_text (str): The phrase to be checked for profanity.
Returns:
bool: True if t... |
evol_instruct_66k | 26,736 | Write a Python function to find the smallest number in a given list that is greater than a specified number. The function should return `None` if no such number exists in the list.
The code should start with:
```python
from typing import List, Optional
def smallest_greater_number(arr: List[int], num: int) -> Optional... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def smallest_greater_number(arr: List[int], num: int) -> Optional[int]:
"""
Find the smallest number in the given list that is greater than the specified number.
Args:
arr (List[in... |
evol_instruct_66k | 26,737 | Write a Python function to condense a given string by removing consecutive duplicate characters. The function should return a new string where each character appears only once in sequence, effectively removing any consecutive duplicates.
The code should start with:
```python
def condense_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def condense_string(s: str) -> str:
"""
Condenses a given string by removing consecutive duplicate characters.
Args:
s (str): The input string to be condensed.
Returns:
str: The condensed string with ... |
evol_instruct_66k | 26,748 | Write a Python function that processes a list of integers by performing two tasks simultaneously: numbering each element in the list in a reverse manner and replicating each element twice during the output process. The function should return a list of strings where each string represents the formatted output for each e... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def process_list(nums: List[int]) -> List[str]:
"""
Processes a list of integers by numbering each element in reverse order and replicating each element twice during the output process.
Args:
... |
evol_instruct_66k | 26,759 | Write a Python function to find the length of the longest sublist within a list of lists and also return the index of the longest sublist. If there are multiple sublists of the same longest length, return the index of the first one. The function should start with:
```python
from typing import List, Tuple
def find_long... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_longest_sublist(lst: List[List[int]]) -> Tuple[int, int]:
"""
Find the length of the longest sublist within a list of lists and return the index of the longest sublist.
Args:
... |
evol_instruct_66k | 26,761 | Write a Python function to determine the highest attainable point value without exceeding a given limit, using a provided set of numerical values and corresponding point values. The goal is to maximize the sum of point values that correspond to the picked numbers, ensuring that the sum of the picked numbers does not ex... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def maximize_score(set: List[int], scores: Dict[int, int], L: int) -> int:
"""
Determine the highest attainable point value without exceeding a given limit.
Args:
set (List[int]): A li... |
evol_instruct_66k | 26,763 | Write a Python function to transform a given list of integers by first amplifying each element by a factor of three and then subtracting 15 from each element. The function should return the transformed list.
The code should start with:
```python
from typing import List
def transform_list(your_list: List[int]) -> List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def transform_list(your_list: List[int]) -> List[int]:
"""
Transforms a list of integers by first amplifying each element by a factor of three and then subtracting 15 from each element.
Args:
... |
evol_instruct_66k | 26,774 | Write a Python function to check if all elements of a given group (group1) are contained within another group (group2) without any repetition. The function should return `True` if all elements of `group1` are present in `group2`, and `False` otherwise. 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 is_contained_without_repetition(group1: List[str], group2: List[str]) -> bool:
"""
Checks if all elements of group1 are contained within group2 without any repetition.
Args:
group1 (List... |
evol_instruct_66k | 26,779 | Write a Python function to sort a list of integers in ascending order while removing duplicate entries and maintaining the original order of appearance for similarly valued entries. The function should have a time complexity no worse than O(n log n). The code should start with:
```python
from typing import List
def so... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def sort_and_remove_duplicates(arr: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order while removing duplicate entries and maintaining the original order of appearance.
Args... |
evol_instruct_66k | 26,784 | Write a Python function to calculate the sum of a specific number range within a given list. The list may contain both integers and characters. If a character is encountered, it should be converted to its ASCII value before summing. The function should start with:
```python
from typing import List
def sum_of_range(arr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_range(arr: List[str], start: int, end: int) -> int:
"""
Calculate the sum of a specific range within a list, converting characters to their ASCII values if necessary.
Args:
arr (L... |
evol_instruct_66k | 26,785 | Write a Python function to identify the integer(s) that occur most frequently in a given list of numbers. If there are multiple integers with the same highest frequency, return all of them. The function should start with:
```python
from typing import List, Union
def find_dominant_numbers(nums: List[int]) -> Union[int,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_dominant_numbers(nums: List[int]) -> Union[int, List[int]]:
"""
Identify the integer(s) that occur most frequently in the given list of numbers.
Args:
nums (List[int]): The l... |
evol_instruct_66k | 26,788 | Write a Python function to find the second smallest number in a given list of floating-point numbers. The function should handle lists with duplicate values and ensure that the second smallest number is correctly identified. The code should start with:
```python
from typing import List
def find_second_smallest(numbers... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_second_smallest(numbers: List[float]) -> float:
"""
Find the second smallest number in a list of floating-point numbers.
Args:
numbers (List[float]): A list of floating-point number... |
evol_instruct_66k | 26,790 | Write a Python function to map the values of one dictionary to another based on the keys of the second dictionary. The function should handle cases where the second dictionary does not contain the key from the first dictionary and should return a new dictionary with the mapped values. The function should also handle ca... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def map_dicts(d1: Dict[Any, Any], d2: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Maps the values of one dictionary to another based on the keys of the second dictionary.
Args:
d1 (Dict[Any,... |
evol_instruct_66k | 26,800 | Write a Python function to generate a hint for the Bulls and Cows game based on the given secret number and a guess. The hint should be formatted as "xAyB", where `x` is the number of bulls (digits in the guess that are in the correct position) and `y` is the number of cows (digits in the guess that are in the secret n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
import random
def get_hint(secret: str, guess: str) -> str:
"""
Generates a hint for the Bulls and Cows game based on the given secret number and a guess.
Args:
secret (str): The secret num... |
evol_instruct_66k | 26,813 | Write a Python function to calculate the sum of squares of the first n natural numbers using an in-line lambda function. The function should take an integer `n` as input and return the sum of squares of the numbers from 1 to `n`. The code should start with:
```python
def sum_of_squares(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_squares(n: int) -> int:
"""
Calculate the sum of squares of the first n natural numbers using an in-line lambda function.
Args:
n (int): The number up to which the sum of squares is to be calculated.
... |
evol_instruct_66k | 26,819 | Write a Python function to invert a given dictionary and sort the resulting dictionary by its values in descending alphanumeric order. The function should take a dictionary as input and return the inverted and sorted dictionary.
The code should start with:
```python
from typing import Dict
def invert_and_sort_dict(in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def invert_and_sort_dict(input_dict: Dict[str, str]) -> Dict[str, str]:
"""
Inverts the given dictionary and sorts the resulting dictionary by its values in descending alphanumeric order.
Args:
... |
evol_instruct_66k | 26,830 | Write a Python function to create an advanced histogram that counts the frequency of each character in a given string, considering both uppercase and lowercase characters as equivalent. The function should also count numerical values and punctuation marks. The code should start with:
```python
from typing import Dict
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def advanced_histogram(text: str) -> Dict[str, int]:
"""
Create a histogram that counts the frequency of each character in a given string,
considering both uppercase and lowercase characters as equiv... |
evol_instruct_66k | 26,848 | Write a Python function to find the longest common subsequence (LCS) of two given strings. The function should return the length of the LCS.
The code should start with:
```python
from typing import List
def longest_common_subsequence(str1: str, str2: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def longest_common_subsequence(str1: str, str2: str) -> int:
"""
Calculate the length of the longest common subsequence (LCS) of two given strings.
Args:
str1 (str): The first string.
... |
evol_instruct_66k | 26,851 | Write a Python function to convert a given string to lowercase and remove all digits and special characters, preserving only alphabetic characters. The function should handle various edge cases, including empty strings, strings with only special characters, and strings with mixed characters.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_lowercase_remove_digits_and_special_chars(text: str) -> str:
"""
Convert a given string to lowercase and remove all digits and special characters, preserving only alphabetic characters.
Args:
text (st... |
evol_instruct_66k | 26,852 | Write a Python function to print each unique letter from a given string, one by one on a new line, in alphabetical order, and disregarding case sensitivity. The function should not return any value but should print the letters directly.
The code should start with:
```python
def print_unique_letters(input_string: str) ... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_unique_letters(input_string: str) -> None:
"""
Prints each unique letter from the given string, one by one on a new line, in alphabetical order, and disregarding case sensitivity.
Args:
input_string (str):... |
evol_instruct_66k | 26,853 | Write a Python function to find the frequency of each distinct letter and the frequency of all letter pairs in a given string, ignoring case sensitivity. The function should return two dictionaries: one for single letter frequencies and one for pair letter frequencies.
The code should start with:
```python
from collec... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import defaultdict
from typing import Dict, Tuple
def letter_and_pair_frequencies(string: str) -> Tuple[Dict[str, int], Dict[str, int]]:
"""
Calculate the frequency of each distinct letter and the frequency of ... |
evol_instruct_66k | 26,855 | Write a Python function to merge two sorted arrays of integers into a single sorted array without using built-in sorting functions. The function should efficiently combine the elements from both arrays while maintaining the sorted order.
The code should start with:
```python
from typing import List
def merge_sorted_a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Merges two sorted arrays of integers into a single sorted array.
Args:
arr1 (List[int]): The first sorted array.
... |
evol_instruct_66k | 26,857 | Write a Python function to count the frequency of each distinct alphanumeric character in a given string. The function should return a dictionary where the keys are the alphanumeric characters and the values are their respective counts.
The code should start with:
```python
from typing import Dict
def count_alphanume... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_alphanumeric_characters(s: str) -> Dict[str, int]:
"""
Counts the frequency of each distinct alphanumeric character in the given string.
Args:
s (str): The input string to analyze.... |
evol_instruct_66k | 26,882 | Write a Python function to find all words in a given text that end with the suffix "able" using regular expressions. The function should return a list of all such words. The code should start with:
```python
import re
from typing import List
def find_words_ending_with_able(text: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def find_words_ending_with_able(text: str) -> List[str]:
"""
Find all words in the given text that end with the suffix "able".
Args:
text (str): The input text in which to search f... |
evol_instruct_66k | 26,886 | Write a Python function to implement a binary search algorithm using a switch-case structure instead of traditional if-else conditionals to determine if a number is between 1 and 1000. Incorporate error handling to account for non-numeric and out-of-range inputs. The function should return a string indicating whether t... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_search_with_switch(n: int) -> str:
"""
Implements a binary search algorithm using a switch-case structure to determine if a number is between 1 and 1000.
Incorporates error handling for non-numeric and out-of-rang... |
evol_instruct_66k | 26,895 | Write a Python function to sort a given array in descending order and calculate the sum of the top three elements. The function should handle arrays of any length, including cases where the array has fewer than three elements.
The code should start with:
```python
from typing import List
def sum_of_top_three(array: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_top_three(array: List[int]) -> int:
"""
Sorts the given array in descending order and calculates the sum of the top three elements.
Args:
array (List[int]): The array of integers ... |
evol_instruct_66k | 26,898 | Write a Python function to iterate through a given dictionary and print each key-value pair using a while loop. The function should handle any dictionary, not just the provided example. The code should start with:
```python
from typing import Dict
def print_dict_with_while_loop(dictionary: Dict[str, str]) -> None:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def print_dict_with_while_loop(dictionary: Dict[str, str]) -> None:
"""
Iterates through a given dictionary and prints each key-value pair using a while loop.
Args:
dictionary (Dict[str, str... |
evol_instruct_66k | 26,900 | Write a Python function to compare two lists of strings and return a list of boolean values indicating whether each corresponding pair of strings are anagrams or not. An anagram is a word, phrase, or name formed by rearranging the letters of another, such as 'cinema', formed from 'iceman'. Your function should ignore s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def are_anagrams(list1: List[str], list2: List[str]) -> List[bool]:
"""
Compare two lists of strings and return a list of boolean values indicating whether each corresponding pair of strings ar... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.