source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 80,804 | Write a Python function to calculate the sum of two distinct numerical entities, ensuring that the function handles different types of numerical inputs (integers, floats, complex numbers) correctly. The function should also handle cases where the inputs are not numerical by raising a `TypeError`.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
def add_numbers(a, b):
"""
Calculate the sum of two distinct numerical entities.
Args:
a (int, float, complex): The first numerical entity.
b (int, float, complex): The second numerical entity.
Returns:... |
magic_evol_110k | 80,808 | Write a Python function to detect if the balance of a bank account falls below zero at any point during a series of deposit and withdrawal operations. The function should handle both integer and floating-point operations based on an optional flag. Additionally, it should correctly manage negative deposits and withdrawa... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def below_zero(operations: List[Union[int, float]], handle_float: bool = False, balance_limit: int = 10) -> bool:
"""
Detects if the balance of a bank account falls below zero at any point during ... |
magic_evol_110k | 80,822 | 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 alphabets as equivalent, and including numerical values and punctuation marks. The function should return a dictionary where the keys are characters (converted ... | 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 an advanced histogram that counts the frequency of each character in a given string,
considering both uppercase and lowercase alphabets... |
magic_evol_110k | 80,834 | Write a Python function to find the highest prime number within a given range from a list of integers. The function should take a list of integers and two integers representing the start and end of the range as input, and return the highest prime number within that range. If no prime numbers are found within the range,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
... |
magic_evol_110k | 80,835 | Write a Python function to calculate the average score for each person in a given list of tuples. Each tuple contains a person's unique identifier followed by their scores in three distinct disciplines. The function should return a dictionary where the key is the person's unique identifier and the value is the average ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def average_score(scores: List[Tuple[str, int, int, int]]) -> Dict[str, float]:
"""
Calculate the average score for each person in a list of tuples.
Args:
scores (List[Tuple[str... |
magic_evol_110k | 80,839 | Write a Python function to check if a variable is uninitialized or empty. The function should handle different types of variables such as lists, strings, dictionaries, and integers. If the variable is uninitialized or empty, the function should return `True`; otherwise, it should return `False`. The function should als... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any
def is_uninitialized_or_empty(variable: Any) -> bool:
"""
Check if a variable is uninitialized or empty.
Args:
variable (Any): The variable to check.
Returns:
bool: True if the v... |
magic_evol_110k | 80,845 | Write a Python function to find the maximum number in a given list of integers. Additionally, provide a flawed code example that seems to work on first glance but doesn't actually solve the problem. Analyze the flawed code and explain the reasons for its erroneous behavior.
The code should start with:
```python
from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_max_number(numbers: List[int]) -> int:
"""
Find the maximum number in a given list of integers.
Args:
numbers (List[int]): The list of integers from which to find the maximum number... |
magic_evol_110k | 80,856 | Write a Python function to calculate the cumulative sum of elements in a given list. The function should iterate through each element in the list, compute the cumulative sum up to that element, and store each intermediate cumulative sum in a new list. The function should return this list of cumulative sums.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_sum(list_of_elements: List[int]) -> List[int]:
"""
Calculate the cumulative sum of elements in a given list.
Args:
list_of_elements (List[int]): The list of integers for which... |
magic_evol_110k | 80,861 | Write a Python function to filter out students who meet specific criteria from a list of student dictionaries. The criteria are that the student must be older than 18 years and have a GPA of at least 3.5. The function should return a list of names of the students who meet these criteria.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def filter_students(students: List[Dict[str, any]]) -> List[str]:
"""
Filters students based on age and GPA criteria and returns a list of their names.
Args:
students (List[Dict[str, a... |
magic_evol_110k | 80,883 | Refactor the given Python code to adhere to PEP8 best practices and use the `enumerate` function. The original code uses a `while` loop to iterate over a list and print each element along with its index. The task is to rewrite this code using a `for` loop with `enumerate` to make it more Pythonic and readable.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_elements_with_index(arr):
"""
Prints each element of the given list along with its index.
Args:
arr (list): The list of elements to be printed with their indices.
Returns:
None: This function ... |
magic_evol_110k | 80,885 | Write a Python function to find the second highest element in a given list without using built-in functions like `max`, `sorted`, or any other similar functions. The function should handle lists with duplicate values and return `None` if the list has fewer than two elements.
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, Optional
def second_highest_element(l: List[int]) -> Optional[int]:
"""
Return the second highest element in the list.
Args:
l (List[int]): The list of integers from which to find the secon... |
magic_evol_110k | 80,910 | Write a Python function to calculate the sum of a given number `a` and the product of two other numbers `b` and `c`. The function should adhere to PEP 8 style guidelines for improved readability and maintainability. The code should start with:
```python
def calculate_sum(a: int, b: int, c: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_sum(a: int, b: int, c: int) -> int:
"""
Calculate the sum of a given number `a` and the product of two other numbers `b` and `c`.
Args:
a (int): The first number to be added.
b (int): The first... |
magic_evol_110k | 80,913 | Write a Python function to manage an academic scholar's profile, including adding courses and calculating the Grade Point Average (GPA). The function should start with:
```python
from typing import List, Dict
def add_course(profile: Dict[str, any], course: Dict[str, any]) -> None:
"""
Adds a course to the scho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def add_course(profile: Dict[str, any], course: Dict[str, any]) -> None:
"""
Adds a course to the scholar's profile.
Args:
profile (dict): The scholar's profile containing name, age, G... |
magic_evol_110k | 80,918 | Write a Python function to determine if two sentences are similar based on given word similarity pairs. The sentences are represented as arrays of words. Two sentences are considered similar if they have the same length and each corresponding pair of words in the sentences are similar. The similarity relation is provid... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def are_sentences_similar(sentence1: List[str], sentence2: List[str], similar_pairs: List[List[str]]) -> bool:
"""
Determines if two sentences are similar based on given word similarity pairs.
Args:... |
magic_evol_110k | 80,922 | Write a Python function to compute the factorial of a given non-negative integer `n` using an iterative approach. The function should handle edge cases such as `n` being 0 or 1, and it should raise a `ValueError` if `n` is negative. The code should start with:
```python
def factorial(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int:
"""
Compute the factorial of a given non-negative integer n using an iterative approach.
Args:
n (int): The non-negative integer for which to compute the factorial.
Returns:
... |
magic_evol_110k | 80,930 | Write a Python function to generate a dictionary containing the distinct characters of a given string and the count of their respective occurrences. The function should handle any string input, including those with special characters, spaces, and mixed case. 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 count_character_occurrences(text: str) -> Dict[str, int]:
"""
Generates a dictionary containing the distinct characters of a given string and the count of their respective occurrences.
Args:
... |
magic_evol_110k | 80,948 | Write a Python function to perform the NOR operation on a pair of binary numerals. The NOR operation is a logical operation that returns `True` (or `1`) if and only if both inputs are `False` (or `0`). The function should take two binary digits as input and return the result of the NOR operation as an integer (`0` or `... | Here is the Python code to solve the given problem in the markdown block:
```python
def nor_operation(x: int, y: int) -> int:
"""
Perform the NOR operation on a pair of binary numerals.
The NOR operation returns 1 if both inputs are 0, otherwise it returns 0.
Args:
x (int): The first binary di... |
magic_evol_110k | 80,990 | Write a Python function to perform a ternary search on a sorted list of integers. The function should return the index of the target element if it exists in the list, otherwise return -1. Additionally, implement a performance comparison between the ternary search algorithm and the binary search algorithm. The compariso... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import time
def ternary_search(arr: List[int], target: int) -> int:
"""
Perform a ternary search on a sorted list of integers to find the index of the target element.
Args:
arr (List[int]): ... |
magic_evol_110k | 80,995 | Write a Python function to traverse a list of names and print each name using a functional programming approach. The function should use the `map` function to apply a lambda function that prints each name. The code should start with:
```python
from typing import List
def print_names_functional(names: List[str]) -> Non... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_names_functional(names: List[str]) -> None:
"""
Prints each name in the given list of names using a functional programming approach.
Args:
names (List[str]): The list of names to b... |
magic_evol_110k | 81,012 | Write a Python function to identify and replace single-character strings in a nested list with a specified non-null value. The function should handle multi-dimensional arrays and cases where the replacement character might be included in the array. An empty string should also be considered for replacement. The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def replace_single_char_strings(arr: List[Union[str, List]], replacement: str) -> List[Union[str, List]]:
"""
Replaces all single-character strings and empty strings in a nested list with a specif... |
magic_evol_110k | 81,017 | Write a Python function to find the nth ugly number. An ugly number is a positive number whose prime factors are limited to 2, 3, and 5. The sequence of ugly numbers starts with `1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ...`. The function should start with:
```python
def nth_ugly_number(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def nth_ugly_number(n: int) -> int:
"""
Find the nth ugly number.
Ugly numbers are positive numbers whose prime factors are limited to 2, 3, and 5.
The sequence of ugly numbers starts with 1, 2, 3, 4, 5, 6, 8, 9, 10, 12... |
magic_evol_110k | 81,024 | Write a Python function to calculate the Least Common Multiple (LCM) of a list of integers, while efficiently handling invalid entries (non-integer or negative values) in the list. The function should be optimized for large lists containing up to \(10^6\) integers, where each integer is between 1 and \(10^9\). The func... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def lcm_of_list(numbers: List[int]) -> int:
"""
Calculate the Least Common Multiple (LCM) of a list of integers, skipping invalid entries.
Args:
numbers (List[int]): A list of in... |
magic_evol_110k | 81,038 | Write a Python function to construct the largest possible positive whole number from an array of integer values. The function should ignore any negative numbers in the array. If the array contains only negative numbers, the function should return `None`. 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, Optional
def construct_largest_number(nums: List[int]) -> Optional[int]:
"""
Constructs the largest possible positive whole number from an array of integer values.
Args:
nums (List[int]): T... |
magic_evol_110k | 81,041 | Write a Python function to multiply all numerical values within a given list of dictionaries. The function should be able to traverse nested dictionary structures and ignore any non-numeric elements. Additionally, the function should handle dictionaries that contain other data structures like lists, sets, and tuples, a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union, List, Dict, Any
def multiply_numeric_values(data: Union[List[Dict[str, Any]], Dict[str, Any]]) -> float:
"""
Multiplies all numerical values within a given list of dictionaries or a single dictionary.
... |
magic_evol_110k | 81,047 | Write a Python function to multiply each element of an array with its consecutive element, handling potential division by zero errors. The array may contain floats and negative numbers. The function should return the modified array.
The code should start with:
```python
from typing import List
def multiply_consecutiv... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_consecutive_pairs(numbers: List[float]) -> List[float]:
"""
Multiplies each element of the input list with its consecutive element, handling potential division by zero errors.
Args:
... |
magic_evol_110k | 81,050 | Write a Python function to generate a list of a given number of unique random numbers within a specified range, ensuring no duplicates and that the list is sorted in ascending order. The function should handle cases where the range is not large enough to provide the requested number of unique numbers by returning an ap... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
from typing import List, Union
def generate_unique_randoms(num: int, start: int, end: int) -> Union[List[int], str]:
"""
Generates a list of a given number of unique random numbers within a specified range, sorted... |
magic_evol_110k | 81,078 | Write a Python function to find and return the smallest number in a given list of numbers. The function should handle lists of any size, including empty lists. If the list is empty, the function should return `None`.
The code should start with:
```python
from typing import List, Optional
def find_smallest_number(numb... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_smallest_number(numbers: List[int]) -> Optional[int]:
"""
Find and return the smallest number in a given list of numbers.
Args:
numbers (List[int]): The list of numbers fr... |
magic_evol_110k | 81,109 | Write a Python function to sort a list of integers in ascending order using an enhanced bubble sort algorithm. The sorting algorithm should increase in complexity based on the number of negative integers in the list. The function should start with:
```python
from typing import List
def enhanced_bubble_sort(lst: List[i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def enhanced_bubble_sort(lst: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order using an enhanced bubble sort algorithm.
The sorting algorithm increases in complexity based on ... |
magic_evol_110k | 81,119 | Write a Python function to perform the Hadamard product (element-wise multiplication) on two 4x4 matrices. The function should check if the input matrices are indeed 4x4 and raise a `ValueError` if they are not. The function should return the resulting matrix from the Hadamard product.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def hadamard_product(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[List[int]]:
"""
Perform the Hadamard product (element-wise multiplication) on two 4x4 matrices.
Args:
matrix1... |
magic_evol_110k | 81,132 | Write a Python function to extract and return a list of elements at even indices from a given list using list slicing. The function should correctly handle the bug in the provided code snippet, which incorrectly selects odd indexed elements instead of even indexed ones.
The code should start with:
```python
from typin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def extract_even_indexed_elements(a: List[int]) -> List[int]:
"""
Extracts and returns a list of elements at even indices from the given list.
Args:
a (List[int]): The input list from which ... |
magic_evol_110k | 81,139 | Write a Python function to convert a given hexadecimal number to its binary representation. The function should handle hexadecimal numbers represented as strings and return the binary representation as a string. The binary representation should not include the '0b' prefix that Python's `bin()` function includes.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_binary(hex_number: str) -> str:
"""
Converts a given hexadecimal number to its binary representation.
Args:
hex_number (str): The hexadecimal number to be converted, represented as a string.
Returns:... |
magic_evol_110k | 81,158 | Write a Python function to print the elements at odd indices in a given array and also find the sum of those elements. The function should return the sum of the elements at odd indices.
The code should start with:
```python
from typing import List
def sum_of_elements_at_odd_indices(array: 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_at_odd_indices(array: List[int]) -> int:
"""
Prints the elements at odd indices in the given array and returns the sum of those elements.
Args:
array (List[int]): The arr... |
magic_evol_110k | 81,171 | Write a Python function to iterate over a list and print each element using a while loop. Ensure that the function handles the list length correctly and increments the loop counter appropriately. The function should start with:
```python
from typing import List
def print_list_elements(array: List[int]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def print_list_elements(array: List[int]) -> None:
"""
Iterates over a list and prints each element using a while loop.
Args:
array (List[int]): The list of integers to be printed.
Re... |
magic_evol_110k | 81,178 | Write a Python function called `find_max_with_index` that takes a list of numbers as input and returns the maximum number in the list along with its index position. If the input is not a list, if the list contains elements that are not numbers, or if the list contains more than 1000 elements, the function should raise ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_max_with_index(lst: List[float]) -> Tuple[float, int]:
"""
Finds the maximum number in the given list and returns it along with its index position.
Args:
lst (List[float]): T... |
magic_evol_110k | 81,186 | Write a Python function to merge two sorted arrays into one sorted array without using any pre-set system functions for sorting. The function should efficiently combine the two arrays by comparing elements from both arrays and placing them in the correct order in the resulting array.
The code should start with:
```pyt... | 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 into one sorted array without using any pre-set system functions for sorting.
Args:
arr1 ... |
magic_evol_110k | 81,191 | Write a Python function to find and return all uneven (odd) numbers within a given range, inclusively. The function should take two integers, `start` and `end`, as input and return a list of all odd numbers within this range.
The code should start with:
```python
from typing import List
def find_odd_numbers(start: in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_odd_numbers(start: int, end: int) -> List[int]:
"""
Find and return all odd numbers within a given range, inclusively.
Args:
start (int): The starting number of the range (inclusive... |
magic_evol_110k | 81,195 | Write a Python function to remove all extra whitespace from a given string, ensuring that only single spaces remain between words. The function should handle leading, trailing, and multiple spaces within the string. The code should start with:
```python
def remove_extra_whitespace(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_extra_whitespace(text: str) -> str:
"""
Removes all extra whitespace from the given string, ensuring that only single spaces remain between words.
Args:
text (str): The input string from which to remove e... |
magic_evol_110k | 81,208 | Write a Python function to combine two dictionaries into a single set, retaining only the unique keys from both dictionaries. The function should start with:
```python
from typing import Dict
def combine_dicts_to_set(dict1: Dict[str, int], dict2: Dict[str, int]) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def combine_dicts_to_set(dict1: Dict[str, int], dict2: Dict[str, int]) -> set:
"""
Combines the keys of two dictionaries into a single set of unique keys.
Args:
dict1 (Dict[str, int]): The f... |
magic_evol_110k | 81,211 | Write a Python function to construct a dictionary that maps each planet in our solar system to its estimated number of moons. The function should take two lists as input: one containing the names of the planets and the other containing their corresponding number of moons. The function should return the constructed dict... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_planet_moon_dict(planets: List[str], moons: List[int]) -> Dict[str, int]:
"""
Constructs a dictionary that maps each planet in our solar system to its estimated number of moons.
Arg... |
magic_evol_110k | 81,235 | Write a Python function to compute the greatest common divisor (GCD) of two provided integer inputs, `a` and `b`, using the Euclidean algorithm. The function should handle both positive and negative integers, and return the absolute value of the GCD.
The code should start with:
```python
def greatest_common_divisor(a:... | Here is the Python code to solve the given problem in the markdown block:
```python
def greatest_common_divisor(a: int, b: int) -> int:
"""
Compute the greatest common divisor (GCD) of two integers a and b using the Euclidean algorithm.
Args:
a (int): The first integer.
b (int): The second ... |
magic_evol_110k | 81,247 | Write a Python function to create a dictionary where the keys are tuple pairs and the values are the multiplication results of the integers within the tuples. The function should accept a list of tuples as input and return the resulting dictionary.
The code should start with:
```python
from typing import List, Dict, T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
def tuple_multiplication_dict(tuples_list: List[Tuple[int, int]]) -> Dict[Tuple[int, int], int]:
"""
Creates a dictionary where the keys are tuple pairs and the values are the multiplication... |
magic_evol_110k | 81,260 | Write a Python function to implement an XOR gate using only two NAND gates and two AND gates. The function should take two boolean inputs and return the result of the XOR operation. The code should start with:
```python
def XOR_gate(a: bool, b: bool) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def AND_gate(a: bool, b: bool) -> bool:
"""
Implements the AND logic gate.
Args:
a (bool): First input.
b (bool): Second input.
Returns:
bool: True if both inputs are True, otherwise False.
... |
magic_evol_110k | 81,264 | Write a Python function to validate a given time string based on the following conditions:
1. The time string should not be empty.
2. The time string should be in the format `hh:mm`.
3. The hours should be between 0 and 23 (inclusive).
4. The minutes should be between 0 and 59 (inclusive).
The function should return `... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_time(time: str) -> bool:
"""
Validates a given time string based on the following conditions:
1. The time string should not be empty.
2. The time string should be in the format 'hh:mm'.
3. The hours shou... |
magic_evol_110k | 81,267 | Write a Python function to generate a list that contains only the non-unique elements from a given list and the sum of their occurrences. Additionally, the function should output the erroneous elements with duplicate indices. The function should start with:
```python
from typing import List, Dict, Tuple
def non_unique... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
from collections import Counter
def non_unique_elements_with_errors(lst: List[int]) -> Tuple[List[int], int, Dict[int, List[int]]]:
"""
Generate a list of non-unique elements from the given ... |
magic_evol_110k | 81,270 | Write a Python function to find all prime numbers within a given list of integers. The function should return a list of prime numbers found in the input list. The code should start with:
```python
from typing import List
def find_primes(num_list: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False oth... |
magic_evol_110k | 81,272 | Write a Python function that generates the squares of the first n natural numbers using a generator expression. The function should accept an integer `n` as input and yield the squares of the numbers from 1 to `n`. The code should start with:
```python
def generate_squares(n: int):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def generate_squares(n: int):
"""
Generates the squares of the first n natural numbers using a generator expression.
Args:
n (int): The number of natural numbers to square.
Yields:
int: The square of ea... |
magic_evol_110k | 81,302 | Write a Python function to sort a given list of integers in descending order and count the occurrences of each element in the sorted list. The function should handle edge cases where the list elements can have duplicate values and can also be negative. The code should start with:
```python
from typing import List, Dict... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def sort_and_count_occurrences(arr: List[int]) -> Dict[int, int]:
"""
Sorts the given list of integers in descending order and counts the occurrences of each element.
Args:
arr (List[i... |
magic_evol_110k | 81,305 | Write a Python function to calculate the factorial of a given positive integer. The function should validate that the input is a positive integer and raise a `ValueError` if it is not. The function should return the factorial of the input number.
The code should start with:
```python
def factorial(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int:
"""
Calculate the factorial of a given positive integer.
Args:
n (int): The positive integer for which to calculate the factorial.
Returns:
int: The factorial of the input ... |
magic_evol_110k | 81,309 | Write a Python function to simulate a dialogue between an advocate and a skeptic discussing the Everett Interpretation of quantum mechanics. The function should generate a sequence of exchanges where the advocate presents arguments and the skeptic responds with questions or skepticism. The dialogue should cover topics ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def simulate_quantum_dialogue() -> List[str]:
"""
Simulate a dialogue between an advocate and a skeptic discussing the Everett Interpretation of quantum mechanics.
Returns:
List[str]: A list... |
magic_evol_110k | 81,315 | Write a Python function to compute the absolute difference between two integers. The function should handle the edge case where the input is not an integer by raising a custom error message. The function should start with:
```python
def absolute_difference(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def absolute_difference(a: int, b: int) -> int:
"""
Computes the absolute difference between two integers.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
int: The absolu... |
magic_evol_110k | 81,317 | Write a Python function to determine if a bank account's balance goes below zero given a list of deposit and withdrawal operations. The function should also handle a `case_insensitive` flag to treat `Deposit/deposit` and `Withdrawal/withdrawal` as the same. Additionally, if `case_insensitive` is `True`, the function sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def below_zero(operations: List[Tuple[str, int]], case_insensitive: bool = False) -> bool:
"""
Determine if a bank account's balance goes below zero given a list of deposit and withdrawal operatio... |
magic_evol_110k | 81,323 | Write a Python function to remove consecutive repeating characters from a given string. The function should handle both alphanumeric characters and special symbols, punctuation, and spacing. The function should be case-sensitive, meaning 'A' and 'a' should be treated as different characters. The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_consecutive_repeats(string: str) -> str:
"""
Removes consecutive repeating characters from the given string.
Args:
string (str): The input string from which consecutive repeating characters are to be remo... |
magic_evol_110k | 81,347 | Write a Python function to find the indexes of all occurrences of a specified character in a given string. The function should return a list of integers representing the positions of the character in the string. The code should start with:
```python
from typing import List
def find_char_indexes(s: str, char: str) -> L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_char_indexes(s: str, char: str) -> List[int]:
"""
Find the indexes of all occurrences of a specified character in a given string.
Args:
s (str): The input string to search within.
... |
magic_evol_110k | 81,352 | Write a Python function to format a given number as a percentage value, rounding it to two decimal places. The function should handle both positive and negative numbers, as well as zero. The code should start with:
```python
def format_percent(value: float) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def format_percent(value: float) -> str:
"""
Formats a given number as a percentage value, rounded to two decimal places.
Args:
value (float): The number to be formatted as a percentage.
Returns:
str: T... |
magic_evol_110k | 81,360 | Write a Python function to implement the merge sort algorithm on a provided integer array. The function should recursively divide the array into halves until each subarray contains only one element, and then merge these subarrays back together in sorted order. The code should start with:
```python
from typing import Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(array: List[int]) -> List[int]:
"""
Sorts the provided integer array using the merge sort algorithm.
Args:
array (List[int]): The array of integers to be sorted.
Returns:... |
magic_evol_110k | 81,361 | Write a Python function to isolate prime numbers from a given list and return a new list composed solely of these prime numbers in descending order. The function should not use any pre-existing library functions for checking prime numbers or sorting. The code should start with:
```python
from typing import List
def is... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def isolate_primes_descending(lst: List[int]) -> List[int]:
"""
Isolates prime numbers from a given list and returns them in descending order.
Args:
lst (List[int]): The list of integers fro... |
magic_evol_110k | 81,362 | Write a Python function to print the current date in the following format: "YYYY-MM-DD". The function should use the `datetime` module to get the current date and format it accordingly. The code should start with:
```python
from datetime import datetime
def print_current_date():
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def print_current_date():
"""
Prints the current date in the "YYYY-MM-DD" format.
This function retrieves the current date using the `datetime` module and formats it
as "YYYY-MM-DD" before... |
magic_evol_110k | 81,386 | Write a Python function to reverse the elements of a given single-dimensional tuple and return the reversed tuple. The function should handle tuples of any length, including empty tuples.
The code should start with:
```python
from typing import Tuple
def reverse_tuple(input_tuple: Tuple) -> Tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def reverse_tuple(input_tuple: Tuple) -> Tuple:
"""
Reverses the elements of a given single-dimensional tuple and returns the reversed tuple.
Args:
input_tuple (Tuple): The tuple to be reve... |
magic_evol_110k | 81,388 | Write a Python function to iterate through a given list and return a new list containing the elements that satisfy a given condition. The condition should be a lambda function that takes an element as input and returns a boolean value. The function should start with:
```python
from typing import List, Callable
def fil... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable
def filter_list(elements: List[any], condition: Callable[[any], bool]) -> List[any]:
"""
Filters the elements of a list based on a given condition.
Args:
elements (List[any]): The ... |
magic_evol_110k | 81,389 | Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should start with:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
"""
Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid.
Args:
m (int): The number of row... |
magic_evol_110k | 81,394 | Write a Python function to check if a given string is a palindrome and ensure that the string contains only uppercase letters. If the string contains any lowercase letters, the function should raise a `ValueError`. The function should return `True` if the string is a palindrome and `False` otherwise.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_palindrome(text: str) -> bool:
"""
Checks if the given string is a palindrome and contains only uppercase letters.
Args:
text (str): The string to be checked.
Returns:
bool: True if the string is... |
magic_evol_110k | 81,401 | Write a Python function to identify and return the smallest prime number from a given list of integers. The function should handle any list of integers, not just the specific list provided in the example. The function should start with:
```python
from typing import List
def find_smallest_prime(numbers: List[int]) -> i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Check if a given number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise... |
magic_evol_110k | 81,405 | Write a Python function to compare two phrases based on the order of their words, ignoring case and non-alphanumeric characters. The function should return `True` if the two phrases have the same words in the same order, otherwise `False`.
The code should start with:
```python
import re
def compare_word_sets_order(ph... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def compare_word_sets_order(phrase1: str, phrase2: str) -> bool:
"""
Compares two phrases based on the order of their words, ignoring case and non-alphanumeric characters.
Args:
phrase1 (str): The first p... |
magic_evol_110k | 81,437 | Write a Python function to transform a given list of string type entities into an equivalent list of elements of the integral numeric type. The function should handle lists of varying lengths and ensure that each string element can be converted to an integer. If any element cannot be converted to an integer, the functi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_string_list_to_int_list(string_list: List[str]) -> List[int]:
"""
Converts a list of string type entities into an equivalent list of integral numeric type.
Args:
string_list (Lis... |
magic_evol_110k | 81,441 | Write a Python function to convert a hexadecimal number, represented as a string, into its equivalent binary representation. The function should ensure that the binary string is padded with leading zeros to maintain the same number of bits as the hexadecimal representation.
The code should start with:
```python
def he... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_binary(hex_value: str) -> str:
"""
Converts a hexadecimal number, represented as a string, into its equivalent binary representation.
Args:
hex_value (str): The hexadecimal number to be converted.
Re... |
magic_evol_110k | 81,445 | Write a Python function to count and print the number of words in a given sentence. The function should handle sentences with multiple spaces between words and sentences that start or end with spaces. The code should start with:
```python
def count_words(sentence: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_words(sentence: str) -> int:
"""
Counts the number of words in a given sentence.
Args:
sentence (str): The sentence to count words in.
Returns:
int: The number of words in the sentence.
""... |
magic_evol_110k | 81,449 | Write a Python function to generate all unique permutations of a given string and return them in alphabetical order. The function should handle strings containing letters, numbers, and special characters. The code should start with:
```python
from typing import List
def generate_unique_permutations(s: str) -> List[str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from itertools import permutations
def generate_unique_permutations(s: str) -> List[str]:
"""
Generate all unique permutations of a given string and return them in alphabetical order.
Args:
... |
magic_evol_110k | 81,457 | Write a Python function to find the length of the longest common subsequence (LCS) between two given strings `s` and `t`. The LCS is defined as the longest sequence of characters that appear in the same order in both strings, but not necessarily consecutively.
The code should start with:
```python
def longest_common_s... | Here is the Python code to solve the given problem in the markdown block:
```python
def longest_common_subsequence(s: str, t: str) -> int:
"""
Calculate the length of the longest common subsequence between two strings s and t.
Args:
s (str): The first string.
t (str): The second string.
... |
magic_evol_110k | 81,469 | Write a Python function to compute the sum of all elements in a given list of integers using a recursive method. The function should not modify the given list during the computation and should use a helper function if necessary. The code should start with:
```python
from typing import List
def recursive_sum(arr: List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def recursive_sum(arr: List[int]) -> int:
"""
Compute the sum of all elements in a given list of integers using a recursive method.
Args:
arr (List[int]): The list of integers to sum.
R... |
magic_evol_110k | 81,487 | Write a Python function to generate a list of multiples of a given number within a specified range. The function should take two arguments: the number to be multiplied and the upper limit of the range (inclusive). The function should return a list of multiples of the given number from 1 up to the specified upper limit.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_multiples(number: int, upper_limit: int) -> List[int]:
"""
Generate a list of multiples of a given number within a specified range.
This function takes a number and an upper limit, and ... |
magic_evol_110k | 81,500 | 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]:
"""
Merge two sorted arrays of integers into a single sorted array.
Args:
arr1 (List[int]): The first sorted array.
... |
magic_evol_110k | 81,501 | Write a Python function to calculate the modulus of two numbers, ensuring that the function handles edge cases such as division by zero and negative numbers. The function should return the modulus as a positive integer if the divisor is positive, and handle the case where the divisor is zero by returning a specific err... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_modulus(num1: int, num2: int) -> int:
"""
Calculate the modulus of two numbers, ensuring the result is a positive integer if the divisor is positive.
If the divisor is zero, return an error message.
Args:
... |
magic_evol_110k | 81,503 | Write a Python function to generate a set of test data based on a specified data model. The data model is defined as follows:
```python
{
"users": [
{
"id": INTEGER,
"name": STRING,
"age": INTEGER
}
]
}
```
The function should generate a list of dictionaries, where each dictionary repres... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
import random
import string
def generate_test_data(num_users: int) -> List[Dict[str, int | str]]:
"""
Generate a set of test data based on the specified data model.
Args:
num_users (in... |
magic_evol_110k | 81,513 | Write a Python function to calculate the maximum sum of a subarray of a given list of integers. The subarray must be contiguous, and the function should return the maximum sum. The function should handle negative numbers and empty subarrays by returning 0.
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 max_subarray_sum(arr: List[int]) -> int:
"""
Calculate the maximum sum of a contiguous subarray of the given list of integers.
Args:
arr (List[int]): The list of integers from which to f... |
magic_evol_110k | 81,514 | Write a Python function to convert a given number of teaspoons to tablespoons using a specified conversion ratio. The function should handle both integer and floating-point inputs for the number of teaspoons and the conversion ratio. The code should start with:
```python
def teaspoons_to_tablespoons(teaspoons: float, c... | Here is the Python code to solve the given problem in the markdown block:
```python
def teaspoons_to_tablespoons(teaspoons: float, conversion_ratio: float) -> float:
"""
Convert a given number of teaspoons to tablespoons using a specified conversion ratio.
Args:
teaspoons (float): The number of tea... |
magic_evol_110k | 81,525 | Write a Python function to determine if two given strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should be case-insensitive and should ignore spaces.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(str1: str, str2: str) -> bool:
"""
Determines if two given strings are anagrams of each other.
Args:
str1 (str): The first string to compare.
str2 (str): The second string to compare.
R... |
magic_evol_110k | 81,536 | Write a Python function to generate a list of prime numbers within a specified range [start, end]. The function should efficiently determine if a number is prime and return a list of all prime numbers within the given range.
The code should start with:
```python
from typing import List
def generate_prime_numbers(star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
if n <... |
magic_evol_110k | 81,555 | Write a Python function to calculate the sum of elements in a given list using a "for loop". The function should correctly iterate through the list and accumulate the sum of its elements. The code should start with:
```python
from typing import List
def sum_array(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_array(arr: List[int]) -> int:
"""
Calculate the sum of all elements in the given list.
Args:
arr (List[int]): The list of integers to sum.
Returns:
int: The sum of all e... |
magic_evol_110k | 81,568 | Write a Python function to check if a given tuple contains any `None` values and return the indices of these `None` values. The function should be able to handle nested tuples, meaning tuples within tuples. The function should start with:
```python
from typing import Tuple, List
def find_none_indices(input_tuple: Tupl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, List
def find_none_indices(input_tuple: Tuple, indices: Tuple = ()) -> List[Tuple]:
"""
Finds and returns the indices of all `None` values in a given nested tuple.
Args:
input_tuple (Tuple... |
magic_evol_110k | 81,578 | Write a Python function to find the sum of all prime numbers within a given range `[start, end]`. Additionally, implement an efficient algorithm to determine if a number is prime. The prime-checking algorithm should have a time complexity of O(sqrt(n)) and a space complexity of O(1).
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise.
"""
if n... |
magic_evol_110k | 81,581 | Write a Python function to convert a binary string to its octal equivalent without using built-in or imported functions. The function should handle leading zeros and invalid binary strings by raising a `ValueError`. The function should start with:
```python
def binary_to_octal(binary_str: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_octal(binary_str: str) -> str:
"""
Converts a binary string to its octal equivalent without using built-in or imported functions.
Args:
binary_str (str): The binary string to be converted.
Returns... |
magic_evol_110k | 81,582 | Write a Python function to compute the cumulative sum of all integer values contained within a multi-tiered dictionary. The dictionary may include nested dictionaries, lists, and integer values. The function should be able to handle any unforeseen anomalies or inconsistencies within the data structures and should be ro... | Here is the Python code to solve the given problem in the markdown block:
```python
def cumulative_sum_of_dict(data: dict) -> int:
"""
Compute the cumulative sum of all integer values contained within a multi-tiered dictionary.
Args:
data (dict): A multi-tiered dictionary that may contain nested di... |
magic_evol_110k | 81,583 | Write a Python function to calculate and print Fibonacci numbers up to a specified limit using a multithreaded approach. The function should handle possible overflow errors and ensure that the input is a valid positive integer. If the user enters a negative number or a non-integer, the function should prompt the user t... | Here is the Python code to solve the given problem in the markdown block:
```python
import threading
import sys
def fibonacci_multithreaded(limit: int):
"""
Calculate and print Fibonacci numbers up to a specified limit using a multithreaded approach.
Args:
limit (int): The upper limit for the Fibo... |
magic_evol_110k | 81,597 | Write a Python function to process a space-separated string and return a dictionary containing the words and their lengths. If there are words with equal length, all must be included. The function should involve multistep reasoning, not just straightforward operations. For instance: `word_length("I love programming")` ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def word_length(text: str) -> Dict[str, int]:
"""
Processes a space-separated string and returns a dictionary containing the words and their lengths.
Args:
text (str): The input string conta... |
magic_evol_110k | 81,614 | Write a Python function to perform a decuple multiplication operation on each unique integer within a given numerical array. The function should return a new list containing the results of the multiplication, while ensuring that the original array retains its original state. The function should start with:
```python
fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def decuple_multiplication(lst: List[int]) -> List[int]:
"""
Performs a decuple multiplication operation on each unique integer within the given numerical array.
Args:
lst (List[int]): The i... |
magic_evol_110k | 81,617 | Write a Python function `get_positive_and_sort` that returns only the positive numbers from a given list, sorted in ascending order. Implement a custom sorting algorithm in a separate helper function called `swap_elements`. The provided code has errors and an incomplete helper function; it's your task to identify and f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_positive_and_sort(l: List[int]) -> List[int]:
"""
Return only positive numbers in the list, sorted in ascending order.
Args:
l (List[int]): The input list of integers.
Returns:
... |
magic_evol_110k | 81,625 | Write a Python function to group the elements of a list of integers into even and odd groups. The function should return a tuple containing two lists: the first list should contain all even numbers, and the second list should contain all odd numbers. The code should start with:
```python
from typing import List, Tuple
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def group_even_odd(lst: List[int]) -> Tuple[List[int], List[int]]:
"""
Groups the elements of a list of integers into even and odd groups.
Args:
lst (List[int]): The list of integers ... |
magic_evol_110k | 81,635 | Write a Python function to construct a dictionary from a list of tuples, where each tuple contains a key-value pair. The function should handle cases where the list might be empty or contain duplicate keys. If a duplicate key is found, the function should update the value for that key to the value from the last occurre... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def construct_dictionary(pairs: List[Tuple[str, int]]) -> Dict[str, int]:
"""
Constructs a dictionary from a list of tuples, where each tuple contains a key-value pair.
If a key appears ... |
magic_evol_110k | 81,646 | Write a Python function to validate and filter a tuple composed of various components, ensuring that each component is an instance of a string data type. The function should return a new tuple containing only the string components from the original tuple.
The code should start with:
```python
from typing import Tuple,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Any
def filter_string_components(tup: Tuple[Any, ...]) -> Tuple[str, ...]:
"""
Filters a tuple to include only components that are instances of the string data type.
Args:
tup (Tuple[Any, ... |
magic_evol_110k | 81,651 | Write a Python function to generate a unique sequence of 24 characters containing only the letters 'x', 'y', 'z', and 'w'. The sequence should not contain any consecutive repeated sequences of 3 characters or more. For instance, 'xxx', 'yyy', 'zzz', 'www', 'xyx', 'xzx', 'yzy', and so on should not appear in the sequenc... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_unique_sequence(length: int) -> str:
"""
Generates a unique sequence of the specified length containing only the letters 'x', 'y', 'z', and 'w'.
The sequence does not conta... |
magic_evol_110k | 81,655 | Write a Python function to sort an array of integers in ascending order using the Insertion Sort algorithm and then perform a binary search to determine if a specified integer is present in the sorted array. The sorting function should not use any built-in sorting methods. The binary search function should be implement... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def insertion_sort(arr: List[int]) -> List[int]:
"""
Sort the array in ascending order using Insertion Sort.
Args:
arr: Unsorted array of integers.
Returns:
Sorted array... |
magic_evol_110k | 81,680 | Write a Python function to translate a given ASCII string into a hexadecimal string and then encode this hexadecimal string into a binary string without using any built-in binary conversion functions. The function should start with:
```python
def ascii_to_binary(ascii_str: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def ascii_to_binary(ascii_str: str) -> str:
"""
Translates a given ASCII string into a hexadecimal string and then encodes this hexadecimal string into a binary string.
Args:
ascii_str (str): The ASCII string to be ... |
magic_evol_110k | 81,689 | Write a Python function to process a given string by removing all special characters except for punctuation marks (.,!?') and replacing all blank spaces with underscores. The function should return the processed string and a tuple containing the counts of replacements and special character removals.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def process_string(s: str) -> tuple:
"""
Processes a given string by removing all special characters except for punctuation marks (.,!?')
and replacing all blank spaces with underscores. Returns the processed stri... |
magic_evol_110k | 81,691 | Write a Python function to generate the first `n` numbers in the Fibonacci sequence using a list comprehension. The Fibonacci sequence starts with 0 and 1, where 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 wi... | 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 using a list comprehension.
Args:
n (int): The number of Fibonacci numbers to generate... |
magic_evol_110k | 81,697 | Write a Python function to convert a given hexadecimal string representation of a capital English alphabet character into its corresponding ASCII character. The function should handle only valid hexadecimal strings that represent capital English alphabet characters.
The code should start with:
```python
def hex_to_asc... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_ascii(hex_str: str) -> str:
"""
Converts a given hexadecimal string representation of a capital English alphabet character into its corresponding ASCII character.
Args:
hex_str (str): A string representin... |
magic_evol_110k | 81,700 | Write a Python function to modify a given string according to the following rules:
1. Replace all instances of one or more consecutive spaces with a single underscore (`_`).
2. Replace any occurrence of two or more consecutive underscores with a hyphen (`-`).
3. Convert all words within the string to their uppercase fo... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def sophisticated_text_modification(input_text: str) -> str:
"""
Modify the given string according to the following rules:
1. Replace all instances of one or more consecutive spaces with a single underscore.
2... |
magic_evol_110k | 81,701 | Write a Python function that takes two alphanumeric strings as arguments. The function should identify numeric characters within each string, sum the corresponding numbers together, and return the sum as a string. If non-numeric characters are encountered in the strings, they should be excluded from the calculation. Ad... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_numeric_strings(string1: str, string2: str) -> str:
"""
Sum the numeric characters from two alphanumeric strings and return the sum as a string.
Args:
string1 (str): The first alphanumeric string.
st... |
magic_evol_110k | 81,702 | Write a Python function to identify even integers within a numerical array, handle exceptions for non-numerical inputs, and return a tuple containing a list of even integers sorted in descending order and the sum of all even integers. The function should start with:
```python
from typing import List, Tuple
def find_ev... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_even_numbers(input_list: List[int]) -> Tuple[List[int], int]:
"""
Identifies even integers within a numerical array, handles non-numerical inputs,
and returns a tuple containing a lis... |
magic_evol_110k | 81,717 | Write a Python function to calculate the minimum number of leaps of a specified length needed to reach or exceed a coordinate of the form `(d, 0)` from the origin in a Cartesian plane. The function should handle cases where the leap length does not evenly divide the distance `d`. The code should start with:
```python
i... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def min_leaps_to_coordinate(d: int, leap_length: int) -> int:
"""
Calculate the minimum number of leaps of a specified length needed to reach or exceed a coordinate (d, 0) from the origin.
Args:
d (int)... |
magic_evol_110k | 81,718 | Write a Python function to convert a range of decimal numbers to their ternary (base-3) representation and store the results in a dictionary. The keys of the dictionary should be the original decimal numbers, and the values should be their corresponding ternary representations. The function should handle the conversion... | Here is the Python code to solve the given problem in the markdown block:
```python
def decimal_to_ternary_range(start: int, end: int) -> dict:
"""
Converts a range of decimal numbers to their ternary (base-3) representation and stores the results in a dictionary.
Args:
start (int): The starting de... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.