source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 105,944 | Write a Python function to find the maximum value in a given list of numerical values without using Python's built-in `max()` function. The function should iterate through the list and keep track of the maximum value encountered so far. The code should start with:
```python
from typing import List
def find_max_value(l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_max_value(lst: List[int]) -> int:
"""
Find the maximum value in a given list of numerical values.
Args:
lst (List[int]): The list of numerical values.
Returns:
int: The... |
magic_evol_110k | 105,952 | Write a Python function to calculate the areas of triangles from a given list of tuples, where each tuple represents the base and height of a triangle. The function should exclude any triangles with negative base or height values and return a list of the areas of the valid triangles.
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, Tuple
def calculate_triangle_areas(triangle_list: List[Tuple[float, float]]) -> List[float]:
"""
Calculate the areas of triangles from a list of tuples, where each tuple represents the base and height o... |
magic_evol_110k | 105,969 | Write a Python function to calculate the total number of pens in multiple bags, given the number of black pens, red pens, and the total number of bags. Each bag contains the same number of black and red pens. The function should return the total number of pens across all bags.
The code should start with:
```python
def... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_total_pens(black_pens: int, red_pens: int, total_bags: int) -> int:
"""
Calculate the total number of pens in multiple bags.
Args:
black_pens (int): The number of black pens in each bag.
red_pe... |
magic_evol_110k | 105,970 | Write a Python function to determine if a loop completes without encountering a `break` statement. The function should accept an iterable and a predicate function as arguments. The predicate function will be used to determine if the loop should break. If the loop completes without breaking, the function should return `... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Callable, Iterable
def loop_completed_without_break(iterable: Iterable, predicate: Callable[[any], bool]) -> bool:
"""
Determines if a loop completes without encountering a break statement.
Args:
... |
magic_evol_110k | 105,986 | Write a Python function to shuffle elements in a numerical list by a single position to the right, preserving the sequence of adjacent elements. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def shuffle_list_right(arr: List[int]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def shuffle_list_right(arr: List[int]) -> List[int]:
"""
Shuffles the elements in a numerical list by a single position to the right.
Args:
arr (List[int]): The list of integers to be shuffl... |
magic_evol_110k | 105,988 | Write a Python function that takes a list of elements and returns a new list where each integer in the original list is incremented by 5, while non-integer elements remain unchanged. The function should handle potential programming anomalies such as modifying the list while iterating over it.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def increment_integers_by_five(lst: List[Any]) -> List[Any]:
"""
Returns a new list where each integer in the original list is incremented by 5,
while non-integer elements remain unchanged.
... |
magic_evol_110k | 105,994 | Write a Python function to sort an input vector of numerical integers in ascending order using a custom sorting algorithm. The function should implement the Bubble Sort algorithm. The code should start with:
```python
from typing import List
def custom_sort(input_vector: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def custom_sort(input_vector: List[int]) -> List[int]:
"""
Sorts the input vector of numerical integers in ascending order using the Bubble Sort algorithm.
Args:
input_vector (List[int]): ... |
magic_evol_110k | 105,998 | Write a Python function to classify a list of words into two categories: Positive or Negative. The function should take a list of words as input and return two lists: one containing the positive words and the other containing the negative words. The classification should be based on predefined sets of positive and nega... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def classify_words(data: List[str]) -> Tuple[List[str], List[str]]:
"""
Classify a list of words into positive and negative categories based on predefined sets of words.
Args:
data (L... |
magic_evol_110k | 106,010 | Write a Python function to print a 10x10 grid of stars, where each star is followed by a space, and each row has alternating colors (red and blue) for the stars. Use ANSI escape codes to set the text color. The function should start with:
```python
def print_colored_grid():
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def print_colored_grid():
"""
Prints a 10x10 grid of stars, where each star is followed by a space, and each row has alternating colors (red and blue) for the stars.
The colors are set using ANSI escape codes:
- Red: \0... |
magic_evol_110k | 106,017 | Write a Python function to substitute each occurrence of the alphabetical figure '0' with the symbol 'x' in a given bi-dimensional lattice (2D list) of alphanumerical constituents. The function should modify the input array in place and return the modified array.
The code 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 substitute_zeros_with_x(lattice: List[List[str]]) -> List[List[str]]:
"""
Substitutes each occurrence of the alphabetical figure '0' with the symbol 'x' in a given bi-dimensional lattice.
Args:
... |
magic_evol_110k | 106,020 | Write a Python function to calculate the frequency of each character in a given string, including spaces and punctuation. The function should return a dictionary where the keys are characters and the values are their respective frequencies. The code should start with:
```python
from typing import Dict
def character_fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def character_frequency(input_str: str) -> Dict[str, int]:
"""
Calculate the frequency of each character in the given string.
Args:
input_str (str): The input string for which character freq... |
magic_evol_110k | 106,026 | Write a Python function to generate all possible combinations of elements between two lists `l1` and `l2`. For each combination, compute the sum if both elements are numbers, or concatenate the elements if one of them is a character. The function should handle lists with mixed types (numbers and characters).
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def generate_combinations(l1: List[Union[int, float, str]], l2: List[Union[int, float, str]]) -> List[Union[int, float, str]]:
"""
Generate all possible combinations of elements between two lists.... |
magic_evol_110k | 106,027 | Write a Python function to find the first `n` twin prime pairs. A twin prime pair is a pair of prime numbers that differ by 2 (e.g., (3, 5), (5, 7)). The function should return a list of tuples, where each tuple represents a twin prime pair.
The code should start with:
```python
from typing import List, Tuple
def fin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
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 otherwis... |
magic_evol_110k | 106,032 | Write a Python function to remove duplicate characters from a given string while preserving the order of the first occurrence of each character. The function should return the modified string.
The code should start with:
```python
def remove_duplicates(string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_duplicates(string: str) -> str:
"""
Removes duplicate characters from the given string while preserving the order of the first occurrence of each character.
Args:
string (str): The input string from which... |
magic_evol_110k | 106,055 | Write a Python function to determine the day of the week for a given date and time. The function should accept a date and time in the format `YYYY-MM-DD HH:MM:SS` and return the corresponding day of the week as a string.
The code should start with:
```python
from datetime import datetime
def get_day_of_week(date_time... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def get_day_of_week(date_time_str: str) -> str:
"""
Determine the day of the week for a given date and time.
Args:
date_time_str (str): A string representing the date and time in the f... |
magic_evol_110k | 106,082 | Write a Python function that generates the factorial of each number in a given list of integers using a generator expression. The function should return a generator that yields the factorial of each number in the list.
The code should start with:
```python
from typing import List, Generator
import math
def generate_f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Generator
import math
def generate_factorials(numbers: List[int]) -> Generator[int, None, None]:
"""
Generates the factorial of each number in the given list of integers.
Args:
numbers (Lis... |
magic_evol_110k | 106,083 | Write a Python function to remove duplicate elements from a given list while preserving the order of the first occurrence of each element. The function should be optimized for time complexity to O(n) and should handle large datasets efficiently in terms of both memory and computational resources. The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates(lst: List[int]) -> List[int]:
"""
Removes duplicate elements from the given list while preserving the order of the first occurrence of each element.
Args:
lst (List[int... |
magic_evol_110k | 106,093 | Write a Python function that takes a list of dictionaries and a list of keys. The function should return a list of dictionaries with elements from the original dictionaries filtered by the list of keys provided. If a key is not found in a dictionary, the function should return an appropriate message with the dictionary... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Any
def filter_dictionaries(dictionaries: List[Dict[str, Any]], keys: List[str]) -> List[Dict[str, Any]]:
"""
Filters a list of dictionaries based on a list of keys. If a key is not found in a dic... |
magic_evol_110k | 106,114 | Write a Python function to replace every instance of the character '0' with the character 'x' in a given two-dimensional matrix composed of alphanumeric characters. The function should modify the matrix in place and return the modified matrix.
The code should start with:
```python
from typing import List
def replace_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def replace_zeros_with_x(matrix: List[List[str]]) -> List[List[str]]:
"""
Replace every instance of the character '0' with the character 'x' in a given two-dimensional matrix.
Args:
matrix (... |
magic_evol_110k | 106,117 | Write a Python function to compute the arithmetic mean of a given list of numerical values. The function should handle lists of any length, including empty lists. If the list is empty, the function should return `None` to indicate that the arithmetic mean cannot be calculated.
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, Optional
def compute_arithmetic_mean(numbers: List[int]) -> Optional[float]:
"""
Compute the arithmetic mean of a given list of numerical values.
Args:
numbers (List[int]): The list of nume... |
magic_evol_110k | 106,119 | Write a Python function to recursively search for a given value in a binary tree represented as a nested dictionary. The tree structure is defined such that each node is a dictionary with keys `"value"`, `"left"`, and `"right"`. The `"value"` key holds the node's value, and the `"left"` and `"right"` keys hold the left... | Here is the Python code to solve the given problem in the markdown block:
```python
def search_tree(tree: dict, value: int) -> bool:
"""
Recursively searches for a given value in a binary tree represented as a nested dictionary.
Args:
tree (dict): The binary tree represented as a nested dictionary.... |
magic_evol_110k | 106,121 | Write a Python function to calculate the standard deviation of a given list of numbers. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
import math
def calculate_standard_deviation(numbers: List[float]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def calculate_standard_deviation(numbers: List[float]) -> float:
"""
Calculate the standard deviation of a list of numbers.
Args:
numbers (List[float]): A list of numbers for whi... |
magic_evol_110k | 106,161 | Write a Python function to iterate through a list of integers and print each integer along with the result of dividing the next integer by the current integer. Handle potential exceptions such as division by zero and index out of range errors. The function should start with:
```python
from typing import List
def print... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_divisions_with_exceptions(numbers: List[int]) -> None:
"""
Iterates through a list of integers and prints each integer along with the result of dividing the next integer by the current integer.... |
magic_evol_110k | 106,170 | Write a Python function to generate a pattern based on the Fibonacci sequence, where each number in the sequence is appended to the previous sequence as a string. The function should take an integer `n` as input and return a string representing the pattern formed by the first `n` Fibonacci numbers.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_fibonacci_pattern(n: int) -> str:
"""
Generate a pattern based on the Fibonacci sequence, where each number in the sequence is appended to the previous sequence as a string.
Args:
n (int): The number of... |
magic_evol_110k | 106,172 | Write a Python function to generate and print all Fibonacci numbers within a specified range. The function should take two parameters: `min_value` and `max_value`, and print all Fibonacci numbers that fall within this range (inclusive). The function should start with:
```python
def print_fibonacci_in_range(min_value: i... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_fibonacci_in_range(min_value: int, max_value: int) -> None:
"""
Prints all Fibonacci numbers within the specified range [min_value, max_value].
Args:
min_value (int): The minimum value of the range (inclus... |
magic_evol_110k | 106,180 | Write a Python function to generate the first `n` prime numbers using a do-while loop structure. The function should return a list of the first `n` prime numbers. The code should start with:
```python
from typing import List
def generate_first_n_primes(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(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 | 106,184 | Write a Python function to find the nth ugly number. An ugly number is defined as a positive integer whose prime factors are exclusively `2`, `3`, and/or `5`. The function should start with:
```python
def nth_ugly_number(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def nth_ugly_number(n: int) -> int:
"""
Find the nth ugly number. An ugly number is a positive integer whose prime factors are exclusively 2, 3, and/or 5.
Args:
n (int): The position of the ugly number to find.
... |
magic_evol_110k | 106,194 | Write a Python function to calculate the mean and median of each list in a given dictionary. The dictionary contains keys representing categories and values as lists of numerical data. If a list is empty, the function should return "N/A" for both mean and median. The function should start with:
```python
from typing im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Union
def calculate_statistics(data: Dict[str, List[int]]) -> Dict[str, Dict[str, Union[float, str]]]:
"""
Calculate the mean and median for each list in the given dictionary.
Args:
d... |
magic_evol_110k | 106,198 | Write a Python function to clamp the values of RGB components to ensure they do not exceed 255. The function should take three integers representing the red, green, and blue components of a color and return a tuple of the clamped values. The clamped values should be the minimum of the input value and 255.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
def clamp_rgb(r: int, g: int, b: int) -> tuple:
"""
Clamps the RGB values to ensure they do not exceed 255.
Args:
r (int): The red component of the color.
g (int): The green component of the color.
b... |
magic_evol_110k | 106,207 | Write a Python function to solve a sequence of mathematical equations given in an array of strings. Each equation can contain parentheses, and the operations include addition, subtraction, multiplication, division, and exponentiation. The exponentiation operator is represented as "^". The function should return a list ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def solve_equations(equations: List[str]) -> List[float]:
"""
Solves a sequence of mathematical equations given in an array of strings.
Each equation can contain parentheses, and the operations inclu... |
magic_evol_110k | 106,211 | Write a Python function to compute the summation of distinct numeric magnitudes, multiplied by the aggregate of their respective signs, from a given array of non-zero integers. The function should return `None` if the array is empty or contains only zero elements. The function 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, Optional
def numeric_signs(array: List[int]) -> Optional[int]:
"""
Computes the summation of distinct numeric magnitudes, multiplied by their respective signs, from a given array of non-zero integers.
... |
magic_evol_110k | 106,226 | Write a Python function to generate an array containing exactly five distinctive integers that fall within the numerical range of 1 to 15. The function should ensure that the integers are unique and within the specified range. The code should start with:
```python
from typing import List
import random
def generate_dis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_distinctive_integers() -> List[int]:
"""
Generates an array containing exactly five distinctive integers within the range of 1 to 15.
Returns:
List[int]: A list co... |
magic_evol_110k | 106,227 | Write a Python function to calculate the total points scored by a basketball player based on the number of successful shots and the points per shot. Additionally, create a function to determine the total number of basketballs if given the counts of old and new basketballs. Finally, create a function to calculate the co... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_total_points(shots: int, points_per_shot: int) -> int:
"""
Calculate the total points scored by a player based on the number of successful shots and the points per shot.
Args:
shots (int): The number o... |
magic_evol_110k | 106,247 | Write a Python function to reverse the digits of a given integer. The function should handle both positive and negative integers. If the input number is negative, the function should return the reversed number with a negative sign. The code should start with:
```python
def reverse_integer(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_integer(n: int) -> int:
"""
Reverses the digits of a given integer. If the input number is negative, the reversed number will also be negative.
Args:
n (int): The integer to be reversed.
Returns:
... |
magic_evol_110k | 106,254 | Write a Python function to count the frequency of a given number in a list. The function should take two parameters: a list of integers and a single integer to count its occurrences in the list. The function should return an integer representing the frequency of the given number in the list.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_frequency(arr: List[int], num: int) -> int:
"""
Counts the frequency of a given number in a list.
Args:
arr (List[int]): The list of integers in which to count the frequency.
... |
magic_evol_110k | 106,260 | Write a Python function to validate a JSON object against a given JSON schema. The function should return `True` if the JSON object is valid according to the schema, and `False` otherwise. The JSON schema is provided as a dictionary and the JSON object is provided as a dictionary.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
from jsonschema import Draft7Validator, ValidationError
def validate_json_against_schema(json_object: Dict, schema: Dict) -> bool:
"""
Validates a JSON object against a given JSON schema.
Args:
... |
magic_evol_110k | 106,261 | Write a Python function to convert a measurement of pressure from atmospheres (atm) to its equivalent in pascals (Pa). The conversion factor from atmospheres to pascals is 1 atm = 101325 Pa. The function should handle both positive and negative values of pressure in atmospheres.
The code should start with:
```python
d... | Here is the Python code to solve the given problem in the markdown block:
```python
def atm_to_pa(atm: float) -> float:
"""
Convert a measurement of pressure from atmospheres (atm) to pascals (Pa).
Args:
atm (float): The pressure in atmospheres.
Returns:
float: The equivalent pressure ... |
magic_evol_110k | 106,272 | Write a Python function to find the longest common subsequence (LCS) of two given strings. The function should return the length of the LCS.
The code should start with:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
"""
Calculate the length of the longest common subsequence (LCS) of two given strings.
Args:
str1 (str): The first string.
str2 (str): The secon... |
magic_evol_110k | 106,275 | 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 | 106,296 | Write a Python function to find both the highest and lowest values from a list of integers without using built-in `min` and `max` functions. The function should handle lists of varying lengths and elements, including an empty list, a list with all identical elements, and a list with negative elements. The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Optional
def find_min_max(lst: List[int]) -> Tuple[Optional[int], Optional[int]]:
"""
Find the minimum and maximum values from a list of integers without using built-in min and max functions.
... |
magic_evol_110k | 106,300 | Write a Python function to calculate and return the prime factors of a given positive integer. The function should handle any positive integer input and return a list of its prime factors in ascending order.
The code should start with:
```python
from typing import List
def prime_factors(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def prime_factors(n: int) -> List[int]:
"""
Calculate and return the prime factors of a given positive integer.
Args:
n (int): The positive integer for which to find the prime factors.
... |
magic_evol_110k | 106,301 | Write a Python function to generate a random number between two given input numbers, inclusive of both endpoints. The function should handle cases where the start number is greater than the end number by swapping them. Additionally, the function should ensure that the input numbers are integers. If the input is not val... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Optional
import random
def generate_random_number(start: int, end: int) -> Optional[int]:
"""
Generates a random integer between the given start and end values, inclusive.
If the start value is greater th... |
magic_evol_110k | 106,320 | Write a Python function to reorder a given array in decreasing order without using any built-in sorting methods. The function should not modify the original array and should use a custom sorting algorithm. The code should start with:
```python
from typing import List
def reorder_descendant(array: List[int]) -> List[in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reorder_descendant(array: List[int]) -> List[int]:
"""
Reorders the given array in decreasing order using a custom sorting algorithm.
Args:
array (List[int]): The array to be reordered.
... |
magic_evol_110k | 106,324 | Write a Python function to generate an array where each element is the maximum value of the corresponding row in a given input matrix. The input matrix is a 2D list of integers. The function should start with:
```python
from typing import List
def max_values_in_rows(matrix: List[List[int]]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_values_in_rows(matrix: List[List[int]]) -> List[int]:
"""
Generates an array where each element is the maximum value of the corresponding row in the input matrix.
Args:
matrix (List[... |
magic_evol_110k | 106,325 | Write a Python function to identify and categorize the datatype of a given input parameter. The function should return a string that describes the category of the datatype. The categories include 'Integer', 'Float', 'String', 'Boolean', 'Tuple', 'List', 'Dictionary', 'Set', 'None', and 'Unknown' for any other types.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
def identify_datatype(value) -> str:
"""
Identifies and categorizes the datatype of a given input parameter.
Args:
value: The input parameter whose datatype needs to be identified.
Returns:
str: A strin... |
magic_evol_110k | 106,327 | Write a Python function to find the first occurrence of a substring in a given string using a `for` loop. The function should return the starting index of the substring if it is found, otherwise return -1. The function should handle edge cases such as an empty substring or an empty string.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_substring(main_string: str, sub_string: str) -> int:
"""
Find the first occurrence of a substring in a given string using a for loop.
Args:
main_string (str): The main string in which to search for the subs... |
magic_evol_110k | 106,335 | Write a Python function to generate a sequence of Fibonacci numbers up to the nth place. The function should be able to identify and correct any erroneous values in the sequence. The function should also be able to handle large values of n efficiently.
The code should start with:
```python
from typing import List
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci_sequence(n: int) -> List[int]:
"""
Generates a Fibonacci sequence up to the nth place and corrects any erroneous values.
Args:
n (int): The number of Fibonacci numbers... |
magic_evol_110k | 106,343 | Write a Python function to calculate the square of the successor of a given number. The function should take an integer as input and return the square of the successor of that integer. The successor of a number `x` is defined as `x + 1`.
The code should start with:
```python
def square_of_successor(x: int) -> int:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
def square_of_successor(x: int) -> int:
"""
Calculate the square of the successor of a given integer.
The successor of a number x is defined as x + 1. This function calculates
the square of this successor.
Args:
... |
magic_evol_110k | 106,345 | Write a Python function to implement the Gnome Sort algorithm, which sorts a list of integers in ascending order. The function should return the sorted list. The code should start with:
```python
from typing import List
def gnome_sort(array: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def gnome_sort(array: List[int]) -> List[int]:
"""
Sorts the given list of integers using the Gnome Sort algorithm.
Args:
array (List[int]): The list of integers to be sorted.
Returns:
... |
magic_evol_110k | 106,352 | Write a Python function to reverse the order of command-line arguments and check for invalid inputs. A valid input contains only alphanumeric characters. If an invalid input is detected, the function should display an error message and return an empty list. The function should start with:
```python
from typing import L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_args_and_validate(args: List[str]) -> List[str]:
"""
Reverses the order of command-line arguments and checks for invalid inputs.
A valid input contains only alphanumeric characters. If an... |
magic_evol_110k | 106,353 | Write a Python function to rotate a given square matrix in a clockwise direction by a specified number of positions. The function should handle errors and manage various types of entries. The function should start with:
```python
from typing import List
def rotate_matrix(matrix: List[List[int]], positions: int) -> Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def rotate_matrix(matrix: List[List[int]], positions: int) -> List[List[int]]:
"""
Rotates a given square matrix in a clockwise direction by a specified number of positions.
Args:
matrix (Li... |
magic_evol_110k | 106,355 | Implement a binary search algorithm to find the index of a given element in a sorted array without using any built-in binary search methods. If the array is not sorted, sort it first. Additionally, correct the provided erroneous code to ensure it works correctly.
The code 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 binary_search(arr: List[int], x: int) -> int:
"""
Perform a binary search to find the index of a given element in a sorted array.
If the array is not sorted, it will be sorted first.
Args:
... |
magic_evol_110k | 106,370 | Write a Python function to determine if the sum of all integers in a given list falls within a specified range, inclusive of the boundaries. The function should return `True` if the sum is within the range, and `False` otherwise.
The code should start with:
```python
from typing import List
def sum_within_bounds(l: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_within_bounds(l: List[int], lower_bound: int, upper_bound: int) -> bool:
"""
Determine if the sum of all integers in the list falls within the specified range, inclusive of the boundaries.
A... |
magic_evol_110k | 106,372 | Write two Python functions to sort the keys of a dictionary in an increasing sequence. The first function should ignore special characters when sorting, while the second function should include special characters in sorting. If the value is an integer, it should be listed first before alphabetical ordering. The functio... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
import re
def sort_dict_ignore_special_chars(myDict: Dict[str, int]) -> List[Tuple[str, int]]:
"""
Sorts the keys of a dictionary in increasing sequence, ignoring special characters.
Int... |
magic_evol_110k | 106,375 | Write a Python function to perform a groupby operation on a CSV file and calculate the mean of each group. The function should read the CSV file, group the data by a specified column, calculate the mean for each group, and save the processed data back to a CSV file. The code should start with:
```python
from typing imp... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import pandas as pd
def groupby_mean(input_file: str, output_file: str, groupby_column: str) -> None:
"""
Perform a groupby operation on a CSV file and calculate the mean of each group.
Save the pr... |
magic_evol_110k | 106,376 | Write a Python function to determine the appropriate URL pattern for a Django view based on the type of primary key (PK) used in the database model. The function should take the primary key type and the view name as input and return the corresponding URL pattern as a string. The primary key types to be considered are `... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_url_pattern(pk_type: str, view_name: str) -> str:
"""
Determine the appropriate URL pattern for a Django view based on the type of primary key.
Args:
pk_type (str): The type of the primary key, which can be ... |
magic_evol_110k | 106,378 | Write a Python function to create a dictionary from a given tuple where each element of the tuple acts as the key and its index as the value. The function should be optimized for larger inputs and should handle edge cases such as empty tuples.
The code should start with:
```python
from typing import Tuple, Dict
def c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict
def create_dict_from_tuple(tup: Tuple) -> Dict:
"""
Creates a dictionary from a given tuple where each element of the tuple acts as the key and its index as the value.
Args:
tup (Tupl... |
magic_evol_110k | 106,397 | Write a Python function that prints numbers from 1 to a given positive integer `n` and classifies each number as either "Fizz", "Buzz", "FizzBuzz", or its actual value based on the following rules:
- If the number is divisible by 3, print "Fizz".
- If the number is divisible by 5, print "Buzz".
- If the number is divis... | Here is the Python code to solve the given problem in the markdown block:
```python
def fizz_buzz(n: int) -> None:
"""
Prints numbers from 1 to n and classifies each number as "Fizz", "Buzz", "FizzBuzz", or its actual value.
Args:
n (int): The upper limit of the range of numbers to classify.
R... |
magic_evol_110k | 106,398 | Write a Python function to determine if a specific integer value exists within a given array of integer elements. The function should return `True` if the value exists in the array, and `False` otherwise. The code should start with:
```python
from typing import List
def value_exists_in_array(array: List[int], value: i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def value_exists_in_array(array: List[int], value: int) -> bool:
"""
Determines if a specific integer value exists within a given array of integer elements.
Args:
array (List[int]): The arra... |
magic_evol_110k | 106,405 | Write a Python function to generate and print the multiplication table for all numbers up to a given limit `n`. The function should ensure that only valid multiplication results are printed and should handle any potential errors gracefully. The function should start with:
```python
def print_multiplication_table(n: int... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_multiplication_table(n: int) -> None:
"""
Generates and prints the multiplication table for all numbers up to a given limit `n`.
Args:
n (int): The limit up to which the multiplication table should be gene... |
magic_evol_110k | 106,409 | Write a Python function to generate a string sequence from 0 to a given integer `n`, inclusive. The sequence should be a single string where each number is separated by a space. The function should handle the input validation to ensure `n` is a non-negative integer.
The code should start with:
```python
def generate_s... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_sequence(n: int) -> str:
"""
Generates a string sequence from 0 to the given integer n, inclusive.
Each number in the sequence is separated by a space.
Args:
n (int): The upper limit of the sequence... |
magic_evol_110k | 106,410 | Write a Python function to calculate the product of a sequence of numbers generated by a while loop. The function should start with a predefined product and a multiplier, and it should update the product during the second iteration of the loop. The loop should run for a specified number of iterations. The function shou... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_product(iterations: int, initial_product: int, multiplier: int) -> int:
"""
Calculate the product of a sequence of numbers generated by a while loop.
The product is updated during the second iteration of the lo... |
magic_evol_110k | 106,427 | Write a Python function to sort each row of a given matrix in ascending order without using any built-in sorting functions. The matrix should retain its original number of rows and columns after sorting. The function should start with:
```python
from typing import List
def sort_matrix_rows(matrix: List[List[int]]) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_matrix_rows(matrix: List[List[int]]) -> List[List[int]]:
"""
Sorts each row of the given matrix in ascending order without using built-in sorting functions.
Args:
matrix (List[List[... |
magic_evol_110k | 106,435 | Write a Python function to filter out blog posts with more than 50 comments from a given stream of blog posts and categorize these posts based on their source website. The function should return a dictionary where the keys are the source websites and the values are lists of posts from that source.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Any
def categorize_popular_posts(stream_of_blog_posts: List[Dict[str, Any]]) -> Dict[str, List[Dict[str, Any]]]:
"""
Filters out blog posts with more than 50 comments and categorizes them based on... |
magic_evol_110k | 106,437 | Write a Python function to determine if a given value is considered "falsy" in Python. A value is considered "falsy" if it evaluates to `False` in a boolean context. The function should return `True` if the value is falsy and `False` otherwise. The function should handle various types of inputs, including `None`, `Fals... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_falsy(value) -> bool:
"""
Determine if a given value is considered "falsy" in Python.
A value is considered "falsy" if it evaluates to `False` in a boolean context.
Common falsy values include `None`, `False`, `0... |
magic_evol_110k | 106,440 | Write a Python function to determine if a given string consists of exactly 5 alphabetic characters. The function should return `True` if the string meets the criteria and `False` otherwise. The code should start with:
```python
def is_five_alpha_chars(appellation: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_five_alpha_chars(appellation: str) -> bool:
"""
Determines if a given string consists of exactly 5 alphabetic characters.
Args:
appellation (str): The string to be checked.
Returns:
bool: True if... |
magic_evol_110k | 106,446 | Write a Python function to convert a timestamp in the 24-hour military time format into its equivalent in the standardized 12-hour civilian time format. The input is a string representing the time in the format "HHMM" (e.g., "1730" for 5:30 PM). The output should be a string in the format "HH:MM AM/PM" (e.g., "05:30 PM... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_time_to_12_hour(time: str) -> str:
"""
Converts a timestamp in the 24-hour military time format to the 12-hour civilian time format.
Args:
time (str): A string representing the time in the format "HHMM" ... |
magic_evol_110k | 106,449 | Write a Python function to count the frequency of each unique word in a given text string and return the result as a dictionary. The keys of the dictionary should be the unique words, and the values should be the number of times each word appears in the input string. The function should handle case sensitivity and punc... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import string
def word_frequency(input_string: str) -> Dict[str, int]:
"""
Counts the frequency of each unique word in the given input string and returns the result as a dictionary.
Args:
in... |
magic_evol_110k | 106,462 | Write a Python function to generate a sequence of numbers where each element is twice the value of its position index (starting from 1). The function should return the sequence up to the nth element. Additionally, create a function to find the nth element in this sequence.
The code should start with:
```python
from ty... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_nth_element(n: int) -> int:
"""
Find the nth element in the sequence where each element is twice its position index (starting from 1).
Args:
n (int): The position index of the eleme... |
magic_evol_110k | 106,485 | Write a Python function to create a 4x4x4 tridimensional tensor using Numpy, populated with random decimal values between -1 and 1. The function should also allow setting a seed for reproducibility. The code should start with:
```python
import numpy as np
def create_random_tensor(seed: int = None) -> np.ndarray:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def create_random_tensor(seed: int = None) -> np.ndarray:
"""
Create a 4x4x4 tridimensional tensor populated with random decimal values between -1 and 1.
Args:
seed (int, optional): Seed for the ... |
magic_evol_110k | 106,489 | Write a Python function to merge `k` sorted integer arrays into one sorted array. Each array `nums[i]` has a specified number of elements `n[i]`. The final merged array should have a size equal to the sum of `n[i]` for all `i`.
The code should start with:
```python
from typing import List
def merge_sorted_arrays(nums... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import heapq
def merge_sorted_arrays(nums: List[List[int]], n: List[int]) -> List[int]:
"""
Merge `k` sorted integer arrays into one sorted array.
Args:
nums (List[List[int]]): A list of `k`... |
magic_evol_110k | 106,518 | Write a Python function to locate and isolate each word starting with a specified letter in a given statement. The function should return a list of words that start with the specified letter. The code should start with:
```python
from typing import List
def find_words_starting_with(statement: str, letter: str) -> List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_words_starting_with(statement: str, letter: str) -> List[str]:
"""
Locate and isolate each word starting with the specified letter in the given statement.
Args:
statement (str): The... |
magic_evol_110k | 106,528 | Write a Python function to count the number of consonants in a given input string. The function should be case-insensitive and should only count the consonants from the English alphabet. The code should start with:
```python
def consonant_count(s: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def consonant_count(s: str) -> int:
"""
Count the number of consonants in the given input string.
Args:
s (str): The input string to count consonants from.
Returns:
int: The total number of consonants p... |
magic_evol_110k | 106,529 | Write a Python function to check if two given strings are anagrams of each other without using built-in library functions or data structures. Additionally, the function should count and print out the frequency of each character in both strings. The function must also ensure that the two strings do not contain any non-a... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_anagram_and_frequency(s1: str, s2: str) -> bool:
"""
Check if two given strings are anagrams of each other and print the frequency of each character.
Args:
s1 (str): The first string to check.
s2 (... |
magic_evol_110k | 106,534 | Write a Python function to calculate the nth Fibonacci number using recursion and memoization to optimize performance. The function should handle edge cases correctly, such as non-positive integers and large values of n. The code should start with:
```python
def fibonacci(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci(n: int, memo: dict = {}) -> int:
"""
Calculate the nth Fibonacci number using recursion and memoization.
Args:
n (int): The position in the Fibonacci sequence to calculate.
memo (dict): A dicti... |
magic_evol_110k | 106,539 | Write a Python function to calculate the average of a list of numbers. The function should handle an empty list by returning 0. The code should start with:
```python
from typing import List
def calculate_average(numbers: List[float]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_average(numbers: List[float]) -> float:
"""
Calculate the average of a list of numbers.
Args:
numbers (List[float]): A list of numbers for which to calculate the average.
... |
magic_evol_110k | 106,540 | Write a Python function to sort a list of mixed variable types (integers, strings, and booleans) such that only the strings are sorted alphabetically, while preserving the original order of non-string variables. The function should handle lists containing integers, strings, and booleans. 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 sort_mixed_list(lst: List[Union[int, str, bool]]) -> List[Union[int, str, bool]]:
"""
Sorts a list of mixed variable types (integers, strings, and booleans) such that only the strings are sort... |
magic_evol_110k | 106,564 | Create a Python function that initializes a dictionary with twenty discrete associative entries involving key-value pairs of varying data types (such as strings, integers, floats, lists, and other dictionaries). The function should then perform at least five operations including retrieval, update, deletion of elements,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def manipulate_dictionary() -> Dict[Any, Any]:
"""
Initializes a dictionary with twenty key-value pairs of varying data types,
performs several operations on it, and returns the final state of t... |
magic_evol_110k | 106,571 | Write a Python function to generate a list of dictionaries, where each dictionary represents a day of the week starting from a given date. Each dictionary should contain the day of the week (as a string) and the corresponding date (as a `datetime.date` object). 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 List, Dict
import datetime
def generate_week_dates(start_date: datetime.date) -> List[Dict[str, datetime.date]]:
"""
Generates a list of dictionaries representing each day of the week starting from a given da... |
magic_evol_110k | 106,578 | Write a Python function to sort a list of tuples based on the length of the second element in each tuple. The function should return the sorted list. The code should start with:
```python
from typing import List, Tuple
def sort_tuples_by_second_element_length(list_of_tuples: List[Tuple[str, str]]) -> List[Tuple[str, s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_tuples_by_second_element_length(list_of_tuples: List[Tuple[str, str]]) -> List[Tuple[str, str]]:
"""
Sorts a list of tuples based on the length of the second element in each tuple.
A... |
magic_evol_110k | 106,583 | Write a Python function to organize a list of strings in alphabetical order, ignoring case sensitivity, and remove any duplicate entries. The function should return a new list with the sorted and unique strings.
The code should start with:
```python
from typing import List
def sort_and_remove_duplicates(strings: List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_and_remove_duplicates(strings: List[str]) -> List[str]:
"""
Organizes a list of strings in alphabetical order, ignoring case sensitivity, and removes any duplicate entries.
Args:
st... |
magic_evol_110k | 106,584 | Write a Python function to simulate the shard rerouting process in an Elasticsearch cluster. The function should take the index name, shard number, source node, and destination node as inputs and return a dictionary representing the reroute command. The function should also validate the inputs to ensure they are non-em... | Here is the Python code to solve the given problem in the markdown block:
```python
def simulate_shard_reroute(index: str, shard: int, from_node: str, to_node: str) -> dict:
"""
Simulate the shard rerouting process in an Elasticsearch cluster.
Args:
index (str): The name of the index whose shard is... |
magic_evol_110k | 106,586 | Write a Python function to transform a given two-dimensional matrix into a one-dimensional list and rearrange the list such that all prime numbers are at the beginning and all non-prime numbers are at the end, while maintaining the relative order of the numbers from the original matrix. The function should handle negat... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Check if a given number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise... |
magic_evol_110k | 106,593 | Write a Python function to find all prime numbers within a given range using the Sieve of Sundaram algorithm. The function should efficiently compute and return a list of prime numbers between the specified lower and upper bounds (inclusive).
The code should start with:
```python
from typing import List
def sieve_of_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sieve_of_sundaram(lower: int, upper: int) -> List[int]:
"""
Find all prime numbers within a given range using the Sieve of Sundaram algorithm.
Args:
lower (int): The lower bound of the r... |
magic_evol_110k | 106,594 | Write a Python function to find the sum of all 0 to 9 pandigital numbers that satisfy the unique sub-string divisibility property. A pandigital number is a number that contains each of the digits 0 through 9 exactly once. The sub-string divisibility property is defined as follows:
- The substring formed by the 2nd, 3rd... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import itertools
def sum_pandigital_numbers_with_property() -> int:
"""
Calculate the sum of all 0 to 9 pandigital numbers that satisfy the sub-string divisibility property.
Returns:
int: Th... |
magic_evol_110k | 106,600 | Write a Python function to determine if a given string `s` is a `k`-palindrome and contains a specified substring `sub`. A string is considered a `k`-palindrome if it can be transformed into a palindrome by removing at most `k` characters from it. The function should return `true` if both conditions are met, otherwise ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_k_palindrome_substring(s: str, k: int, sub: str) -> bool:
"""
Determines if the string `s` is a `k`-palindrome and contains the substring `sub`.
Args:
s (str): The input string to check.
k (int)... |
magic_evol_110k | 106,647 | Write a Python function to determine if a given integer is a prime number using an optimized approach. The function should return `True` if the number is prime and `False` otherwise. The optimization should include checking divisibility up to the square root of the number and skipping even numbers and multiples of 3.
... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def is_prime(n: int) -> bool:
"""
Determines if a given integer is a prime number using an optimized approach.
Args:
n (int): The integer to check for primality.
Returns:
bool: True if the ... |
magic_evol_110k | 106,655 | Write a Python function to categorize the values in a given dictionary based on their types. The function should return a dictionary where the keys are the types of the values found in the input dictionary, and the values are lists of the corresponding values from the input dictionary.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Any
def categorize_values(entity: Dict[str, Any]) -> Dict[type, List[Any]]:
"""
Categorizes the values in a given dictionary based on their types.
Args:
entity (Dict[str, Any]): The i... |
magic_evol_110k | 106,677 | Write a Python function to calculate the maximum disparity between the smallest and the largest elements in each sub-array of a given two-dimensional integer array. The disparity for each sub-array is defined as the difference between the maximum and minimum values within that sub-array. The function should return a li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_max_disparities(two_dim_arr: List[List[int]]) -> List[int]:
"""
Calculate the maximum disparity between the smallest and the largest elements in each sub-array of a given two-dimensional in... |
magic_evol_110k | 106,680 | Write a Python function to concatenate two strings and remove duplicate alphabetic characters from the resultant string, while preserving the order of their first appearance. The function should ignore any special characters and numbers. The resultant string should be in lowercase.
The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import OrderedDict
def concatenate_alphabets(str1: str, str2: str) -> str:
"""
Concatenates two strings and removes duplicate alphabetic characters from the resultant string,
while p... |
magic_evol_110k | 106,718 | Write a Python function to generate the Collatz sequence starting from a positive integer `n` up to 1 and count the number of steps taken to reach 1. The function should handle multiple inputs stored in a list and return an output for each of them as a list of tuples. Each tuple should contain the generated Collatz seq... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
# Define a global dictionary to store previously computed results
collatz_dict = {1: ([1], 0)}
def collatz(n: int) -> Tuple[List[int], int]:
"""
Generate the Collatz sequence starting from a posi... |
magic_evol_110k | 106,721 | Write a Python function to calculate the average of a list of numbers. The function should take a list of integers as input and return the average as a float. The code should start with:
```python
from typing import List
def calculate_average(numbers: List[int]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_average(numbers: List[int]) -> float:
"""
Calculate the average of a list of integers.
Args:
numbers (List[int]): A list of integers for which the average is to be calculated.
... |
magic_evol_110k | 106,722 | Write a Python function to aggregate user aliases from a list of tuples into a dictionary where each key is a `UserId` and the value is a comma-separated string of aliases. The input is a list of tuples, where each tuple contains a `UserId` and an `Alias`. The function should return a dictionary with the aggregated ali... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def aggregate_user_aliases(aliases: List[Tuple[int, str]]) -> Dict[int, str]:
"""
Aggregates user aliases from a list of tuples into a dictionary.
Args:
aliases (List[Tuple[int,... |
magic_evol_110k | 106,725 | Write a Python function to implement a linear search algorithm that locates a specific element within a one-dimensional array or list. The function should return the index of the first occurrence of the element if it is found, otherwise, it should return -1. The code should start with:
```python
from typing import List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def linear_search(array: List[int], search_value: int) -> int:
"""
Perform a linear search to find the index of the first occurrence of a specific element in the array.
Args:
array (List[int... |
magic_evol_110k | 106,732 | Write a Python function that takes in two lists of varying length and returns both the common and unique items between the two lists. The common items should be returned in one list, and the unique items should be returned in a separate list. Do this without using Python's built-in set data structure. The function shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_common_and_unique_items(list1: List[int], list2: List[int]) -> Tuple[List[int], List[int]]:
"""
Finds the common and unique items between two lists without using Python's built-in set dat... |
magic_evol_110k | 106,735 | Write a Python function to count the occurrence rate of each distinct alphabetic character in a given linguistic phrase, considering both uppercase and lowercase characters as the same. The function should return a dictionary where the keys are the characters and the values are their respective counts. The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import Counter
from typing import Dict
def count_character_occurrences(phrase: str) -> Dict[str, int]:
"""
Count the occurrence rate of each distinct alphabetic character in the given phrase.
Args:
... |
magic_evol_110k | 106,738 | Write a Python function to determine whether a given input string represents a valid numerical value. The function should handle various edge cases, including empty strings, strings with leading/trailing spaces, and strings containing non-numeric characters. The function should return `True` if the input string represe... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_number(input_str: str) -> bool:
"""
Determines whether the given input string represents a valid numerical value.
Args:
input_str (str): The input string to be checked.
Returns:
bool: True ... |
magic_evol_110k | 106,742 | Write a Python function to filter out elements from a given list that are less than a specified threshold. The function should return a new list containing only the elements that are greater than or equal to the threshold. The code should start with:
```python
from typing import List
def filter_by_threshold(numbers: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_by_threshold(numbers: List[int], threshold: int) -> List[int]:
"""
Filters out elements from the given list that are less than the specified threshold.
Args:
numbers (List[int]): ... |
magic_evol_110k | 106,758 | Write a Python function to find the Nth prime number. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The function should be efficient and correctly handle edge cases.
The code should start with:
```python
def nth_prime(N: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def nth_prime(N: int) -> int:
"""
Returns the Nth prime number.
Args:
N (int): The position of the prime number to find.
Returns:
int: The Nth prime number.
"""
def is_prime(n: int) -> bool:
... |
magic_evol_110k | 106,773 | Write a Python function to remove all instances of a specified number from a given list. The function should return a new list that contains all elements from the original list except the specified number. The code should start with:
```python
from typing import List
def remove_all_instances(lst: List[int], num: int) ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_all_instances(lst: List[int], num: int) -> List[int]:
"""
Removes all instances of the specified number from the given list.
Args:
lst (List[int]): The list from which to remove t... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.