source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 85,765 | Write a Python function to calculate the sum of cubes of only the odd and positive integers within a given list, disregarding negative or non-integer values. If the input list is empty, the function should return 0. The function should be named `positive_odd_cubes_sum` and should start with:
```python
from typing impor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def positive_odd_cubes_sum(lst: List[int]) -> int:
"""
Calculate the sum of cubes of only the odd and positive integers within the given list.
Args:
lst (List[int]): The list of integers to ... |
magic_evol_110k | 85,780 | Write a Python function to sort an array of numerical values in ascending order, with a specific emphasis on sorting fractions before integers in case of a tie. The array may include negative numbers and fractions. The function should start with:
```python
from typing import List
def sort_array_with_fractions(arr: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_array_with_fractions(arr: List[float]) -> List[float]:
"""
Sorts an array of numerical values in ascending order, with fractions sorted before integers in case of a tie.
Args:
arr (... |
magic_evol_110k | 85,783 | Write a Python function to check if a given number is within a specified range. The function should return a boolean value indicating whether the number is within the range (inclusive). The code should start with:
```python
def is_number_in_range(number: int, lower_bound: int, upper_bound: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_number_in_range(number: int, lower_bound: int, upper_bound: int) -> bool:
"""
Check if a given number is within a specified range (inclusive).
Args:
number (int): The number to check.
lower_bound (int... |
magic_evol_110k | 85,796 | Write a Python function to count the frequency of each unique character in a given text string. The function should return a dictionary where the keys are the characters and the values are the counts of those characters in the string. The function should handle any string input, including empty strings.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_character_frequencies(text: str) -> Dict[str, int]:
"""
Counts the frequency of each unique character in the given text string.
Args:
text (str): The input string for which charact... |
magic_evol_110k | 85,804 | Write a Python function that takes a list of random integers, which can include duplicates, and returns two outputs:
1. A list of unique numbers sorted in descending order.
2. A dictionary mapping each unique number to its frequency in the original list.
The function should not use Python's built-in sorting functions ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def unique_and_frequency(nums: List[int]) -> (List[int], Dict[int, int]):
"""
Returns a list of unique numbers sorted in descending order and a dictionary mapping each unique number to its frequenc... |
magic_evol_110k | 85,808 | Create a Python function to validate an email address based on the given JavaScript validation logic. The function should check if the email address contains exactly one "@" symbol, and the "@" symbol should be followed by at least one character before a dot (".") and at least two characters after the dot. The function... | Here is the Python code to solve the given problem in the markdown block:
```python
def validate_email(email: str) -> bool:
"""
Validates an email address based on the following criteria:
- The email must contain exactly one "@" symbol.
- The "@" symbol should be followed by at least one character befor... |
magic_evol_110k | 85,812 | Write a Python function to sort a list of n distinct integers using the insertion sort algorithm. The function should return the sorted list. The code should start with:
```python
from typing import List
def insertion_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 insertion_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of n distinct integers using the insertion sort algorithm.
Args:
arr (List[int]): The list of n distinct integers to be sort... |
magic_evol_110k | 85,813 | Write a Python function to sort a list of dictionaries in ascending order based on the values associated with a specified key. The function should handle cases where the key might not exist in some dictionaries and should return the sorted list. If a dictionary does not contain the specified key, it should be placed at... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def sort_dicts_by_key(lst: List[Dict[str, int]], key: str) -> List[Dict[str, int]]:
"""
Sorts a list of dictionaries in ascending order based on the values associated with a specified key.
If a... |
magic_evol_110k | 85,847 | Write a Python function to find the smallest repeating unit of a given string. The function should return the smallest substring that, when repeated, forms the original string. If no such repeating unit exists, the function should return the original string.
The code should start with:
```python
def find_smallest_repe... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_smallest_repeating_unit(string: str) -> str:
"""
Finds the smallest repeating unit of a given string.
Args:
string (str): The input string to find the smallest repeating unit for.
Returns:
str:... |
magic_evol_110k | 85,850 | Write a Python function to update and retrieve the number of known moons for a given planet in a dictionary that stores the list of planets in our solar system and their number of known moons. The function should handle the case where the planet is not already in the dictionary by adding it with the provided number of ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def update_or_add_planet_moons(planets_with_moons: Dict[str, int], planet: str, moons: int) -> None:
"""
Updates the number of known moons for a given planet in the dictionary.
If the planet is not a... |
magic_evol_110k | 85,862 | Write a Python function `is_prime_and_largest_prime_factor(n)` that checks if a given integer `n` is a prime number and, if not, finds its largest prime factor. The function should return a tuple `(is_prime, largest_prime_factor)`, where `is_prime` is a boolean indicating whether `n` is prime, and `largest_prime_factor... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime_and_largest_prime_factor(n: int) -> tuple:
"""
Determine if a given integer `n` is a prime number and find its largest prime factor.
Args:
n (int): The integer to check for primality and find the larges... |
magic_evol_110k | 85,892 | Write a Python function to sort a mixed list of integers and strings in ascending order using an optimized bubble sort algorithm. The function should segregate the integers and strings into separate lists, sort each list individually, and then concatenate the sorted lists. The function should not use any built-in sort ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def optimized_bubble_sort(input_list: List[Union[int, str]]) -> List[Union[int, str]]:
"""
Sorts a mixed list of integers and strings in ascending order using an optimized bubble sort algorithm.
... |
magic_evol_110k | 85,902 | Write a Python function to sort a given list of integers using the bubble sort algorithm. The function should return the sorted list. The code should start with:
```python
from typing import List
def bubble_sort(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the bubble sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
Li... |
magic_evol_110k | 85,921 | Write a Python function to find the minimum integer in a given triplet of integers. The function should accept a tuple of three integers as input and return the smallest integer among them. The code should start with:
```python
from typing import Tuple
def find_minimum_in_triplet(triplet: Tuple[int, int, int]) -> int:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def find_minimum_in_triplet(triplet: Tuple[int, int, int]) -> int:
"""
Find the minimum integer in a given triplet of integers.
Args:
triplet (Tuple[int, int, int]): A tuple containing exac... |
magic_evol_110k | 85,936 | Write a Python function to recursively invert the sequence of elements within a provided numerical array. The function should ensure that it does not consume more than O(log N) extra space. The code should start with:
```python
from typing import List
def recursive_reverse(arr: List[int], start: int, end: int) -> None... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def recursive_reverse(arr: List[int], start: int, end: int) -> None:
"""
Recursively inverts the sequence of elements within a provided numerical array.
Args:
arr (List[int]): The array to b... |
magic_evol_110k | 85,937 | Write a Python function to identify the longest continuous segment in a given string that forms a palindrome consisting of repetitive characters (twin characters). If multiple palindromes of the same length exist, return all of them. The function should start with:
```python
from typing import List
def find_longest_tw... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def find_longest_twin_palindromes(text: str) -> List[str]:
"""
Finds the longest continuous segments in the given text that form palindromes of repetitive characters (twin characters).
If m... |
magic_evol_110k | 85,951 | Write a Python function to generate a dynamic matrix of increasing prime numbers beginning from 1 and of dimensions `m` by `n` with the additional restriction that no two adjacent cells can have the same value. The function should start with:
```python
from typing import List
def generate_prime_matrix(m: int, n: int) ... | 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 | 85,960 | Write a Python function to find the most frequently occurring word in a given string. The function should handle case sensitivity and punctuation. The code should start with:
```python
from typing import Optional
def most_frequent_word(sentence: str) -> Optional[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Optional
import string
def most_frequent_word(sentence: str) -> Optional[str]:
"""
Find the most frequently occurring word in a given string.
Args:
sentence (str): The input string from which to ... |
magic_evol_110k | 85,972 | Write a Python function to retrieve and print the values of a dictionary in ascending order of their keys. The dictionary contains strings as keys and values. The function should start with:
```python
from typing import Dict
def print_dict_values_sorted_by_keys(d: 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_values_sorted_by_keys(d: Dict[str, str]) -> None:
"""
Prints the values of a dictionary in ascending order of their keys.
Args:
d (Dict[str, str]): The dictionary containing s... |
magic_evol_110k | 85,991 | Write a Python function to calculate the total number of unique integers across multiple matrices. Each matrix is a 2D list of integers, and the function should return the count of unique integers present in all the matrices combined.
The code should start with:
```python
from typing import List
def count_unique_inte... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_unique_integers(matrices: List[List[List[int]]]) -> int:
"""
Calculate the total number of unique integers across multiple matrices.
Args:
matrices (List[List[List[int]]]): A list ... |
magic_evol_110k | 86,003 | Write a Python function to reverse the order of elements in a given array without using any in-built or third-party library functions for reversing. The function should create a new array with the elements in reverse order and return it. The code should start with:
```python
from typing import List
def reverse_array(i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_array(input_array: List[int]) -> List[int]:
"""
Reverses the order of elements in a given array without using any in-built or third-party library functions for reversing.
Args:
i... |
magic_evol_110k | 86,010 | Write a Python function to find the sum of the second smallest and second largest integers from a given list of integers. The function should handle lists with at least two elements and should be efficient.
The code should start with:
```python
from typing import List
def sum_of_second_smallest_and_largest(numbers: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_second_smallest_and_largest(numbers: List[int]) -> int:
"""
Calculate the sum of the second smallest and second largest integers from a given list of integers.
Args:
numbers (List... |
magic_evol_110k | 86,030 | Write a Python function to calculate the total distance between the deepest part of the Earth (the base of the Mariana Trench) and the highest part (the peak of Mount Everest) in a linear journey. The function should take the depths of the Mariana Trench and the height of Mount Everest as inputs and return the total di... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_total_distance(mariana_trench: int, mount_everest: int) -> int:
"""
Calculate the total distance between the deepest part of the Earth (the base of the Mariana Trench)
and the highest part (the peak of Mount Ev... |
magic_evol_110k | 86,040 | Write a Python function to generate a randomized matrix of a specified shape, populated with elements that fluctuate within given numerical bounds. The function should use a suitable Python library to ensure the randomness of each element. The code should start with:
```python
import numpy as np
def generate_random_ma... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def generate_random_matrix(low: float, high: float, shape: tuple) -> np.ndarray:
"""
Generates a randomized matrix of the specified shape with elements uniformly distributed between the given bounds.
Arg... |
magic_evol_110k | 86,053 | Write a Python function to calculate the net salary after tax deductions. The function should take the gross salary and the tax rate as inputs and return the net salary after applying the tax. The code should start with:
```python
def calculate_net_salary(gross_salary: float, tax_rate: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_net_salary(gross_salary: float, tax_rate: float) -> float:
"""
Calculate the net salary after applying the given tax rate to the gross salary.
Args:
gross_salary (float): The gross salary before tax de... |
magic_evol_110k | 86,058 | Write a Python function to find the minimum element in an unordered 2D array without using built-in Python functions like `min()` and sorting algorithms like `quickSort` or `mergeSort`. The function should iterate through the array to find the smallest element.
The code should start with:
```python
from typing import ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_minimum_element(arr: List[List[int]]) -> int:
"""
Find the minimum element in an unordered 2D array.
Args:
arr (List[List[int]]): The 2D array in which to find the minimum element.
... |
magic_evol_110k | 86,066 | Write a Python function to calculate the number of unique combinations for a given set without repetition, considering subsets with a minimum of 2 elements. The function should return the count of such combinations.
The code should start with:
```python
from typing import Set
def count_unique_combinations(my_set: Set... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
import itertools
def count_unique_combinations(my_set: Set[int]) -> int:
"""
Calculate the number of unique combinations for the given set without repetition,
considering subsets with a minimum of 2 e... |
magic_evol_110k | 86,088 | Write a Python function to extract the integral part of a given positive real number and return it only if it is a prime number. If the integral part is not a prime number, the function should return `None`.
The code should start with:
```python
def extract_prime_integer(number: float) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def extract_prime_integer(number: float) -> int:
"""
Extracts the integral part of a given positive real number and returns it if it is a prime number.
If the integral part is not a prime number, returns None.
Args:
... |
magic_evol_110k | 86,094 | Write a Python function to implement the Merge Sort algorithm, which is known for its O(n log n) time complexity in both average and worst cases. The function should take a list of integers as input and return the sorted list. The code should start with:
```python
from typing import List
def merge_sort(arr: List[int])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the Merge Sort algorithm.
Merge Sort is a divide-and-conquer algorithm that works by recursively
dividing the inpu... |
magic_evol_110k | 86,110 | Write a Python function to determine the number of T-shirts sold given the total amount raised and the price per T-shirt. Additionally, the function should identify which of the given four numbers (632, 643, 655, or 668) is closest to the calculated number of T-shirts sold.
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 calculate_tshirts_sold(total_amount: int, price_per_shirt: int, possible_numbers: List[int]) -> (int, int):
"""
Calculate the number of T-shirts sold given the total amount raised and the price per T... |
magic_evol_110k | 86,154 | Write a Python function to compute the minimum element within a given array without using any built-in functions or libraries for calculating the minimum value. The function should iterate through the array and determine the smallest element by comparing each element with a variable that holds the current minimum value... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_min_element(array: List[int]) -> int:
"""
Computes the minimum element within a given array without using built-in functions or libraries.
Args:
array (List[int]): The array of inte... |
magic_evol_110k | 86,155 | Write a Python function to validate if a given string consists solely of uppercase English alphabets and numerical digits. The function should return `True` if the string matches the criteria, and `False` otherwise. The code should start with:
```python
import re
def is_valid_string(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_string(s: str) -> bool:
"""
Validates if the given string consists solely of uppercase English alphabets and numerical digits.
Args:
s (str): The string to be validated.
Returns:
... |
magic_evol_110k | 86,157 | Write a Python function to recursively transform a nested list of integers by appending '5' to each integer, converting it to a string. The function should handle lists nested at any level and should not modify the original list. The code should start with:
```python
from typing import List, Union
def append_five_to_i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def append_five_to_integers(lst: List[Union[int, str, List]]) -> List[Union[int, str, List]]:
"""
Recursively transforms a nested list of integers by appending '5' to each integer and converting i... |
magic_evol_110k | 86,164 | Write a Python function to recursively determine the minimum value in an array of integers. The array may contain both positive and negative numbers, as well as zero, and its length may vary. You should not use any built-in functions to determine the minimum number. The function should start with:
```python
from typing... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_minimum_recursive(arr: List[int], index: int = 0, min_num: int = None) -> int:
"""
Recursively determines the minimum value in an array of integers.
Args:
arr (List[int]): The array... |
magic_evol_110k | 86,178 | Write a Python function to convert a hexadecimal string to its corresponding binary representation. The function should handle hexadecimal strings of any length and return the binary string without the '0b' prefix that Python's `bin()` function adds.
The code should start with:
```python
def hex_to_binary(hex_string: ... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_binary(hex_string: str) -> str:
"""
Converts a hexadecimal string to its corresponding binary representation.
Args:
hex_string (str): The hexadecimal string to convert.
Returns:
str: The bina... |
magic_evol_110k | 86,185 | Write a Python function to predict the future processing speed of a computer after a given number of years, assuming that the processing speed doubles every two years. The function should take the initial processing speed and the number of years as inputs and return the predicted processing speed.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
def predict_future_speed(initial_speed: float, years: int) -> float:
"""
Predicts the future processing speed of a computer after a given number of years,
assuming that the processing speed doubles every two years.
Args... |
magic_evol_110k | 86,190 | Write a Python function to create a new list of 10 elements by randomly selecting elements from a given list of integers. The function should ensure that the new list contains exactly 10 elements, and each element in the new list should be randomly chosen from the given list. The function should handle cases where the ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def create_random_assembly(numeral_list: List[int]) -> List[int]:
"""
Creates a new list of 10 elements by randomly selecting elements from the given list.
Args:
numeral_list (... |
magic_evol_110k | 86,208 | Write a Python function to calculate the sum of all integers in a given list. The function should handle lists of varying lengths, including empty lists. The code should start with:
```python
from typing import List
def sum_of_list(input_list: 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_list(input_list: List[int]) -> int:
"""
Calculate the sum of all integers in the given list.
Args:
input_list (List[int]): A list of integers to be summed.
Returns:
i... |
magic_evol_110k | 86,209 | Write a Python function to search for a target element in a sorted and rotated array in less than O(log n) time complexity. The array is sorted in ascending order and then rotated at some pivot unknown to you beforehand. The function should also handle duplicate entries in the array. The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def search_in_rotated_sorted_array(nums: List[int], target: int) -> bool:
"""
Searches for a target element in a sorted and rotated array with possible duplicates.
Args:
nums (List[int]): Th... |
magic_evol_110k | 86,210 | Write a Python function to generate and yield the first N numbers from the Fibonacci sequence dynamically. The function should yield each number one by one instead of returning a list of all numbers at once. The code should start with:
```python
def generate_fibonacci(n: int):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def generate_fibonacci(n: int):
"""
Generates and yields the first N numbers from the Fibonacci sequence dynamically.
Args:
n (int): The number of Fibonacci numbers to generate.
Yields:
int: The next nu... |
magic_evol_110k | 86,216 | Write a Python function to calculate the edit distance (also known as Levenshtein distance) between two strings. The edit distance is the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other. The function should be efficient and use dynamic prog... | Here is the Python code to solve the given problem in the markdown block:
```python
def edit_distance(str1: str, str2: str) -> int:
"""
Calculate the edit distance (Levenshtein distance) between two strings.
Args:
str1 (str): The first string.
str2 (str): The second string.
Returns:
... |
magic_evol_110k | 86,220 | Write a Python function to convert a hexadecimal string to a binary string and a binary string to a hexadecimal string. The function should handle input validation and raise a `ValueError` if the input is not a valid hexadecimal or binary string, respectively.
The code should start with:
```python
def hex_to_binary(y:... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_binary(y: str) -> str:
"""
Convert a hexadecimal string to a binary string.
Args:
y (str): The hexadecimal string to convert.
Returns:
str: The binary string representation of the hexadecimal... |
magic_evol_110k | 86,222 | Write a Python function to sort a list of integers and decimals in a peculiar order using a heap sort. The peculiar order should start with the smallest value, then the largest value, then the smallest of the remaining values not yet included in the output, and repeat this process until all elements are sorted. The fun... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import heapq
def strange_sort_list_heap(lst: List[float]) -> List[float]:
"""
Sorts a list of integers and decimals in a peculiar order using a heap sort.
The peculiar order starts with the smallest ... |
magic_evol_110k | 86,223 | Write a Python function to generate a list of all prime numbers within a given range `[start, end]`. The function should efficiently determine if a number is prime and then collect all prime numbers within the specified range.
The code should start with:
```python
from typing import List
def generate_primes_in_range(... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(num: int) -> bool:
"""
Check if a given number is prime.
Args:
num (int): The number to check for primality.
Returns:
bool: True if the number is prime, False other... |
magic_evol_110k | 86,225 | Write a Python function to simulate a simple message queue system. The function should allow creating a queue, adding messages to the queue, reading messages from the queue, and destroying the queue. The queue should be implemented using a list to store messages. The function should handle multiple queues identified by... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
# Dictionary to store queues
queues = {}
def create_queue(queue_name: str) -> None:
"""
Create a new message queue with the given name.
Args:
queue_name (str): The name of the que... |
magic_evol_110k | 86,228 | Write a Python function to convert a given string into its corresponding binary representation. Each character in the string should be converted to its 8-bit binary equivalent. The function should return a single string containing the concatenated binary representations of all characters in the input string.
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
def text_to_binary(text: str) -> str:
"""
Converts a given string into its corresponding binary representation.
Each character in the input string is converted to its 8-bit binary equivalent,
and the binary strings are ... |
magic_evol_110k | 86,231 | Write a Python function to safely perform arithmetic operations on two integers, ensuring that no division by zero occurs. The function should return the result of the operations or a specific message if a division by zero is attempted. The operations to be performed are addition, subtraction, multiplication, and divis... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_arithmetic_operations(a: int, b: int) -> dict:
"""
Safely performs addition, subtraction, multiplication, and division on two integers.
If a division by zero is attempted, it returns a specific message indicating th... |
magic_evol_110k | 86,241 | Write a Python function to determine whether each number in a given list is even or odd. The function should return a dictionary where the keys are the numbers from the list and the values are strings indicating whether the number is 'Even' or 'Odd'.
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 classify_numbers(numbers: List[int]) -> Dict[int, str]:
"""
Classify each number in the given list as 'Even' or 'Odd'.
Args:
numbers (List[int]): A list of integers to be classifie... |
magic_evol_110k | 86,251 | Write a Python function to find and return the second smallest element in a given list of integers. If the list has fewer than two elements, the function should return `None`. The function should handle duplicate values by considering only unique values.
The code should start with:
```python
from typing import List, O... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_second_smallest(nums: List[int]) -> Optional[int]:
"""
Finds and returns the second smallest element in a given list of integers.
Args:
nums (List[int]): The list of integ... |
magic_evol_110k | 86,261 | Write a Python function to sort a list of complex numbers in descending order based on their real parts. If the real parts are equal, the numbers should be ordered by their imaginary parts in descending order. The function should start with:
```python
from typing import List
def sort_complex_numbers(numbers: List[comp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_complex_numbers(numbers: List[complex]) -> List[complex]:
"""
Sorts a list of complex numbers in descending order based on their real parts.
If the real parts are equal, the numbers are orde... |
magic_evol_110k | 86,278 | Write a Python function to determine if two given alphanumeric sequences 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 and... | 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 alphanumeric sequences are anagrams of each other.
Args:
str1 (str): The first alphanumeric sequence.
str2 (str): The second alphan... |
magic_evol_110k | 86,289 | Write a Python function to sort a given list of integers in descending order using the Bubble Sort algorithm. The function should not use any built-in sorting functions. The code should start with:
```python
from typing import List
def bubble_sort_descending(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort_descending(arr: List[int]) -> List[int]:
"""
Sorts a list of integers in descending order using the Bubble Sort algorithm.
Args:
arr (List[int]): The list of integers to be s... |
magic_evol_110k | 86,294 | Write a Python function to find the smallest whole number that cannot be expressed as the sum of any two prime numbers. The function should use a helper function to check if a number is prime and another helper function to check if a number can be expressed as the sum of two primes. The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
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 <= 1:
... |
magic_evol_110k | 86,308 | Write a Python function to flatten a given multidimensional array (up to three tiers) into a single list of its elements. The function should iterate through each tier of the array and collect all individual items into a single list. The code should start with:
```python
from typing import List, Any
def flatten_multid... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def flatten_multidimensional_array(arr: List[List[List[Any]]]) -> List[Any]:
"""
Flattens a given multidimensional array (up to three tiers) into a single list of its elements.
Args:
ar... |
magic_evol_110k | 86,318 | Write a Python function to filter out strings containing either the phrase "regardless of" or "in spite of" from a list of strings. The function should correctly handle upper and lower case variations of these phrases. To increase complexity, use character comparison instead of Python's inbuilt string methods. Addition... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_strings(lst: List[str]) -> List[str]:
"""
Filters out strings containing either the phrase "regardless of" or "in spite of" from a list of strings.
The function handles upper and lower cas... |
magic_evol_110k | 86,320 | Write a Python function to filter and return a list of unique prime numbers from a given array of integers, sorted in ascending order. The function should handle non-integer inputs by raising a `ValueError`. The code should start with:
```python
from typing import List
def get_unique_prime_numbers(array: List[int]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_int(num: int) -> bool:
"""
Check if the given number is an integer.
Args:
num (int): The number to check.
Returns:
bool: True if the number is an integer, False otherwise... |
magic_evol_110k | 86,331 | 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.
... |
magic_evol_110k | 86,356 | Write a Python function to sort a collection of floating-point values in ascending order while handling duplicates and null values appropriately. The function should return a list where null values are placed at the end of the sorted list.
The code should start with:
```python
from typing import List, Optional
def so... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def sort_floats_with_nulls(nums: List[Optional[float]]) -> List[Optional[float]]:
"""
Sorts a collection of floating-point values in ascending order while handling duplicates and null values.
... |
magic_evol_110k | 86,371 | Write a Python function to identify and return the second smallest numerical value within a provided list. The list may contain integers, floating point numbers, and strings. The function should handle these different data types and return the second smallest numerical value. If the list does not contain at least two n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def is_number(value: Union[int, float, str]) -> bool:
"""
Helper function to check if a value is a number (int or float).
Args:
value: The value to check.
Returns:
bool: ... |
magic_evol_110k | 86,377 | 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(inp... | 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:
... |
magic_evol_110k | 86,387 | Write a Python function to calculate the final price after applying a random discount percentage between 10 and 20 percent to an initial total price. The function should generate the discount percentage randomly each time it is called. The initial total price is set to 100. The function should return the final price af... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def calculate_final_price() -> float:
"""
Calculate the final price after applying a random discount percentage between 10 and 20 percent to an initial total price of 100.
Returns:
float: The final pr... |
magic_evol_110k | 86,409 | Write a Python function that accepts a list of integer tuples and a separate tuple as input. The function should return a list of tuples sorted by the second element of each tuple in descending order, but also remove any tuple that matches exactly with the given separate tuple.
The code should start with:
```python
fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_and_remove_tuples(tuples_list: List[Tuple[int, int]], remove_tuple: Tuple[int, int]) -> List[Tuple[int, int]]:
"""
Sorts a list of integer tuples by the second element in descending order... |
magic_evol_110k | 86,416 | Write a Python function to create a dictionary where the keys are elements from a given tuple and the values are the counts of their prime factors. Implement a custom function to count the prime factors of a number rather than using a library function. The code should start with:
```python
from typing import Dict, Tupl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def prime_factor_count(n: int) -> int:
"""
Counts the number of prime factors of a given integer n.
Args:
n (int): The integer for which to count the prime factors.
Returns:
... |
magic_evol_110k | 86,440 | Write a Python function to perform a ternary search on a sorted array to find the index of a given element. The ternary search algorithm should divide the array into three parts and recursively search for the element in the appropriate segment. If the element is not found, the function should return -1.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def ternary_search(arr: List[int], l: int, r: int, x: int) -> int:
"""
Perform a ternary search on a sorted array to find the index of a given element.
Args:
arr (List[int]): The sorted arra... |
magic_evol_110k | 86,441 | Write a Python function to find all prime numbers within a given range `[start, end]`. The function should return a list of all prime numbers in this range. The function should be efficient and handle edge cases such as negative numbers, zero, and one.
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
import math
def is_prime(num: int) -> bool:
"""
Check if a number is prime.
Args:
num (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
... |
magic_evol_110k | 86,449 | Write a Python function to compute the factorial of a given non-negative integer `n` using a while loop. The factorial of a number `n` (denoted as `n!`) is the product of all positive integers less than or equal to `n`. The function should start with:
```python
def compute_factorial(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def compute_factorial(n: int) -> int:
"""
Compute the factorial of a given non-negative integer n using a while loop.
Args:
n (int): The non-negative integer for which to compute the factorial.
Returns:
... |
magic_evol_110k | 86,451 | Write a Python function to sort a list of prime numbers in monotonically decreasing order. The function should take a list of integers as input and return a new list with the same integers sorted in descending order. The original list should not be modified.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_primes_descending(primes: List[int]) -> List[int]:
"""
Sorts a list of prime numbers in monotonically decreasing order.
Args:
primes (List[int]): A list of prime numbers.
Retur... |
magic_evol_110k | 86,455 | Write a Python function to calculate the squares of numbers within a given range [start, end]. The function should return a dictionary where the keys are the numbers in the range and the values are their corresponding squares. The function should handle cases where the range is invalid (e.g., `start` is greater than `e... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def calculate_squares(start: int, end: int) -> Dict[int, int]:
"""
Calculate the squares of numbers within a given range [start, end].
Args:
start (int): The starting number of the range (in... |
magic_evol_110k | 86,475 | Write a Python function to convert a temperature from Celsius to Fahrenheit, ensuring that the input is valid and numeric. The function should handle invalid inputs gracefully and provide appropriate feedback to the user. Additionally, debug the provided faulty code that attempts to convert Celsius to Fahrenheit but co... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_fahrenheit(celsius: str) -> str:
"""
Converts a temperature from Celsius to Fahrenheit.
Args:
celsius (str): The temperature in Celsius as a string.
Returns:
str: The temperature in Fahre... |
magic_evol_110k | 86,476 | Write a Python function to calculate the areas of various geometric shapes given their parameters and types. The function should accept two lists: one containing the names of the shapes and the other containing the corresponding parameters for each shape. The function should return a list of areas for each shape.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def calculate_areas(shapes: List[str], shape_parameters: List[List[float]]) -> List[float]:
"""
Calculate the areas of various geometric shapes given their parameters and types.
Args:
... |
magic_evol_110k | 86,505 | Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of a given 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 | 86,508 | Write a Python function to determine if two given strings are anagrams of each other, considering that the strings may contain multiple words, spaces, punctuation, and varying capitalization. The function should ignore spaces, punctuation, and case sensitivity when comparing the strings.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(string1: str, string2: str) -> bool:
"""
Determines if two strings are anagrams of each other, ignoring spaces, punctuation, and case sensitivity.
Args:
string1 (str): The first string to compare.
... |
magic_evol_110k | 86,521 | Write a Python function to sort a list of string entities in alphabetical order, ignoring case sensitivity. The function should utilize Python's built-in functions or libraries and should not rely on external modules or libraries. The code should start with:
```python
from typing import List
def sort_strings_ignore_ca... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_strings_ignore_case(str_list: List[str]) -> List[str]:
"""
Sorts a list of string entities in alphabetical order, ignoring case sensitivity.
Args:
str_list (List[str]): The list of ... |
magic_evol_110k | 86,526 | Write a Python function to find and return the first five prime numbers from a given numerical array. If there are fewer than five prime numbers, return all the primes found. If there are no prime numbers in the array, return a specific message indicating that no prime numbers were found.
The code should start with:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def is_prime(n: int) -> bool:
"""
Helper function to determine if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number i... |
magic_evol_110k | 86,531 | Write a Python function to calculate the average movie rating based on ratings from different sources. The function should take a dictionary containing movie information, including a nested dictionary of ratings, and return the average rating. The code should handle potential errors in the input data, such as incorrect... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Union
def calculate_average_rating(movie_info: Dict[str, Union[str, int, Dict[str, float]]]) -> float:
"""
Calculate the average movie rating based on ratings from different sources.
Args:
... |
magic_evol_110k | 86,546 | Write a Python function to convert a given time in the 24-hour format into its equivalent in the 12-hour format. The function should handle any valid time string in the "HH:MM" format and return a string in the "HH:MM AM/PM" format.
The code should start with:
```python
from datetime import datetime
def convert_24_to... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def convert_24_to_12_hour_format(time_str: str) -> str:
"""
Converts a given time in the 24-hour format to its equivalent in the 12-hour format.
Args:
time_str (str): The time in the "... |
magic_evol_110k | 86,549 | Write a Python function to reverse the order of elements in a given list of integers. The function should take a list of integers as input and return a new list with the elements in reversed order. The code should start with:
```python
from typing import List
def reverse_list(lst: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_list(lst: List[int]) -> List[int]:
"""
Reverses the order of elements in a given list of integers.
Args:
lst (List[int]): The list of integers to be reversed.
Returns:
... |
magic_evol_110k | 86,552 | Write a Python function that takes a list of non-negative integers as input and returns a tuple containing two lists: one with the squares of the elements and the other with the factorials of the elements. The function should handle edge cases such as an empty list and a single-element list.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import math
def square_and_factorial(nums: List[int]) -> Tuple[List[int], List[int]]:
"""
Computes the squares and factorials of each element in the input list.
Args:
nums (List[int])... |
magic_evol_110k | 86,564 | Write a Python function to generate an HTML table that illustrates the array of academic scores pertaining to a group of students. The function should accept a list of integers representing the scores and return a string containing the HTML table. The table should have two columns: "Student" and "Mark". The "Student" c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_html_table(scores: List[int]) -> str:
"""
Generates an HTML table that illustrates the array of academic scores pertaining to a group of students.
Args:
scores (List[int]): A li... |
magic_evol_110k | 86,565 | Write a Python function to count the occurrences of each lowercase Roman letter in a given string, regardless of its order, and return the total number of all lowercase letters. The function should be case-insensitive, meaning uppercase Roman letters should also be counted. The function should return a dictionary with ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
from collections import Counter
def count_lowercase_letters(s: str) -> Tuple[Dict[str, int], int]:
"""
Counts the occurrences of each lowercase Roman letter in the given string and returns the tot... |
magic_evol_110k | 86,577 | Write a Python function to validate a URL using a regular expression. The URL must start with 'https', end with '.com', and include one or more subdomains. Additionally, the URL should not contain any query or fragment identifiers. The function should return `True` if the URL is valid and `False` otherwise.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_url(url: str) -> bool:
"""
Validates a URL using a regular expression. The URL must start with 'https', end with '.com',
and include one or more subdomains. The URL should not contain any query or fra... |
magic_evol_110k | 86,585 | Write a Python function to generate a message that encapsulates the temporal age of an individual and formats it into an eloquent expression. The function should accept the age as an integer and return a string that includes the age in a well-structured sentence.
The code should start with:
```python
def generate_age_... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_age_message(age: int) -> str:
"""
Generates a message that encapsulates the temporal age of an individual in an eloquent expression.
Args:
age (int): The age of the individual.
Returns:
str... |
magic_evol_110k | 86,586 | Write a Python function `unique_max_integers` that accepts three lists of integers `x`, `y`, and `z` as parameters. The function should return a new list consisting of unique maximum integers from each provided list. If a list is empty, consider the maximum of that list to be 0. Implement your solution without using bu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def unique_max_integers(x: List[int], y: List[int], z: List[int]) -> List[int]:
"""
Returns a list of unique maximum integers from each of the three provided lists.
If a list is empty, its maximum is... |
magic_evol_110k | 86,596 | Write a Python function to concatenate a list of strings into a single string, allowing for line continuation using the backslash (`\`) character. The function should handle any number of strings in the list and ensure that the concatenation is done efficiently and correctly.
The code should start with:
```python
from... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def concatenate_strings(strings: List[str]) -> str:
"""
Concatenates a list of strings into a single string, allowing for line continuation using the backslash character.
Args:
strings (List... |
magic_evol_110k | 86,598 | Write a Python function that removes all repeated elements from a list while maintaining the original order of the remaining elements, and counts the frequency of each element initially present. The function should return two outputs: the new list with duplicates removed and a dictionary showing the initial count of ea... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def remove_duplicates_and_count_frequencies(elements_list: List[int]) -> (List[int], Dict[int, int]):
"""
Removes all repeated elements from a list while maintaining the original order of the remai... |
magic_evol_110k | 86,615 | Write a Python function to select a random unique character from a given string. A unique character is defined as a character that appears only once in the string. If there are no unique characters, the function should return an appropriate message. The function should be case sensitive.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union
import random
def get_random_unique_char(s: str) -> Union[str, None]:
"""
Selects a random unique character from the given string. A unique character is defined as a character that appears only once in ... |
magic_evol_110k | 86,620 | Write a Python function to partition a given list of integers into two separate lists: one containing all even numbers and the other containing all odd numbers. The function should return a tuple with the first element being the list of even numbers and the second element being the list of odd numbers.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def partition_numbers(numbers: List[int]) -> Tuple[List[int], List[int]]:
"""
Partition a list of integers into two lists: one containing all even numbers and the other containing all odd numbers.... |
magic_evol_110k | 86,629 | Write a Python function to generate a list of prime numbers within a given discrete numerical range. The function should take two integers, `start` and `end`, as input and return a list of prime numbers that fall within this range, inclusive of both `start` and `end`.
The code should start with:
```python
from typing ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise.
... |
magic_evol_110k | 86,631 | Write a Python function that checks if the given list of tuples contains the integer `k` and returns the indices of the tuples where `k` is found. If `k` is not found in any of the tuples, the function should return a custom error message. Additionally, the function should handle cases where the input is not a tuple or... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Union
def find_indices_of_k(tuples: List[Tuple[int, ...]], k: int) -> Union[List[int], str]:
"""
Finds the indices of tuples in the list that contain the integer `k`.
Args:
tuples (L... |
magic_evol_110k | 86,632 | Write a Python function to generate a list of `n` unique random numbers between `min_val` and `max_val` (inclusive) in ascending order. The solution must be optimized to have a minimum time complexity.
The code should start with:
```python
from typing import List
import random
def generate_unique_random_numbers(n: in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_unique_random_numbers(n: int, min_val: int, max_val: int) -> List[int]:
"""
Generate a list of n unique random numbers between min_val and max_val (inclusive) in ascending orde... |
magic_evol_110k | 86,635 | Write a Python function to filter out all instances of a specified target word from a given string of words. The words in the string may be separated by commas, spaces, or both. The function should return an array of words in the original order, but with all instances of the target word eliminated. The function should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_words(s: str, target: str) -> List[str]:
"""
Filters out all instances of a specified target word from a given string of words.
The words in the string may be separated by commas, spaces, ... |
magic_evol_110k | 86,637 | Write a Python function to generate a list of prime numbers that are smaller than a given non-negative integer `n`. The function should be efficient and avoid unnecessary computations. The code should start with:
```python
from typing import List
def generate_primes_below(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_primes_below(n: int) -> List[int]:
"""
Generate a list of prime numbers that are smaller than the given non-negative integer n.
Args:
n (int): The upper limit (exclusive) for ge... |
magic_evol_110k | 86,640 | Write a Python function to generate a frequency dictionary from an array of alphanumeric symbols. The dictionary should have unique English alphabets as keys and their respective counts (frequency) in the input array as values. The function should be case-insensitive, meaning 'A' and 'a' should be treated as the same c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def generate_frequency_dict(array: List[str]) -> Dict[str, int]:
"""
Generates a frequency dictionary from an array of alphanumeric symbols.
Args:
array (List[str]): The array of alpha... |
magic_evol_110k | 86,642 | Write a Python function to construct a new list by replicating each string from a given list of strings based on the corresponding integer value from another list of integers. The position of each string in the first list corresponds to the position of the integer in the second list.
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 replicate_strings(str_list: List[str], num_list: List[int]) -> List[str]:
"""
Constructs a new list by replicating each string from `str_list` based on the corresponding integer value from `num_list`... |
magic_evol_110k | 86,655 | Write a Python function to calculate the average marks of students from a given dictionary containing student names and their corresponding marks. The function should handle cases where the dictionary might be empty.
The code should start with:
```python
from typing import Dict
def calculate_average_marks(student_mar... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def calculate_average_marks(student_marks: Dict[str, int]) -> float:
"""
Calculate the average marks of students from a given dictionary containing student names and their corresponding marks.
Args:... |
magic_evol_110k | 86,687 | Write a Python function to edit a given list by replacing an existing element with a new value. The replacement should only be performed if the length of the new value is greater than the length of the old value. If the new value has the same or shorter length, the replacement should not be performed. The function shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def replace_element_conditionally(mylist: List[str], old_value: str, new_value: str) -> List[str]:
"""
Replaces an existing element in the list with a new value if the length of the new value is greater ... |
magic_evol_110k | 86,717 | Write a Python function to convert a given list of integers to a list of floats. The function should take a list of integers as input and return a new list where each element is the corresponding float value of the original integer. The function should handle an empty list by returning an empty list.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_to_float_list(int_list: List[int]) -> List[float]:
"""
Converts a list of integers to a list of floats.
Args:
int_list (List[int]): A list of integers to be converted.
Retur... |
magic_evol_110k | 86,727 | Write a Python function to determine the number of valid trinary sequences of length `n` that would result in a student receiving a reward, given the following rules:
1. The student forfeits the reward if they are absent for a continuous span of three days.
2. The student forfeits the reward if they are tardy (late) mo... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_reward_sequences(n: int) -> int:
"""
Calculate the number of valid trinary sequences of length n that would result in a student receiving a reward.
Args:
n (int): The length of the trinary sequence.
R... |
magic_evol_110k | 86,728 | Write a Python function to generate all possible permutations resulting from the combination of two distinct numerical sequences. Each permutation should be a tuple containing one element from each sequence. The function should handle any two lists of integers and return a list of tuples representing all possible permu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import itertools
def generate_permutations(list1: List[int], list2: List[int]) -> List[Tuple[int, int]]:
"""
Generates all possible permutations resulting from the combination of two distinct nume... |
magic_evol_110k | 86,731 | Write a Python function to find the number that appears most frequently in a given list of numerical values. If there are multiple numbers with the same highest frequency, return the smallest number. The function should be efficient and handle edge cases such as an empty list.
The code should start with:
```python
fro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def most_frequent_number(num_list: List[int]) -> int:
"""
Find the number that appears most frequently in the given list.
If there are multiple numbers with the same highest frequency, return the sma... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.