source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 3,049 | Write a Python function to reverse the order of words in a given string. The function should handle strings with multiple spaces between words and leading/trailing spaces. The code should start with:
```python
def reverse_words_order(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_words_order(s: str) -> str:
"""
Reverses the order of words in a given string.
Args:
s (str): The input string containing words to be reversed.
Returns:
str: A string with the words in rev... |
evol_instruct_66k | 3,051 | Write a Python function to calculate the number of ways to reach the bottom-right corner of a grid from the top-left corner, moving only right or down, given the dimensions of the grid. The function should handle grids of any size, including those with a single row or column.
The code should start with:
```python
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_paths(m: int, n: int) -> int:
"""
Calculate the number of ways to reach the bottom-right corner of an m x n grid
from the top-left corner, moving only right or down.
Args:
m (int): The number of rows i... |
evol_instruct_66k | 3,053 | Write a Python function to encode a text string using the ROT13 cipher, which shifts each letter by 13 positions in the alphabet while maintaining case sensitivity and preserving non-alphabetic characters. Additionally, create a corresponding ROT13 decoding function to reverse the encoded string back to its original fo... | Here is the Python code to solve the given problem in the markdown block:
```python
def rot13_encode(text: str) -> str:
"""
Encodes the given text using the ROT13 cipher.
Args:
text (str): The text to be encoded.
Returns:
str: The ROT13 encoded text.
"""
encoded_text = []
... |
evol_instruct_66k | 3,061 | Write a Python function to reorganize an array of non-negative integers based on the length of their binary representations. The array should be sorted first by the length of the binary representation of each number, and if two numbers have the same binary length, they should be sorted by their decimal value. The funct... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_by_binary_len(arr: List[int]) -> List[int]:
"""
Reorganizes an array of non-negative integers based on the length of their binary representations.
Numbers are sorted first by the length of t... |
evol_instruct_66k | 3,074 | 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... |
evol_instruct_66k | 3,081 | Write a Python function to filter out and return the even-valued integers from a given list of heterogeneous odd and even integers using the Sieve of Eratosthenes algorithm. The function should start with:
```python
from typing import List
def sieve_of_eratosthenes_even_numbers(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 sieve_of_eratosthenes_even_numbers(arr: List[int]) -> List[int]:
"""
Filters and returns the even-valued integers from a given list of heterogeneous odd and even integers.
Args:
arr (Lis... |
evol_instruct_66k | 3,083 | Write a Python function to find the item that is positioned immediately before the very last element within a given tuple. The function should take a tuple as input and return the second-to-last element.
The code should start with:
```python
from typing import Tuple, Any
def find_item_before_last(items: Tuple[Any, ..... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Any
def find_item_before_last(items: Tuple[Any, ...]) -> Any:
"""
Find the item that is positioned immediately before the very last element within a given tuple.
Args:
items (Tuple[Any, ..... |
evol_instruct_66k | 3,103 | Write a Python function to calculate the average rating of movies from a given list of movie ratings. Each movie rating is represented as a dictionary with the movie's title and its rating out of five stars. The function should return a dictionary with the average rating rounded to two decimal places and the number of ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def calculate_average_rating(movies: List[Dict[str, float]]) -> Dict[str, float]:
"""
Calculate the average rating of movies from a given list of movie ratings.
Args:
movies (List[Dict... |
evol_instruct_66k | 3,106 | Write a Python function to calculate the maximum sum of a subarray of a given array using the Kadane's Algorithm. The function should return the maximum sum of the subarray.
The code should start with:
```python
from typing import List
def max_subarray_sum(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def max_subarray_sum(arr: List[int]) -> int:
"""
Calculate the maximum sum of a subarray using Kadane's Algorithm.
Args:
arr (List[int]): The input array of integers.
Returns:
... |
evol_instruct_66k | 3,110 | Write a Python function to count the frequency of each vowel (a, e, i, o, u) in a given string. The function should return a dictionary where the keys are the vowels and the values are their respective counts. The function should be case-insensitive, meaning 'A' and 'a' should be treated as the same vowel.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_vowel_frequencies(text: str) -> Dict[str, int]:
"""
Counts the frequency of each vowel (a, e, i, o, u) in the given text.
Args:
text (str): The input string to analyze.
Return... |
evol_instruct_66k | 3,112 | Write a Python function to generate all possible combinations and permutations of a given array where the length of each subset is exactly three. The function should return a tuple containing two lists: one for permutations and one for combinations.
The code should start with:
```python
from typing import List, Tuple
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import itertools
def generate_subsets(array: List[int]) -> Tuple[List[Tuple[int, int, int]], List[Tuple[int, int, int]]]:
"""
Generate all possible permutations and combinations of a given array w... |
evol_instruct_66k | 3,122 | Write a Python function to compute the sum of the cubes of all elements in a given list of integers. The function should take a list of integers as input and return the sum of the cubes of these integers. The code should start with:
```python
from typing import List
def sum_of_cubes(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def sum_of_cubes(numbers: List[int]) -> int:
"""
Compute the sum of the cubes of all elements in the given list of integers.
Args:
numbers (List[int]): A list of integers for which the sum... |
evol_instruct_66k | 3,127 | Write a Python function to remove all instances of a specified character from a given text input while maintaining the original sentence structure. The function should also count and return the number of deleted characters. The code should start with:
```python
def remove_and_count_char(text: str, char_to_remove: str) ... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_and_count_char(text: str, char_to_remove: str) -> tuple:
"""
Removes all instances of a specified character from the given text and counts the number of deletions.
Args:
text (str): The input text from wh... |
evol_instruct_66k | 3,133 | Write a Python function to compute the sum of all elements in a given list of integers. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def compute_sum(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def compute_sum(numbers: List[int]) -> int:
"""
Computes the sum of all elements in the given list of integers.
Args:
numbers (List[int]): The list of integers to sum.
Returns:
... |
evol_instruct_66k | 3,138 | Write a Python function that multiplies an input integer by 2 and raises a custom `TypeError` if the input is not an integer. The function should be robust and handle various data types appropriately. The code should start with:
```python
def double_integer(y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def double_integer(y: int) -> int:
"""
Doubles the input integer and raises a custom TypeError if the input is not an integer.
Args:
y (int): The integer to be doubled.
Returns:
int: The result of doubl... |
evol_instruct_66k | 3,140 | Write a Python function to identify and return a list of prime numbers within a given range `[start, end]`. The function should efficiently determine if a number is prime and collect all prime numbers within the specified range. The code should start with:
```python
from typing import List
def find_primes_in_range(sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def find_primes_in_range(start: int, end: int) -> List[int]:
"""
Returns a list of prime numbers within the given range [start, end].
Args:
start (int): The starting number of th... |
evol_instruct_66k | 3,142 | Write a Python function to find the fruit name with the maximum character length from a given list of fruit names. The function should handle cases where the list is empty and return `None` in such cases. The code should start with:
```python
from typing import List, Optional
def longest_fruit(fruits: List[str]) -> Op... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def longest_fruit(fruits: List[str]) -> Optional[str]:
"""
Finds the fruit name with the maximum character length from a given list of fruit names.
Args:
fruits (List[str]): A list... |
evol_instruct_66k | 3,146 | Write a Python function to generate a random permutation of a given list without using any built-in function or library to shuffle the list. Implement your own randomizing algorithm to solve this problem. Ensure that your implementation is capable of producing all possible permutations for any given list and also consi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_random_permutation(lst: List[int]) -> List[int]:
"""
Generates a random permutation of the given list without using any built-in shuffle function.
Args:
lst (List[... |
evol_instruct_66k | 3,150 | Write a Python function to compute the product of three given integers. The function should handle the input validation to ensure that all inputs are integers. If any input is not an integer, the function should return `None`. The function should also handle the case where any of the inputs is zero by returning `0`.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
def multiply_three_numbers(num1: int, num2: int, num3: int) -> int:
"""
Computes the product of three given integers.
Args:
num1 (int): The first integer.
num2 (int): The second integer.
num3 (int): ... |
evol_instruct_66k | 3,162 | Write a Python function to shuffle a given list in place. The function should use the Fisher-Yates (Knuth) shuffle algorithm to ensure a uniform random permutation of the list. The function should not return a new list but modify the input list directly.
The code should start with:
```python
from typing import List
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def shuffle_list(input_list: List[int]) -> None:
"""
Shuffles the given list in place using the Fisher-Yates (Knuth) shuffle algorithm.
Args:
input_list (List[int]): The list t... |
evol_instruct_66k | 3,166 | Write a Python function to convert a list of tuples into a dictionary where each tuple contains a full name and a unique identifier, and the dictionary should use the unique identifiers as keys and the corresponding full names as values. The code should start with:
```python
from typing import List, Tuple, Dict
def co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def convert_to_dict(tuple_list: List[Tuple[str, str]]) -> Dict[str, str]:
"""
Converts a list of tuples into a dictionary where each tuple contains a full name and a unique identifier.
T... |
evol_instruct_66k | 3,170 | Write a Python function to calculate the sum of elements in a list, but with a twist: the function should also handle lists containing nested lists. Each element in the nested list should be added to the total sum. The function should start with:
```python
from typing import List, Union
def sum_nested_list_elements(ls... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Union
def sum_nested_list_elements(lst: List[Union[int, List]]) -> int:
"""
Calculate the sum of elements in a list, including elements in nested lists.
Args:
lst (List[Union[int, List]])... |
evol_instruct_66k | 3,179 | Write a Python function to perform a ternary search on a jagged (or "ragged") array. A jagged array is a multi-dimensional array where sub-arrays can have different lengths. The function should search for a target value in the jagged array and return `True` if the target is found, otherwise `False`. The jagged array is... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def ternary_search_jagged_array(jagged_array: List[List[int]], target: int) -> bool:
"""
Perform a ternary search on a jagged array to find the target value.
Args:
jagged_array (List[List[in... |
evol_instruct_66k | 3,184 | Write a Python function to find the first and last occurrence of a target value in a sorted list of integers. If the target value is not found in the list, the function should return a tuple `(-1, -1)`. The function should be efficient and avoid using exception handling for control flow.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_target_occurrences(lst: List[int], target: int) -> Tuple[int, int]:
"""
Find the first and last occurrence of a target value in a sorted list of integers.
Args:
lst (List[int... |
evol_instruct_66k | 3,206 | Write a Python function to convert any given hexadecimal number to its binary representation. The function should handle both uppercase and lowercase letters in the hexadecimal input. The code should start with:
```python
def hex_to_binary(hex_num: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def hex_to_binary(hex_num: str) -> str:
"""
Convert a given hexadecimal number to its binary representation.
Args:
hex_num (str): The hexadecimal number to be converted. Can include digits 0-9 and letters A-F (or ... |
evol_instruct_66k | 3,210 | Write a Python function to implement the merge sort algorithm on a given dataset. The function should take a list of integers as input and return the sorted list. The merge sort algorithm should be implemented using a recursive approach. The code should start with:
```python
from typing import List
def merge_sort(arr:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the merge sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
List... |
evol_instruct_66k | 3,213 | Write a Python function to calculate the power of a given base number raised to a specified exponent using an iterative approach. The function should handle both positive and negative exponents. The code should start with:
```python
def power_calculation(base: float, exponent: int) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def power_calculation(base: float, exponent: int) -> float:
"""
Calculate the power of a given base number raised to a specified exponent using an iterative approach.
Args:
base (float): The base number to be rais... |
evol_instruct_66k | 3,216 | Write a Python function to remove surplus spacing from a given sentence string, ensuring uniform intervals between alphabetical characters and discrete lexemes. The function should handle multiple spaces between words and leading/trailing spaces. The code should start with:
```python
def remove_surplus_spacing(sentence... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_surplus_spacing(sentence: str) -> str:
"""
Removes surplus spacing from a given sentence string, ensuring uniform intervals between alphabetical characters and discrete lexemes.
Args:
sentence (str): The ... |
evol_instruct_66k | 3,237 | Write a Python function to find the highest value in a given numerical array using the `numpy` library. The function should take a list of integers as input and return the highest value in the list. The code should start with:
```python
from typing import List
import numpy as np
def find_highest_value(arr: List[int]) ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import numpy as np
def find_highest_value(arr: List[int]) -> int:
"""
Find the highest value in a given numerical array using the numpy library.
Args:
arr (List[int]): A list of integers fro... |
evol_instruct_66k | 3,247 | Write a Python function to determine if a binary tree is symmetric around its center. A binary tree is symmetric if it is a mirror image of itself, meaning that the left subtree of the root is a mirror reflection of the right subtree. The function should work both recursively and iteratively.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import deque
from typing import Optional
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def is_symmetric_recursive(root... |
evol_instruct_66k | 3,248 | Write a Python function to construct a numerical distribution table that represents the frequency of each integer within a given input list of integers. The function should return a dictionary where the keys are the unique integers from the input list and the values are their respective frequencies.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_distribution_table(numbers: List[int]) -> Dict[int, int]:
"""
Constructs a numerical distribution table representing the frequency of each integer within a given input list of integers.
... |
evol_instruct_66k | 3,252 | Write a Python function to process a list containing multiple data types, where each element is incremented by 1 if it is a numeric type (integer or float), and a message is printed if the operation cannot be performed on a non-numeric type. The function should be optimized for computational efficiency, particularly in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def increment_numeric_elements(myList: List[Union[int, float, str]]) -> None:
"""
Processes a list containing multiple data types, incrementing numeric elements by 1.
If an element is a non-nu... |
evol_instruct_66k | 3,256 | Write a Python function to group a list of strings based on their lengths. The function should return a dictionary where the keys are the lengths of the strings and the values are lists of strings that have the same length.
The code should start with:
```python
from typing import List, Dict
def group_strings_by_lengt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
from collections import defaultdict
def group_strings_by_length(strings: List[str]) -> Dict[int, List[str]]:
"""
Groups a list of strings based on their lengths.
Args:
strings (List[st... |
evol_instruct_66k | 3,258 | Write a Python function to reverse an array of integers without using any built-in functions or loops. The function should handle arrays of varying lengths. The code should start with:
```python
from typing import List
def reverse_array(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 reverse_array(arr: List[int]) -> List[int]:
"""
Reverses an array of integers without using any built-in functions or loops.
Args:
arr (List[int]): The array of integers to be reversed.
... |
evol_instruct_66k | 3,267 | Write a Python function to find the first 10 prime numbers greater than a given number. The function should take an integer as input and return a list of the first 10 prime numbers that are greater than this integer.
The code should start with:
```python
from typing import List
def find_first_10_primes_greater_than(n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(num: int) -> bool:
"""
Helper function to check if a number is prime.
Args:
num (int): The number to check for primality.
Returns:
bool: True if the number is prime... |
evol_instruct_66k | 3,285 | Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of a given m x n grid, where you can only move right or down. The function should start with:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
"""
Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid.
Args:
m (int): The number of row... |
evol_instruct_66k | 3,299 | Write a Python function to calculate the sum of all digits of a given integer, considering that the input integer may be very large (up to 10^1000) and handle negative integers as well. The function should return the sum of the digits as an integer.
The code should start with:
```python
def sum_of_digits(n: int) -> in... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_digits(n: int) -> int:
"""
Calculate the sum of all digits of a given integer, considering that the input integer may be very large (up to 10^1000) and handle negative integers as well.
Args:
n (int): The... |
evol_instruct_66k | 3,308 | Write a Python function to generate the first `n` numbers of the Lucas number series, starting from a given pair of initial values. The Lucas number series is similar to the Fibonacci series but starts with the numbers 2 and 1. The function should also allow updating the series with a new starting point. The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def generate_lucas_series(n: int, start: Tuple[int, int] = (2, 1)) -> List[int]:
"""
Generate the first n numbers of the Lucas number series starting from a given pair of initial values.
Args... |
evol_instruct_66k | 3,312 | Write a Python function to safely access a character at a specified index in a given string. If the index is out of range, the function should return a default value instead of raising an error. The function should handle both positive and negative indices.
The code should start with:
```python
def safe_char_at(s: str... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_char_at(s: str, index: int, default: str = '') -> str:
"""
Safely access a character at a specified index in a given string.
If the index is out of range, return a default value.
Args:
s (str): The inpu... |
evol_instruct_66k | 3,334 | Write a Python function to determine whether a given string is a valid C++ identifier. A valid C++ identifier must follow these rules:
1. It must start with either an underscore (`_`) or a letter (either uppercase or lowercase).
2. The rest of the characters can be underscores, letters, or digits.
3. It cannot contain ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_cpp_identifier(identifier: str) -> bool:
"""
Determines whether the given string is a valid C++ identifier.
A valid C++ identifier must start with an underscore or a letter and can be followed by
underscore... |
evol_instruct_66k | 3,339 | Write a Python function to divide a given sequence of characters into equal segments by slicing it at every fourth character. The function should return a list of these segments.
The code should start with:
```python
from typing import List
def divide_into_segments(sequence: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def divide_into_segments(sequence: str) -> List[str]:
"""
Divides a given sequence of characters into equal segments by slicing it at every fourth character.
Args:
sequence (str): The sequen... |
evol_instruct_66k | 3,345 | Write a Python function to determine if a given string matches a specific pattern: an octal numeral followed by an upper-case consonant. An octal numeral is a number in base 8, which includes digits from 0 to 7. An upper-case consonant is any letter from A to Z, excluding vowels (A, E, I, O, U).
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_octal_with_consonant(string: str) -> bool:
"""
Determines if a given string matches the pattern of an octal numeral followed by an upper-case consonant.
Args:
string (str): The string to be chec... |
evol_instruct_66k | 3,349 | Write a Python function to detect duplicate elements in a tuple and return a dictionary where the keys are the duplicate elements and the values are the counts of their occurrences. The function should not use any built-in Python libraries for this task.
The code should start with:
```python
def detect_duplicates(t: t... | Here is the Python code to solve the given problem in the markdown block:
```python
def detect_duplicates(t: tuple) -> dict:
"""
Detects duplicate elements in a tuple and returns a dictionary where the keys are the duplicate elements
and the values are the counts of their occurrences.
Args:
t (... |
evol_instruct_66k | 3,369 | Write a Python function to calculate the sum of all elements in a given list efficiently. The function should be optimized for speed execution. The code should start with:
```python
from typing import List
def sum_all_elements(my_list: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def sum_all_elements(my_list: List[int]) -> int:
"""
Calculate the sum of all elements in the given list efficiently.
Args:
my_list (List[int]): The list of integers to sum.
Returns:
... |
evol_instruct_66k | 3,370 | Write a Python function to calculate the sum and product of the digits of a given integer. The function should handle both positive and negative integers and should return a tuple containing the sum and product of the digits. If the input is not an integer, the function should return `None`. The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
def additive_multiplicative(num: int) -> tuple:
"""
Calculate the sum and product of the digits of a given integer.
Args:
num (int): The integer whose digits' sum and product are to be calculated.
Returns:
... |
evol_instruct_66k | 3,371 | Write a Python function to calculate the Least Common Multiple (LCM) of three integers `x`, `y`, and `z` using an optimized algorithm. The function should handle the constraints where `1 <= x, y, z <= 10^9`. The function should start with:
```python
import math
def lcm_three_numbers(x: int, y: int, z: int) -> int:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def lcm_three_numbers(x: int, y: int, z: int) -> int:
"""
Compute the Least Common Multiple (LCM) of three integers x, y, and z.
Args:
x (int): The first integer.
y (int): The second integer.
... |
evol_instruct_66k | 3,380 | Write a Python function to find the most frequent phrase in a list of text elements. Each text element in the list is a string that may contain multiple words. The function should return the phrase that appears most frequently in the list. If there are multiple phrases with the same highest frequency, return any one of... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import collections
def most_frequent_phrase(texts: List[str]) -> Tuple[str, int]:
"""
Find the most frequent phrase in a list of text elements.
Args:
texts (List[str]): A list of stri... |
evol_instruct_66k | 3,387 | Write a Python function to generate a 3x3 array of random integers ranging from 1 to 5 using the NumPy library. The function should return the generated array.
The code should start with:
```python
import numpy as np
def generate_random_array() -> np.ndarray:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def generate_random_array() -> np.ndarray:
"""
Generate a 3x3 array of random integers ranging from 1 to 5.
Returns:
np.ndarray: A 3x3 array of random integers.
"""
# Generate a 3x3 array... |
evol_instruct_66k | 3,391 | Write a Python function to classify each character in a given string into one of the following categories: vowel, consonant, digit, special character, or space. The function should handle both uppercase and lowercase characters and punctuation marks. The function should return a list of tuples, where each tuple contain... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def classify_characters(s: str) -> List[Tuple[str, str]]:
"""
Classify each character in the given string into one of the following categories:
vowel, consonant, digit, special character, or s... |
evol_instruct_66k | 3,406 | Write a Python function to split a given string into a list of characters, excluding any numbers and special characters. The function should only include alphabetic characters (both uppercase and lowercase) in the resulting list.
The code should start with:
```python
from typing import List
def split_string_to_chars(... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def split_string_to_chars(input_string: str) -> List[str]:
"""
Splits a given string into a list of characters, excluding any numbers and special characters.
Args:
input_string (str): The in... |
evol_instruct_66k | 3,415 | Write a Python function to create a 3D array of size 4x4x4 and populate it with random floating-point numbers between -1 and 1 using NumPy. The function should return the generated 3D array.
The code should start with:
```python
import numpy as np
def generate_3d_array() -> np.ndarray:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def generate_3d_array() -> np.ndarray:
"""
Generate a 3D array of size 4x4x4 filled with random floating-point numbers between -1 and 1.
Returns:
np.ndarray: A 3D array of size 4x4x4 with random ... |
evol_instruct_66k | 3,425 | Write a Python function to rank a list of tuples based on the character length of the second element in each tuple. The function should return a new list of tuples sorted in ascending order of the length of the second element. The code should start with:
```python
from typing import List, Tuple
def rank_tuples_by_leng... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def rank_tuples_by_length(tuples_list: List[Tuple[str, str]]) -> List[Tuple[str, str]]:
"""
Rank a list of tuples based on the character length of the second element in each tuple.
Args:
... |
evol_instruct_66k | 3,428 | Write a Python function to find the number of rows in a specified DataFrame from a list of DataFrames. The function should take a list of DataFrames and the name of the target DataFrame as input, and return the number of rows in the specified DataFrame.
The code should start with:
```python
from typing import List, An... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def find_dataframe_size(dataframes: List[Any], target_name: str) -> int:
"""
Find the number of rows in a specified DataFrame from a list of DataFrames.
Args:
dataframes (List[Any]): A ... |
evol_instruct_66k | 3,436 | Write a Python function to extract the first five distinct characters from a given text string and return them as a list. If the text string has fewer than five distinct characters, the function should return all distinct characters found.
The code should start with:
```python
from typing import List
def extract_firs... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def extract_first_five_distinct_characters(text: str) -> List[str]:
"""
Extracts the first five distinct characters from the given text string and returns them as a list.
Args:
text (str): T... |
evol_instruct_66k | 3,441 | 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(input_str: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(input_str: str) -> str:
"""
Reverses the given string.
Args:
input_str (str): The string to be reversed.
Returns:
str: The reversed string.
"""
# Use slicing to reverse the st... |
evol_instruct_66k | 3,451 | Write a Python function to determine the indices of the negative elements in a given 2-D array and return them as coordinate pairs (x, y) corresponding to the row and column positions of the negative elements. Handle edge cases where there might be no negative elements or when the array itself is empty.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_negative_indices(arr: List[List[int]]) -> List[Tuple[int, int]]:
"""
Determines the indices of the negative elements in a given 2-D array and returns them as coordinate pairs (x, y).
... |
evol_instruct_66k | 3,455 | Write a Python function to count the number of isolated linguistic constituents (words) in a given sentence. The function should handle various edge cases, such as sentences with multiple spaces, leading/trailing spaces, and empty strings. The code should start with:
```python
def count_linguistic_constituents(sentence... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_linguistic_constituents(sentence: str) -> int:
"""
Count the number of isolated linguistic constituents (words) in a given sentence.
Args:
sentence (str): The input sentence to count the words from.
R... |
evol_instruct_66k | 3,456 | Write a Python function to combine the elements of two lists into a list of tuples. The function should ensure that the resulting list of tuples contains elements from both lists in the same order as they appear in the input lists. If the lists are of different lengths, the function should only combine elements up to t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def combine_lists_to_tuples(list1: List[int], list2: List[int]) -> List[Tuple[int, int]]:
"""
Combines the elements of two lists into a list of tuples.
Args:
list1 (List[int]): The fi... |
evol_instruct_66k | 3,478 | Write a Python function to categorize a list of lexical items in accordance with their alphabetical order. The function should take a list of strings as input and return a sorted list of strings. The code should start with:
```python
from typing import List
def sort_lexical_items(lexical_items: List[str]) -> List[str]... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def sort_lexical_items(lexical_items: List[str]) -> List[str]:
"""
Sorts a list of lexical items in alphabetical order.
Args:
lexical_items (List[str]): A list of strings to be sorted.
... |
evol_instruct_66k | 3,499 | Write a Python function to generate a dictionary where the keys are the first 'n' prime numbers and their corresponding values are their squares. The function should be scalable to handle any positive integer 'n'. The code should start with:
```python
def generate_prime_squares_dict(n: int) -> dict:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def generate_prime_squares_dict(n: int) -> dict:
"""
Generate a dictionary with the first 'n' prime numbers as keys and their squares as values.
Args:
n (int): The number of prime numbers to include in the dictionar... |
evol_instruct_66k | 3,513 | Write a Python function to transform a given string such that the first letter of each word is capitalized, and any non-alphabetical characters at the start of words are discarded. The function should handle edge cases such as empty strings and strings starting with non-alphabetical characters.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
def transform_string(text: str) -> str:
"""
Transforms the input string such that the first letter of each word is capitalized,
and any non-alphabetical characters at the start of words are discarded.
Args:
text... |
evol_instruct_66k | 3,516 | Write a Python function to merge two sorted arrays of integers into a single sorted array without using built-in sorting functions. The resulting array should not contain any duplicate numbers. The function should have a linear time complexity of O(n + m), where n is the size of the first array and m is the size of the... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Merge two sorted arrays of integers into a single sorted array without duplicates.
Args:
arr1 (List[int]): The fir... |
evol_instruct_66k | 3,521 | Write a Python function to perform shell sort on a given list of integers. The function should return the sorted list. The code should start with:
```python
from typing import List
def shell_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 shell_sort(lst: List[int]) -> List[int]:
"""
Sorts the given list of integers using the Shell sort algorithm.
Args:
lst (List[int]): The list of integers to be sorted.
Returns:
... |
evol_instruct_66k | 3,531 | Write a Python function to create and return a dictionary with ten discrete associative entries. Each entry should have a key in the format "EntryX" where X is a number from 1 to 10, and the corresponding value should be in the format "ValueX". The function should also print each key-value pair in the dictionary.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
def create_and_display_dictionary() -> dict:
"""
Creates a dictionary with ten discrete associative entries and prints each key-value pair.
Returns:
dict: A dictionary with keys in the format "EntryX" and values in ... |
evol_instruct_66k | 3,546 | Write a Python function to perform a linear search on a list of integers to find the index of a target integer. If the target is not found, return -1. The function should be efficient and easy to understand, with detailed comments explaining each step of the operation. 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 linear_search(arr: List[int], target: int) -> int:
"""
Perform a linear search on a list of integers to find the index of a target integer.
Args:
arr (List[int]): A list of integers to s... |
evol_instruct_66k | 3,549 | Write a Python function to find the maximum profit that can be achieved by buying and selling a stock once, given a list of stock prices on consecutive days. The function should return the maximum profit, or 0 if no profit can be made.
The code should start with:
```python
from typing import List
def max_profit(price... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_profit(prices: List[int]) -> int:
"""
Calculate the maximum profit that can be achieved by buying and selling a stock once.
Args:
prices (List[int]): A list of stock prices on consec... |
evol_instruct_66k | 3,560 | Write a Python function to convert an alpha-numeric expression of numerals in the English language into its corresponding numerical representation. The function should handle numbers up to billions. The code should start with:
```python
def convert_num_string_to_num(num_string: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def convert_num_string_to_num(num_string: str) -> int:
"""
Converts an alpha-numeric expression of numerals in the English language into its corresponding numerical representation.
Args:
num_string (str): The alpha-... |
evol_instruct_66k | 3,561 | Write a Python function to search and replace all instances of elements from two arrays, `words1` and `words2`, in a given character sequence `s`. Each element in `words1` should be replaced by the corresponding element in `words2`. The function should handle both single words and phrases (sets of words) efficiently. T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def search_replace_context(s: str, words1: List[str], words2: List[str]) -> str:
"""
Search and replace all instances of elements from `words1` with corresponding elements from `words2` in the character ... |
evol_instruct_66k | 3,562 | Write a Python function to calculate the cumulative sum from 1 to N using M threads. Each thread should divide the task amongst themselves and calculate the partial sum relevant to the division. The function should return the total sum from all threads. The synchronization and management of threads should be handled ca... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import threading
def cumulative_sum_with_threads(N: int, M: int) -> int:
"""
Calculate the cumulative sum from 1 to N using M threads.
Args:
N (int): The upper limit of the range to sum.
... |
evol_instruct_66k | 3,568 | Write a Python function to validate and print a list and a dictionary, ensuring they are syntactically correct and handling any potential runtime errors gracefully. The function should accept a list and a dictionary as input, validate their syntax, and print them if they are valid. If any syntax errors or runtime error... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def validate_and_print_data(my_list: List[int], my_dict: Dict[int, str]) -> None:
"""
Validates and prints a list and a dictionary, handling any potential runtime errors.
Args:
my_list... |
evol_instruct_66k | 3,585 | Write a Python function to convert a string of space-separated decimal values into a list of precise floating-point numbers. The input string contains only valid decimal numbers separated by spaces. The function should handle any number of decimal values in the string.
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 string_to_float_list(s: str) -> List[float]:
"""
Converts a string of space-separated decimal values into a list of precise floating-point numbers.
Args:
s (str): A string containing spa... |
evol_instruct_66k | 3,587 | Write a Python function to generate the nth Fibonacci number efficiently, ensuring it can handle larger inputs effectively and safely. The function should optimize both time complexity and space complexity. Additionally, implement an error handling mechanism to validate the input 'n' and ensure it is a positive integer... | Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci(n: int) -> int:
"""
Generate the nth Fibonacci number efficiently.
Args:
n (int): The position in the Fibonacci sequence to generate.
Returns:
int: The nth Fibonacci number.
Raises:
... |
evol_instruct_66k | 3,589 | Write a Python function that counts the number of occurrences of each alphabetic character in a provided string, ignoring case differences. The function should raise a `TypeError` with a specific error message if the input is not a string. Additionally, the function should ignore digits, spaces, and special characters.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_alphabetic_chars(s: str) -> Dict[str, int]:
"""
Counts the number of occurrences of each alphabetic character in the provided string, ignoring case differences.
Non-alphabetic characters (d... |
evol_instruct_66k | 3,599 | Write a Python function to determine if a given string contains any numerical representation using regular expressions. The function should return `True` if the string contains any digit, and `False` otherwise. The code should start with:
```python
import re
def contains_number(input_string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_number(input_string: str) -> bool:
"""
Determines if the given string contains any numerical representation.
Args:
input_string (str): The string to be checked for the presence of any digit.
... |
evol_instruct_66k | 3,601 | Write a Python function to convert a given decimal number to its binary representation without using Python's built-in `bin()` function. The function should handle both positive and negative integers. The code should start with:
```python
def decimal_to_binary(n: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def decimal_to_binary(n: int) -> str:
"""
Converts a given decimal number to its binary representation without using the built-in bin() function.
Args:
n (int): The decimal number to be converted.
Returns:
... |
evol_instruct_66k | 3,624 | Write a Python function to identify the unique element(s) in an array of integers and return their positions. A unique element is defined as an element that appears exactly once in the array. The function should efficiently handle time and space complexity.
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, Dict
def find_unique_elements_positions(arr: List[int]) -> Dict[int, List[int]]:
"""
Identify the unique elements in the array and return their positions.
Args:
arr (List[int]): The array o... |
evol_instruct_66k | 3,633 | Write a Python function to calculate the greatest common divisor (GCD) of two given integers using the Euclidean algorithm. The function should return the GCD as an integer.
The code should start with:
```python
def gcd_euclidean(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def gcd_euclidean(a: int, b: int) -> int:
"""
Calculate the greatest common divisor (GCD) of two integers using the Euclidean algorithm.
Args:
a (int): The first integer.
b (int): The second integer.
Re... |
evol_instruct_66k | 3,644 | Implement a Two-way bubble sort (or Cocktail sort) algorithm in Python. The algorithm should sort an array from both ends, starting from the beginning and moving to the end, then reversing direction and moving back to the beginning. The algorithm should also detect if no swaps are made during a full pass, indicating th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cocktail_sort(arr: List[int]) -> List[int]:
"""
Sorts the given array using the Cocktail sort algorithm.
Cocktail sort is a variation of bubble sort that sorts the array in both directions,
... |
evol_instruct_66k | 3,645 | Write a Python function to find the median of three distinct humidity percentages. The function should take a list of exactly three integers representing humidity percentages and return the median value. The code should start with:
```python
from typing import List
def find_median_of_three(humidity_values: List[int]) ... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def find_median_of_three(humidity_values: List[int]) -> int:
"""
Find the median of three distinct humidity percentages.
Args:
humidity_values (List[int]): A list of exactly three distinct... |
evol_instruct_66k | 3,646 | Write a Python function to generate a list of squared results of the first `n` odd numbers in ascending order. The function should take an integer `n` as input and return a list of integers. The code should start with:
```python
from typing import List
def generate_odd_squares(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_odd_squares(n: int) -> List[int]:
"""
Generate a list of squared results of the first n odd numbers in ascending order.
Args:
n (int): The number of odd numbers to consider.
... |
evol_instruct_66k | 3,652 | 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 either down or right at any point in time. The function should handle edge cases such as when the grid dimensions are 0 or when the grid is a single cell.
The co... | 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... |
evol_instruct_66k | 3,656 | Write a Python function to determine if one string is a permutation of another. A permutation is defined as a rearrangement of characters. The function should return `True` if one string is a permutation of the other, and `False` otherwise. The function should handle strings of different lengths by returning `False` im... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_permutation(str1: str, str2: str) -> bool:
"""
Determines if one string is a permutation of another.
Args:
str1 (str): The first string to compare.
str2 (str): The second string to compare.
Retur... |
evol_instruct_66k | 3,669 | Write a Python function to convert a given list of strings to a dictionary where each unique item (case insensitive) is a key and its first occurrence index in the list is the value. If the list contains duplicate items (case insensitive), only the first occurrence should be considered.
The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def convert_list_to_dict(lst: List[str]) -> Dict[str, int]:
"""
Converts a given list of strings to a dictionary where each unique item (case insensitive)
is a key and its first occurrence inde... |
evol_instruct_66k | 3,676 | Write a Python function to calculate the sum of elements in a list. The function should handle both lists and individual integers as input. If the input is a single integer, it should return that integer. If the input is a list, it should return the sum of the elements in the list. If the input is neither a list nor an... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union, List
def calculate_sum(elements: Union[int, List[int]]) -> int:
"""
Calculate the sum of elements in a list or return a single integer.
Args:
elements: An integer or a list of integers.
... |
evol_instruct_66k | 3,679 | Write a Python function to determine if a given character sequence is a pangram. A pangram is a sentence that contains every letter of the alphabet at least once. The function should be case-insensitive and should ignore non-alphabetic characters.
The code should start with:
```python
def is_pangram(sentence: str) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_pangram(sentence: str) -> bool:
"""
Determine if the given sentence is a pangram.
A pangram is a sentence that contains every letter of the alphabet at least once.
This function is case-insensitive and ignores no... |
evol_instruct_66k | 3,688 | Write a Python function to convert a given year into ISO 8601 format. The function should handle both integer and string inputs, ensuring that the year is correctly formatted according to ISO 8601 standards. The function should also validate the input to ensure it is either a valid integer or a string that can be conve... | Here is the Python code to solve the given problem in the markdown block:
```python
def iso_8601_year(year):
"""
Converts a given year into ISO 8601 format.
Args:
year (int or str): The year to be converted. Can be either an integer or a string that can be converted to an integer.
Returns:
... |
evol_instruct_66k | 3,711 | Write a Python function to find the complex numbers with the least prevalence (i.e., the least number of occurrences) in a given list of complex numbers. If there are multiple complex numbers with the same least prevalence, return all of them.
The code should start with:
```python
from typing import List
from collecti... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import Counter
def least_prevalent_complex_numbers(arr: List[complex]) -> List[complex]:
"""
Find the complex numbers with the least prevalence in a given list.
Args:
arr (L... |
evol_instruct_66k | 3,724 | Write a Python function to convert a tuple containing strings as elements to a list. The function should handle tuples of varying lengths and ensure that the output list maintains the order of elements from the input tuple.
The code should start with:
```python
from typing import Tuple, List
def tuple_to_list(input_t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, List
def tuple_to_list(input_tuple: Tuple[str, ...]) -> List[str]:
"""
Converts a tuple containing strings to a list.
Args:
input_tuple (Tuple[str, ...]): A tuple containing string element... |
evol_instruct_66k | 3,733 | Write a Python function to validate whether a given string is a valid email address according to a standardized format. The function should use a regular expression to check if the email address conforms to the general structure of an email, which includes a local part, an "@" symbol, and a domain part. The local part ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_email(email: str) -> bool:
"""
Validate whether the given string is a valid email address according to a standardized format.
Args:
email (str): The email address to validate.
Returns:
... |
evol_instruct_66k | 3,736 | Write a Python function to perform a binary search on a sorted list of integers to find the index of a given value. If the value is not found, return -1. The function should be efficient and should handle edge cases such as an empty list or a value that is not present in the list.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(nums: List[int], val: int) -> int:
"""
Perform a binary search on a sorted list of integers to find the index of a given value.
Args:
nums (List[int]): A sorted list of int... |
evol_instruct_66k | 3,740 | Write a Python function to implement a ternary operation that returns 10 if a given integer `x` is greater than 0, otherwise returns 5. The function should be named `ternary_operation` and should take a single integer parameter `x`. The code should start with:
```python
def ternary_operation(x: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def ternary_operation(x: int) -> int:
"""
Returns 10 if the given integer x is greater than 0, otherwise returns 5.
Args:
x (int): The integer to evaluate.
Returns:
int: 10 if x is greater than 0, other... |
evol_instruct_66k | 3,750 | Write a Python function to determine if the term "phoenix" appears at the beginning of a given text passage, considering case insensitivity. The function should return `True` if the term "phoenix" is found at the start of the text, regardless of its case, and `False` otherwise.
The code should start with:
```python
im... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def starts_with_phoenix(text: str) -> bool:
"""
Determines if the term "phoenix" appears at the beginning of the given text in a case-insensitive manner.
Args:
text (str): The text passage to be checked.
... |
evol_instruct_66k | 3,758 | Write a Python function to calculate the arithmetic mean of a given list of numbers. The function should handle lists of any length, including empty lists, and return `None` for an empty list. The code should start with:
```python
from typing import List, Optional
def calculate_mean(numbers: List[float]) -> Optional[f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def calculate_mean(numbers: List[float]) -> Optional[float]:
"""
Calculate the arithmetic mean of a given list of numbers.
Args:
numbers (List[float]): The list of numbers for whic... |
evol_instruct_66k | 3,759 | Write a Python function to determine if a given integer is negative, and if so, return a specific message. If the integer is not negative, return a different message. The function should handle both positive and negative integers, as well as zero.
The code should start with:
```python
def check_number_sign(x: int) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_number_sign(x: int) -> str:
"""
Determine if the given integer is negative or non-negative and return an appropriate message.
Args:
x (int): The integer to check.
Returns:
str: A message indic... |
evol_instruct_66k | 3,767 | Write a Python function to remove all occurrences of a specified integer from a given list of integers. The function should return a new list with all instances of the specified integer removed. The original list should remain unchanged.
The code should start with:
```python
from typing import List
def remove_all_occ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_all_occurrences(lst: List[int], target: int) -> List[int]:
"""
Removes all occurrences of the specified integer from the given list.
Args:
lst (List[int]): The list of integers fr... |
evol_instruct_66k | 3,768 | Write a Python function to convert pressure readings from Pascal (Pa) to Bar (bar). The function should take a single argument representing the pressure in Pascal and return the corresponding pressure in Bar. The conversion factor from Pascal to Bar is 1 Pa = 0.00001 bar. The code should start with:
```python
def conve... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_pascal_to_bar(pascal: float) -> float:
"""
Converts pressure from Pascal (Pa) to Bar (bar).
Args:
pascal (float): The pressure value in Pascal.
Returns:
float: The pressure value converted t... |
evol_instruct_66k | 3,771 | Write a Python function to create a dictionary where the keys are positive integers from 1 to 25, and the values are their corresponding square roots. The function should use dictionary comprehension for efficiency.
The code should start with:
```python
from typing import Dict
def generate_square_roots_dict() -> Dict... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import math
def generate_square_roots_dict() -> Dict[int, float]:
"""
Generates a dictionary where the keys are positive integers from 1 to 25,
and the values are their corresponding square roots.
... |
evol_instruct_66k | 3,772 | Write a Python function to generate a sequence of integers from a given two-dimensional matrix in a clockwise spiral order. The function should start with:
```python
from typing import List
def spiral_order(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 spiral_order(matrix: List[List[int]]) -> List[int]:
"""
Generate a sequence of integers from a given two-dimensional matrix in a clockwise spiral order.
Args:
matrix (List[List[int]]): T... |
evol_instruct_66k | 3,774 | Write a Python function to merge two sorted arrays into a single sorted array. The function should take two lists of integers as input, sort each list in ascending order, and then merge them into a new sorted list. The function should be efficient and avoid using built-in sorting functions for the merging step.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Merges two sorted arrays into a single sorted array.
Args:
arr1 (List[int]): The first sorted array.
arr2 ... |
evol_instruct_66k | 3,822 | Write a Python function to implement the XOR cipher methodology for encrypting and decrypting textual messages. The function should adhere to the following constraints:
1. The function should accept a specific reserved key `'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`. Any other key should raise a `ValueError` with an appropriate err... | Here is the Python code to solve the given problem in the markdown block:
```python
def xor_encrypt(text: str, key: str) -> str:
"""
Encrypts the given text using the XOR cipher with the provided key.
Args:
text (str): The text to be encrypted.
key (str): The encryption key.
Returns:
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.