source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 93,094 | Write a Python function to calculate the cumulative sum of all numerical values contained within a provided list of tuples. The function should be capable of navigating nested tuple structures and disregarding any non-numeric entities. The code should start with:
```python
from typing import Tuple, Union
def cumulativ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Union
def cumulative_sum_of_tuples(tuples: Tuple[Union[int, float, Tuple], ...]) -> float:
"""
Calculate the cumulative sum of all numerical values contained within a provided list of tuples.
This ... |
magic_evol_110k | 93,099 | Write a Python function to print the elements of a given list in reverse order using a while loop. The function should take a list of strings as input and print each element on a new line in reverse order.
The code should start with:
```python
from typing import List
def print_reverse_order(fruits: List[str]) -> None... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_reverse_order(fruits: List[str]) -> None:
"""
Prints the elements of the given list in reverse order.
Args:
fruits (List[str]): A list of strings to be printed in reverse order.
... |
magic_evol_110k | 93,110 | Write a Python function to check if a given string is a palindrome without using any built-in functions or methods. The function should iterate through the string and compare characters from both ends towards the center to determine if the string reads the same forwards and backwards.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_palindrome(s: str) -> bool:
"""
Check if a given string is a palindrome without using any built-in functions or methods.
Args:
s (str): The string to check.
Returns:
bool: True if the string is a... |
magic_evol_110k | 93,112 | Write a Python function to initialize a 2D array (matrix) with a given number of rows and columns, where each element is initialized to a specified value. The function should handle cases where the number of rows or columns is zero, returning an empty list in such cases. 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 initialize_2d_array(rows: int, cols: int, value: int) -> List[List[int]]:
"""
Initializes a 2D array (matrix) with the specified number of rows and columns,
where each element is initialized to t... |
magic_evol_110k | 93,130 | Write a Python function to check if a certain element is present in a given sorted array using a binary search algorithm. The function should not use any built-in array methods except for sorting. The code should start with:
```python
def is_element_in_sorted_array(arr, element):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_element_in_sorted_array(arr, element):
"""
Checks if a certain element is present in a given sorted array using binary search.
Args:
arr (list): The sorted array to search in.
element: The element to ... |
magic_evol_110k | 93,136 | Write a Python function to delete the first occurrence of a specified item from a given list. If the item is not found in the list, the function should return the original list without any modifications. The function should handle lists of integers and strings.
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, Union
def delete_item(lst: List[Union[int, str]], item: Union[int, str]) -> List[Union[int, str]]:
"""
Deletes the first occurrence of the specified item from the given list.
Args:
lst ... |
magic_evol_110k | 93,142 | Write a Python function to determine the total number of non-repeating elements in a provided 3D array and to identify and count the repeating elements in each 2D array present within the 3D array. The function should return the total count of unique elements in the whole 3D array and a dictionary where the keys are th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_elements_in_3d_array(array: List[List[List[int]]]) -> (int, Dict[int, int]):
"""
Determine the total number of non-repeating elements in a provided 3D array and count the repeating elemen... |
magic_evol_110k | 93,146 | Write a Python function to reverse a given string without using built-in functions to reverse the string or aid directly in the process. The function should handle edge cases such as empty strings or single character strings and should be efficient enough to handle extremely long strings. The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(s: str) -> str:
"""
Reverses a given string without using built-in functions to reverse the string or aid directly in the process.
Args:
s (str): The input string to be reversed.
Returns:
... |
magic_evol_110k | 93,172 | Write a Python function to generate the first `n` elements of the Fibonacci sequence and another function to find all prime numbers within these first `n` elements of the Fibonacci sequence. The first function should be named `generate_fibonacci` and the second function should be named `fibonacci_primes`. The `generate... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_fibonacci(n: int) -> list:
"""
Generate the first n elements of the Fibonacci sequence.
Args:
n (int): The number of elements to generate.
Returns:
list: A list containing the first n eleme... |
magic_evol_110k | 93,195 | Refactor the given Python script to use a dictionary and a `for` loop control structure instead of a list and an `if` conditional. The script should check if a given value `x` is a key in the dictionary and print a corresponding message if it is.
The code should start with:
```python
def check_value_in_dict(x: int, di... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_value_in_dict(x: int, dict_: dict) -> None:
"""
Checks if the given value `x` is a key in the provided dictionary and prints a corresponding message if it is.
Args:
x (int): The value to check in the dicti... |
magic_evol_110k | 93,232 | Write a Python function to calculate the sum of all numbers in a given list that are divisible by a specified integer `k`. The function should handle both positive and negative numbers in the list. The code should start with:
```python
from typing import List
def sum_divisible_by_k(nums: List[int], k: int) -> int:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_divisible_by_k(nums: List[int], k: int) -> int:
"""
Calculate the sum of all numbers in the given list that are divisible by the specified integer k.
Args:
nums (List[int]): The list... |
magic_evol_110k | 93,240 | Write a Python function to convert an octal number represented as a string into its corresponding decimal representation also as a string. The function should handle any valid octal string input.
The code should start with:
```python
def octal_to_decimal(x: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def octal_to_decimal(x: str) -> str:
"""
Convert an octal input (string) into its corresponding decimal representation (string).
Args:
x (str): The octal number to be converted, represented as a string.
Returns... |
magic_evol_110k | 93,246 | Write a Python function to calculate the Least Common Multiple (LCM) of three positive integers, ensuring that the function handles the constraint where the integers are within the range of 32-bit signed integer values. The function should be efficient and avoid overflow issues.
The code should start with:
```python
d... | Here is the Python code to solve the given problem in the markdown block:
```python
def gcd(a: int, b: int) -> int:
"""
Calculate the Greatest Common Divisor (GCD) of two integers.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
int: The GCD of the two i... |
magic_evol_110k | 93,247 | Write a Python function to perform a binary search on a sorted list of integers. The function should return the index of the target value if it exists in the list, otherwise it should return `None`. The function should be optimized for efficiency and handle edge cases such as an empty list or a target value that is not... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def binary_search(sorted_list: List[int], target_value: int) -> Optional[int]:
"""
Perform a binary search on a sorted list of integers to find the index of the target value.
Args:
... |
magic_evol_110k | 93,252 | Write a Python function to find and return the index of the first occurrence of a specified target value in a given list of integers. If the target value is not found in the list, the function should return `-1`.
The code should start with:
```python
from typing import List
def find_first_occurrence(nums: List[int], ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_first_occurrence(nums: List[int], target: int) -> int:
"""
Find the index of the first occurrence of a specified target value in a list of integers.
Args:
nums (List[int]): The list... |
magic_evol_110k | 93,264 | Write a Python function to determine if all the characters in a given list of strings are uppercase. The function should return `True` if all characters in all strings are uppercase, and `False` otherwise. The function should handle an empty list by returning `True`.
The code should start with:
```python
from typing i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def are_all_uppercase(words: List[str]) -> bool:
"""
Determines if all characters in a given list of strings are uppercase.
Args:
words (List[str]): A list of strings to be checked.
Ret... |
magic_evol_110k | 93,270 | Write a Python function to interchange the first and last elements in a list. The list should contain at least 3 elements and should not contain any duplicate elements. The function should return the modified list if the conditions are met, otherwise it should return an appropriate error message.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def swap_first_last_elements(lst: List[int]) -> Union[List[int], str]:
"""
Interchange the first and last elements in a list. The list should contain at least 3 elements and should not contain any... |
magic_evol_110k | 93,291 | Write a Python function to calculate the cumulative sum of all natural numbers less than a given number `n` that are divisible by either 3 or 5. The function should efficiently compute this sum for large values of `n`.
The code should start with:
```python
def sum_divisible_by_3_or_5(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_divisible_by_3_or_5(n: int) -> int:
"""
Calculate the cumulative sum of all natural numbers less than `n` that are divisible by either 3 or 5.
Args:
n (int): The upper limit (exclusive) for the natural numbe... |
magic_evol_110k | 93,295 | Write a Python function to perform an insertion sort on a given list of integers. The function should sort the list in ascending order and return the sorted list. The code should start with:
```python
from typing import List
def insertion_sort(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 insertion_sort(lst: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order using the insertion sort algorithm.
Args:
lst (List[int]): The list of integers to be sorted.... |
magic_evol_110k | 93,303 | Write a Python function to generate the first `n` Fibonacci numbers using an array-oriented storage model. The function should ensure optimal memory utilization and facilitate rapid data access. The code should start with:
```python
from typing import List
def generate_fibonacci(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_fibonacci(n: int) -> List[int]:
"""
Generate the first n Fibonacci numbers using an array-oriented storage model.
Args:
n (int): The number of Fibonacci numbers to generate.
... |
magic_evol_110k | 93,320 | Write a Python function to determine the maximum nesting level of parentheses in a given string. The function should handle cases of unbalanced parentheses and raise a specific exception for such cases. The function should start with:
```python
def max_nesting_level(expression: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def max_nesting_level(expression: str) -> int:
"""
Calculate the maximum nesting level of parentheses in a given string.
Args:
expression (str): The string containing nested parentheses.
Returns:
int: T... |
magic_evol_110k | 93,325 | Write a Python function to generate a sequence of five distinct dictionaries, each representing a different web development framework. Each dictionary should contain at least two elements: the name of the framework and its main programming language. The function should return a list of these dictionaries.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def generate_web_frameworks() -> List[Dict[str, str]]:
"""
Generates a sequence of five distinct dictionaries, each representing a different web development framework.
Each dictionary contains ... |
magic_evol_110k | 93,344 | Write a Python function to create a NumPy array that incorporates an equal distribution of specified elements with their respective counts. The function should take two lists as input: one for the values and another for their corresponding counts. The function should return a NumPy array with the specified distribution... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List
def create_distribution_array(values: List[int], counts: List[int]) -> np.ndarray:
"""
Creates a NumPy array with a specified distribution of elements.
Args:
values (List[... |
magic_evol_110k | 93,348 | Write a Python function to evaluate whether a provided integer is odd or even, and to determine if it is a prime number. The function should handle potential errors like non-integer inputs and inputs less than or equal to zero. The code should start with:
```python
def check_integer_properties(n: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def check_integer_properties(n: int) -> str:
"""
Evaluates whether a provided integer is odd or even, and determines if it is a prime number.
Handles potential errors like non-integer inputs and inputs less than or equal to ... |
magic_evol_110k | 93,350 | Write a Python function to determine if a given number is a prime number or not. The function should handle potential errors and edge cases, such as non-integer inputs and numbers less than 2. The function should return a string "Prime" if the number is prime and "Not Prime" otherwise.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(n: int) -> str:
"""
Determine if a given number is a prime number.
Args:
n (int): The number to check for primality.
Returns:
str: "Prime" if the number is prime, "Not Prime" otherwise.
... |
magic_evol_110k | 93,352 | Write a Python function to find the most frequent numbers in an array of integers and return them along with their counts in a dictionary format. If there are multiple numbers with the same highest frequency, the function should return all of them. The function should handle edge cases such as an empty array by returni... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def most_frequent_numbers(arr: List[int]) -> Dict[int, int]:
"""
Finds the most frequent numbers in an array of integers and returns them along with their counts.
If there are multiple numbers ... |
magic_evol_110k | 93,404 | Write a Python function to swap the values of two variables using three different methods: using a temporary variable, without using a temporary variable, and using arithmetic operations. The function should take two integers as input and return a tuple containing the swapped values. The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
def swap_variables(x: int, y: int) -> tuple:
"""
Swaps the values of two variables using three different methods and returns the swapped values.
Args:
x (int): The first integer.
y (int): The second integer.... |
magic_evol_110k | 93,405 | Write a Python function to filter a list of words based on the number of syllables they contain. The function should take a list of words and two integers `A` and `B` such that `B > A`, and return a new list containing only the words that have syllables in the range `[A, B]`. The number of syllables in a word should be... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_syllables(word: str) -> int:
"""
Counts the number of vowels in a word, assuming each vowel represents one syllable.
Args:
word (str): The word to count syllables in.
Returns:... |
magic_evol_110k | 93,412 | Write a Python function to rotate an array by a given number of positions to the right. The function should handle both positive and negative rotation values, where a positive value indicates a right rotation and a negative value indicates a left rotation. The function should also handle cases where the number of rotat... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def rotate_array(arr: List[int], num_rotations: int) -> List[int]:
"""
Rotates the given array by the specified number of positions.
Args:
arr (List[int]): The array to be rotated.
n... |
magic_evol_110k | 93,428 | Write a Python function to find the length of the longest increasing subsequence (LIS) in a given unsorted array of integers. The function should efficiently compute the result in `O(n log n)` time complexity.
The code should start with:
```python
from typing import List
from bisect import bisect_left
def longest_inc... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from bisect import bisect_left
def longest_increasing_subsequence(nums: List[int]) -> int:
"""
Find the length of the longest increasing subsequence in a given unsorted array of integers.
Args:
... |
magic_evol_110k | 93,431 | Write a Python function to reverse a given list of integers without using any built-in Python functions or methods that directly reverse a list (e.g., `reverse()`, `reversed()`, `[::-1]`). The function should use basic list operations and loops to achieve the reversal.
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 reverse_list(input_list: List[int]) -> List[int]:
"""
Reverses a given list of integers without using built-in reverse functions.
Args:
input_list (List[int]): The list of integers to be... |
magic_evol_110k | 93,443 | Write a Python function to find and replace all occurrences of a specified word in a given text with a replacement word. The function should handle cases where the word to be replaced is a substring of another word (e.g., replacing "cat" in "The cathedral" should not replace "cathedral"). The function should also handl... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def find_and_replace(text: str, word: str, replacement: str) -> str:
"""
Replaces all occurrences of a specified word in a given text with a replacement word.
The function ensures that the word to be replaced is a... |
magic_evol_110k | 93,446 | Write a Python function to generate a syntactically correct JSON object that represents a person's profile. The profile should include the person's complete identity, chronological age (in years), and professional role. The function should accept three parameters: the person's complete identity (a string), their chrono... | Here is the Python code to solve the given problem in the markdown block:
```python
import json
def create_profile_json(identity: str, age: int, role: str) -> str:
"""
Generates a JSON object representing a person's profile.
Args:
identity (str): The complete identity of the person.
age (i... |
magic_evol_110k | 93,477 | Write a Python function to sort a list of numbers using the Bubble Sort algorithm. 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 bubble_sort(number_list: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(number_list: List[int]) -> List[int]:
"""
Sorts a list of integers using the Bubble Sort algorithm.
Args:
number_list (List[int]): The list of integers to be sorted.
Ret... |
magic_evol_110k | 93,485 | Write a Python function to generate and return a list of squares of numbers within a specified range, inclusively. The function should take two parameters: the start of the range and the end of the range. The function should efficiently compute the squares of all numbers within this range and return them in a list.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_squares(start: int, end: int) -> List[int]:
"""
Generate a list of squares of numbers within the specified range, inclusively.
Args:
start (int): The start of the range (inclusi... |
magic_evol_110k | 93,520 | Write a Python function to count the occurrences of the distinct pattern "xyz" in a given string. The function should handle cases where the input string is empty or does not contain any three-character patterns. The patterns should not overlap, and the string is case sensitive. The function should also provide necessa... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_xyz_patterns(text: str) -> int:
"""
Counts the occurrences of the distinct pattern "xyz" in the given string.
The patterns should not overlap, and the string is case sensitive.
Args:
text (str): The in... |
magic_evol_110k | 93,545 | Write a Python function to compute and display the initial 20 numbers from the Fibonacci sequence. Additionally, create a function that identifies and displays only the prime numbers from these computed Fibonacci numbers. The function should handle invalid input by raising a `ValueError` with the message "Invalid Input... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_fibonacci(n: int) -> list:
"""
Generate the first n numbers in the Fibonacci sequence.
Args:
n (int): The number of Fibonacci numbers to generate.
Returns:
list: A list containing the first... |
magic_evol_110k | 93,553 | Write a Python function to split a given string into individual characters and count the number of vowels in the string. The function should be case-insensitive, meaning it should count both uppercase and lowercase vowels. The function should return a tuple containing the list of characters and the count of vowels.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def split_and_count_vowels(s: str) -> Tuple[List[str], int]:
"""
Splits the given string into individual characters and counts the number of vowels.
Args:
s (str): The input string to... |
magic_evol_110k | 93,555 | Write a Python function to compute the product of three given integers. The function should handle both positive and negative integers, as well as zero. The code should start with:
```python
def multiply_triplet(a: int, b: int, c: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def multiply_triplet(a: int, b: int, c: int) -> int:
"""
Computes the product of three given integers.
Args:
a (int): The first integer.
b (int): The second integer.
c (int): The third integer.
... |
magic_evol_110k | 93,576 | Write a Python function to determine the maximum number of groups of four people that can be accommodated in a cinema with `n` rows of seats, each row containing ten seats labeled from 1 to 10. The function should take an integer `n` representing the number of rows and a list of lists `reservedSeats` indicating the sea... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import defaultdict
def max_number_of_families(n: int, reservedSeats: List[List[int]]) -> int:
"""
Determine the maximum number of groups of four people that can be accommodated in a cine... |
magic_evol_110k | 93,579 | Write a Python function to validate United States phone numbers using a regular expression pattern. The function should accept a phone number as a string and return `True` if the phone number is in a valid format, and `False` otherwise. The valid formats include:
- `(123) 456-7890`
- `123 456 7890`
- `123.456.7890`
- `... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_us_phone_number(phone_number: str) -> bool:
"""
Validates if the given phone number is in a valid United States phone number format.
Args:
phone_number (str): The phone number to validate.
... |
magic_evol_110k | 93,592 | Write a Python function to remove all occurrences of vowel characters (both lowercase and uppercase) from a given string. The function should return the modified string without vowels. The code should start with:
```python
def remove_vowels(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_vowels(input_string: str) -> str:
"""
Removes all vowel characters (both lowercase and uppercase) from the given string.
Args:
input_string (str): The input string from which vowels are to be removed.
... |
magic_evol_110k | 93,600 | Write a Python function to augment an existing tuple by introducing a new element at the foremost position. The function should take two parameters: the existing tuple and the new element to be added. The function should return the augmented tuple.
The code should start with:
```python
from typing import Tuple
def au... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def augment_tuple(existing_tuple: Tuple, new_element) -> Tuple:
"""
Augments an existing tuple by introducing a new element at the foremost position.
Args:
existing_tuple (Tuple): The exist... |
magic_evol_110k | 93,610 | Write a Python function to find the length of the longest consecutive sequence of integers in a given list. The function should efficiently determine the longest sequence of consecutive numbers, where a sequence is defined as a series of numbers that can be ordered without any gaps.
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 longest_consecutive_sequence(nums: List[int]) -> int:
"""
Find the length of the longest consecutive elements sequence in a list of integers.
Args:
nums (List[int]): The list of integers... |
magic_evol_110k | 93,611 | Write a Python function to replace a for loop with a while loop and include error handling for scenarios where the loop limit is not certain or may include non-integer values. The function should take an integer `limit` as input and print the numbers from 0 to `limit-1`. If the `limit` is not an integer, the function s... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_numbers_with_while_loop(limit):
"""
Prints numbers from 0 to limit-1 using a while loop with error handling.
Args:
limit (int): The upper limit of the loop.
Raises:
TypeError: If the limit is ... |
magic_evol_110k | 93,612 | Write a Python function to generate a random digital key of a specified length, ensuring that the key contains at least one uppercase alphabetic character and one numerical digit. The function should handle cases where the specified length is less than the minimum required length.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
import string
def generate_digital_key(length: int) -> str:
"""
Generates a random digital key of the specified length, ensuring it contains at least one uppercase alphabetic character and one numerical digit.
... |
magic_evol_110k | 93,621 | Write a Python function to sort a given list in ascending order using the selection sort algorithm. Additionally, implement a functionality that checks for and removes any duplicate values prior to sorting. The function should start with:
```python
from typing import List
def sort_and_remove_duplicates(array: List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_and_remove_duplicates(array: List[int]) -> List[int]:
"""
Sorts the given list in ascending order using the selection sort algorithm and removes any duplicate values.
Args:
array (L... |
magic_evol_110k | 93,636 | Write a Python function to multiply all the elements of a 2D array by a given number. The function should handle edge cases such as empty sub-arrays or the entire array being empty. The code should start with:
```python
from typing import List
def multiply_2d_array(arr: List[List[int]], num: int) -> List[List[int]]:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_2d_array(arr: List[List[int]], num: int) -> List[List[int]]:
"""
Multiplies all elements of a 2D array by a given number.
Args:
arr (List[List[int]]): The 2D array of integers t... |
magic_evol_110k | 93,637 | Write a Python function to generate the first `n` Fibonacci numbers and their corresponding perfect cubes. The function should return a list of tuples, where each tuple contains a Fibonacci number and its cube. The function should have a time complexity less than O(n^2).
The code should start with:
```python
from typi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def fibonacci_and_cubes(n: int) -> List[Tuple[int, int]]:
"""
Generate the first n Fibonacci numbers and their corresponding perfect cubes.
Args:
n (int): The number of Fibonacci numb... |
magic_evol_110k | 93,639 | Write a Python function to separate distinct and nested balanced parentheses clusters from a given string, ignoring whitespace characters. The function should correctly identify and return only balanced clusters as a list of strings. The code should start with:
```python
from typing import List
def separate_paren_grou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def separate_paren_groups(paren_string: str) -> List[str]:
"""
Separates distinct and nested balanced parentheses clusters from a given string, ignoring whitespace characters.
Args:
paren_st... |
magic_evol_110k | 93,658 | Write a Python function to determine whether a given string can be rearranged to form a palindrome, considering white spaces and case sensitivity. The function should return a boolean value (`True` if the string can be rearranged to form a palindrome, `False` otherwise).
The code should start with:
```python
def is_an... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_anagram_of_palindrome(s: str) -> bool:
"""
Determines whether a given string can be rearranged to form a palindrome.
Args:
s (str): The input string to check.
Returns:
bool: True if the string ca... |
magic_evol_110k | 93,659 | Write a Python function to generate a list of random floating-point numbers within a specified range and length. The function should allow the user to specify the length of the list, the lower bound, and the upper bound of the range for the random numbers. The code should start with:
```python
from typing import List
i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_random_floats(length: int, lower_bound: float, upper_bound: float) -> List[float]:
"""
Generates a list of random floating-point numbers within a specified range and length.
... |
magic_evol_110k | 93,679 | Write a Python function to reverse a given string. The function should take a string as input and return the reversed string. The code should start with:
```python
def reverse_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(s: str) -> str:
"""
Reverses the given string.
Args:
s (str): The string to be reversed.
Returns:
str: The reversed string.
"""
# Use slicing to reverse the string
reverse... |
magic_evol_110k | 93,698 | Write a Python function to count the frequency of unique words in multiple sentences, ignoring case, stopwords, and punctuation. The function should return a dictionary where the keys are the unique words and the values are their respective counts.
The code should start with:
```python
from typing import List, Dict
im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
import string
from collections import Counter
def word_frequency(sentences: List[str], stopwords: List[str]) -> Dict[str, int]:
"""
Counts the frequency of unique words in multiple sentences, ignor... |
magic_evol_110k | 93,705 | Write a Python function to calculate the arithmetic mean of a given numerical array using the `numpy` library. The function should handle arrays of any length and return the mean value as a float. The code should start with:
```python
from typing import List
import numpy as np
def calculate_mean(array: List[int]) -> f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import numpy as np
def calculate_mean(array: List[int]) -> float:
"""
Calculate the arithmetic mean of a given numerical array using the numpy library.
Args:
array (List[int]): A list of int... |
magic_evol_110k | 93,709 | Write a Python function to detect and count the occurrences of each vowel in a given string. The function should return a dictionary where the keys are the vowels and the values are the counts of those vowels in the string. The function should be case-insensitive, meaning 'A' and 'a' should be treated as the same vowel... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_vowels(string: str) -> Dict[str, int]:
"""
Counts the occurrences of each vowel in the given string.
Args:
string (str): The input string to count vowels from.
Returns:
... |
magic_evol_110k | 93,710 | Write a Python function to replace each alphabetic character in a given string with its immediate succeeding character in the English alphabet. If the character is 'z' or 'Z', it should wrap around to 'a' or 'A', respectively. Non-alphabetic characters should remain unchanged.
The code should start with:
```python
def... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_with_next_character(word: str) -> str:
"""
Replace each alphabetic character in the given string with its immediate succeeding character in the English alphabet.
If the character is 'z' or 'Z', it wraps around to... |
magic_evol_110k | 93,716 | Write a Python function to convert a given dictionary into a list of tuples, where each tuple contains a key-value pair from the dictionary. The function should also handle the case where the dictionary is empty by returning an empty list. The code should start with:
```python
from typing import Dict, List, Tuple
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def dict_to_list_of_tuples(dictionary: Dict) -> List[Tuple]:
"""
Converts a given dictionary into a list of tuples, where each tuple contains a key-value pair from the dictionary.
Args:... |
magic_evol_110k | 93,741 | Write a Python function to reverse an array in-place without using any built-in functions or additional data structures. The function should validate the input to ensure it's a list filled with integers only. If the input is invalid, the function should return an appropriate error message.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_array(arr):
"""
Reverses an array in-place without using any built-in functions or additional data structures.
Validates the input to ensure it's a list filled with integers only.
Args:
arr (list): T... |
magic_evol_110k | 93,767 | Write a Python function to implement the Bubble Sort algorithm, which sorts a list of integers in ascending order. The function should correctly handle the swapping of elements to ensure the list is sorted. 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 in ascending order using the Bubble Sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
... |
magic_evol_110k | 93,786 | Write a Python function to generate and display a pattern of stars with a variable size. The pattern should consist of two parts:
1. A right-angled triangle of stars where each row has one more star than the previous row.
2. An isosceles triangle of stars where each row has an increasing number of stars centered with s... | Here is the Python code to solve the given problem in the markdown block:
```python
def display_star_pattern(size: int) -> None:
"""
Generates and displays a pattern of stars with a variable size.
The pattern consists of two parts:
1. A right-angled triangle of stars where each row has one more star th... |
magic_evol_110k | 93,788 | Write a Python function to find all pixels in an image that are grey and that are immediately to the left of a black pixel. The function should efficiently use NumPy operations to achieve this. The image is represented as a 3D NumPy array where the first two dimensions represent the rows and columns of the image, and t... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def find_grey_pixels_left_of_black(img: np.ndarray, grey_color: tuple, grey_tolerance: int) -> np.ndarray:
"""
Find all pixels in an image that are grey and that are immediately to the left of a black pixel.
... |
magic_evol_110k | 93,791 | Write a Python function to determine whether a provided list contains a specified item using a multi-step approach. The function should first check if the list is empty, then print the list, and finally search for the item in the list. If the item is found, it should return a message indicating the item was found. If t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def check_list_for_item(data: List[Union[int, float, str]], item: Union[int, float, str]) -> str:
"""
Determines whether a provided list contains a specified item using a multi-step approach.
... |
magic_evol_110k | 93,797 | Write a Python function to iterate over a list of strings and return a new list containing the lengths of each string in the original list. The function should handle lists of varying lengths and ensure that the returned list maintains the same order as the original list.
The code should start with:
```python
from typ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def string_lengths(strings: List[str]) -> List[int]:
"""
Returns a list of the lengths of each string in the input list.
Args:
strings (List[str]): A list of strings for which to calculate t... |
magic_evol_110k | 93,801 | Write a Python function to convert a given string to its lowercase version. The function should handle various edge cases, such as an empty string, strings with only uppercase letters, strings with only lowercase letters, and strings with a mix of uppercase and lowercase letters, including special characters and number... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_lowercase(input_string: str) -> str:
"""
Converts the given string to its lowercase version.
Args:
input_string (str): The string to be converted to lowercase.
Returns:
str: The lowercase... |
magic_evol_110k | 93,808 | Write a Python function to find the two greatest numbers from a given list of integers. The function should be optimized to handle a large list efficiently. The code should start with:
```python
from typing import List, Tuple
def find_two_greatest_numbers(nums: List[int]) -> Tuple[int, int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_two_greatest_numbers(nums: List[int]) -> Tuple[int, int]:
"""
Finds the two greatest numbers from a given list of integers.
Args:
nums (List[int]): The list of integers from ... |
magic_evol_110k | 93,813 | Write a Python function that prints the phrase "I love Python" five times, followed by printing the reverse of the phrase "I love Python" five times. The function should not use any in-built or external libraries for reversing the string. The code should start with:
```python
def print_phrases():
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def print_phrases():
"""
Prints the phrase "I love Python" five times, followed by printing the reverse of the phrase "I love Python" five times.
This function does not use any in-built or external libraries for reversing t... |
magic_evol_110k | 93,816 | 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 | 93,817 | Write a Python function to perform arithmetic operations on Roman numerals and convert the result between Roman numerals and integers. The function should accept two Roman numerals, an arithmetic operation, and a conversion type. The function should return the result of the operation in the specified format (either Rom... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union
def roman_number_operations(first_number: Union[str, int], operation: str, second_number: Union[str, int], conversion_type: str) -> Union[str, int]:
"""
Perform arithmetic operations on Roman numerals a... |
magic_evol_110k | 93,820 | Write a Python function to determine if there exists a triplet in a given list of integers that sums up to a specified target number. The function should return `True` if such a triplet exists, otherwise `False`. The code should start with:
```python
from typing import List
def find_triplet_sum(nums: List[int], target... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_triplet_sum(nums: List[int], target: int) -> bool:
"""
Determines if there exists a triplet in the given list of integers that sums up to the specified target number.
Args:
nums (Li... |
magic_evol_110k | 93,832 | Write a Python function to find and return the k most frequent characters along with their corresponding frequencies from a given string. If there are multiple characters with the same frequency, return them in the order of their first appearance in the string. The function should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
from collections import Counter
def k_most_frequent_chars(s: str, k: int) -> Dict[str, int]:
"""
Find and return the k most frequent characters along with their frequencies from a given string.
... |
magic_evol_110k | 93,848 | Write a Python function to verify if all the elements in a given 2D array are in ascending order both row-wise and column-wise. The function should return `True` if the array is sorted in both directions, and `False` otherwise. The code should start with:
```python
from typing import List
def is_sorted_2d(arr: List[Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_sorted_2d(arr: List[List[int]]) -> bool:
"""
Verify if all the elements in a given 2D array are in ascending order both row-wise and column-wise.
Args:
arr (List[List[int]]): The 2D a... |
magic_evol_110k | 93,850 | Write a Python function to calculate the absolute difference between two numbers and then compute the absolute value of the result. The function should take two integers as input and return the absolute value of their difference. The code should start with:
```python
def absolute_difference_of_differences(a: int, b: in... | Here is the Python code to solve the given problem in the markdown block:
```python
def absolute_difference_of_differences(a: int, b: int) -> int:
"""
Calculate the absolute difference between two numbers and then compute the absolute value of the result.
Args:
a (int): The first integer.
b... |
magic_evol_110k | 93,854 | Write a Python function to generate the first 'n' elements of the Fibonacci sequence. The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. The function should return a list containing the first 'n' Fibonacci numbers.
The code should start ... | 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' elements of the Fibonacci sequence.
The Fibonacci sequence is a series of numbers where each number is the sum of the two prec... |
magic_evol_110k | 93,856 | Write a Python function to determine the mode of a given list of integers. The mode is the number that appears most frequently in the list. If there are multiple numbers with the same highest frequency, return any one of them.
The code should start with:
```python
from typing import List, Optional
from collections imp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
from collections import Counter
def find_mode(numbers: List[int]) -> Optional[int]:
"""
Determine the mode of a given list of integers.
The mode is the number that appears most frequently ... |
magic_evol_110k | 93,863 | Write a Python function to calculate the Levenshtein Distance between two given strings. The Levenshtein Distance is defined as 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 programmin... | Here is the Python code to solve the given problem in the markdown block:
```python
def levenshtein_distance(str1: str, str2: str) -> int:
"""
Calculate the Levenshtein Distance between two strings.
The Levenshtein Distance is the minimum number of single-character edits
(insertions, deletions, or subs... |
magic_evol_110k | 93,864 | Write a Python function to compute the sum of the individual digits of a given non-negative integer. The function should handle any non-negative integer input and return the sum of its digits. The code should start with:
```python
def sum_of_digits(number: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_digits(number: int) -> int:
"""
Computes the sum of the individual digits of a given non-negative integer.
Args:
number (int): The non-negative integer whose digits are to be summed.
Returns:
... |
magic_evol_110k | 93,870 | Write a Python function to transform a given tuple into a list and retrieve the nth entity from the newly formed list. The function should handle cases where n is out of bounds by returning `None`. The code should start with:
```python
from typing import Tuple, Union
def get_nth_entity(animals: Tuple[str], n: int) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Union
def get_nth_entity(animals: Tuple[str], n: int) -> Union[str, None]:
"""
Transforms a given tuple into a list and retrieves the nth entity from the newly formed list.
Args:
animals (... |
magic_evol_110k | 93,885 | Write a Python function to calculate the mean of a given dataset. If the dataset is empty, the function should raise a `ValueError` with an appropriate message. The function should be corrected to ensure it calculates the mean correctly without any logical errors.
The code should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_mean(dataset: List[float]) -> float:
"""
Calculate the mean of a given dataset. If the dataset is empty, raise a ValueError.
Args:
dataset (List[float]): The dataset for which ... |
magic_evol_110k | 93,892 | Write a Python function to calculate the product of all unique dictionary keys converted to integers. The dictionary keys are decimal numbers represented as strings, and the dictionary size can vary from 100 to 1000 key-value pairs. The function should efficiently handle the conversion of decimal keys to integers and e... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
from functools import reduce
import operator
def calculate_product_of_unique_keys(dictionary: Dict[str, str]) -> int:
"""
Calculate the product of all unique dictionary keys converted to integers.
A... |
magic_evol_110k | 93,903 | Write a Python function to count the number of words in a given sentence, considering that words are separated by spaces. The function should handle sentences with multiple spaces between words and leading/trailing 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 input sentence to count words from.
Returns:
int: The number of words in the sentence... |
magic_evol_110k | 93,910 | Write a Python function to calculate the frequency of each character in a given string. The function should return a dictionary where the keys are characters and the values are the counts of those characters in the string. The function should handle all characters, including spaces and punctuation.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def character_frequency(input_string: str) -> Dict[str, int]:
"""
Calculate the frequency of each character in the given string.
Args:
input_string (str): The input string for which characte... |
magic_evol_110k | 93,928 | Write a Python function to determine the number of days one must wait for a temperature increase for each day in a given sequence of daily temperatures. If no such day exists in the future, the value should be `0`. The function should start with:
```python
from typing import List
def daily_temperatures(temperatures: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def daily_temperatures(temperatures: List[int]) -> List[int]:
"""
Calculate the number of days to wait for a temperature increase for each day in the given sequence of daily temperatures.
Args:
... |
magic_evol_110k | 93,935 | Write a Python function to determine the frequency of each character in a given set of characters within a specified string. The function should return the result as a dictionary where the keys are the characters from the set and the values are their respective frequencies in the string. The function should be case-sen... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Set
def char_frequency(string: str, char_set: Set[str]) -> Dict[str, int]:
"""
Calculate the frequency of each character in a given set of characters within a specified string.
Args:
string... |
magic_evol_110k | 93,960 | Write a Python function to reorder a list of integers and decimal numbers in a peculiar manner. The peculiar ordering should adhere to the following rules:
1. Start with the smallest value.
2. Then, find the maximum among the remaining numbers.
3. After that, locate the smallest remaining number not yet in the output, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def peculiar_ordering(lst: List[Union[int, float, None]]) -> List[Union[int, float]]:
"""
Reorders a list of integers and decimal numbers in a peculiar manner.
The peculiar ordering follows t... |
magic_evol_110k | 93,973 | Write a Python function to count the frequency of each distinct word in a given sentence. The function should return a dictionary where the keys are the words and the values are the counts of those words in the sentence. The sentence should be case-insensitive, meaning that 'Word' and 'word' should be considered the sa... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def word_frequency(sentence: str) -> Dict[str, int]:
"""
Calculate the frequency of each distinct word in a given sentence.
Args:
sentence (str): The input sentence to analyze.
Returns:... |
magic_evol_110k | 93,978 | Write a Python function to determine if two given phrases contain the same set of unique words. The function should return `True` if the two phrases have the same unique words, regardless of the order or frequency of the words, and `False` otherwise.
The code should start with:
```python
def compare_word_sets(phrase1:... | Here is the Python code to solve the given problem in the markdown block:
```python
def compare_word_sets(phrase1: str, phrase2: str) -> bool:
"""
Determine if two phrases contain the same set of unique words.
Args:
phrase1 (str): The first phrase to compare.
phrase2 (str): The second phras... |
magic_evol_110k | 93,983 | Write a Python function to identify all distinct morphemic units that end with the specific alphabetic series "ing" in a given text. The function should be case-insensitive and should return a list of unique matches.
The code should start with:
```python
from typing import List
import re
def find_ing_morphemes(text: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def find_ing_morphemes(text: str) -> List[str]:
"""
Identify all distinct morphemic units that end with the specific alphabetic series "ing" in a given text.
Args:
text (str): The ... |
magic_evol_110k | 93,986 | Write a Python function to convert an array of floating-point numbers to their nearest whole numbers, but return 'Error' for any number outside the range of -100 to 100. Additionally, handle cases where the array is empty or null.
The function should start with:
```python
from typing import List, Union
def convert_fl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def convert_floats_to_nearest_whole(array: List[float]) -> List[Union[int, str]]:
"""
Converts an array of floating-point numbers to their nearest whole numbers.
Returns 'Error' for any number... |
magic_evol_110k | 93,997 | Write a Python function to simulate a series of deposit and withdrawal transactions on a banking account with an initial zero balance. The function should determine if the balance ever goes into deficit (below zero) and return a tuple containing a boolean indicating whether the balance went below zero and the final bal... | 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[int]) -> Tuple[bool, int]:
"""
Simulate a series of deposit and withdrawal transactions on a banking account with an initial zero balance.
Determine if the bala... |
magic_evol_110k | 94,004 | Write a Python function to create a dictionary that enumerates the square values of integers within a given range. The function should take two parameters: the starting integer (`start`) and the ending integer (`end`). The dictionary should map each integer in the range from `start` to `end` (inclusive) to its square v... | Here is the Python code to solve the given problem in the markdown block:
```python
def create_square_dictionary(start: int, end: int) -> dict:
"""
Create a dictionary that maps each integer in the range from `start` to `end` (inclusive) to its square value.
Args:
start (int): The starting integer ... |
magic_evol_110k | 94,008 | Write a Python function to compute the dynamic mean value of a provided numeric array consisting of statistical data. The dynamic mean at each step should be calculated as the cumulative sum of the elements up to that point divided by the number of elements up to that point. The function should return a list of these d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def dynamic_mean(data: List[float]) -> List[float]:
"""
Compute the dynamic mean value of a provided numeric array consisting of statistical data.
Args:
data (List[float]): The numeric array... |
magic_evol_110k | 94,033 | Write a Python function to match all numeric strings in a given text using regular expressions. The function should return a list of all numeric strings found in the text.
The code should start with:
```python
from typing import List
import re
def find_numeric_strings(text: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def find_numeric_strings(text: str) -> List[str]:
"""
Finds all numeric strings in the given text using regular expressions.
Args:
text (str): The input text in which to search for... |
magic_evol_110k | 94,039 | Write a Python function that performs the following operations on a given string:
1. Removes all leading and trailing spaces.
2. Replaces all consecutive spaces with a single `'%20'`.
3. Substitutes each instance of the characters `'a'`, `'b'`, `'c'` with their ASCII equivalents in hexadecimal format, maintaining case-... | Here is the Python code to solve the given problem in the markdown block:
```python
def substitute_string(input_string: str) -> str:
"""
Substitutes all spaces within the provided string with '%20', eliminates leading or trailing spaces,
and replaces instances of 'a', 'b', 'c', 'A', 'B', 'C' with their ASCI... |
magic_evol_110k | 94,041 | Write a Python function to identify identical elements present within two distinct sorted arrays. The function should not use any pre-existing Python methods for set operations or list comparisons. The elements in the arrays are distinct and not consecutive. The function 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_common_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Identifies identical elements present within two distinct sorted arrays.
Args:
list1 (List[int]): The first sor... |
magic_evol_110k | 94,067 | Write a Python function to calculate the geometric mean of a list of positive integers and determine which number in the list is closest to the geometric mean. If there is a tie for the closest number, the function should return the smallest of these numbers. The function should also validate that all elements in the l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_closest_to_geometric_mean(lst: List[int]) -> int:
"""
Calculate the geometric mean of a list of positive integers and return the number closest to the geometric mean.
If there is a tie, retu... |
magic_evol_110k | 94,084 | Write a Python function to calculate the square of a number, ensuring it complies with PEP 257 docstring standards and includes exception handling for error cases. The function should raise a custom `TypeError` if the input is not a number (int or float) and provide a meaningful error message.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
def square(n):
"""
Calculate the square of a number.
This function takes a single number as input and returns its square.
If the input is not a number (int or float), a TypeError is raised.
Args:
n (int or ... |
magic_evol_110k | 94,090 | Write a Python function to generate and return a list of the first N Fibonacci numbers. The function should handle cases where N is less than or equal to 0 by returning an empty list. The function should also handle cases where N is 1 by returning a list containing only the first Fibonacci number.
The code should star... | 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 and return a list of the first N Fibonacci numbers.
Args:
n (int): The number of Fibonacci numbers to generate.
Returns:
... |
magic_evol_110k | 94,103 | Write a Python function to rearrange the letters in a given string in alphabetical order. The function should handle strings of any length, including empty strings. The code should start with:
```python
def sort_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sort_string(s: str) -> str:
"""
Rearranges the letters in a given string in alphabetical order.
Args:
s (str): The input string to be sorted.
Returns:
str: The sorted string with letters in alphabet... |
magic_evol_110k | 94,115 | Write a Python function to convert a given string into its hexadecimal representation, where each byte is separated by a colon. The function should handle any string input and return the corresponding hexadecimal string.
The code should start with:
```python
def string_to_hex(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def string_to_hex(input_string: str) -> str:
"""
Converts a given string into its hexadecimal representation, with each byte separated by a colon.
Args:
input_string (str): The string to be converted into hexadecima... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.