source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 27,794 | Write a Python function to compute the nth Fibonacci number efficiently using dynamic programming. The function should use an iterative approach to avoid the exponential time complexity of the naive recursive solution. The code should start with:
```python
def get_fibonacci(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_fibonacci(n: int) -> int:
"""
Compute the nth Fibonacci number using an iterative approach.
Args:
n (int): The position in the Fibonacci sequence to compute.
Returns:
int: The nth Fibonacci numb... |
evol_instruct_66k | 27,799 | Write a Python function to extract the license plate number, state of issue, and issue date from a given pipe-separated string. The string format is `state|license_plate|issue_date`, where:
- `state` is a two-letter uppercase abbreviation (e.g., "NY").
- `license_plate` is an alphanumeric string (e.g., "ABC1234").
- `i... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import Dict
def extract_license_info(data: str) -> Dict[str, str]:
"""
Extracts the license plate number, state of issue, and issue date from a pipe-separated string.
Args:
data (str): A pipe-... |
evol_instruct_66k | 27,810 | Write a Python function to clean up a list of emails and put them into a new list. The cleaning process involves the following steps:
1. Split each email into the local part and the domain part.
2. Remove any characters after the '+' character in the local part.
3. Remove any characters after the '.' character in the d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clean_emails(emails: List[str]) -> List[str]:
"""
Cleans up a list of emails by removing characters after '+' in the local part and after '.' in the domain part.
Args:
emails (List[str])... |
evol_instruct_66k | 27,814 | Write a Python function to replace all space characters in a given string with hyphen characters. The function should handle strings of varying lengths, including empty strings. The code should start with:
```python
def replace_spaces_with_hyphens(sentence: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def replace_spaces_with_hyphens(sentence: str) -> str:
"""
Replace all space characters in the given string with hyphen characters.
Args:
sentence (str): The input string in which spaces need to be replaced.
... |
evol_instruct_66k | 27,826 | Write a Python function to calculate the product of three integers, ensuring that the function handles edge cases such as zero and negative numbers correctly. The function should also be able to handle large integers without overflow issues.
The code should start with:
```python
def multiply_three_numbers(a: int, b: i... | Here is the Python code to solve the given problem in the markdown block:
```python
def multiply_three_numbers(a: int, b: int, c: int) -> int:
"""
Calculate the product of three integers.
Args:
a (int): The first integer.
b (int): The second integer.
c (int): The third integer.
... |
evol_instruct_66k | 27,859 | Write a Python function to compute the product of distinct numerical elements in a given array. The function should ignore non-numeric elements and ensure that each number is only considered once in the calculation. The code should start with:
```python
from typing import List, Union
def product_of_distinct_numbers(ar... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def product_of_distinct_numbers(array: List[Union[int, float, str, None]]) -> Union[int, float]:
"""
Computes the product of distinct numerical elements in the given array.
Args:
arra... |
evol_instruct_66k | 27,864 | Write a Python function to sort a list of strings based on their character count in ascending order. The function should take a list of strings as input and return the sorted list. The code should start with:
```python
from typing import List
def sort_strings_by_length(strings: 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_strings_by_length(strings: List[str]) -> List[str]:
"""
Sorts a list of strings based on their character count in ascending order.
Args:
strings (List[str]): The list of strings to ... |
evol_instruct_66k | 27,866 | 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:
i... |
evol_instruct_66k | 27,877 | Write a Python function to count the frequency of each word in a given string. The string contains words separated by commas, spaces, or both. The function should return a dictionary where the keys are the words and the values are the frequencies of those words.
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 Dict
def count_words(s: str) -> Dict[str, int]:
"""
Count the frequency of each word in a given string.
Args:
s (str): The input string containing words separated by commas, spaces, or both.
... |
evol_instruct_66k | 27,882 | Write a Python function to determine if the product of any three unique integers in a given list is an even number. The list will have a length in the range of 3 to 1000, and the integers in the list will be in the range of -10^6 to 10^6. The function should be optimized for performance.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def has_even_product_of_three(lst: List[int]) -> bool:
"""
Determines if the product of any three unique integers in the given list is an even number.
Args:
lst (List[int]): A list of intege... |
evol_instruct_66k | 27,892 | Write a Python function that iterates through each character in a given string and returns a list of these characters. The function should handle strings of any length, including empty strings. The code should start with:
```python
from typing import List
def string_to_char_list(s: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def string_to_char_list(s: str) -> List[str]:
"""
Converts a given string into a list of its characters.
Args:
s (str): The input string to be converted.
Returns:
List[str]: A... |
evol_instruct_66k | 27,893 | Write a Python function to calculate the product of all elements in a given list of numbers. The function should handle an empty list by returning 1, as the multiplicative identity. The code should start with:
```python
from typing import List
def product_of_list(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def product_of_list(numbers: List[int]) -> int:
"""
Calculate the product of all elements in a given list of integers.
Args:
numbers (List[int]): The list of integers whose product is to b... |
evol_instruct_66k | 27,894 | Write a Python function to find and return all uneven (odd) numbers within a given range, inclusively. The function should take two integers, `start` and `end`, as input and return a list of all odd numbers within this range.
The code should start with:
```python
from typing import List
def find_odd_numbers(start: in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_odd_numbers(start: int, end: int) -> List[int]:
"""
Find and return all odd numbers within a given range, inclusively.
Args:
start (int): The starting number of the range (inclusive... |
evol_instruct_66k | 27,895 | Write a Python function to disintegrate a given string into its constituent words using a provided dictionary of valid words. The function should return a single string with the words separated by a single space. The input string does not contain any spaces, and the function should ensure that all resulting words are v... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def disintegrate_string(txt: str, dictionary: Set[str]) -> str:
"""
Disintegrates a given string into its constituent words using a provided dictionary of valid words.
Args:
txt (str): The in... |
evol_instruct_66k | 27,908 | Write a Python function to compute the pairwise products of consecutive elements in a tuple. The function should return a new tuple where each element is the product of the corresponding element and the next element in the input tuple. The function should also handle negative numbers and zeros. If the input is not a tu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Union
def pairwise_product(input_tuple: Tuple[int, ...]) -> Union[Tuple[int, ...], str]:
"""
Compute the pairwise products of consecutive elements in a tuple.
Args:
input_tuple (Tuple[int,... |
evol_instruct_66k | 27,943 | Write a Python function to convert a given sentence into its binary representation, where each character is represented by its 8-bit binary code. The function should return a single string where each binary code is separated by a space. The code should start with:
```python
def sentence_to_binary(sentence: str) -> str:... | Here is the Python code to solve the given problem in the markdown block:
:
```python
def sentence_to_binary(sentence: str) -> str:
"""
Converts a given sentence into its binary representation, where each character is represented by its 8-bit binary code.
Args:
sentence (str): The input sentence to... |
evol_instruct_66k | 27,950 | Write a Python function to calculate the total price of a given list of items including taxes. Each item in the list has additional attributes such as weight and category, and taxes are applied differently based on the category of the item. If a category has no specified tax rate, apply a default tax rate.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def calculate_total_cost(items: List[Dict[str, any]], tax_rates: Dict[str, float], default_tax_rate: float) -> float:
"""
Calculate the total price of a given list of items including taxes.
Ar... |
evol_instruct_66k | 27,961 | Write a Python function to count the frequency of each unique keyword in a given narrative text. The function should systematically scan the text, distinguish each unique keyword, and quantify their recurrences. The function should return a dictionary where the keys are the unique keywords and the values are their resp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import re
from collections import Counter
def count_keyword_frequency(narrative: str) -> Dict[str, int]:
"""
Count the frequency of each unique keyword in the given narrative text.
Args:
nar... |
evol_instruct_66k | 27,966 | Write a Python function to determine if two given strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should be case-insensitive and should ignore spaces.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(str1: str, str2: str) -> bool:
"""
Determines if two given strings are anagrams of each other.
Args:
str1 (str): The first string to compare.
str2 (str): The second string to compare.
R... |
evol_instruct_66k | 27,970 | Write a Python function to extract and return a list of distinct elements from a given numerical vector. The function should handle vectors with duplicate elements and ensure that each distinct element is included in the result exactly once.
The code should start with:
```python
from typing import List
def extract_di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def extract_distinct_elements(arr: List[int]) -> List[int]:
"""
Extracts and returns a list of distinct elements from the given numerical vector.
Args:
arr (List[int]): The numerical vector ... |
evol_instruct_66k | 27,976 | Write a Python function that takes a single alphanumeric character sequence as input and returns a new string where each character from the input sequence is repeated twice consecutively. The function should handle any alphanumeric string, including those with spaces.
The code should start with:
```python
def double_c... | Here is the Python code to solve the given problem in the markdown block:
```python
def double_characters(s: str) -> str:
"""
Returns a new string where each character from the input string is repeated twice consecutively.
Args:
s (str): The input alphanumeric character sequence.
Returns:
... |
evol_instruct_66k | 27,985 | Write a Python function to reverse the order of characters in a given string. The function should handle strings of varying lengths, including empty strings. The code should start with:
```python
def reverse_string(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(input_string: str) -> str:
"""
Reverses the order of characters in the given string.
Args:
input_string (str): The string to be reversed.
Returns:
str: The reversed string.
"""
... |
evol_instruct_66k | 27,987 | Write a Python function to find all employees in a given organization who hold a specific role. The organization's structure is represented as a hierarchical JSON object. The function should traverse the JSON structure and return a list of employee names who match the specified role.
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, Dict
def find_employees_by_role(organization: Dict, role: str) -> List[str]:
"""
Find all employees in the organization who hold a specific role.
Args:
organization (Dict): A hierarchical J... |
evol_instruct_66k | 27,994 | Write a Python function to generate the Fibonacci sequence up to a specified number of terms using list comprehension. The function should return a list containing the Fibonacci sequence up to the nth term. If n is less than or equal to 0, the function should return an empty 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 generate_fibonacci(n: int) -> List[int]:
"""
Generates the Fibonacci sequence up to the nth term using list comprehension.
Args:
n (int): The number of terms in the Fibonacci sequence ... |
evol_instruct_66k | 28,002 | Write a Python function to implement the insertion sort algorithm on a given list of integers. The function should sort the list in ascending order. Additionally, provide a detailed explanation of the time complexity and space complexity of the chosen approach.
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 insertion_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order using the insertion sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.... |
evol_instruct_66k | 28,012 | Write a Python function to remove all empty strings from a given list of strings and then sort the remaining strings lexicographically. The function should not use Python's built-in `sort` function or any auxiliary data structures. The function should aim for a time complexity of O(n log n), where n is the number of el... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_empty_and_sort(strings: List[str]) -> List[str]:
"""
Removes all empty strings from the given list and sorts the remaining strings lexicographically.
Args:
strings (List[str]): Th... |
evol_instruct_66k | 28,015 | Write a Python function to find all positive factors of a given distinct mathematical integer `X`. The function should return a list of all positive factors of `X`.
The code should start with:
```python
from typing import List
def find_positive_factors(x: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_positive_factors(x: int) -> List[int]:
"""
Find all positive factors of a given positive integer `X`.
Args:
x (int): The positive integer for which to find the factors.
Returns... |
evol_instruct_66k | 28,024 | Write a Python function to find the last position of a target element in a sorted array. The array may contain duplicate elements and negative numbers. Implement this function without using built-in methods and with a time complexity better than O(n).
The code should start with:
```python
def find_last_position(nums: ... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_last_position(nums: list, target: int) -> int:
"""
Find the last position of a target element in a sorted array.
Args:
nums (list): A sorted list of integers, which may contain duplicates and negative numbe... |
evol_instruct_66k | 28,057 | Write a Python function to check if a given integer is present in a dictionary. The function should iterate over the dictionary's keys and print a message if the integer is found. The dictionary should be predefined with some integer keys and boolean values.
The code should start with:
```python
def check_integer_in_d... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_integer_in_dict(integer_to_check: int, dictionary: dict) -> None:
"""
Checks if a given integer is present in the dictionary's keys and prints a message if found.
Args:
integer_to_check (int): The integer ... |
evol_instruct_66k | 28,058 | Write a Python function to organize two distinct sets: one containing integers and the other containing words. The function should sort the integer set in ascending numerical order and the word set in lexicographic (alphabetical) order. The function should return a tuple containing the sorted integer list and the sorte... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def organize_collections(integer_collection: List[int], word_collection: List[str]) -> Tuple[List[int], List[str]]:
"""
Organizes two distinct collections: one containing integers and the other co... |
evol_instruct_66k | 28,060 | Write a Python function to calculate the cumulative sum of every odd number in a given list of integers. The function should return the cumulative sum of all odd numbers found in the list. The code should start with:
```python
from typing import List
def cumulative_sum_of_odds(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_sum_of_odds(numbers: List[int]) -> int:
"""
Calculate the cumulative sum of every odd number in the given list of integers.
Args:
numbers (List[int]): The list of integers fro... |
evol_instruct_66k | 28,065 | Write a Python function to implement the Quick Sort algorithm using recursion. The function should sort a list of integers in ascending order. The code should start with:
```python
from typing import List
def quick_sort(array: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def quick_sort(array: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order using the Quick Sort algorithm.
Args:
array (List[int]): The list of integers to be sorted.
... |
evol_instruct_66k | 28,070 | Write a Python function to generate an array that comprises the first `n` integers raised to the power of `k`, where `n` and `k` are provided as input parameters. The function should return the resulting array.
The code should start with:
```python
from typing import List
def generate_power_array(n: int, k: int) -> L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_power_array(n: int, k: int) -> List[int]:
"""
Generate an array that comprises the first `n` integers raised to the power of `k`.
Args:
n (int): The number of integers to proces... |
evol_instruct_66k | 28,079 | Write a Python function to find the longest text in a given array of textual elements that has a number of characters no more than a specified limit `k`. If no text meets the criteria, return a specific message indicating that no valid text was found.
The code should start with:
```python
from typing import List
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_longest_valid_text(texts: List[str], k: int) -> str:
"""
Finds the longest text in the given array of textual elements that has a number of characters no more than k.
Args:
texts (L... |
evol_instruct_66k | 28,080 | Write a Python function to create an infinite cyclical iterator for a given list of elements while preserving the original sequence. The function should return an iterator that cycles through the elements of the list indefinitely. The code should start with:
```python
from typing import List, Iterator
def create_cycli... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Iterator
import itertools
def create_cyclical_iterator(elements: List[str]) -> Iterator[str]:
"""
Creates an infinite cyclical iterator for a given list of elements.
Args:
elements (List[st... |
evol_instruct_66k | 28,088 | Write a Python function to generate a Boolean array where each element is `True` if the corresponding element in the input list is odd, and `False` if it is even. The function should be applicable to any list of integers.
The code should start with:
```python
from typing import List
def odd_even_boolean_array(numbers... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def odd_even_boolean_array(numbers: List[int]) -> List[bool]:
"""
Generates a Boolean array where each element is True if the corresponding element in the input list is odd, and False if it is even.
... |
evol_instruct_66k | 28,089 | Write a Python function to generate a random integer within a specified range, ensuring that the function can handle cases where the minimum range is greater than the maximum range by swapping the values. The function should also handle cases where the range values are equal, returning the single value in such cases. T... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_random_integer(min_range: int, max_range: int) -> int:
"""
Generates a random integer within the specified range [min_range, max_range].
Args:
min_range (int): The lower bound of the rang... |
evol_instruct_66k | 28,101 | Write a Python function to find the length of the longest increasing subsequence (LIS) in a given list of distinct integers. The function should return the length of the LIS.
The code should start with:
```python
from typing import List
def longest_increasing_subsequence(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_increasing_subsequence(arr: List[int]) -> int:
"""
Calculate the length of the longest increasing subsequence in a given list of distinct integers.
Args:
arr (List[int]): A list ... |
evol_instruct_66k | 28,115 | Write a Python function to find the k-th largest number from a given array of integers. The function should handle duplicate values by treating them as a single entity. If the array has fewer than k unique elements, the function should return a specific message indicating the array does not have enough unique elements.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def kth_largest(numbers: List[int], k: int) -> int or str:
"""
Find the k-th largest number from a given array of integers.
Args:
numbers (List[int]): The array of integers from which to fin... |
evol_instruct_66k | 28,124 | Write a Python function to manipulate the last element of a dynamically sized array. The function should take a list and an optional integer value as input. If the integer value is provided, it should replace the last element of the list with this value. If the integer value is not provided, the function should return ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def manipulate_last_element(array: List[int], new_value: Optional[int] = None) -> Optional[int]:
"""
Manipulates the last element of a dynamically sized array.
If `new_value` is provided, ... |
evol_instruct_66k | 28,129 | Write a Python function to convert a given tuple, containing only integer data types, into a nested dictionary format. The function should recursively build the dictionary such that each integer in the tuple becomes a key in the dictionary, and the value associated with that key is another dictionary created from the r... | Here is the Python code to solve the given problem in the markdown block:
```python
def tuple_to_nested_dict(input_tuple: tuple) -> dict:
"""
Converts a tuple of integers into a nested dictionary format.
Args:
input_tuple (tuple): A tuple containing only integer data types.
Returns:
di... |
evol_instruct_66k | 28,131 | Write a Python function to calculate the sum of all elements in a given list of integers. The function should iterate through the list and accumulate the sum of its elements. The code should start with:
```python
from typing import List
def sum_of_list(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_list(numbers: List[int]) -> int:
"""
Calculate the sum of all elements in a given list of integers.
Args:
numbers (List[int]): The list of integers to sum.
Returns:
i... |
evol_instruct_66k | 28,144 | Write a Python function to perform a binary search on a sorted list of integers to find the index of a given number. If the number is not found, return -1. The function should start with:
```python
from typing import List
def binary_search(data: List[int], search_num: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(data: List[int], search_num: int) -> int:
"""
Perform a binary search on a sorted list of integers to find the index of a given number.
Args:
data (List[int]): A sorted... |
evol_instruct_66k | 28,148 | Write a Python function to compute the sum of the squares of two numbers. The function should take two integers as input and return the sum of their squares. The code should start with:
```python
def sum_of_squares(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_squares(a: int, b: int) -> int:
"""
Compute the sum of the squares of two integers.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
int: The sum of the squares... |
evol_instruct_66k | 28,151 | Write a Python function to implement a parallel quicksort algorithm using the `concurrent.futures` module. The function should take a list of integers as input and return the sorted list. The function should leverage the `ThreadPoolExecutor` to parallelize the sorting process.
The code should start with:
```python
fro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from concurrent.futures import ThreadPoolExecutor, as_completed
def parallel_quicksort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using a parallel quicksort algorithm.
Args:
... |
evol_instruct_66k | 28,153 | Write a Python function to convert a given angle from turns to radians. One turn is equivalent to 360 degrees or \(2\pi\) radians. The function should take a single parameter representing the number of turns and return the equivalent angle in radians.
The code should start with:
```python
import math
def turns_to_rad... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def turns_to_radians(turns: float) -> float:
"""
Convert a given angle from turns to radians.
Args:
turns (float): The number of turns to convert.
Returns:
float: The equivalent angle in ra... |
evol_instruct_66k | 28,159 | Write a Python function to calculate the cumulative significance score of an employee and all their subordinates up to a specified hierarchical level in an organization. The organization is represented by a list of employees, where each employee is represented by a list containing their unique identifier, significance ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_significance(employee_data: List[List[int]], employee_id: int, target_level: int) -> int:
"""
Calculate the cumulative significance score of an employee and all their subordinates up to a ... |
evol_instruct_66k | 28,161 | Write a Python function to generate a list of Fibonacci numbers up to a given number `n`. The function should be efficient and performant, ensuring that it handles large values of `n` without significant performance degradation. The function should start with:
```python
from typing import List
def generate_fibonacci_s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci_sequence(n: int) -> List[int]:
"""
Generate a list of Fibonacci numbers up to the n-th number.
Args:
n (int): The index up to which the Fibonacci sequence should be ge... |
evol_instruct_66k | 28,164 | Write a Python function to create a 3x3 identity matrix and a 3x3 matrix of random integers between 1 and 10, and then perform matrix multiplication between them. The function should return the result of the matrix multiplication.
The code should start with:
```python
import numpy as np
def matrix_multiplication_with... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def matrix_multiplication_with_identity(random_matrix: np.ndarray) -> np.ndarray:
"""
Perform matrix multiplication between a 3x3 identity matrix and a 3x3 random matrix.
Args:
random_matrix (np.... |
evol_instruct_66k | 28,177 | Write a Python function to determine if two binary sequences can be transformed into each other by exactly one bit inversion operation. The function should return `True` if the transformation is possible, and `False` otherwise. The function should handle binary sequences of equal length and return `False` if the length... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_single_bit_inversion_possible(bin_seq1: str, bin_seq2: str) -> bool:
"""
Determines if two binary sequences can be transformed into each other by exactly one bit inversion.
Args:
bin_seq1 (str): The first bin... |
evol_instruct_66k | 28,180 | Write a Python function to determine if a given integer is a prime number. The function should return `True` if the integer is prime and `False` otherwise. The function should handle edge cases such as negative numbers, 0, and 1, which are not prime numbers.
The code should start with:
```python
def is_prime(n: int) -... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(n: int) -> bool:
"""
Determine if a given integer is a prime number.
Args:
n (int): The integer to check for primality.
Returns:
bool: True if the integer is prime, False otherwise.
"""... |
evol_instruct_66k | 28,181 | Write a Python function to find the length of the longest increasing subsequence (LIS) in a given list of integers. The function should return the length of the LIS.
The code should start with:
```python
from typing import List
def longest_increasing_subsequence(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_increasing_subsequence(arr: List[int]) -> int:
"""
Calculate the length of the longest increasing subsequence in a given list of integers.
Args:
arr (List[int]): The list of inte... |
evol_instruct_66k | 28,185 | Write a Python function to simulate the behavior of the Animal and Lion objects described in the JavaScript code snippet. The function should create an instance of the Lion object, perform operations on it, and return the results of these operations. The function should start with:
```python
def simulate_animal_behavio... | Here is the Python code to solve the given problem in the markdown block:
```python
class Animal:
def __init__(self, type: str, name: str, age: int, is_endangered: bool):
"""
Initialize an Animal object.
Args:
type (str): The type of the animal (e.g., mammal, bird, fish).
... |
evol_instruct_66k | 28,204 | Write a Python function to calculate the exponential value of two integers, `x` and `y`, where `x` is the base and `y` is the exponent. The function should correctly handle the calculation without any logical errors. The code should start with:
```python
def exponential_function(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def exponential_function(x: int, y: int) -> int:
"""
Calculate the exponential value of the base `x` raised to the exponent `y`.
Args:
x (int): The base integer.
y (int): The exponent integer.
Returns:
... |
evol_instruct_66k | 28,222 | Write a Python function to flatten a given tri-dimensional array into a one-dimensional list. The tri-dimensional array is characterized by its `p` layers, `m` horizontal lines, and `n` vertical lines. The function should start with:
```python
from typing import List
def flatten_3d_array(matrix: List[List[List[int]]])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def flatten_3d_array(matrix: List[List[List[int]]]) -> List[int]:
"""
Flattens a given tri-dimensional array into a one-dimensional list.
Args:
matrix (List[List[List[int]]]): The tri-dimens... |
evol_instruct_66k | 28,242 | Write a Python function to filter out elements from a given list of integers that are substantially larger than a specified numerical benchmark. The function should return a new list containing only the elements that are greater than the benchmark. The code should start with:
```python
from typing import List
def filt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_elements_above_benchmark(nums: List[int], benchmark: int = 10) -> List[int]:
"""
Filters out elements from the given list of integers that are substantially larger than the specified benchmark... |
evol_instruct_66k | 28,251 | Write a Python function to calculate the standard deviation of a given list of numbers. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
import math
def calculate_standard_deviation(numbers: List[float]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def calculate_standard_deviation(numbers: List[float]) -> float:
"""
Calculate the standard deviation of a list of numbers.
Args:
numbers (List[float]): A list of numbers for whi... |
evol_instruct_66k | 28,256 | Write a Python function to find the maximum value from a given list of integers. The function should handle lists of any length, 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_max_value(numbers: List[int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_max_value(numbers: List[int]) -> Optional[int]:
"""
Find the maximum value from a given list of integers.
Args:
numbers (List[int]): A list of integers from which to find ... |
evol_instruct_66k | 28,261 | Write a Python function to extract the terminal element (the last element) from each sub-array in a given 2D array while preserving their respective order. If a sub-array is empty, the function should return a specific string indicating that the sub-array is empty.
The code should start with:
```python
from typing imp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_terminal_elements(mylist: List[List[int]]) -> List[int]:
"""
Extracts the terminal element (the last element) from each sub-array in a given 2D array.
If a sub-array is empty, returns a speci... |
evol_instruct_66k | 28,281 | Write a Python function to create a new array of a specified size with all elements initialized to a given integer value. The function should take two parameters: the size of the array and the integer value to initialize all elements. The function should return the newly created array.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_initialized_array(size: int, value: int) -> List[int]:
"""
Creates a new array of the specified size with all elements initialized to the given value.
Args:
size (int): The size o... |
evol_instruct_66k | 28,282 | Write a Python function to check whether a given string consists entirely of vowels. The function should return `True` if all characters in the string are vowels, and `False` otherwise. The function should be case-insensitive, meaning both uppercase and lowercase vowels should be considered.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_vowel_string(s: str) -> bool:
"""
Check whether a given string consists entirely of vowels.
Args:
s (str): The input string to be checked.
Returns:
bool: True if all characters in the string are ... |
evol_instruct_66k | 28,292 | Write a Python function to combine two nested dictionaries, ensuring no loss of contained information during the process. If there are conflicting keys, the value from the second dictionary should overwrite the value from the first dictionary. The function should handle nested dictionaries recursively.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def combine_nested_dicts(dict1: Dict, dict2: Dict) -> Dict:
"""
Combines two nested dictionaries, ensuring no loss of contained information.
If there are conflicting keys, the value from the second d... |
evol_instruct_66k | 28,313 | Write a Python function to extract all public email addresses from a given string. The function should be able to handle various formats of email addresses and should return a list of all valid email addresses found in the input string.
The code should start with:
```python
from typing import List
import re
def extra... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def extract_emails(text: str) -> List[str]:
"""
Extracts all public email addresses from a given string.
Args:
text (str): The input string from which to extract email addresses.
... |
evol_instruct_66k | 28,330 | Write a Python function to check if a given string contains any invalid characters. The function should return `True` if any invalid character is found, otherwise `False`. The invalid characters are defined in a list.
The code should start with:
```python
def check_invalid_characters(input_string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def check_invalid_characters(input_string: str) -> bool:
"""
Check if the given string contains any invalid characters.
Args:
input_string (str): The string to be checked for invalid characters.
Returns:
... |
evol_instruct_66k | 28,335 | Write two Python functions that interact with each other. The first function should accept two lists of strings and return two dictionaries. Each dictionary should have keys that are the strings from the respective lists, and the corresponding values should be the lengths of those strings.
The second function should t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_dictionaries(arr1: List[str], arr2: List[str]) -> (Dict[str, int], Dict[str, int]):
"""
Create two dictionaries from the given lists of strings.
Args:
arr1 (List[str]): ... |
evol_instruct_66k | 28,342 | Write a Python function to identify a character sequence of arbitrary length that ends with the consecutive bigram "oo" and begins with a combination of any two alphanumeric characters. The sequence should also exclude any white spaces. The function should return `True` if the sequence matches the criteria, otherwise `... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_sequence(seq: str) -> bool:
"""
Identifies if a given sequence of characters ends with the consecutive bigram "oo",
begins with a combination of any two alphanumeric characters, and does not contain
... |
evol_instruct_66k | 28,350 | Write a Python function to sort an array of integers in ascending order. The function should handle arrays with lengths between 1 and 50,000 and integers within the range of -50,000 to 50,000. The function should be efficient and should not use Python's built-in sorting functions (`sort()` or `sorted()`). Instead, impl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_array(nums: List[int]) -> List[int]:
"""
Sorts an array of integers in ascending order using the Merge Sort algorithm.
Args:
nums (List[int]): The array of integers to be sorted.
... |
evol_instruct_66k | 28,357 | Write a Python function to generate a matrix of random integers within the range of 1 to 50 with 5 rows and 6 columns. The function should ensure that the matrix is created through a multi-step process. The code should start with:
```python
from typing import List
import numpy as np
def generate_random_matrix() -> Lis... | 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_random_matrix() -> List[List[int]]:
"""
Generates a matrix of random integers within the range of 1 to 50 with 5 rows and 6 columns.
Returns:
List[List[int]]:... |
evol_instruct_66k | 28,359 | Write a Python function to sort a given array of integers using the Shell Sort algorithm. The function should return the sorted array. The code should start with:
```python
from typing import List
def shell_sort(array: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def shell_sort(array: List[int]) -> List[int]:
"""
Sorts the given array of integers using the Shell Sort algorithm.
Args:
array (List[int]): The array of integers to be sorted.
Returns... |
evol_instruct_66k | 28,373 | Write a Python function to find the longest common subsequence (LCS) of two given strings. The function should return the length of the LCS.
The code should start with:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
"""
Calculate the length of the longest common subsequence (LCS) of two given strings.
Args:
str1 (str): The first string.
str2 (str): The second ... |
evol_instruct_66k | 28,380 | Write a Python function to compute the nth Fibonacci number using dynamic programming. The function should efficiently store and reuse previously computed Fibonacci numbers to avoid redundant calculations. The code should start with:
```python
def fibonacci_dp(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def fibonacci_dp(n: int) -> int:
"""
Compute the nth Fibonacci number using dynamic programming.
Args:
n (int): The position in the Fibonacci sequence to compute.
Returns:
int: The nth Fibonacci numbe... |
evol_instruct_66k | 28,388 | Write a Python function to determine if a given integer `x` is greater than 10. If `x` is greater than 10, the function should return the string "x is greater than 10". Otherwise, it should return the string "x is not greater than 10". The function should handle any integer input.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_greater_than_ten(x: int) -> str:
"""
Determines if the given integer x is greater than 10 and returns an appropriate message.
Args:
x (int): The integer to be evaluated.
Returns:
str: A string... |
evol_instruct_66k | 28,390 | Write a Python function to generate all possible dyadic permutations (permutations of length 2) from a given list of integers. The function should return a list of tuples, where each tuple represents a unique dyadic permutation.
The code should start with:
```python
from typing import List, Tuple
import itertools
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import itertools
def generate_dyadic_permutations(nums: List[int]) -> List[Tuple[int, int]]:
"""
Generate all possible dyadic permutations (permutations of length 2) from a given list of integers.... |
evol_instruct_66k | 28,403 | Write a Python function to create and return a dictionary that encapsulates and digitizes human workforce information. The dictionary should include the following keys: "Occupation", "Experience_Years", and "Location". The function should accept three parameters corresponding to these keys and return the constructed di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def create_workforce_info(occupation: str, experience_years: int, location: str) -> Dict[str, str]:
"""
Creates and returns a dictionary encapsulating human workforce information.
Args:
occu... |
evol_instruct_66k | 28,412 | Write a Python function to check if a specific element is present in a given list. The function should return `True` if the element is found in the list, and `False` otherwise. The code should start with:
```python
from typing import List, Any
def is_element_in_list(array: List[Any], element: Any) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def is_element_in_list(array: List[Any], element: Any) -> bool:
"""
Check if a specific element is present in a given list.
Args:
array (List[Any]): The list in which to search for the ... |
evol_instruct_66k | 28,415 | Write a Python function to transform a provided list of string type elements into a list of integer type elements. The function should handle lists of varying lengths and ensure that each string element can be converted to an integer without errors. The code should start with:
```python
from typing import List
def tra... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def transform_to_int_list(str_list: List[str]) -> List[int]:
"""
Transforms a list of string type elements into a list of integer type elements.
Args:
str_list (List[str]): A list of string ... |
evol_instruct_66k | 28,418 | Write a Python function to calculate the cube of a given number. The function should take an integer or a floating-point number as input and return its cube. The code should start with:
```python
def cube(n: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def cube(n: float) -> float:
"""
Calculate the cube of a given number.
Args:
n (float): The number to calculate the cube of.
Returns:
float: The cube of the given number.
"""
return n ** 3
```... |
evol_instruct_66k | 28,423 | Write a Python function to flatten a given two-dimensional matrix into a one-dimensional list. The function should correct any errors in the provided pseudocode and ensure that the matrix is transformed correctly regardless of its dimensions. The code should start with:
```python
from typing import List
def flatten_ma... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def flatten_matrix(matrix: List[List[int]]) -> List[int]:
"""
Flattens a given two-dimensional matrix into a one-dimensional list.
Args:
matrix (List[List[int]]): A two-dimensional list of i... |
evol_instruct_66k | 28,424 | Write a Python function to append a specified text to a given list if the list contains at least one element. If the list is empty, the function should return the list unchanged. The function should also ensure that the input is a list and raise a `TypeError` if it is not.
The code should start with:
```python
from ty... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def append_text_to_list(arr: List[str], text: str) -> List[str]:
"""
Appends the specified text to the given list if the list contains at least one element.
If the list is empty, it returns the list ... |
evol_instruct_66k | 28,427 | Write a Python function to determine if the words "hello" and "world" are consecutively present in the provided list without case sensitivity. The function should return `True` if the words are found consecutively in the list, and `False` otherwise. The code should start with:
```python
from typing import List
def are... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def are_hello_world_consecutive(words: List[str]) -> bool:
"""
Determine if the words "hello" and "world" are consecutively present in the provided list without case sensitivity.
Args:
words... |
evol_instruct_66k | 28,430 | Write a Python function to compute the power of a given n x n matrix to a specified exponential value efficiently using the matrix exponentiation method. The matrix is a 2D list of integers, and the exponential value is a non-negative integer. The function should return the resulting matrix after raising the input matr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_matrices(matrix1: List[List[int]], matrix2: List[List[int]], n: int) -> List[List[int]]:
"""
Multiplies two n x n matrices.
Args:
matrix1 (List[List[int]]): The first matrix.
... |
evol_instruct_66k | 28,435 | Write a Python function to convert a list of hexadecimal numbers into their equivalent representation in the octal number system. The function should handle a list of any length and return a list of octal numbers. The code should start with:
```python
from typing import List
def convert_hex_to_octal(hex_numbers: List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_hex_to_octal(hex_numbers: List[str]) -> List[str]:
"""
Converts a list of hexadecimal numbers into their equivalent octal representation.
Args:
hex_numbers (List[str]): A list of... |
evol_instruct_66k | 28,437 | Write a Python function to invert the keys and values of a given dictionary. If the values are not unique, the new dictionary should have a list of keys as values. The function should handle dictionaries with non-unique values by grouping the keys that share the same value into a list.
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, Union
def invert_dictionary(my_dict: Dict[str, Union[str, int]]) -> Dict[Union[str, int], List[str]]:
"""
Inverts the keys and values of a given dictionary. If the values are not unique,
the n... |
evol_instruct_66k | 28,447 | Write a Python function to extend a given dictionary with additional key-value pairs and update the dictionary based on a list of tuples. Each tuple in the list contains a key and a new value to be updated in the dictionary. The function should iterate over the list of tuples and update the dictionary accordingly. The ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def extend_and_update_dict(my_dict: Dict[str, any], new_pairs: List[Tuple[str, any]]) -> Dict[str, any]:
"""
Extends the given dictionary with new key-value pairs and updates existing keys w... |
evol_instruct_66k | 28,461 | Write a Python function to flatten a nested list structure into a unified, unidimensional array. The nested list can have an arbitrary depth, meaning it can contain lists within lists of any level of nesting. The function should handle any level of nesting and return a single list containing all the elements in a flat ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def flatten_list(nested_list: List[Any]) -> List[Any]:
"""
Flattens a nested list structure into a unified, unidimensional array.
Args:
nested_list (List[Any]): The nested list to be fl... |
evol_instruct_66k | 28,463 | Write a Python function to extract all integer values from a given string and compute their sum. The string contains arbitrary characters and integers, and it is guaranteed that the string will contain at least one integer. The integers in the string can be more than one digit long. The function should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def sum_of_integers_in_string(input_str: str) -> int:
"""
Extracts all integer values from a given string and computes their sum.
Args:
input_str (str): The input string containing arbitrary characters an... |
evol_instruct_66k | 28,509 | 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 | 28,520 | Write a Python function that takes two dictionaries as input and returns a new dictionary. For each key in the first dictionary, if the same key exists in the second dictionary, multiply the values of both keys and include the result in the new dictionary. If a key is not present in the second dictionary, include the v... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_and_multiply_dicts(dict1: Dict[str, int], dict2: Dict[str, int]) -> Dict[str, int]:
"""
Merges two dictionaries and multiplies the values of matching keys.
Args:
dict1 (Dict[str, i... |
evol_instruct_66k | 28,527 | Write a Python function to analyze a given string by counting the total number of characters and the frequency of each character in the string. The function should return the total character count and a dictionary where each key is a character from the string and the value is the frequency of that character.
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import Counter
def analyse_characters_in_string(submitted_string: str) -> tuple[int, dict[str, int]]:
"""
Analyze a given string by counting the total number of characters and the frequency of each character.
... |
evol_instruct_66k | 28,549 | Write a Python function to compute the minimum element within a given array without using any built-in functions or libraries for calculating the minimum value. The function should iterate through the array and determine the smallest element by comparing each element with a variable that holds the current minimum value... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_min_element(array: List[int]) -> int:
"""
Computes the minimum element within a given array without using built-in functions or libraries.
Args:
array (List[int]): The array of inte... |
evol_instruct_66k | 28,550 | Write a Python function to detect and merge consecutive duplicate elements in a given sorted array. The function should return a new array where all consecutive duplicate elements are merged into a single element. The input array is guaranteed to be sorted in ascending order.
The code should start with:
```python
from... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_consecutive_duplicates(arr: List[int]) -> List[int]:
"""
Merges consecutive duplicate elements in a given sorted array.
Args:
arr (List[int]): The sorted array with consecutive dup... |
evol_instruct_66k | 28,551 | Write a Python function to augment an existing tuple by introducing a new element at the foremost position. The function should take two parameters: the existing tuple and the new element to be added. The function should return the augmented tuple.
The code should start with:
```python
from typing import Tuple
def au... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def augment_tuple(existing_tuple: Tuple, new_element) -> Tuple:
"""
Augments an existing tuple by introducing a new element at the foremost position.
Args:
existing_tuple (Tuple): The exist... |
evol_instruct_66k | 28,552 | Write a Python function to split a given input sentence into a list of individual words. The function should handle various edge cases, such as sentences with multiple spaces, leading/trailing spaces, and punctuation marks. The code should start with:
```python
from typing import List
def split_sentence(sentence: str)... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import string
def split_sentence(sentence: str) -> List[str]:
"""
Splits a given input sentence into a list of individual words.
Args:
sentence (str): The input sentence to be split.
Re... |
evol_instruct_66k | 28,561 | Write a Python function to save a given NumPy array to a binary file with a `.npy` extension and then load it back to ensure it retains its original form. The function should handle the saving and loading operations and return the loaded array.
The code should start with:
```python
import numpy as np
from typing impor... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List
def save_and_load_array(array: List[int], filename: str) -> np.ndarray:
"""
Saves a given NumPy array to a binary file with a .npy extension and then loads it back.
Args:
... |
evol_instruct_66k | 28,583 | Write a Python function to construct a dictionary from two tuples of equal length. The first tuple contains keys, and the second tuple contains values. The function should ensure that the tuples are of equal length before constructing the dictionary. If the tuples are not of equal length, the function should return an ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict
def construct_dictionary(tuple1: Tuple[str], tuple2: Tuple[str]) -> Dict[str, str]:
"""
Constructs a dictionary from two tuples of equal length.
Args:
tuple1 (Tuple[str]): A tuple con... |
evol_instruct_66k | 28,587 | Write a Python function to perform an insertion sort on a given list of numbers. The function should sort the list in ascending order. The code should start with:
```python
from typing import List
def insertion_sort(numbers: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def insertion_sort(numbers: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order using the insertion sort algorithm.
Args:
numbers (List[int]): The list of integers to be... |
evol_instruct_66k | 28,603 | Write a Python function to validate and classify the attributes of multiple entities. Each entity has a name, age, and sex. The function should:
1. Validate the gender type to ensure it is one of the acceptable values: "male", "female", or "non-binary".
2. Validate the age to ensure it is a numeric value and within a r... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def validate_entities(entities: List[Dict[str, any]]) -> List[Dict[str, any]]:
"""
Validate and classify the attributes of multiple entities.
Args:
entities (List[Dict[str, any]]): A l... |
evol_instruct_66k | 28,616 | Write a Python function to count the frequency of each distinct alphabetic character in a given text string. The function should return a dictionary where the keys are the lowercase alphabetic characters and the values are their respective counts in the input text. The function should be case-insensitive, meaning 'A' a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_alphabetic_chars(text: str) -> Dict[str, int]:
"""
Counts the frequency of each distinct alphabetic character in the given text string.
Args:
text (str): The input text string to a... |
evol_instruct_66k | 28,638 | Write a Python function to concatenate an array of individual alphabetic characters into a single, continuous textual string. The function should handle any list of characters, including those with spaces and special characters. The code should start with:
```python
from typing import List
def concatenate_characters(c... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def concatenate_characters(characters: List[str]) -> str:
"""
Concatenates an array of individual alphabetic characters into a single, continuous textual string.
Args:
characters (List[str... |
evol_instruct_66k | 28,641 | Write a Python function to swap the first and second characters in a given string. If the string has fewer than two characters, it should return the string unchanged. The function should handle strings of any length, including empty strings.
The code should start with:
```python
def swap_first_two_chars(string: str) -... | Here is the Python code to solve the given problem in the markdown block:
```python
def swap_first_two_chars(string: str) -> str:
"""
Swaps the first and second characters in a given string.
Args:
string (str): The input string in which the first two characters need to be swapped.
Retu... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.