source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 16,464 | 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 either down or right at any point in time.
The code 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 rows ... |
evol_instruct_66k | 16,465 | Write a Python function to identify the largest number in a given list of integers. The function should handle lists of any size, including empty lists. If the list is empty, the function should return `None`.
The code should start with:
```python
from typing import List, Optional
def find_largest_number(numbers: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_largest_number(numbers: List[int]) -> Optional[int]:
"""
Find the largest number in a given list of integers.
Args:
numbers (List[int]): The list of integers from which to... |
evol_instruct_66k | 16,474 | Write a Python function to compute the cumulative sum of each number's square within a provided list. The function should return a list where each element at index `i` is the cumulative sum of the squares of the elements from the start of the list up to index `i`.
The code should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_square_sum(numbers: List[int]) -> List[int]:
"""
Computes the cumulative sum of each number's square within the provided list.
Args:
numbers (List[int]): A list of integers fo... |
evol_instruct_66k | 16,483 | Write a Python function to safely divide two numbers and handle potential division by zero errors gracefully. The function should return the result of the division if it is valid, and a custom error message if division by zero occurs.
The code should start with:
```python
def safe_division(numerator: float, denominato... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_division(numerator: float, denominator: float) -> str:
"""
Safely divides two numbers and returns the result as a string.
If division by zero occurs, returns a custom error message.
Args:
numerator (flo... |
evol_instruct_66k | 16,489 | Write a Python function to invert the elements of a specified list in situ, without resorting to instantiation of a new list or array. The function should modify the original list directly.
The code should start with:
```python
from typing import List
def invert_list_in_place(lst: List[int]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def invert_list_in_place(lst: List[int]) -> None:
"""
Inverts the elements of a specified list in situ, without resorting to instantiation of a new list or array.
Args:
lst (List[int]): The ... |
evol_instruct_66k | 16,491 | Write a Python function to convert an angle measurement from gradians to degrees. The function should take a single argument representing the angle in gradians and return the equivalent angle in degrees. The conversion factor from gradians to degrees is 180/200.
The code should start with:
```python
def convert_gradia... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_gradians_to_degrees(gradians: float) -> float:
"""
Converts an angle measurement from gradians to degrees.
Args:
gradians (float): The angle measurement in gradians.
Returns:
float: The equi... |
evol_instruct_66k | 16,493 | Write a Python function to find the length of the Longest Common Subsequence (LCS) between two given strings. The function should use dynamic programming to efficiently compute the result. The code should start with:
```python
def longest_common_subsequence_length(str1: str, str2: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def longest_common_subsequence_length(str1: str, str2: str) -> int:
"""
Calculate the length of the Longest Common Subsequence (LCS) between two strings.
Args:
str1 (str): The first string.
str2 (str): The s... |
evol_instruct_66k | 16,497 | Write a Python function to perform floor division on two integers and return the result. The function should handle the case where the divisor is zero by returning a specific error message. The code should start with:
```python
def floor_division(dividend: int, divisor: int) -> int or str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def floor_division(dividend: int, divisor: int) -> int or str:
"""
Perform floor division on two integers and return the result.
If the divisor is zero, return an error message.
Args:
dividend (int): The number ... |
evol_instruct_66k | 16,503 | Write a Python function to retrieve the last element from a given list. The function should handle cases where the list is empty by returning `None`. The code should start with:
```python
from typing import List, Optional
def get_last_element(sequence: List[int]) -> Optional[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def get_last_element(sequence: List[int]) -> Optional[int]:
"""
Retrieves the last element from a given list of integers.
Args:
sequence (List[int]): The list from which to retriev... |
evol_instruct_66k | 16,511 | Write a Python function to generate a list of unique random numbers within a specified range. The function should ensure that all numbers in the list are unique and within the given range. The code should start with:
```python
from typing import List
import random
def generate_unique_random_numbers(n: int, start: int,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_unique_random_numbers(n: int, start: int, end: int) -> List[int]:
"""
Generate a list of n unique random numbers within the specified range [start, end].
Args:
n (... |
evol_instruct_66k | 16,545 | Write a Python function to generate a stochastic sequence of a specified length, where each element in the sequence is a randomly chosen lowercase letter from the English alphabet. The function should return the generated sequence as a string.
The code should start with:
```python
from typing import List
import random... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
import string
def generate_stochastic_sequence(length: int) -> str:
"""
Generates a stochastic sequence of the specified length, where each element is a randomly chosen lowercase letter fro... |
evol_instruct_66k | 16,549 | Write a Python function to generate a dictionary that maps elements from the first tuple to elements from the second tuple. The function should ensure that the dictionary is created correctly by identifying and correcting the errors within the provided erroneous code. The code should start with:
```python
from typing i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict
def create_mapping(tuple1: Tuple[str], tuple2: Tuple[str]) -> Dict[str, str]:
"""
Generates a dictionary that maps elements from the first tuple to elements from the second tuple.
Args:
... |
evol_instruct_66k | 16,560 | Write a Python function to implement the Quick Sort algorithm to sort a given list of integers in ascending order. The function should be recursive and should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def quicksort(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 quicksort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order using the Quick Sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Ret... |
evol_instruct_66k | 16,582 | Write a Python function to analyze a given string and categorize the occurrences of vowels, consonants, numbers, special characters, and whitespace. The function should sort these occurrences in descending order based on frequency. The output should be a dictionary where each key represents a category (vowels, consonan... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import defaultdict, Counter
from typing import Dict, List, Tuple
import re
def categorize_and_sort_characters(input_string: str) -> Dict[str, List[Tuple[str, int]]]:
"""
Analyzes the given string and categorize... |
evol_instruct_66k | 16,593 | Write a Python function to convert a given tuple of strings into a list and then extract and return the element at the specified index from the transformed list. The function should handle cases where the index is out of bounds by returning `None`.
The code should start with:
```python
from typing import Tuple, List, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, List, Optional
def convert_tuple_to_list_and_get_element(creatures: Tuple[str], index: int) -> Optional[str]:
"""
Converts a given tuple of strings into a list and returns the element at the specified ... |
evol_instruct_66k | 16,598 | Write a Python function to identify and return all narcissistic numbers that are less than or equal to a given integer input. Additionally, the function should handle negative numbers and return an error message if the input is not an integer. The function should be optimized for large inputs.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_narcissistic_numbers(n: int) -> list[int] | str:
"""
Identifies and returns all narcissistic numbers that are less than or equal to a given integer input.
If the input is not a non-negative integer, returns an error... |
evol_instruct_66k | 16,614 | Write a Python function to find and return the string with the greatest length from a given list of strings. If there are multiple strings with the same maximum length, return the first one encountered. The function should handle an empty list by returning `None`.
The code should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_longest_string(strings: List[str]) -> Optional[str]:
"""
Finds and returns the string with the greatest length from a given list of strings.
If there are multiple strings with the ... |
evol_instruct_66k | 16,615 | Write a Python function to remove all occurrences of a specified number from a given list and return the modified list. The function should be efficient and handle various edge cases, such as an empty list or a list where the specified number does not exist.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_all_occurrences(input_list: List[int], target: int) -> List[int]:
"""
Removes all occurrences of the specified number from the given list and returns the modified list.
Args:
inpu... |
evol_instruct_66k | 16,620 | Write a Python function to combine two lists element-wise using the built-in `zip()` function and return a list of tuples. Each tuple should contain elements from the same positions in the input lists. If the input lists are of different lengths, the function should return only the tuples formed from the common length ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def combine_lists(list1: List, list2: List) -> List[Tuple]:
"""
Combines two lists element-wise using the zip() function and returns a list of tuples.
Args:
list1 (List): The first li... |
evol_instruct_66k | 16,623 | Write a Python function to determine the cumulative count of distinct elements within a nested list structure adorned with numerical constituents. The nested list structure can have varying depths, and the function should handle any level of nesting. The function should start with:
```python
from typing import List
de... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_distinct_elements(nested_list: List) -> int:
"""
Counts the cumulative number of distinct elements in a nested list structure.
Args:
nested_list (List): A nested list structure con... |
evol_instruct_66k | 16,624 | Write a Python function to determine whether a given number is prime, odd, or even. The function should handle non-numeric inputs with appropriate error messages. The function should not use any built-in functions except for basic arithmetic operations and type conversion.
The code should start with:
```python
def che... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_number_properties(number: str) -> str:
"""
Determine whether a given number is prime, odd, or even, and handle non-numeric inputs.
Args:
number (str): The input number as a string.
Returns:
st... |
evol_instruct_66k | 16,636 | Write a Python function to sort a list of dictionaries in ascending order based on the values associated with a specified key. The function should handle cases where the key might not exist in some dictionaries and should return the sorted list. If a dictionary does not contain the specified key, it should be placed at... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def sort_dicts_by_key(lst: List[Dict[str, int]], key: str) -> List[Dict[str, int]]:
"""
Sorts a list of dictionaries in ascending order based on the values associated with a specified key.
If a... |
evol_instruct_66k | 16,637 | Write a Python function to identify the smallest even number in a given list of integers. If there are no even numbers in the list, the function should return `None`. The function should be efficient and handle various edge cases, such as an empty list or a list with no even numbers.
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, Optional
def find_smallest_even(input_list: List[int]) -> Optional[int]:
"""
Identifies the smallest even number in a given list of integers.
Args:
input_list (List[int]): The list of integ... |
evol_instruct_66k | 16,638 | Write a Python function to initialize a list with a specified number of elements, each set to a given value. The function should handle cases where the number of elements is zero or negative by returning an empty list.
The code should start with:
```python
from typing import List
def initialize_list(value: int, num_e... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def initialize_list(value: int, num_elements: int) -> List[int]:
"""
Initializes a list with a specified number of elements, each set to a given value.
Args:
value (int): The value to set ea... |
evol_instruct_66k | 16,644 | Write a Python function to find the longest common subsequence (LCS) between two given strings. The LCS is the longest sequence of characters that appear in the same order in both strings, but not necessarily consecutively. The function should return the length of the LCS.
The code should start with:
```python
def lon... | 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) between two strings.
Args:
str1 (str): The first string.
str2 (str): The second s... |
evol_instruct_66k | 16,645 | Write a Python function to check if a given key exists in a dictionary. The function should return `True` if the key exists in the dictionary, and `False` otherwise. The code should start with:
```python
def key_exists(dictionary: dict, key: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def key_exists(dictionary: dict, key: str) -> bool:
"""
Check if a given key exists in the provided dictionary.
Args:
dictionary (dict): The dictionary in which to check for the key.
key (str): The key to ... |
evol_instruct_66k | 16,647 | Write a Python function to perform a postorder traversal of a binary tree without using recursion and without using any additional data structures like stacks or queues. The function should return a list of node values in postorder traversal order.
The binary tree is represented using a `TreeNode` class where each nod... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
class TreeNode:
def __init__(self, val=0, left=None, right=None, parent=None):
self.val = val
self.left = left
self.right = right
self.parent = parent
def postorder... |
evol_instruct_66k | 16,652 | Write a Python function to compute the transpose of a given 2D array without using any external libraries like NumPy. The function should handle any rectangular 2D array and return the transposed array. The code should start with:
```python
from typing import List
def transpose_2d_array(arr: List[List[int]]) -> List[L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def transpose_2d_array(arr: List[List[int]]) -> List[List[int]]:
"""
Computes the transpose of a given 2D array.
Args:
arr (List[List[int]]): The input 2D array to be transposed.
Return... |
evol_instruct_66k | 16,653 | Write a Python function to transform a given three-dimensional NumPy array into a two-dimensional array. The transformation should be done by reshaping the array such that the first two dimensions are combined into one, and the third dimension remains unchanged. The function should handle any valid 3D array input.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def transform_3d_to_2d(arr: np.ndarray) -> np.ndarray:
"""
Transforms a given 3D NumPy array into a 2D array by combining the first two dimensions.
Args:
arr (np.ndarray): A 3D NumPy array to be ... |
evol_instruct_66k | 16,655 | 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 | 16,656 | Write a Python function to calculate the Least Common Multiple (LCM) of four integers (w, x, y, and z) efficiently, ensuring that the algorithm conserves computational resources. The function should adhere to the following constraints:
- The input integers w, x, y, and z are within the range 1 to 10^9.
- The function s... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def lcm_of_four(w: int, x: int, y: int, z: int) -> int:
"""
Calculate the Least Common Multiple (LCM) of four integers (w, x, y, and z) efficiently.
Args:
w (int): The first integer.
x (int): Th... |
evol_instruct_66k | 16,658 | Write a Python function to generate the first `n` prime numbers using the Sieve of Eratosthenes algorithm. The function should be optimized for both time and space complexity.
The code should start with:
```python
from typing import List
def generate_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
import math
def generate_n_primes(n: int) -> List[int]:
"""
Generate the first n prime numbers using the Sieve of Eratosthenes algorithm.
Args:
n (int): The number of prime numbers to genera... |
evol_instruct_66k | 16,660 | Write a Python function to convert pressure from Pascal to Bar. The function should take a single argument representing the pressure in Pascals and return the pressure in Bars. The conversion factor is 1 Bar = 100000 Pascals. The function should handle both integer and floating-point inputs.
The code should start with... | 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 to Bar.
Args:
pascal (float): The pressure in Pascals.
Returns:
float: The pressure in Bars.
"""
# Conversion... |
evol_instruct_66k | 16,684 | Write a Python function to convert a given time duration in hours into its equivalent in milliseconds. The function should handle any non-negative integer input for the number of hours. The code should start with:
```python
def convert_hours_to_milliseconds(hours: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def convert_hours_to_milliseconds(hours: int) -> int:
"""
Converts a given time duration in hours to its equivalent in milliseconds.
Args:
hours (int): The time duration in hours to be converted. Must be a non-negat... |
evol_instruct_66k | 16,691 | Write a Python function to concatenate two strings with specific modifications based on a numeric parameter. The first string should be reversed, and the second string should be repeated according to the numeric parameter. The function should also handle errors for invalid input types and negative or zero numeric value... | Here is the Python code to solve the given problem in the markdown block:
```python
def string_manipulation(str1: str, str2: str, num: int) -> str:
"""
Concatenates two strings with specific modifications based on a numeric parameter.
The first string is reversed, and the second string is repeated accordin... |
evol_instruct_66k | 16,695 | Write a Python function to calculate 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 calculate_sum(array: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_sum(array: List[int]) -> int:
"""
Calculate the sum of all elements in a given list of integers.
Args:
array (List[int]): The list of integers whose sum is to be calculated.
... |
evol_instruct_66k | 16,705 | Write a Python function to sort a given list of Fibonacci numbers in ascending order. The function should take a list of integers as input and return the sorted list. The code should start with:
```python
from typing import List
def sort_fibonacci_numbers(fib_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 sort_fibonacci_numbers(fib_list: List[int]) -> List[int]:
"""
Sorts a given list of Fibonacci numbers in ascending order.
Args:
fib_list (List[int]): A list of integers representing Fibo... |
evol_instruct_66k | 16,707 | Write a Python function to generate a regular expression that matches specific strings while excluding others, ensuring the first letter is capitalized, and demonstrating understanding of string boundaries. The function should validate if a given string matches the criteria.
The code should start with:
```python
impor... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_string(word: str) -> bool:
"""
Validates if the given string matches the criteria:
- The string must start with 'R' and be capitalized.
- The string must match one of the following: "Run", "Rune",... |
evol_instruct_66k | 16,709 | Write a Python function to find the indices of all negative elements in a given list of integers. The function should return a list of indices where the corresponding elements are negative.
The code should start with:
```python
from typing import List
def find_negative_indices(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 find_negative_indices(arr: List[int]) -> List[int]:
"""
Find the indices of all negative elements in the given list.
Args:
arr (List[int]): The list of integers to search for negative ... |
evol_instruct_66k | 16,737 | Write a Python function to generate a new list where each element in the given ordered list of integers is amplified by a specified doubling factor. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def amplify_by_factor(arr: List[int],... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def amplify_by_factor(arr: List[int], factor: int) -> List[int]:
"""
Generate a new list where each element in the given list is amplified by the specified factor.
Args:
arr (List[int]): The... |
evol_instruct_66k | 16,738 | Write a Python function to validate and populate a `Person` class with attributes `name`, `age`, `street`, `city`, `state`, and `zip_code`. The function should handle data validation and ensure that the provided details are in the correct format. The function should start with:
```python
from typing import Dict
class ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
class Person:
def __init__(self, name: str, age: int, street: str, city: str, state: str, zip_code: str):
self.name = name
self.age = age
self.street = street
self.city = city... |
evol_instruct_66k | 16,746 | Write a Python function to remove all duplicate numeric elements from a given list while preserving the order of the first occurrence of each element. The function should take a list of integers as input and return a new list with all duplicates removed.
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
def remove_duplicates(data: List[int]) -> List[int]:
"""
Removes duplicate elements from the given list while preserving the order of the first occurrence of each element.
Args:
data (List[i... |
evol_instruct_66k | 16,752 | Write a Python function to determine the type of a given data structure and return a string describing the type. The function should handle three types of data structures: lists, tuples, and dictionaries. If the input is not one of these three types, the function should return "Unknown".
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def determine_data_structure_type(data):
"""
Determine the type of a given data structure and return a string describing the type.
Args:
data: The data structure to determine the type of.
Returns:
str: ... |
evol_instruct_66k | 16,775 | Write a Python function to incorporate a given numeral into each element of an array. The function should take two parameters: an array of integers and a numeral (also an integer). The function should return a new array where each element is the sum of the corresponding element in the input array and the numeral. The o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def incorporate_numeral_into_array(arr: List[int], num: int) -> List[int]:
"""
Incorporates a given numeral into each element of the input array.
Args:
arr (List[int]): The input array of in... |
evol_instruct_66k | 16,781 | Write a Python function to rotate a square matrix by 90 degrees a specified number of times (N times). The matrix should be a square matrix of any dimension, and it should handle negative values and not just integers. The function should also handle cases where N is negative, which means rotating the matrix countercloc... | 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[float]], N: int) -> List[List[float]]:
"""
Rotates a square matrix by 90 degrees clockwise N times.
Args:
matrix (List[List[float]]): The square matrix to... |
evol_instruct_66k | 16,793 | Write a Python function to calculate the maximum volume of rainwater that can be captured between the given structures. Each structure is represented by a non-negative integer in the list `elevation`, where each integer signifies the height of the structure at the coordinate `(i, elevation[i])`. The task is to identify... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_rainwater_captured(elevation: List[int]) -> int:
"""
Calculate the maximum volume of rainwater that can be captured between the given structures.
Args:
elevation (List[int]): A list ... |
evol_instruct_66k | 16,795 | Write a Python function to correct the punctuation in a given string by replacing sequences of incorrect punctuation marks with the correct single punctuation marks. The function should handle multiple types of incorrect punctuation sequences.
The code should start with:
```python
def correct_punctuation(input_string:... | Here is the Python code to solve the given problem in the markdown block:
```python
def correct_punctuation(input_string: str) -> str:
"""
Corrects the punctuation in a given string by replacing sequences of incorrect punctuation marks with the correct single punctuation marks.
Args:
input_string (... |
evol_instruct_66k | 16,806 | Write a Python function to invert the digits of a given integer. The function should handle both positive and negative integers. If the input integer is negative, the function should return the inverted integer with the negative sign preserved. The function should also handle edge cases such as zero and single-digit in... | Here is the Python code to solve the given problem in the markdown block:
```python
def invert_digits(n: int) -> int:
"""
Inverts the digits of a given integer. If the integer is negative, the negative sign is preserved.
Args:
n (int): The integer whose digits are to be inverted.
Returns:
... |
evol_instruct_66k | 16,808 | Write a Python function to find the longest common subsequence (LCS) between two given strings. The function should return the LCS as a string. The code should start with:
```python
def longest_common_subsequence(str1: str, str2: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def longest_common_subsequence(str1: str, str2: str) -> str:
"""
Finds the longest common subsequence (LCS) between two given strings.
Args:
str1 (str): The first string.
str2 (str): The second string.
... |
evol_instruct_66k | 16,841 | Write a Python function to extract all valid IPv6 addresses from a given text string. The function should use a regular expression to identify and return all IPv6 addresses present in the text. The IPv6 addresses should be in their full form (e.g., `2001:0db8:85a3:0000:0000:8a2e:0370:7334`). The function should handle ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def extract_ipv6_addresses(text: str) -> List[str]:
"""
Extracts all valid IPv6 addresses from the given text string.
Args:
text (str): The input text string from which to extract ... |
evol_instruct_66k | 16,853 | Write a Python function to generate a list of `n` random numbers between a specified range `[low, high]`. The function should return the list of random numbers. The code should start with:
```python
from typing import List
import random
def generate_random_numbers(n: int, low: int, high: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_random_numbers(n: int, low: int, high: int) -> List[int]:
"""
Generates a list of n random numbers within the specified range [low, high].
Args:
n (int): The numbe... |
evol_instruct_66k | 16,877 | Write a Python function to convert a given string from snake_case to kebab-case. The function should replace all underscores (`_`) in the input string with hyphens (`-`). The code should start with:
```python
def snake_to_kebab(snake_case_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def snake_to_kebab(snake_case_string: str) -> str:
"""
Converts a given string from snake_case to kebab-case.
Args:
snake_case_string (str): The input string in snake_case format.
Returns:
str: The co... |
evol_instruct_66k | 16,881 | Write a Python function to initialize an associative array (dictionary) named `students`, where the keys are unique student ID numbers and the values are dictionaries representing individual students. Each student dictionary should contain the student's `name` and a list of `grades` for three subjects: Math, Science, a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
import random
def initialize_students(student_ids: List[int], student_names: List[str]) -> Dict[int, Dict[str, any]]:
"""
Initializes an associative array (dictionary) of students with unique IDs a... |
evol_instruct_66k | 16,892 | Write a Python function to convert a binary string to its octal representation. The function should take a binary string as input and return the corresponding octal string. The function should handle binary strings of any length, including those that are not multiples of three.
The code should start with:
```python
de... | Here is the Python code to solve the given problem in the markdown block:
```python
def bin_to_octal(b: str) -> str:
"""
Convert a binary input (string) to its octal representation (string).
Args:
b (str): The binary string to be converted.
Returns:
str: The octal representation of the... |
evol_instruct_66k | 16,905 | Write a Python function to sort a list of dictionaries based on the values associated with the 'score' key. The function should return the sorted list. The code should start with:
```python
from typing import List, Dict
def sort_by_score(lst: List[Dict[str, int]]) -> List[Dict[str, int]]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Dict
def sort_by_score(lst: List[Dict[str, int]]) -> List[Dict[str, int]]:
"""
Sorts a list of dictionaries based on the 'score' key's values in ascending order.
Args:
lst (List[Dict[str,... |
evol_instruct_66k | 16,910 | Write a Python function to multiply all numerical values within a given list of dictionaries. The function should be able to traverse nested dictionary structures and ignore any non-numeric elements. Additionally, the function should handle dictionaries that contain other data structures like lists, sets, and tuples, a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union, List, Dict, Tuple, Set
def multiply_numeric_values(data: Union[List, Dict, Tuple, Set]) -> float:
"""
Multiplies all numerical values within a given list of dictionaries.
This function traverses n... |
evol_instruct_66k | 16,927 | Write a Python function to create a new list by randomly selecting a specified number of elements from a given list. The function should ensure that the selected elements are unique and that the number of elements to select does not exceed the length of the given list. 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
import random
def random_selection(original_list: List[int], num_elements: int) -> List[int]:
"""
Creates a new list by randomly selecting a specified number of unique elements from the given list.
... |
evol_instruct_66k | 16,928 | Write a Python function to return an array containing the unique elements of a given array of integers in ascending order. The function should perform the operation in O(n log n) time complexity and O(1) space complexity, where n is the number of elements in the input array. The function should also handle edge cases s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def unique_elements_sorted(arr: List[int]) -> List[int]:
"""
Returns an array containing the unique elements of the input array in ascending order.
The function operates in O(n log n) time complexity... |
evol_instruct_66k | 16,937 | Write a Python function to process a multidimensional matrix such that each element in the matrix is tripled, and for each inner list, the sum of these tripled elements is computed. The function should return a list of lists, where each inner list contains two elements: the first element is the list of tripled numbers,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def process_matrix(matrix: List[List[int]]) -> List[List[List[int]]]:
"""
Processes a multidimensional matrix such that each element in the matrix is tripled,
and for each inner list, the sum of thes... |
evol_instruct_66k | 16,939 | Write a Python function to compute an output array where each element is the product of all elements in the input array except the one at the corresponding index. The function should not use division and should efficiently compute the result in O(n) time complexity.
The code 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 List
def product_except_self(nums: List[int]) -> List[int]:
"""
Compute an output array where each element is the product of all elements in the input array except the one at the corresponding index.
Arg... |
evol_instruct_66k | 17,007 | Write a Python function to calculate the product of all elements in a given list of numerical elements. The function should handle lists of integers and floating-point numbers. The code should start with:
```python
from typing import List
def calculate_product(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_product(numbers: List[float]) -> float:
"""
Calculate the product of all elements in a given list of numerical elements.
Args:
numbers (List[float]): A list of numerical elemen... |
evol_instruct_66k | 17,016 | Write a Python function to convert a binary number to its hexadecimal representation. The function should handle binary numbers of any length and return the hexadecimal equivalent as a string. The code should start with:
```python
def binary_to_hex(binary: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_hex(binary: str) -> str:
"""
Converts a binary number to its hexadecimal representation.
Args:
binary (str): A string representing the binary number.
Returns:
str: A string representing th... |
evol_instruct_66k | 17,023 | Write a Python function to find and return the penultimate element from a provided list. If the list has fewer than two elements, the function should return `None`.
The code should start with:
```python
from typing import List, Optional
def get_penultimate_element(lst: List[int]) -> Optional[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def get_penultimate_element(lst: List[int]) -> Optional[int]:
"""
Returns the penultimate element from the provided list.
Args:
lst (List[int]): The list from which to extract the ... |
evol_instruct_66k | 17,032 | Write a Python function to reduce a given floating-point number to exactly four decimal places, adhering to standard floating point notation. The function should handle both positive and negative numbers, as well as numbers with fewer than four decimal places. The code should start with:
```python
def reduce_to_four_de... | Here is the Python code to solve the given problem in the markdown block:
```python
def reduce_to_four_decimal_places(number: float) -> float:
"""
Reduces a given floating-point number to exactly four decimal places.
Args:
number (float): The floating-point number to be reduced.
Returns:
... |
evol_instruct_66k | 17,033 | Write a Python function to create a five-dimensional tensor of dimensions 3x3x3x3x3 using the NumPy library, and populate it with randomly generated integer values within the range of -50 to 50. The function should return the generated tensor.
The code should start with:
```python
import numpy as np
def create_random... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def create_random_tensor() -> np.ndarray:
"""
Create a five-dimensional tensor of dimensions 3x3x3x3x3 and populate it with randomly generated integer values within the range of -50 to 50.
Returns:
... |
evol_instruct_66k | 17,042 | Write a Python function to check if the lexeme "python" (case-insensitive) appears in a given string. The function should return `True` if the lexeme is found, and `False` otherwise. The code should start with:
```python
def contains_python_lexeme(input_string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def contains_python_lexeme(input_string: str) -> bool:
"""
Checks if the lexeme "python" (case-insensitive) appears in the given input string.
Args:
input_string (str): The string to be checked for the presence of t... |
evol_instruct_66k | 17,047 | Write a Python function to determine the highest and lowest numerical values within a given list of integers. The function should return a tuple containing the highest and lowest values. The code should start with:
```python
from typing import List, Tuple
def find_extremes(numbers: List[int]) -> Tuple[int, int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Tuple, Optional
def find_extremes(numbers: List[int]) -> Optional[Tuple[int, int]]:
"""
Determine the highest and lowest numerical values within a given list of integers.
Args:
numbers (L... |
evol_instruct_66k | 17,060 | 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... |
evol_instruct_66k | 17,070 | Write a Python function to subtract two matrices element-wise. The matrices are represented as lists of lists, where each inner list represents a row of the matrix. The function should ensure that the matrices are of the same dimensions before performing the subtraction. If the matrices are not of the same dimensions, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def subtract_matrices(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[List[int]]:
"""
Subtracts two matrices element-wise.
Args:
matrix1 (List[List[int]]): The first matrix.
... |
evol_instruct_66k | 17,078 | Write a Python function to check if a given value `y` exists in a dictionary. The function should iterate through the dictionary using a for loop and return `True` if `y` is found as a value in the dictionary, otherwise return `False`. The code should start with:
```python
from typing import Dict, Any
def is_value_in_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def is_value_in_dict(dictionary: Dict[Any, Any], y: Any) -> bool:
"""
Check if a given value `y` exists in the provided dictionary.
Args:
dictionary (Dict[Any, Any]): The dictionary to ... |
evol_instruct_66k | 17,084 | Write a Python function to find and return the bottom `k` lowest numbers from a given list of integers. The function should handle cases where `k` is greater than the length of the list, and it should return an empty list if `k` is less than or equal to 0. The function should be efficient and use the `heapq` module to ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import heapq
def get_bottom_k_lowest(arr: List[int], k: int) -> List[int]:
"""
Returns the bottom k lowest numbers from the given list.
Args:
arr (List[int]): The list of integers from which... |
evol_instruct_66k | 17,095 | Write a Python function to generate a sequence of distinct random numbers between a given range `[start, end]`. The sequence should include all the numbers from `start` to `end` exactly once. Validate the output by ensuring that every number appears only once in the sequence.
The code should start with:
```python
from... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_unique_random_sequence(start: int, end: int) -> List[int]:
"""
Generates a sequence of distinct random numbers between `start` and `end` (inclusive).
Args:
start (... |
evol_instruct_66k | 17,105 | Write a Python function to capitalize the first character of each word in a given list of sentences. Each sentence is a string in lowercase form, and the function should return a new list of sentences where each word in the sentences starts with an uppercase letter. The function should handle sentences that end with a ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def capitalize_words_in_sentences(sentences: List[str]) -> List[str]:
"""
Capitalizes the first character of each word in a list of sentences.
Args:
sentences (List[str]): A list of sentence... |
evol_instruct_66k | 17,115 | 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... |
evol_instruct_66k | 17,128 | Write a Python function to create a dictionary where the keys are numbers between 1 and `n` (both included), and the values are the squares of the keys. The final output should be sorted in ascending order of their respective squares. Ensure the program is efficient by using only a single loop for computations.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def generate_sorted_squares_dict(n: int) -> Dict[int, int]:
"""
Generates a dictionary where keys are numbers from 1 to n (inclusive) and values are their squares.
The dictionary is sorted in ascendi... |
evol_instruct_66k | 17,137 | Write a Python function to calculate the sum of the first five elements in a given list. If the list has fewer than five elements, the function should return the sum of all elements in the list. The function should handle lists of any length and ensure that it does not attempt to access elements that do not exist.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_first_five(arr: List[int]) -> int:
"""
Calculate the sum of the first five elements in a given list.
If the list has fewer than five elements, return the sum of all elements.
Args:
... |
evol_instruct_66k | 17,153 | Write a Python function to generate an HTML document featuring a table that presents individuals' names, ages, and telephone numbers, sorted by age in ascending order. The function should accept a list of dictionaries, where each dictionary contains the keys 'Name', 'Age', and 'Phone number'. The function should return... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def generate_sorted_html_table(people: List[Dict[str, str]]) -> str:
"""
Generates an HTML document featuring a table that presents individuals' names, ages, and telephone numbers, sorted by age in... |
evol_instruct_66k | 17,163 | Write a Python function to determine the day of the week for a given date string in the format "Month Day, Year". The function should return the day of the week as a string (e.g., "Monday", "Tuesday", etc.).
The code should start with:
```python
from datetime import datetime
def get_day_of_week(date: str) -> str:
```... | 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: str) -> str:
"""
Determine the day of the week for a given date string in the format "Month Day, Year".
Args:
date (str): The date string in the format "Month... |
evol_instruct_66k | 17,170 | Write a Python function to perform a ternary search on a sorted array to find the index of a given key. The function should recursively divide the array into three parts and search for the key in the appropriate segment. If the key is found, return its index; otherwise, return -1.
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 ternary_search(arr: List[int], key: int, left: int, right: int) -> int:
"""
Perform a ternary search on a sorted array to find the index of a given key.
Args:
arr (List[int]): The sorted... |
evol_instruct_66k | 17,171 | Write a Python function to calculate the largest disparity between the values contained in two numerical arrays. The elements in the arrays can either be integers or floating point numbers, and the arrays won't necessarily be of equal length. If any array is empty, the function should return `None`.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union, Optional
def calculate_largest_disparity(arr1: List[Union[int, float]], arr2: List[Union[int, float]]) -> Optional[Union[int, float]]:
"""
Calculate the largest disparity between the values conta... |
evol_instruct_66k | 17,180 | Write a Python function to determine if one string (`string_2`) is a substring of another string (`string_1`) using only basic string operations. The function should return the starting index of the first occurrence of `string_2` within `string_1`. If `string_2` is not a substring of `string_1`, the function should ret... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_substring(string_1: str, string_2: str) -> int:
"""
Determines if string_2 is a substring of string_1 and returns the starting index of the first occurrence.
If string_2 is not a substring of string_1, returns -1.
... |
evol_instruct_66k | 17,185 | Write a Python function to sort a given list of integers in ascending order using the merge sort algorithm. The function should return the sorted list. The code should start with:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order using the merge sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
... |
evol_instruct_66k | 17,193 | Write a Python function to determine if a given year is a leap year and then use this function to generate a list of all leap years within a specified range. The function should start with:
```python
def is_leap_year(year: int) -> bool:
```
and the function to generate the list of leap years should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_leap_year(year: int) -> bool:
"""
Determine if a given year is a leap year.
Args:
year (int): The year to check.
Returns:
bool: True if the year is a leap year, False oth... |
evol_instruct_66k | 17,205 | Write a Python function to evaluate the congruity of two strings based on the specified criteria of regenerative syntax. The regenerative syntax criteria is defined by the regular expression `^[a-z]+$`, which ensures that both strings consist only of lowercase alphabetical characters. The function should return `True` ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def check_congruity(string1: str, string2: str) -> bool:
"""
Evaluates the congruity of two strings based on the specified criteria of regenerative syntax.
The criteria is defined by the regular expression `^[a-z]... |
evol_instruct_66k | 17,206 | Write a Python function to convert a list of hexadecimal strings into their corresponding ASCII characters. The function should return a list of these ASCII characters. The code should start with:
```python
from typing import List
def hex_to_ascii(hex_list: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def hex_to_ascii(hex_list: List[str]) -> List[str]:
"""
Converts a list of hexadecimal strings into their corresponding ASCII characters.
Args:
hex_list (List[str]): A list of hexadecimal ... |
evol_instruct_66k | 17,208 | Write a Python function to generate a jumbled 5x5 two-dimensional array filled with numbers from 1 to 25 in random order. The function should return the generated array.
The code should start with:
```python
from typing import List
import numpy as np
def generate_jumbled_array() -> List[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 generate_jumbled_array() -> List[List[int]]:
"""
Generates a jumbled 5x5 two-dimensional array filled with numbers from 1 to 25 in random order.
Returns:
List[List[int... |
evol_instruct_66k | 17,209 | Write a Python function to create a complex multi-stacked Nim game board with size `n`. The board should be represented as a list of lists (2D array) where each sub-list denotes a separate stack of stones. Each stack should contain a random number of stones, and the stones within each stack should be misarranged. The f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def create_nim_board(n: int) -> List[List[int]]:
"""
Creates a complex multi-stacked Nim game board with size `n`.
Args:
n (int): The size of the board. Each stack will contain... |
evol_instruct_66k | 17,215 | Write a Python function to determine the day of the week for a given date and timestamp. The function should accept a date and timestamp as input 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: datetime) -> st... | 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: datetime) -> str:
"""
Determine the day of the week for a given date and timestamp.
Args:
date_time (datetime): A datetime object representing the date a... |
evol_instruct_66k | 17,216 | Write a Python function to find and return a list of all indices in a given list where a specified numerical value can be found. The function should handle cases where the specified value is not present in the list by returning an empty list. The code should start with:
```python
from typing import List
def find_all_i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_all_indices(num_list: List[int], val: int) -> List[int]:
"""
Find all indices in the given list where the specified numerical value is found.
Args:
num_list (List[int]): The list of... |
evol_instruct_66k | 17,217 | Write a Python function to optimize and refactor the given code snippet. The original code contains unnecessary redundancy, inappropriate computations, and logical mistakes. The task is to identify and fix these issues, improve the code's structure and non-functional properties, and provide the optimized Python code. A... | Here is the Python code to solve the given problem in the markdown block:
```python
def optimized_computation(x: int, z: int) -> int:
"""
Optimize and refactor the given code snippet to improve its structure and non-functional properties.
Args:
x (int): The first integer input.
z (int): The... |
evol_instruct_66k | 17,220 | Write a Python function to filter customers based on their order history. The function should take a list of customer dictionaries, where each dictionary contains information about a customer's orders. The function should return a list of customers who have made more than 5 orders in the last month and have ordered at ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def filter_customers(customers: List[Dict]) -> List[Dict]:
"""
Filters customers based on their order history and returns a list of customers who have made more than 5 orders in the last month
... |
evol_instruct_66k | 17,225 | Write a Python function to capitalize the first letter of each word in a given text string. The function should handle various edge cases, such as empty strings, strings with only one word, and strings with multiple spaces between words. The function should return the modified string with each word capitalized.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
def capitalize_words(text: str) -> str:
"""
Capitalizes the first letter of each word in the given text string.
Args:
text (str): The input text string to be processed.
Returns:
str: The modified text s... |
evol_instruct_66k | 17,230 | Write a Python function to find and return the only composite number in a given array that is less than 20. If no such number exists, return `None`.
The code should start with:
```python
from typing import List, Optional
def find_composite_less_than_20(array: List[int]) -> Optional[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def is_composite(n: int) -> bool:
"""
Check if a number is composite.
Args:
n (int): The number to check.
Returns:
bool: True if the number is composite, False otherwi... |
evol_instruct_66k | 17,232 | Write a Python function to convert a given date string to a `datetime` object. The function should handle different date formats and include robust exception handling to manage potential errors during the conversion process. The function should start with:
```python
from datetime import datetime
from typing import Opti... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
from typing import Optional
def convert_to_datetime(date_string: str, date_format: str) -> Optional[datetime]:
"""
Converts a given date string to a datetime object based on the provided date forma... |
evol_instruct_66k | 17,234 | Write a Python function to filter out non-string elements from a list of mixed data types and return a new list containing only the string elements. The function should handle lists with various data types, including integers, floats, strings, and other objects. The code should start with:
```python
from typing import... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_strings(mixed_list: List[object]) -> List[str]:
"""
Filters out non-string elements from a list of mixed data types and returns a new list containing only the string elements.
Args:
... |
evol_instruct_66k | 17,235 | Write a Python function to apply a given function `g` to every second element of an input list. The function should return a new list where every second element (starting from the first element) has been transformed by the function `g`, while the other elements remain unchanged.
The code should start with:
```python
f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable
def apply_function_to_every_second_element(input_list: List, g: Callable) -> List:
"""
Applies the given function `g` to every second element of the input list.
Args:
input_list (L... |
evol_instruct_66k | 17,237 | Write a Python function to convert a list of string representations of numbers into their corresponding integer formats. The function should handle a list of strings where each string represents a valid integer. The function should return a list of integers.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_strings_to_integers(string_list: List[str]) -> List[int]:
"""
Converts a list of string representations of numbers into their corresponding integer formats.
Args:
string_list (Li... |
evol_instruct_66k | 17,250 | Write a Python function to create and return a dictionary with a key "location" that stores a tuple containing coordinates in the form of latitude and longitude. The function should accept two floating-point numbers representing the latitude and longitude as input parameters.
The code should start with:
```python
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
def create_location_dict(latitude: float, longitude: float) -> dict:
"""
Creates and returns a dictionary with a key "location" that stores a tuple of coordinates (latitude, longitude).
Args:
latitude (float): The l... |
evol_instruct_66k | 17,257 | Write a Python function to convert a given hexadecimal string representation of a capital English alphabet character into its corresponding ASCII character. The function should handle only valid hexadecimal strings that represent capital English alphabet characters.
The code should start with:
```python
def hex_to_asc... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_ascii(hex_str: str) -> str:
"""
Converts a given hexadecimal string representation of a capital English alphabet character into its corresponding ASCII character.
Args:
hex_str (str): A string representin... |
evol_instruct_66k | 17,268 | Write a Python function to calculate the average of a list of heights. The function should handle the case where the list is empty by returning a specific error message. The code should start with:
```python
from typing import List, Union
def calculate_average_height(heights: List[int]) -> Union[float, str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def calculate_average_height(heights: List[int]) -> Union[float, str]:
"""
Calculate the average height from a list of heights.
Args:
heights (List[int]): A list of integers represent... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.