source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 11,472 | Write a Python function to print a 10x10 grid of stars (`*`), with an additional diagonal line of stars from the top-left to the bottom-right corner of the grid. The function should handle the printing logic and ensure that the grid is correctly formatted.
The code should start with:
```python
def print_star_grid():
`... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_star_grid():
"""
Prints a 10x10 grid of stars ('*'), with an additional diagonal line of stars from the top-left to the bottom-right corner.
Args:
None
Returns:
None
"""
for row in ran... |
evol_instruct_66k | 11,473 | Write a Python function to perform element-wise operations (addition, subtraction, and multiplication) on two five-dimensional arrays of size 5 x 5 x 5 x 5 x 5. The function should return a dictionary containing the results of these operations.
The code should start with:
```python
from typing import Dict
import numpy... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import numpy as np
def manipulate_five_dimensional_arrays(arr1: np.ndarray, arr2: np.ndarray) -> Dict[str, np.ndarray]:
"""
Perform element-wise addition, subtraction, and multiplication on two five-dime... |
evol_instruct_66k | 11,478 | Write a Python function to create a dictionary from a given list of tuples, where each tuple contains a key and a value, but only include the key-value pairs where the value is even. The function should start with:
```python
from typing import List, Tuple, Dict
def filter_even_values(input_list: List[Tuple[str, int]])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def filter_even_values(input_list: List[Tuple[str, int]]) -> Dict[str, int]:
"""
Creates a dictionary from a list of tuples, including only the key-value pairs where the value is even.
... |
evol_instruct_66k | 11,489 | Write a Python function to process a list containing both strings and integers. The function should identify the strings, convert them to uppercase without using any built-in Python method or function for direct conversion, and replace the original strings in the list with their uppercase versions. The integers in the ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def to_upper(s: str) -> str:
"""
Converts a given string to uppercase without using built-in methods.
Args:
s (str): The string to be converted to uppercase.
Returns:
str... |
evol_instruct_66k | 11,499 | Write a Python function to sort a given numerical array using the Bubble Sort algorithm. The function should return the sorted array. The code should start with:
```python
from typing import List
def bubble_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 bubble_sort(array: List[int]) -> List[int]:
"""
Sorts a given numerical array using the Bubble Sort algorithm.
Args:
array (List[int]): The numerical array to be sorted.
Returns:
... |
evol_instruct_66k | 11,500 | Write a Python function to find all unique factors of a given number, including both prime and composite factors, without any repetitions. The function should return a sorted list of these factors.
The code should start with:
```python
def find_unique_factors(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_unique_factors(n: int) -> List[int]:
"""
Find all unique factors of a given number, including both prime and composite factors, without any repetitions.
Args:
n (int): The number fo... |
evol_instruct_66k | 11,502 | Write a Python function to reverse a given list of integers. The function should return a new list that is the reverse of the input list. The code should start with:
```python
from typing import List
def reverse_list(input_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 reverse_list(input_list: List[int]) -> List[int]:
"""
Reverses the given list of integers and returns the reversed list.
Args:
input_list (List[int]): The list of integers to be revers... |
evol_instruct_66k | 11,505 | Implement the Quick Sort algorithm to sort a given array of n elements. Additionally, identify and correct the mistakes in the provided erroneous code. The Quick Sort algorithm should have a time complexity of O(n log n) in the average case.
The code should start with:
```python
from typing import List
def quick_sort... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def quick_sort(arr: List[int]) -> List[int]:
"""
Sorts the given array using the Quick Sort algorithm.
Args:
arr (List[int]): The array to be sorted.
Returns:
List[int]: The sor... |
evol_instruct_66k | 11,508 | Write a Python function to parse a date string in the format 'YYYY-MM-DD' and return the month, day, and year as integers. The function should handle the input date string and return the parsed date components in the order of day, month, and year.
The code should start with:
```python
from datetime import datetime
de... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def parse_date(date_str: str) -> tuple:
"""
Parses a date string in the format 'YYYY-MM-DD' and returns the day, month, and year as integers.
Args:
date_str (str): The date string to b... |
evol_instruct_66k | 11,509 | Write a Python function to find the highest odd number from a given list of integers. The function should return the highest odd number if there is at least one odd number in the list, otherwise it should return `None`.
The code should start with:
```python
from typing import List, Optional
def find_highest_odd(numbe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_highest_odd(numbers: List[int]) -> Optional[int]:
"""
Find the highest odd number from a given list of integers.
Args:
numbers (List[int]): A list of integers from which t... |
evol_instruct_66k | 11,516 | Write a Python function to identify the absent values in one numerical array (`array1`) that are not present in another numerical array (`array2`). The function should return a list of these absent values. The code should start with:
```python
from typing import List
def find_absent_values(array1: List[int], array2: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_absent_values(array1: List[int], array2: List[int]) -> List[int]:
"""
Identify and return the values in array1 that are not present in array2.
Args:
array1 (List[int]): The first nu... |
evol_instruct_66k | 11,517 | Write a Python function to find the penultimate highest numerical value in a given array of whole numbers. The function should handle duplicate values by considering only unique values. The code should start with:
```python
from typing import List
def penultimate_highest_value(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def penultimate_highest_value(numbers: List[int]) -> int:
"""
Find the penultimate highest numerical value in a given array of whole numbers, considering only unique values.
Args:
numbers (L... |
evol_instruct_66k | 11,523 | Write a Python function to generate a list of `n` randomly generated integers, where each integer is within a specified range `[min_value, max_value]`. The function should ensure that the generated integers are unique and sorted in ascending order. The code should start with:
```python
from typing import List
import ra... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_unique_sorted_random_numbers(n: int, min_value: int, max_value: int) -> List[int]:
"""
Generates a list of `n` unique and sorted random integers within the specified range `[mi... |
evol_instruct_66k | 11,524 | Write a Python function to find all the keys in a given one-dimensional dictionary whose corresponding values are of type string. The function should return a list of these keys.
The code should start with:
```python
from typing import Dict, List
def find_string_keys(dict_input: Dict[str, object]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def find_string_keys(dict_input: Dict[str, object]) -> List[str]:
"""
Finds all the keys in a given one-dimensional dictionary whose corresponding values are of type string.
Args:
dict... |
evol_instruct_66k | 11,525 | Write a Python function to reverse a given string. The function should take a string as input and return the reversed string. The code should start with:
```python
def reverse_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_string(s: str) -> str:
"""
Reverses the given string.
Args:
s (str): The string to be reversed.
Returns:
str: The reversed string.
"""
# Use slicing to reverse the string
rever... |
evol_instruct_66k | 11,528 | Write a Python function to recursively remove key-value pairs from a dictionary where the values are less than 10. The function should handle nested dictionaries and remove keys only if all associated values in all nested levels are less than 10. The code should start with:
```python
from typing import Dict
def remove... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def remove_values_less_than_ten(dictionary: Dict) -> Dict:
"""
Recursively removes key-value pairs from a dictionary where the values are less than 10.
Handles nested dictionaries and removes keys on... |
evol_instruct_66k | 11,534 | Write a Python function to find the common elements (both keys and values) in three given dictionaries. The function should return a dictionary containing the common elements. The code should start with:
```python
from typing import Dict
def find_common_elements(C: Dict, D: Dict, E: Dict) -> Dict:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def find_common_elements(C: Dict, D: Dict, E: Dict) -> Dict:
"""
Find the common elements (both keys and values) in three given dictionaries.
Args:
C (Dict): The first dictionary.
D ... |
evol_instruct_66k | 11,540 | Write a Python function to merge two sorted lists of integers into a single sorted list. The function should efficiently merge the two lists by comparing elements from both lists and appending the smaller element to the result list. The code should start with:
```python
from typing import List
def merge_sorted_lists(l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two sorted lists of integers into a single sorted list.
Args:
list1 (List[int]): The first sorted list of i... |
evol_instruct_66k | 11,547 | Write a Python function to count the occurrences of each unique integer in a given two-dimensional array and return the results sorted by the frequency of occurrences in descending order. The function should handle arrays with varying row sizes and include negative integers.
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, Tuple, Dict
def count_unique_occurrences(two_d_array: List[List[int]]) -> List[Tuple[int, int]]:
"""
Counts the occurrences of each unique integer in a given two-dimensional array and returns the result... |
evol_instruct_66k | 11,555 | Write a Python function to create a new nested list from a given three-dimensional array. Each nested list in the new list should be derived from the initial and terminal integer values of each subarray found within the three-dimensional array. The function should handle missing values, negative values, and non-integer... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def create_nested_list(array: List[List[List[Union[int, None]]]]) -> List[List[int]]:
"""
Create a new nested list from a given three-dimensional array. Each nested list in the new list is derived... |
evol_instruct_66k | 11,564 | Write a Python function to display each element of a provided list of incomplete sentences, ensuring each fragment occupies a distinct line. The function should take a list of strings as input and print each string on a new line.
The code should start with:
```python
from typing import List
def display_sentences(sent... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def display_sentences(sentences: List[str]) -> None:
"""
Display each element of the provided list of incomplete sentences, ensuring each fragment occupies a distinct line.
Args:
sentences (... |
evol_instruct_66k | 11,570 | Write a Python function to find the nth term in a geometric progression series given the first term and the position of the term. The geometric progression follows the pattern where each term is obtained by multiplying the previous term by a fixed non-zero number called the common ratio.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_nth_term(first_term: int, common_ratio: int, n: int) -> int:
"""
Calculate the nth term in a geometric progression series.
Args:
first_term (int): The first term of the geometric progression.
common... |
evol_instruct_66k | 11,579 | Write a Python function to create a mirror image of a given list by reversing its order. The function should take a list of integers as input and return a new list that is the reverse of the input list. The code should start with:
```python
from typing import List
def mirror_image(input_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 mirror_image(input_list: List[int]) -> List[int]:
"""
Creates a mirror image of the input list by reversing its order.
Args:
input_list (List[int]): The list of integers to be reversed.
... |
evol_instruct_66k | 11,596 | Write a Python function that takes a list of fruit names as strings and returns a new list where each fruit name is converted to uppercase. The function should handle an empty list gracefully by returning an empty list. The code should start with:
```python
from typing import List
def convert_fruits_to_uppercase(fruit... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_fruits_to_uppercase(fruit_list: List[str]) -> List[str]:
"""
Converts each fruit name in the input list to uppercase and returns a new list.
Args:
fruit_list (List[str]): A list ... |
evol_instruct_66k | 11,597 | Write a Python function to generate a character sequence that starts with a given prefix and is followed by the mirrored reflection of a provided character collection. The function should take two parameters: the prefix string and the character collection string. The function should return the concatenated result of th... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_mirrored_sequence(prefix: str, character_collection: str) -> str:
"""
Generates a character sequence that starts with the given prefix and is followed by the mirrored reflection of the provided character collection.... |
evol_instruct_66k | 11,601 | Write a Python function to generate a random 6-digit number. The function should ensure that the generated number is within the range of 100000 to 999999 inclusive. The code should start with:
```python
import random
def generate_random_6_digit_number() -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_random_6_digit_number() -> int:
"""
Generates a random 6-digit number.
Returns:
int: A random integer between 100000 and 999999 inclusive.
"""
# Generate a random integer between ... |
evol_instruct_66k | 11,621 | Write a Python function that iterates through a given list and returns a list of items up to and including the first encountered item that is greater than a specified threshold. The function should stop iterating once it encounters such an item.
The code should start with:
```python
from typing import List
def items_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def items_up_to_threshold(my_list: List[int], threshold: int) -> List[int]:
"""
Returns a list of items from the given list up to and including the first item greater than the specified threshold.
A... |
evol_instruct_66k | 11,635 | Write a Python function to reduce a given list of integers to its unique values only, while preserving the order of their first occurrence. The function should start with:
```python
from typing import List
def unique_elements_preserve_order(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 unique_elements_preserve_order(arr: List[int]) -> List[int]:
"""
Returns a list of unique elements from the input list, preserving the order of their first occurrence.
Args:
arr (List[... |
evol_instruct_66k | 11,645 | Write a Python function to check if two given integers are equal. The function should return `True` if the integers are equal, and `False` otherwise. The code should start with:
```python
def are_integers_equal(first_integer: int, second_integer: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def are_integers_equal(first_integer: int, second_integer: int) -> bool:
"""
Check if two given integers are equal.
Args:
first_integer (int): The first integer to compare.
second_integer (int): The second i... |
evol_instruct_66k | 11,658 | Write a Python function to calculate the aggregate sum of all numerical constituents within a nested list structure. The function should handle lists that may contain other lists, integers, or a mix of both. The function should recursively traverse the nested structure to sum all integers.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def aggregate_sum(arr: Union[List, int]) -> int:
"""
Calculate the aggregate sum of all numerical constituents within a nested list structure.
Args:
arr (Union[List, int]): A list tha... |
evol_instruct_66k | 11,683 | Write a Python function to efficiently find the k-th smallest element in a list of integers using the Quickselect algorithm. The Quickselect algorithm is a selection algorithm to find the k-th smallest element in an unordered list. It is similar to the QuickSort algorithm but only recurses into one half of the data.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_kth_smallest(nums: List[int], k: int) -> int:
"""
Finds the k-th smallest element in the given list of integers using the Quickselect algorithm.
Args:
nums (List[int]): The list of ... |
evol_instruct_66k | 11,687 | Write a Python function to extract and return the type of a given object. The function should handle both simple and compound Python objects such as lists, strings, dictionaries, and tuples. The code should start with:
```python
from typing import Any
def get_object_type(obj: Any) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any
def get_object_type(obj: Any) -> str:
"""
Extract and return the type of a given object as a string.
Args:
obj (Any): The object whose type needs to be determined.
Returns:
str: ... |
evol_instruct_66k | 11,704 | Write a Python function to reverse the elements of a given list without using any built-in reverse methods or functions. Additionally, justify the time complexity of your solution.
The code should start with:
```python
from typing import List
def reverse_list(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_list(arr: List[int]) -> List[int]:
"""
Reverses the elements of a given list without using any built-in reverse methods.
Args:
arr (List[int]): The list of integers to be reverse... |
evol_instruct_66k | 11,720 | Write a Python function to convert a non-negative integer to its hexadecimal representation and ensure the output is in uppercase. The function should also validate the input to ensure it is a non-negative integer. If the input is invalid, the function should return an error message.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
def int_to_hex(n: int) -> str:
"""
Converts a non-negative integer to its hexadecimal representation in uppercase.
Args:
n (int): The non-negative integer to be converted.
Returns:
str: The hexadecimal ... |
evol_instruct_66k | 11,738 | Write a Python function to flatten a two-dimensional grid composed of integer entities into a one-dimensional list. The function should handle grids of varying sizes and ensure that all elements from the original grid are included in the flattened list in the order they appear.
The code should start with:
```python
fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def flatten_grid(grid: List[List[int]]) -> List[int]:
"""
Flattens a two-dimensional grid of integers into a one-dimensional list.
Args:
grid (List[List[int]]): A list of lists containing in... |
evol_instruct_66k | 11,740 | Write a Python function to dynamically convert a string into a corresponding mathematical expression and evaluate its numerical outcome. The function should handle basic arithmetic operations such as addition, subtraction, multiplication, and division. The code should start with:
```python
def evaluate_expression(expre... | Here is the Python code to solve the given problem in the markdown block:
```python
def evaluate_expression(expression: str) -> float:
"""
Dynamically converts a string into a corresponding mathematical expression and evaluates its numerical outcome.
Args:
expression (str): The mathematical express... |
evol_instruct_66k | 11,741 | Write a Python function to determine the output of a conditional statement based on the values of two integers `a` and `b`. The function should check if `a` is divisible by `b` and print "Yes" if true. If `a` is not divisible by `b`, the function should then check if `a` is divisible by 3 and print "Divisible by 3" if ... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_divisibility(a: int, b: int) -> None:
"""
Determines the output based on the divisibility of two integers `a` and `b`.
Args:
a (int): The first integer.
b (int): The second integer.
Prints:
... |
evol_instruct_66k | 11,747 | Write a Python function to flatten a nested list into a single, flat list. The nested list can contain any number of levels of nested lists. The function should handle lists of integers, strings, and other types of elements. The code should start with:
```python
from typing import List, Any
def flatten_list(nested_lis... | 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 into a single, flat list.
Args:
nested_list (List[Any]): The nested list to be flattened.
Return... |
evol_instruct_66k | 11,754 | Write a Python function to count the total number of vowels and the frequency of each vowel in a given string. The function should consider both uppercase and lowercase vowels and ignore punctuation marks. The code should start with:
```python
from typing import Dict, Tuple
def count_vowels_and_frequency(sentence: str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def count_vowels_and_frequency(sentence: str) -> Tuple[int, Dict[str, int]]:
"""
Counts the total number of vowels and the frequency of each vowel in a given string.
Args:
sentence (s... |
evol_instruct_66k | 11,772 | Write a Python function to convert a list of hexadecimal numbers into their corresponding binary representations. Each hexadecimal number should first be converted to a decimal number, and then the decimal number should be converted to a binary string. The binary string should not include the "0b" prefix.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def hex_to_binary(hex_values: List[str]) -> List[str]:
"""
Converts a list of hexadecimal numbers into their corresponding binary representations.
Args:
hex_values (List[str]): A list of hex... |
evol_instruct_66k | 11,776 | Write a Python function to subtract one number from another without raising any syntax error. The function should handle both integer and floating-point numbers. The code should start with:
```python
def subtract_two_numbers(a: float, b: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def subtract_two_numbers(a: float, b: float) -> float:
"""
Subtracts one number from another and returns the result.
Args:
a (float): The number from which another number will be subtracted.
b (float): The... |
evol_instruct_66k | 11,788 | Write a Python function to determine if two integers are anagrams of each other. Two integers are considered anagrams if they contain the same digits in any order. The function should handle positive integers only.
The code should start with:
```python
def are_anagrams(num1: int, num2: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(num1: int, num2: int) -> bool:
"""
Determines if two integers are anagrams of each other.
Args:
num1 (int): The first positive integer.
num2 (int): The second positive integer.
Returns:... |
evol_instruct_66k | 11,801 | Write a Python function to count and list the distinct elements in a given list of strings. The function should return a tuple containing the list of distinct elements and the count of these distinct elements. The function should not use any built-in set or dictionary data structures. Instead, implement a custom data s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def count_distinct_elements(elements: List[str]) -> Tuple[List[str], int]:
"""
Count and list the distinct elements in a given list of strings.
Args:
elements (List[str]): The list of... |
evol_instruct_66k | 11,804 | Write a Python function to calculate the factorial of a given non-negative integer `n` using an optimized approach. The function should use a `for` loop to iterate through the numbers from 1 to `n` and compute the factorial. Additionally, the function should handle edge cases such as `n` being 0 or 1, and ensure that t... | Here is the Python code to solve the given problem in the markdown block:
```python
def factorial_optimized(n: int) -> int:
"""
Calculate the factorial of a given non-negative integer n using an optimized iterative approach.
Args:
n (int): The non-negative integer for which to calculate the factori... |
evol_instruct_66k | 11,805 | Write a Python function to transform a given block of text into uppercase and analyze the transformed text to return the frequency count of each alphabet character used in the text. The function should efficiently handle large texts of up to 100,000 characters long. If the input text exceeds this limit, the function sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def transform_and_analyze_text(text: str) -> Tuple[str, Dict[str, int]]:
"""
Transforms the input text into uppercase and analyzes the frequency of each alphabet character.
Args:
text... |
evol_instruct_66k | 11,808 | Write a Python function to count the number of occurrences of a specific sequence of characters within a larger character string. The function should handle overlapping occurrences and be case-sensitive. The code should start with:
```python
def count_occurrences(target: str, base_string: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def count_occurrences(target: str, base_string: str) -> int:
"""
Counts the number of occurrences of a specific sequence of characters within a larger character string,
including overlapping occurrences.
Args:
... |
evol_instruct_66k | 11,810 | Write a Python function to compute the factorial of a given non-negative integer using recursion and memoization. The function should handle and return appropriate errors for negative numbers and non-integer inputs. Additionally, provide a performance analysis to demonstrate how memoization affects the function's perfo... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import lru_cache
@lru_cache(maxsize=None)
def factorial(n: int) -> int:
"""
Compute the factorial of a given non-negative integer using recursion and memoization.
Args:
n (int): The non-negative inte... |
evol_instruct_66k | 11,816 | Write a Python function to convert time from 12-hour format to 24-hour format, including seconds and milliseconds. The input will be a string in the format "HH:MM:SS.mmmAM" or "HH:MM:SS.mmmPM", where "HH" is the hour, "MM" is the minute, "SS" is the second, "mmm" is the millisecond, and "AM" or "PM" indicates the perio... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_24hr(time_str: str) -> str:
"""
Converts a time string from 12-hour format to 24-hour format, including seconds and milliseconds.
Args:
time_str (str): The input time string in the format "HH:MM:SS.mm... |
evol_instruct_66k | 11,828 | Write a Python function to generate an array of length `n` filled with random integers between a specified range `[low, high)`. The function should handle cases where `n` is zero or negative by returning an empty array. Additionally, if `low` is greater than or equal to `high`, the function should return an empty array... | 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_array(n: int, low: int, high: int) -> List[int]:
"""
Generate an array of length n filled with random integers between low (inclusive) and high (exclusive).
Ar... |
evol_instruct_66k | 11,833 | Write a Python function to generate a list of four distinct integers within a specified range. The function should ensure that all integers in the list are unique and within the given range. If the range is too small to generate four distinct integers, the function should return `None`.
The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
import random
def generate_four_distinct_ints(range_start: int, range_end: int) -> Optional[List[int]]:
"""
Generates a list of four distinct integers within the specified range.
Args:
... |
evol_instruct_66k | 11,858 | Write a Python function to validate an email address based on the principles of Regular Expressions' pattern matching techniques. The email should conform to RFC standards and should also check for common domain extensions like `.com`, `.org`, `.edu`, `.net`, and country-specific ones. The function should return `True`... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_email(email: str) -> bool:
"""
Validates an email address based on the principles of Regular Expressions' pattern matching techniques.
The email should conform to RFC standards and should also check f... |
evol_instruct_66k | 11,863 | Write a Python function to find the largest three numbers in a given list of integers. The function should return a list containing the three largest numbers in descending order. If the list has fewer than three elements, the function should return the largest numbers available in descending order.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_largest_three_numbers(lst: List[int]) -> List[int]:
"""
Find the largest three numbers in a given list of integers.
Args:
lst (List[int]): The list of integers from which to find th... |
evol_instruct_66k | 11,869 | Write a Python function to calculate the aggregated sum of the "price" values across a list of dictionaries, only for those dictionaries where an accompanying key "available" is set to `True`. The function should return the result as an integer value.
The code should start with:
```python
from typing import List, Dict... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def aggregate_price_sum(list_of_dictionaries: List[Dict[str, any]]) -> int:
"""
Calculate the aggregated sum of the "price" values across a list of dictionaries,
only for those dictionaries whe... |
evol_instruct_66k | 11,875 | Write a Python function that takes a list of integers as input and returns a new list containing the squares of the even numbers from the input list. The function should use list comprehension for this purpose.
The code should start with:
```python
from typing import List
def square_even_numbers(input_list: List[int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def square_even_numbers(input_list: List[int]) -> List[int]:
"""
Returns a new list containing the squares of the even numbers from the input list.
Args:
input_list (List[int]): The list of ... |
evol_instruct_66k | 11,883 | Write a Python function to reverse the keys and values of a given dictionary. The function should take a dictionary as input and return a new dictionary where the keys are the values from the original dictionary and the values are the corresponding keys. The code should start with:
```python
from typing import Dict
de... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import Dict
def reverse_dictionary(input_dict: Dict[str, int]) -> Dict[int, str]:
"""
Reverses the keys and values of a given dictionary.
Args:
input_dict (Dict[str, int]): The dictionary to be revers... |
evol_instruct_66k | 11,886 | Write a Python function to calculate and return a list of the square roots of numbers from 1 to n (inclusive). The function should handle cases where n is less than 1 by returning an empty list. The code should start with:
```python
from typing import List
import math
def calculate_square_roots(n: int) -> List[float]:... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import math
def calculate_square_roots(n: int) -> List[float]:
"""
Calculate and return a list of the square roots of numbers from 1 to n (inclusive).
Args:
n (int): The upper limit of the... |
evol_instruct_66k | 11,889 | Write a Python function to count the number of non-overlapping occurrences of a search sequence within a principal sequence. The function should handle cases where the search sequence is an empty string and should be efficient in terms of time complexity.
The code should start with:
```python
def count_occurrences(mai... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_occurrences(main_sequence: str, search_sequence: str) -> int:
"""
Counts the number of non-overlapping occurrences of a search sequence within a principal sequence.
Args:
main_sequence (str): The principal... |
evol_instruct_66k | 11,912 | Write a Python function to construct a clockwise spiral pathway through a given bidimensional matrix composed of integral numeric values. The function should return a list of elements in the order they are encountered in the spiral path.
The code should start with:
```python
from typing import List
def spiral_pathway... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def spiral_pathway(matrix: List[List[int]]) -> List[int]:
"""
Constructs a clockwise spiral pathway through a given bidimensional matrix.
Args:
matrix (List[List[int]]): A 2D list of integer... |
evol_instruct_66k | 11,921 | Write a Python function to generate a list of `n` distinct random decimal numbers, each ranging from greater than 0 up to, but not including, 1. The function should ensure that all numbers are distinct and should return the list sorted in ascending order.
The code should start with:
```python
from typing import List
i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_distinct_random_numbers(n: int) -> List[float]:
"""
Generates a list of `n` distinct random decimal numbers, each ranging from greater than 0 up to, but not including, 1.
... |
evol_instruct_66k | 11,928 | Write a Python function to recursively flatten a multidimensional list. The function should handle lists of arbitrary depth and return a single list containing all the elements in the original list, but in a flattened form.
The code should start with:
```python
from typing import List, Any
def flatten_list(multidimen... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def flatten_list(multidimensional_list: List[Any]) -> List[Any]:
"""
Recursively flattens a multidimensional list into a single list.
Args:
multidimensional_list (List[Any]): The multid... |
evol_instruct_66k | 11,945 | Write a Python function that iterates through a list of integers using a `while` loop and prints each element. The function should handle empty lists gracefully and avoid accessing out-of-bounds elements. The function should start with:
```python
from typing import List
def print_list_elements(arr: List[int]) -> None:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_list_elements(arr: List[int]) -> None:
"""
Iterates through a list of integers using a while loop and prints each element.
Args:
arr (List[int]): The list of integers to be printed... |
evol_instruct_66k | 11,951 | Write a Python function that calculates the cube of each integer within a specified range, starting from a given integer `start` and ending at a given integer `end` (both inclusive). The function should return a list of tuples, where each tuple contains the integer and its corresponding cube.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def calculate_cubes_in_range(start: int, end: int) -> List[Tuple[int, int]]:
"""
Calculate the cube of each integer within the specified range [start, end] (both inclusive).
Args:
sta... |
evol_instruct_66k | 11,953 | Write a Python function to safely calculate the sum of two numbers represented as strings, ensuring robust error handling. The function should return the sum if both inputs can be converted to integers, and a specific error message if either input cannot be converted.
The code should start with:
```python
def safe_sum... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_sum_of_strings(x: str, y: str) -> str:
"""
Safely calculates the sum of two numbers represented as strings.
Args:
x (str): The first number as a string.
y (str): The second number as a string.
... |
evol_instruct_66k | 11,978 | Write a Python function to generate the Look and Say sequence up to the given number `n`. The Look and Say sequence starts with "1" and each subsequent term is constructed by "reading" the previous term. For example, the second term is "11" because the first term has "one 1", the third term is "21" because the second t... | Here is the Python code to solve the given problem in the markdown block:
```python
def look_and_say_sequence(n: int) -> str:
"""
Generate the n-th term of the Look and Say sequence.
The Look and Say sequence starts with "1" and each subsequent term is constructed by "reading" the previous term.
For ex... |
evol_instruct_66k | 11,981 | Write a Python function to find the smallest number in a given list of integers. The function should be efficient and handle various edge cases, such as an empty list or a list with all identical elements. The code should start with:
```python
from typing import List
def find_smallest_number(numbers: List[int]) -> int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_smallest_number(numbers: List[int]) -> int:
"""
Find the smallest number in a given list of integers.
Args:
numbers (List[int]): The list of integers from which to find the smallest... |
evol_instruct_66k | 11,988 | Write a Python function to determine if a given string contains any numerical characters. The function should return `True` if the string contains at least one numerical character, and `False` otherwise. The code should start with:
```python
def contains_numerical_characters(input_string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def contains_numerical_characters(input_string: str) -> bool:
"""
Determines if the given string contains any numerical characters.
Args:
input_string (str): The string to be checked for numerical characters.
R... |
evol_instruct_66k | 11,989 | Write a Python function to convert a given time in 24-hour format to its equivalent in 12-hour format. The function should handle edge cases such as midnight (00:00) and noon (12:00). The input time is a string in the format "HH:MM" where HH is the hour (00 to 23) and MM is the minutes (00 to 59). The output should be ... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_24_to_12_hour_format(time_24: str) -> str:
"""
Converts a given time in 24-hour format to its equivalent in 12-hour format.
Args:
time_24 (str): The time in 24-hour format as a string "HH:MM".
Retur... |
evol_instruct_66k | 12,007 | Write a Python function to compute the sum of squares of the 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 sum_of_squares(arr: 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_squares(arr: List[int]) -> int:
"""
Compute the sum of squares of the elements in a given list of integers.
Args:
arr (List[int]): The list of integers for which the sum of square... |
evol_instruct_66k | 12,024 | Write a Python function to create two 2-dimensional arrays of size 10x10, populated with random integer values within the range of 0 to 99. The function should then compare these arrays to find and return a list of tuples, where each tuple contains a common integer found at the same location in both arrays and the corr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import numpy as np
def find_common_integers(seed: int) -> List[Tuple[int, Tuple[int, int]]]:
"""
Creates two 10x10 arrays with random integers between 0 and 99, and finds common integers at the sa... |
evol_instruct_66k | 12,025 | Write a Python function to determine the frequency of a particular character in a given string. The function should be case-sensitive and should handle any string and character inputs.
The code should start with:
```python
def count_character_frequency(string: str, character: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_character_frequency(string: str, character: str) -> int:
"""
Counts the frequency of a particular character in a given string.
Args:
string (str): The string in which to count the character.
charac... |
evol_instruct_66k | 12,033 | Write a Python function to invert the initial `k` characters for every `2k` characters starting from the beginning of the sequence `s`. If there are fewer than `k` characters remaining, invert all of them. If there are fewer than `2k` but more than or equal to `k` characters, invert the initial `k` characters and retai... | Here is the Python code to solve the given problem in the markdown block:
```python
def invert_sequence(s: str, k: int) -> str:
"""
Inverts the initial `k` characters for every `2k` characters starting from the beginning of the sequence `s`.
Args:
s (str): The input sequence of characters.
... |
evol_instruct_66k | 12,036 | Write a Python function to sort a list of integers in ascending order using the built-in `sorted` function. Additionally, provide a function to sort the list in descending order. The function should handle an empty list gracefully and return an empty list in such cases.
The code should start with:
```python
from typin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_ascending(input_list: List[int]) -> List[int]:
"""
Sorts the input list in ascending order.
Args:
input_list (List[int]): The list of integers to be sorted.
Returns:
Li... |
evol_instruct_66k | 12,047 | Write a Python function to calculate the factorial of a given non-negative integer. The factorial of a number `n` is the product of all positive integers less than or equal to `n`. The function should handle edge cases such as `n = 0` and `n = 1` correctly.
The code should start with:
```python
def factorial(n: int) -... | Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int:
"""
Calculate the factorial of a given non-negative integer.
The factorial of a number n (denoted as n!) is the product of all positive integers
less than or equal to n. By definition, 0! =... |
evol_instruct_66k | 12,067 | Write a Python function to construct a tuple containing eight distinct numerical values in ascending order from a given list of integers. The function should ensure that the input list contains exactly eight distinct integers and raise an error if the input list does not meet this requirement.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def construct_sorted_tuple(num_list: List[int]) -> Tuple[int, ...]:
"""
Constructs a tuple containing eight distinct numerical values in ascending order from a given list of integers.
Args:
... |
evol_instruct_66k | 12,086 | Write a Python function to merge two lists of dictionaries, where each dictionary represents an item in a Ruby list and contains a unique key. The function should return a single list of dictionaries that includes all unique items from both input lists. If an item with the same key exists in both lists, the item from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def merge_ruby_lists(list1: List[Dict[str, any]], list2: List[Dict[str, any]]) -> List[Dict[str, any]]:
"""
Merges two lists of dictionaries based on unique keys. If an item with the same key exist... |
evol_instruct_66k | 12,116 | Write a Python function to rearrange the elements of a given list in decreasing order. The function should use a stable sorting algorithm to ensure that the relative order of equal elements is preserved. The function should start with:
```python
from typing import List
def rearrange_in_decreasing_order(arr: List[int])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def rearrange_in_decreasing_order(arr: List[int]) -> List[int]:
"""
Rearranges the elements of the given list in decreasing order.
Args:
arr (List[int]): The list of integers to be rearrange... |
evol_instruct_66k | 12,126 | Write a Python function to amplify the element at a specified index in a list by a given factor, while ensuring that the rest of the list elements remain unaffected. If the specified index is out of bounds, the function should return the original list without any modifications.
The code should start with:
```python
fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def amplify_element(arr: List[int], index: int, factor: int) -> List[int]:
"""
Amplifies the element at the specified index in the list by the given factor,
while ensuring that the rest of the list e... |
evol_instruct_66k | 12,129 | Write a Python function to determine if two given phrases contain the same set of unique words, regardless of their order or frequency. The function should return `True` if the phrases have the same set of unique words, and `False` otherwise. The code should start with:
```python
def compare_word_sets(phrase1: str, phr... | Here is the Python code to solve the given problem in the markdown block:
```python
def compare_word_sets(phrase1: str, phrase2: str) -> bool:
"""
Determine if two phrases contain the same set of unique words, regardless of their order or frequency.
Args:
phrase1 (str): The first phrase to compare.... |
evol_instruct_66k | 12,142 | Write a Python function to reconstruct a balanced binary search tree (BST) from a sorted doubly-linked list. The function should ensure that the BST maintains the property of balanced binary search trees: for every node, the height difference between the left and right subtrees is no more than one.
The doubly-linked l... | Here is the Python code to solve the given problem in the markdown block:
```python
class Node:
def __init__(self, value):
self.value = value
self.prev = None
self.next = None
def sorted_list_to_bst(head: Node) -> Node:
"""
Reconstructs a balanced binary search tree from a sorted do... |
evol_instruct_66k | 12,143 | 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 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 row... |
evol_instruct_66k | 12,153 | Write a Python function to process a given dictionary that contains both numerical and string values. The function should compute the sum of all numerical values and concatenate all string values together, both in reverse order of their appearance in the dictionary. The output should be a tuple where the first element ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Union
def process_dictionary(an_dict: Dict[str, Union[int, float, str]]) -> tuple:
"""
Processes a dictionary containing both numerical and string values.
Computes the sum of all numerical values an... |
evol_instruct_66k | 12,154 | Write a Python function to arrange a given sequence of numerical values into a structured, three-dimensional matrix. The function should take a list of integers and return a 3D NumPy array with dimensions specified by the user. The function should handle cases where the sequence length does not perfectly fit the specif... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List, Tuple
def arrange_into_3d_matrix(sequence: List[int], dimensions: Tuple[int, int, int], default_value: int = 0) -> np.ndarray:
"""
Arrange a given sequence of numerical values into a ... |
evol_instruct_66k | 12,159 | Write a Python function to calculate the product of corresponding elements from two given arrays. The function should handle arrays of equal length and ensure that the product is calculated correctly without any mismatches. Additionally, provide a piece of erroneous code that beginners often write, which creates a mism... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def elementwise_product(array1: List[int], array2: List[int]) -> List[int]:
"""
Calculate the product of corresponding elements from two given arrays.
Args:
array1 (List[int]): The first arr... |
evol_instruct_66k | 12,161 | Write a Python function to reverse a given list in-place. The function should modify the original list without using additional data structures or creating a new list. The code should start with:
```python
from typing import List
def reverse_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 reverse_list_in_place(lst: List[int]) -> None:
"""
Reverses the given list in-place.
Args:
lst (List[int]): The list to be reversed.
Returns:
None: The function modifies t... |
evol_instruct_66k | 12,170 | Write a Python function to find the largest prime factor of a given integer. The function should efficiently determine and return the most significant prime divisor of the input number.
The code should start with:
```python
def largest_prime_factor(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def largest_prime_factor(n: int) -> int:
"""
Find the largest prime factor of a given integer.
Args:
n (int): The integer for which to find the largest prime factor.
Returns:
int: The largest prime fact... |
evol_instruct_66k | 12,171 | Write a Python function to calculate the sum of all elements in a three-dimensional array. The function should correctly iterate through each dimension of the array and accumulate the sum of all its elements.
The code should start with:
```python
from typing import List
def sum_3d_array(data: List[List[List[int]]]) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_3d_array(data: List[List[List[int]]]) -> int:
"""
Calculate the sum of all elements in a three-dimensional array.
Args:
data: A three-dimensional list of integers.
Returns:
... |
evol_instruct_66k | 12,173 | Write a Python function to determine whether the sum of the squares of the digits of a given number is divisible by 17. The function should return `True` if the sum is divisible by 17, and `False` otherwise. The code should start with:
```python
def is_sum_of_squares_divisible_by_17(n: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_sum_of_squares_divisible_by_17(n: int) -> bool:
"""
Determines whether the sum of the squares of the digits of a given number is divisible by 17.
Args:
n (int): The number to check.
Returns:
bool... |
evol_instruct_66k | 12,174 | Write a Python function to calculate the factorial of a given integer using an iterative approach. The function should be able to handle the factorial calculation for any non-negative integer. The code should start with:
```python
def factorial_iterative(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def factorial_iterative(n: int) -> int:
"""
Calculate the factorial of a given non-negative integer using an iterative approach.
Args:
n (int): The non-negative integer for which to calculate the factorial.
R... |
evol_instruct_66k | 12,176 | Write a Python function to find the longest string in a given list of strings. The function should return the longest string or the first occurrence of the longest string if there are multiple strings with the same maximum length.
The code should start with:
```python
from typing import List
def find_longest_string(s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_longest_string(strings: List[str]) -> str:
"""
Find the longest string in a given list of strings.
Args:
strings (List[str]): A list of strings to search through.
Returns:
... |
evol_instruct_66k | 12,189 | Write a Python function to identify the largest numerical component within a given dataset and its index. If there are duplicate largest values in the dataset, raise an exception with a specific error message. The function should start with:
```python
from typing import List, Tuple
def find_largest_num_and_index(datas... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_largest_num_and_index(dataset: List[int]) -> Tuple[int, int]:
"""
Identifies the largest numerical component within the provided dataset and its index.
Raises an exception if duplicat... |
evol_instruct_66k | 12,198 | Write a Python function to deeply merge two dictionaries, ensuring that nested dictionaries and lists within the dictionaries are also merged recursively. The function should handle complex data types and ensure minimal loss of information. The code should start with:
```python
from typing import Any, Dict, List
def d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, Dict, List
def deep_merge_dicts(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Deeply merges two dictionaries, including nested dictionaries and lists.
Args:
dict1 (Dic... |
evol_instruct_66k | 12,204 | Write a Python function to determine if a given number is a prime number and ensure that the number is less than or equal to 100. The function should return a string indicating whether the number is a prime number or not, or if the number is greater than 100.
The code should start with:
```python
def check_prime_and_l... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_prime_and_limit(num: int) -> str:
"""
Check if the given number is a prime number and ensure it is less than or equal to 100.
Args:
num (int): The number to check.
Returns:
str: A string indic... |
evol_instruct_66k | 12,239 | Write a Python function to calculate the total number of words in a given sentence, considering various edge cases such as punctuation, multiple spaces, and empty sentences. The function should handle these cases gracefully and return the correct word count.
The code should start with:
```python
def count_words(senten... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_words(sentence: str) -> int:
"""
Calculate the total number of words in a given sentence.
Args:
sentence (str): The input sentence to count words from.
Returns:
int: The total number of words ... |
evol_instruct_66k | 12,242 | Write a Python function to compute the sum of squares of even numbers from 0 up to a given integer `n`. If `n` is negative, the function should compute the sum of squares of even numbers from 0 up to the absolute value of `n`.
The code should start with:
```python
def sum_even_squares(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_even_squares(n: int) -> int:
"""
Compute the sum of squares of even numbers from 0 up to a given integer n.
If n is negative, the function computes the sum of squares of even numbers from 0 up to the absolute value o... |
evol_instruct_66k | 12,257 | 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
from typing import List
def longest_common_subsequence(str1: str, str2: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
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.
... |
evol_instruct_66k | 12,259 | Write a Python function to find and return the intersecting elements present in two given lists. The function should efficiently determine the common elements between the two lists and return them as a new list. The code should start with:
```python
from typing import List
def find_intersection(arr1: List[int], arr2: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_intersection(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Finds and returns the intersecting elements present in two given lists.
Args:
arr1 (List[int]): The first list of in... |
evol_instruct_66k | 12,271 | Write a Python function to find all strings in a list that contain a given substring efficiently. The function should return a list of strings that include the substring. The code should start with:
```python
from typing import List
def find_strings_with_substring(listStr: List[str], s: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_strings_with_substring(listStr: List[str], s: str) -> List[str]:
"""
Find all strings in the given list that contain the specified substring.
Args:
listStr (List[str]): The list of ... |
evol_instruct_66k | 12,275 | Write a Python function to implement the bubble sort algorithm for sorting an array of floating-point numbers in ascending order. The function should modify the input list in place and return the sorted list.
The code should start with:
```python
from typing import List
def bubble_sort(float_nums: List[float]) -> Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(float_nums: List[float]) -> List[float]:
"""
Sorts an array of floating-point numbers in ascending order using the bubble sort algorithm.
Args:
float_nums (List[float]): The ... |
evol_instruct_66k | 12,276 | Write a Python function to calculate the power of a given number raised to an exponent. The function should handle both positive and negative exponents, as well as the case where the exponent is zero. The function should also handle edge cases such as raising zero to a negative exponent, which is mathematically undefin... | Here is the Python code to solve the given problem in the markdown block:
```python
def power(number: float, exponent: float) -> float:
"""
Calculate the power of a given number raised to an exponent.
Args:
number (float): The base number.
exponent (float): The exponent to which the base nu... |
evol_instruct_66k | 12,285 | Write a Python function that demonstrates the behavior of the "else" clause within a "for" loop. The function should iterate over a list of integers and check if a specific integer is present in the list. If the integer is found, it should print "Found" and break out of the loop. If the loop completes without finding t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_integer_in_list(lst: List[int], target: int) -> None:
"""
Demonstrates the behavior of the "else" clause within a "for" loop.
Args:
lst (List[int]): The list of integers to search t... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.