source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 42,373 | Write a Python function to filter out and return a list of even numbers from a given list of integers. The function should only include numbers that are divisible by 2 (i.e., even numbers). The code should start with:
```python
from typing import List
def filter_even_numbers(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 filter_even_numbers(numbers: List[int]) -> List[int]:
"""
Filters out and returns a list of even numbers from the given list of integers.
Args:
numbers (List[int]): The list of integer... |
evol_instruct_66k | 42,382 | Write a Python function to calculate the sum of the first n terms of the Fibonacci sequence using a dynamic programming approach. The function should be efficient and avoid redundant calculations.
The code should start with:
```python
def fibonacci_sum(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci_sum(n: int) -> int:
"""
Calculate the sum of the first n terms of the Fibonacci sequence using dynamic programming.
Args:
n (int): The number of terms in the Fibonacci sequence to sum.
Returns:
... |
evol_instruct_66k | 42,392 | Write a Python function to count the number of distinct islands in a given 2D binary grid. An island is defined as a contiguous landmass formed by horizontally or vertically adjacent land cells ('1'), and is entirely surrounded by water ('0'). The grid is represented as a list of lists, where each element is either '0'... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_islands(grid: List[List[str]]) -> int:
"""
Count the number of distinct islands in a given 2D binary grid.
Args:
grid (List[List[str]]): A 2D list representing the binary grid wher... |
evol_instruct_66k | 42,399 | Write a Python function to extract and return a list of unique even integers from an unordered collection of numerical values. The function should ensure that each unique even integer appears only once in the output list, in the order of their first appearance. The function should handle various edge cases, such as rep... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def unique_even_numbers(collection: List[Union[int, float, str]]) -> List[int]:
"""
Extracts and returns a list of unique even integers from an unordered collection of numerical values.
Args:... |
evol_instruct_66k | 42,403 | Write a Python function to calculate the total sum of the "price" values from a given list of dictionaries. Each dictionary in the list contains a single key "price" with an integer value. The function should return the total sum as an integer.
The code should start with:
```python
from typing import List, Dict
def s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def sum_prices(list_of_dictionaries: List[Dict[str, int]]) -> int:
"""
Calculate the total sum of the "price" values from a given list of dictionaries.
Args:
list_of_dictionaries (List... |
evol_instruct_66k | 42,405 | Write a Python function to convert a list of monetary values from their originating currencies to their target currencies using predefined exchange rates. The function should handle multiple conversions simultaneously and include error checking for invalid inputs.
The code should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def convert_currency(monetary_values: List[float], originating_currencies: List[str], target_currencies: List[str], exchange_rates: Dict[str, Dict[str, float]]) -> List[float]:
"""
Convert a list o... |
evol_instruct_66k | 42,408 | Write a Python function to multiply an array of numbers with every consecutive pair of elements in the array. The array may include floats and negative numbers. Handle potential division by zero errors by setting the result to 0 if a division by zero would occur. The function should return the modified array.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_consecutive_pairs(numbers: List[float]) -> List[float]:
"""
Multiplies each element in the list with its consecutive element, handling potential division by zero by setting the result to 0.
... |
evol_instruct_66k | 42,415 | Write a Python function to perform floor division on two given integers and return the result. The function should handle cases where the divisor is zero by returning a special value, such as `None`.
The code should start with:
```python
def floor_division(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def floor_division(x: int, y: int) -> int:
"""
Perform floor division on two integers and return the result.
If the divisor is zero, return None to indicate an error.
Args:
x (int): The dividend.
y (int)... |
evol_instruct_66k | 42,430 | Write a Python function to insert the string "Welcome to the party" at the end of a given list of strings, and then remove any duplicate elements while maintaining their original order. The function should start with:
```python
from typing import List
def insert_and_remove_duplicates(words: List[str]) -> List[str]:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def insert_and_remove_duplicates(words: List[str]) -> List[str]:
"""
Inserts the string "Welcome to the party" at the end of the given list of strings,
and removes any duplicate elements while mainta... |
evol_instruct_66k | 42,436 | Write a Python function to calculate the nth Bell number using a dynamic programming approach. The Bell number represents the number of ways to partition a set of n elements. The function should start with:
```python
def bell_number(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def bell_number(n: int) -> int:
"""
Calculate the nth Bell number using a dynamic programming approach.
Args:
n (int): The index of the Bell number to calculate.
Returns:
int: The nth Bell number.
"... |
evol_instruct_66k | 42,457 | Write a Python function to find and return a list of all non-even integers within a given inclusive range `[start, end]`, along with their squares. The function should handle cases where `start` and `end` are not necessarily 1 and 10, respectively. The function should start with:
```python
from typing import List, Tupl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_non_even_with_squares(start: int, end: int) -> List[Tuple[int, int]]:
"""
Find all non-even (odd) integers within the inclusive range [start, end] and return a list of tuples,
where e... |
evol_instruct_66k | 42,458 | Write a Python function to generate the first N numbers of the Fibonacci sequence. The function should return a list containing these numbers. The code should start with:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the first N numbers of the Fibonacci sequence.
Args:
n (int): The number of Fibonacci numbers to generate.
Returns:
L... |
evol_instruct_66k | 42,459 | Write a Python function to generate the initial `n` elements of a Fibonacci progression with the option to specify custom starting values for the first and second elements of the sequence. The function should validate the inputs to ensure they are non-negative integers. The code should start with:
```python
from typing... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def custom_fibonacci(n: int, a: int = 0, b: int = 1) -> List[int]:
"""
Generate the initial n elements of a Fibonacci progression with custom starting values.
Args:
n (int): The number of el... |
evol_instruct_66k | 42,460 | Write a Python function to generate a list of random numbers between given 'low' and 'high' values, with a specified length. The function should ensure that the generated numbers are within the specified range and the length of the list matches the specified length.
The code should start with:
```python
from typing im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_random_numbers(low: int, high: int, length: int) -> List[int]:
"""
Generates a list of random numbers between the given 'low' and 'high' values, with the specified length.
... |
evol_instruct_66k | 42,464 | Write a Python function to find and return the smallest numerical value from a given list of mixed data types (integers, floats, and non-numeric values). The function should handle non-numeric values gracefully by filtering them out and only considering numeric values for the minimum calculation. If no numeric values a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_smallest_numeric_value(lst: List[Union[int, float, str]]) -> Union[int, float, None]:
"""
Finds and returns the smallest numerical value from a given list of mixed data types.
Args:
... |
evol_instruct_66k | 42,477 | Write a Python function to extend a given list with elements from another list. The function should handle cases where the input lists are empty or contain different types of elements. The function should return the extended list.
The code should start with:
```python
from typing import List, Any
def extend_list(list... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def extend_list(list1: List[Any], list2: List[Any]) -> List[Any]:
"""
Extends the first list with elements from the second list.
Args:
list1 (List[Any]): The list to be extended.
... |
evol_instruct_66k | 42,479 | Write a Python function to filter and sort a list of dictionaries based on specified conditions. Each dictionary represents a record with keys corresponding to columns `C`, `D`, `E`, `F`, and `G`. The function should filter out records where the value of `C` is less than or equal to 500, the value of `D` is in the list... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Any
from datetime import datetime
def filter_and_sort_records(records: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
"""
Filters and sorts a list of dictionaries based on specified conditions.
... |
evol_instruct_66k | 42,490 | Write a Python function to generate the first `n` terms of the Fibonacci sequence, starting from the initial term of 1. The function should return a list containing the Fibonacci sequence up to the `n`th term. The code should start with:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the first n terms of the Fibonacci sequence starting from 1.
Args:
n (int): The number of terms to generate.
Returns:
L... |
evol_instruct_66k | 42,545 | Write a Python function to identify and count the types of values found in a given dictionary. The function should return a dictionary where the keys are the names of the types (e.g., "str", "int", "bool", "list") and the values are the counts of how many times each type appears in the input dictionary.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_value_types(dictionary: Dict) -> Dict[str, int]:
"""
Counts the types of values in a given dictionary and returns a dictionary with the type names as keys and their counts as values.
Args:... |
evol_instruct_66k | 42,547 | Write a Python function to calculate the sum of a list of numbers and determine the time complexity of the original code snippet. Additionally, optimize the function to reduce space complexity. The function should start with:
```python
from typing import List
def calculate_sum_optimized(numbers: List[int]) -> int:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_sum_optimized(numbers: List[int]) -> int:
"""
Calculate the sum of a list of numbers.
Args:
numbers (List[int]): The list of numbers to sum.
Returns:
int: The sum ... |
evol_instruct_66k | 42,564 | Write a Python function to generate a three-dimensional matrix filled with random integer values within a specified range, and then flatten this 3D matrix into a one-dimensional array. The function should take three parameters: the number of rows, the number of columns, and the number of depth layers for the 3D matrix,... | 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_and_flatten_3d_matrix(rows: int, cols: int, depth: int, low: int, high: int) -> List[int]:
"""
Generates a 3D matrix filled with random integers within a specified range a... |
evol_instruct_66k | 42,565 | Write a Python function to calculate the sum of absolute values of elements in a given list. The function should take a list of integers as input and return the sum of their absolute values. The code should start with:
```python
from typing import List
def sum_of_absolute_values(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_absolute_values(numbers: List[int]) -> int:
"""
Calculate the sum of absolute values of elements in a given list.
Args:
numbers (List[int]): A list of integers.
Returns:
... |
evol_instruct_66k | 42,572 | Write a Python function to find the last index of a specified item in a given list. If the item is not found in the list, the function should return -1. The code should start with:
```python
from typing import List
def find_last_index(my_list: List[int], item_to_find: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_last_index(my_list: List[int], item_to_find: int) -> int:
"""
Find the last index of a specified item in a given list.
Args:
my_list (List[int]): The list in which to search for the... |
evol_instruct_66k | 42,581 | Write a Python function to combine two lists that may contain some identical entries, ensuring that the resulting list contains only unique elements. The function should maintain the order of elements as they appear in the input lists, with elements from the first list taking precedence in case of duplicates.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def combine_unique_lists(arr1: List[str], arr2: List[str]) -> List[str]:
"""
Combines two lists of strings, ensuring that the resulting list contains only unique elements
and maintains the order of e... |
evol_instruct_66k | 42,591 | Write a Python function to sort an array of integers based on the count of 1's in their binary representation. If multiple integers have the same count of 1's, they should be sorted in ascending order. The function should start with:
```python
from typing import List
def sort_by_bits(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 sort_by_bits(arr: List[int]) -> List[int]:
"""
Sorts an array of integers based on the count of 1's in their binary representation.
If multiple integers have the same count of 1's, they are sorte... |
evol_instruct_66k | 42,596 | Write a Python function to determine if a given number is an even integer and return the string "Yes, it's even" if it is. If the number is not an integer or is not even, return an appropriate message.
The code should start with:
```python
def is_even_integer(number) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_even_integer(number) -> str:
"""
Determines if the given number is an even integer and returns an appropriate message.
Args:
number: The number to be checked.
Returns:
str: A string indicating wh... |
evol_instruct_66k | 42,622 | Write a Python function to generate the Fibonacci sequence up to the nth term and another function to check if a given number exists within the generated sequence. The code should start with:
```python
from typing import List, Tuple
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the Fibonacci sequen... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the Fibonacci sequence up to the nth term.
Args:
n (int): The number of terms in the Fibonacci sequence to generate.
Ret... |
evol_instruct_66k | 42,630 | Write a Python function to determine if two given strings are isomorphic. Two strings are considered isomorphic if there is a one-to-one mapping between every character in the first string and every character in the second string. This means that each character in the first string can be replaced by a unique character ... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_isomorphic(str1: str, str2: str) -> bool:
"""
Determines if two strings are isomorphic.
Two strings are considered isomorphic if there is a one-to-one mapping between every character in the first string
and ever... |
evol_instruct_66k | 42,636 | Write a Python function to verify if a sequence of given strings is present in a nested list. The function should have a time complexity of O(N), where N is the total number of elements in the nested list. The function should start with:
```python
from typing import List, Union
def is_sequence_in_nested_list(nested_li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def flatten_list(nested_list: List[Union[str, List]]) -> List[str]:
"""
Flatten a nested list into a flat list of strings.
Args:
nested_list: A nested list containing strings and othe... |
evol_instruct_66k | 42,642 | Write a Python function to extract and return a list of tuples representing the key-value pairs from a given dictionary. The function should handle dictionaries with any number of key-value pairs and any types of keys and values. The code should start with:
```python
from typing import Dict, List, Tuple, Any
def extra... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple, Any
def extract_key_value_pairs(dictionary: Dict[Any, Any]) -> List[Tuple[Any, Any]]:
"""
Extracts and returns a list of tuples representing the key-value pairs from a given dictionary.
... |
evol_instruct_66k | 42,655 | Write a Python function to create a dictionary where each unique element of a tuple acts as the key and a list of its positions (indices) in the tuple as the value. If an element appears more than once, its positions should be stored in a list. The function should handle tuples with duplicate elements correctly.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def create_position_dict(tuple1: Tuple[int]) -> Dict[int, List[int]]:
"""
Create a dictionary where each unique element of a tuple acts as the key and a list of its positions (indices) in th... |
evol_instruct_66k | 42,665 | Write a Python function to calculate the mean, median, and mode of a given list of integers. The function should handle edge cases such as repeated values, even-sized collections, and scenarios where there's no mode (no number is repeated). The code should start with:
```python
from typing import List, Tuple
def calcu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
from collections import defaultdict
def calculate_statistics(numbers: List[int]) -> Tuple[float, float, List[int]]:
"""
Calculate the mean, median, and mode of a list of integers.
Args:
... |
evol_instruct_66k | 42,671 | Write a Python function to convert an integer within the range from zero to five inclusive into its corresponding textual representation. If the integer is outside this range, return "Invalid number". The function should use a dictionary to map the integers to their textual representations.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
def number_to_text(num: int) -> str:
"""
Converts an integer within the range from zero to five inclusive into its corresponding textual representation.
Args:
num (int): The integer to be converted. Must be within t... |
evol_instruct_66k | 42,681 | Write a Python function to convert a given string to uppercase. The function should handle any string input and return the string with all characters converted to uppercase. The code should start with:
```python
def convert_to_uppercase(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def convert_to_uppercase(s: str) -> str:
"""
Converts the given string to uppercase.
Args:
s (str): The input string to be converted.
Returns:
str: The uppercase version of the input string.
"""
... |
evol_instruct_66k | 42,686 | Write a Python function to perform a linear search on a given dataset to find all occurrences of a specified target value. The function should return a list of indices where the target value is found in the dataset. If the target value is not found, the function should return an empty list.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def linear_search_all(data: List[int], target: int) -> List[int]:
"""
Perform a linear search on the given dataset to find all occurrences of the target value.
Args:
data (List[int]): The da... |
evol_instruct_66k | 42,691 | Write a Python function to compute the greatest common divisor (GCD) of two integers using the Euclidean algorithm. The Euclidean algorithm is a more efficient method compared to prime factorization for finding the GCD of two numbers. The function should take two integers as input and return their GCD.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
def gcd_euclidean(a: int, b: int) -> int:
"""
Compute the greatest common divisor (GCD) of two integers using the Euclidean algorithm.
Args:
a (int): The first integer.
b (int): The second integer.
Retu... |
evol_instruct_66k | 42,708 | Write a Python function to calculate the total number of iterations executed by a nested loop structure. The function should take two integers, `outer_range` and `inner_range`, representing the range of the outer and inner loops respectively. The function should return the total number of iterations performed by the ne... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_iterations(outer_range: int, inner_range: int) -> int:
"""
Calculate the total number of iterations executed by a nested loop structure.
Args:
outer_range (int): The number of iterations for the outer ... |
evol_instruct_66k | 42,711 | Write a Python function to find the sum of the two largest distinct elements in a given list of integers. The function should return the sum of these two elements. The code should start with:
```python
from typing import List
def max_pair_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_pair_sum(arr: List[int]) -> int:
"""
Find the sum of the two largest distinct elements in the given list of integers.
Args:
arr (List[int]): The list of integers from which to find t... |
evol_instruct_66k | 42,717 | Write a Python function to compute the arithmetic average of a given numerical array using the Numpy library. The function should handle arrays of any length and return the average as a floating-point number. The code should start with:
```python
from typing import List
import numpy as np
def compute_average(arr: List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import numpy as np
def compute_average(arr: List[float]) -> float:
"""
Compute the arithmetic average of a given numerical array using the Numpy library.
Args:
arr (List[float]): The numeric... |
evol_instruct_66k | 42,723 | Write a Python function to sort a list of tuples based on the first element. If the first elements are the same, sort the list based on the second element of the tuple. For any further ties, consider the subsequent elements in the tuple for the sort. If all elements are the same, maintain the original order of the tupl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_tuples(tuples: List[Tuple[int, ...]]) -> List[Tuple[int, ...]]:
"""
Sorts a list of tuples based on the first element. If the first elements are the same,
it sorts based on the second... |
evol_instruct_66k | 42,739 | Write a Python function to perform addition of two binary strings and return the result as a binary string. The function should first convert the binary strings to their decimal (integer) equivalents, perform the addition, and then convert the result back to a binary string.
The code should start with:
```python
def b... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_addition(element1: str, element2: str) -> str:
"""
Adds two binary strings and returns the result as a binary string.
Args:
element1 (str): The first binary string.
element2 (str): The second bina... |
evol_instruct_66k | 42,751 | Write a Python function that checks if a given list contains any duplicates. If duplicates are found, the function should return `True`; otherwise, it should return `False`. The function should utilize the "else" clause within a "for" loop to determine if the loop completes without finding any duplicates.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def has_duplicates(lst: List[int]) -> bool:
"""
Checks if a given list contains any duplicates.
Args:
lst (List[int]): The list of integers to check for duplicates.
Returns:
boo... |
evol_instruct_66k | 42,755 | Write a Python function to print the words from a given list in reverse order, but only if the word has an even number of characters. The function should not use the built-in `reverse()` function or any other built-in functions that directly reverse a string or list.
The code should start with:
```python
from typing i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_even_length_words_reversed(words: List[str]) -> None:
"""
Prints each word from the given list in reverse order, but only if the word has an even number of characters.
Args:
words ... |
evol_instruct_66k | 42,758 | Write a Python function to traverse through each individual character in a provided string and return a list of characters that are vowels (a, e, i, o, u). The function should handle both uppercase and lowercase vowels.
The code should start with:
```python
from typing import List
def extract_vowels(prompt: str) -> L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def extract_vowels(prompt: str) -> List[str]:
"""
Extracts and returns a list of vowels from the given string.
Args:
prompt (str): The input string from which to extract vowels.
Returns... |
evol_instruct_66k | 42,771 | Write a Python function to calculate the greatest common divisor (GCD) of a list of numbers. The function should take a list of integers as input and return the GCD of those integers. The code should start with:
```python
from typing import List
def gcd_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
import math
from functools import reduce
def gcd_of_list(numbers: List[int]) -> int:
"""
Calculate the greatest common divisor (GCD) of a list of integers.
Args:
numbers (List[int]): A lis... |
evol_instruct_66k | 42,793 | Write a Python function to determine if a given integer is a power of two. The function should return `True` if the integer is a power of two, and `False` otherwise. The function should handle edge cases such as zero and negative numbers.
The code should start with:
```python
def is_power_of_two(num: int) -> bool:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_power_of_two(num: int) -> bool:
"""
Determine if a given integer is a power of two.
Args:
num (int): The integer to check.
Returns:
bool: True if the integer is a power of two, False otherwise.
... |
evol_instruct_66k | 42,797 | Write a Python function to convert a given integer to its binary representation without using the built-in `bin()` function. The function should handle both positive and negative integers. The binary representation should be returned as a string, prefixed with '0b' for positive numbers and '-0b' for negative numbers.
... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_binary(n: int) -> str:
"""
Converts a given integer to its binary representation without using the built-in `bin()` function.
Args:
n (int): The integer to be converted to binary.
Returns:
... |
evol_instruct_66k | 42,823 | Write a Python function to remove recurrent (duplicate) elements from a given list while maintaining the order of the first occurrence of each element. The function should be optimized for time complexity, achieving O(n) time complexity. The code should start with:
```python
from typing import List
def remove_duplicat... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates(lst: List[int]) -> List[int]:
"""
Removes recurrent (duplicate) elements from the given list while maintaining the order of their first occurrence.
Args:
lst (List[int]... |
evol_instruct_66k | 42,831 | Write a Python function to determine if a specific substring exists within a larger text string. The function should return a binary outcome (True or False). The code should start with:
```python
def substring_exists(string: str, substring: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def substring_exists(string: str, substring: str) -> bool:
"""
Determines if a specific substring exists within a larger text string.
Args:
string (str): The larger text string in which to search for the substring... |
evol_instruct_66k | 42,848 | Write a Python function to simulate the behavior of JavaScript's `localStorage` for storing and retrieving data locally. The function should allow setting a key-value pair and retrieving the value associated with a given key. The data should persist across function calls within the same session.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
# Global dictionary to simulate local storage
local_storage = {}
def set_local_storage(key: str, value: str) -> None:
"""
Simulate the behavior of JavaScript's localStorage.setItem method.
Args:
key (str): The key ... |
evol_instruct_66k | 42,849 | Write a Python function to calculate the time complexity of a given nested loop structure. The function should take the dimensions of the data structures involved as input and return the time complexity as a string in Big O notation.
The code should start with:
```python
def calculate_time_complexity(n: int) -> str:
`... | Here is the Python code to solve the given problem in the markdown block:
:
```python
def calculate_time_complexity(n: int) -> str:
"""
Calculate the time complexity of a nested loop structure where both loops iterate over the same range.
Args:
n (int): The number of elements in the array.
Ret... |
evol_instruct_66k | 42,852 | Write a Python function to calculate the maximum and minimum number of nodes in a binary tree given its height. The function should return a tuple containing the maximum and minimum number of nodes. The binary tree can either be full or not full.
The code should start with:
```python
def calculate_nodes(height: int) -... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_nodes(height: int) -> tuple:
"""
Calculate the maximum and minimum number of nodes in a binary tree given its height.
Args:
height (int): The height of the binary tree.
Returns:
tuple: A t... |
evol_instruct_66k | 42,858 | Write a Python function to replace all occurrences of special characters in a given string with a specified replacement character. The function should handle any string input and replace all non-alphanumeric characters (excluding whitespace) with the specified replacement character.
The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def replace_special_characters(text: str, replacement: str = '_') -> str:
"""
Replaces all occurrences of special characters in the given string with the specified replacement character.
Args:
text (str):... |
evol_instruct_66k | 42,863 | Write a Python function to remove the greatest number from a sequence of numerical values separated by commas and return the modified sequence. The input is a string where each number is separated by a comma and a space. The output should be a string with the same format, excluding the greatest number.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_max_from_sequence(sequence: str) -> str:
"""
Removes the greatest number from a sequence of numerical values separated by commas and returns the modified sequence.
Args:
sequence (str): A string where eac... |
evol_instruct_66k | 42,867 | Write a Python function to insert a new integer element into a given 2D list (matrix) at a specified position. The function should handle the insertion by replacing the existing element at the specified position with the new element. The code should start with:
```python
from typing import List
def insert_element_in_m... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def insert_element_in_matrix(matrix: List[List[int]], new_element: int, row: int, col: int) -> List[List[int]]:
"""
Inserts a new integer element into a given 2D list (matrix) at a specified position.
... |
evol_instruct_66k | 42,871 | Write a Python function to find the prime numbers up to a given limit using a multithreaded approach. The function should demonstrate the use of synchronization to avoid race conditions when updating shared resources. Additionally, include a piece of erroneous code that demonstrates a race condition and provide a detai... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import threading
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
... |
evol_instruct_66k | 42,873 | Write a Python function to generate all unique subsets (power set) of a given string, where the order of characters in the subsets does not matter. The function should return a list of strings, where each string represents a subset. The code should start with:
```python
from typing import List
def generate_subsets(s: ... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
from itertools import chain, combinations
def generate_subsets(s: str) -> List[str]:
"""
Generate all unique subsets of a given string.
Args:
s (str): The input string for which to generat... |
evol_instruct_66k | 42,881 | Write a Python function to compute the Cartesian product of two given sets (represented as lists). The Cartesian product of two sets A and B is the set of all ordered pairs (a, b) where a is in A and b is in B. The function should return a list of tuples, where each tuple represents an ordered pair.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def cartesian_product(set1: List[int], set2: List[int]) -> List[Tuple[int, int]]:
"""
Computes the Cartesian product of two sets represented as lists.
Args:
set1 (List[int]): The firs... |
evol_instruct_66k | 42,890 | Write a Python function to generate the first `n` elements of the Fibonacci sequence, and then compute the sum of the squares of these elements. The function should return the computed total.
The code should start with:
```python
def sum_of_fibonacci_squares(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_fibonacci_squares(n: int) -> int:
"""
Calculate the sum of the squares of the first n Fibonacci numbers.
Args:
n (int): The number of Fibonacci numbers to consider.
Returns:
int: The sum of t... |
evol_instruct_66k | 42,896 | Write a Python function to concatenate two strings with a specified delimiter. The function should take three parameters: the first string, the second string, and an optional delimiter. If the delimiter is not provided, it should default to an empty string. The function should return the concatenated string.
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
def concatenate_strings(str1: str, str2: str, delimiter: str = "") -> str:
"""
Concatenates two strings with a specified delimiter.
Args:
str1 (str): The first string to concatenate.
str2 (str): The second s... |
evol_instruct_66k | 42,908 | Write a Python function to create a dictionary from a list of tuples where each tuple contains a name and an age. The function should return the dictionary with names as keys and ages as values.
The code should start with:
```python
from typing import List, Tuple, Dict
def create_age_dictionary(people: List[Tuple[str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def create_age_dictionary(people: List[Tuple[str, int]]) -> Dict[str, int]:
"""
Create a dictionary from a list of tuples where each tuple contains a name and an age.
Args:
peop... |
evol_instruct_66k | 42,950 | Write a Python function to determine the largest number in a given list of integers. The function should efficiently find the maximum value in the list and return it. The code should start with:
```python
from typing import List
def find_largest_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_largest_number(numbers: List[int]) -> int:
"""
Determine the largest number in a given list of integers.
Args:
numbers (List[int]): A list of integers from which to find the largest... |
evol_instruct_66k | 42,956 | Write a Python function to rearrange the subsequent alphabets in alphabetical order without utilizing any built-in sorting methods. The function should use the Bubble Sort algorithm to achieve this.
The code should start with:
```python
from typing import List
def bubble_sort_alphabets(alphabets: List[str]) -> List[s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort_alphabets(alphabets: List[str]) -> List[str]:
"""
Sorts the given list of alphabets in alphabetical order using the Bubble Sort algorithm.
Args:
alphabets (List[str]): The li... |
evol_instruct_66k | 42,965 | Write a Python function to sort a provided list in ascending order after filtering out all the even numbers. The function should take a list of integers as input and return a new list containing only the odd numbers sorted in ascending order. The code should start with:
```python
from typing import List
def sort_odd_n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_odd_numbers(lst: List[int]) -> List[int]:
"""
Sorts the provided list in ascending order after filtering out all the even numbers.
Args:
lst (List[int]): The list of integers to be ... |
evol_instruct_66k | 42,979 | Write a Python function to disassemble a specified common spoken phrase into a collection of distinct words. The function should take a string as input and return a set of unique words found in the string. The code should start with:
```python
from typing import Set
def disassemble_phrase(phrase: str) -> Set[str]:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def disassemble_phrase(phrase: str) -> Set[str]:
"""
Disassembles a specified common spoken phrase into a collection of distinct words.
Args:
phrase (str): The input phrase to be disassembled... |
evol_instruct_66k | 42,984 | Write a Python function to generate a random string of a specified length using a combination of uppercase letters, lowercase letters, and digits. The function should ensure that the generated string is unique by checking against a list of previously generated strings. If a duplicate is found, the function should gener... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import string
import random
def generate_unique_random_string(length: int, existing_strings: List[str]) -> str:
"""
Generates a unique random string of the specified length using uppercase letters, lower... |
evol_instruct_66k | 42,987 | Write a Python function to find the maximum value from a list of user-inputted elements. The function should handle scenarios for an empty list and a list of strings in addition to numbers. If the list contains non-numeric values, the function should return a message indicating that the list should only contain numeric... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_max_value(elements: List[Union[int, float, str]]) -> Union[int, float, str]:
"""
Find the maximum value from a list of elements.
Args:
elements (List[Union[int, float, str]])... |
evol_instruct_66k | 43,013 | Write a Python function to update the frequency of a user's visits to a specific web domain in a JSON-like dictionary structure. If the domain does not exist in the dictionary, it should be added with an initial count of 1. If the domain already exists, its count should be incremented by 1.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def update_domain_visit_count(user_data: Dict, domain: str) -> None:
"""
Updates the frequency of a user's visits to a specific web domain in a JSON-like dictionary structure.
Args:
user_dat... |
evol_instruct_66k | 43,014 | Write a Python function to determine if a given string contains all unique characters without using any additional data structures. Additionally, optimize the method to minimize the time complexity. The function should return `True` if all characters in the string are unique, and `False` otherwise. The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
def has_unique_chars(s: str) -> bool:
"""
Determines if a given string contains all unique characters without using any additional data structures.
Args:
s (str): The input string to check for unique characters.
... |
evol_instruct_66k | 43,040 | Write a Python function to sort a given list of odd numbers in descending order. The function should only consider and sort the odd numbers, leaving any even numbers in their original positions. The code should start with:
```python
from typing import List
def sort_odd_numbers(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 sort_odd_numbers(numbers: List[int]) -> List[int]:
"""
Sorts the odd numbers in the given list in descending order while keeping even numbers in their original positions.
Args:
numbers... |
evol_instruct_66k | 43,041 | Write a Python function to remove all occurrences of a specified letter from a given string of text. The function should return the refined text content without the specified letter. The code should start with:
```python
def remove_letter(text: str, alphabet: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def remove_letter(text: str, alphabet: str) -> str:
"""
Removes all occurrences of a specified letter from a given string of text.
Args:
text (str): The input string from which the specified letter is to be remove... |
evol_instruct_66k | 43,054 | Write a Python function to compute the element-wise difference between two numerical arrays and return the result in a new numerical array. The function should handle arrays of different lengths by taking the minimum length of the two arrays for the computation.
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 element_wise_difference(a: List[int], b: List[int]) -> List[int]:
"""
Compute the element-wise difference between two numerical arrays and return the result in a new numerical array.
Args:
... |
evol_instruct_66k | 43,056 | Write a Python function to filter a list of integers, retaining only the elements that are divisible by a given divisor without any remainder. The function should handle cases where the divisor is zero and return the original list in such cases.
The code should start with:
```python
from typing import List
def filter... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_divisible_elements(lst: List[int], divisor: int) -> List[int]:
"""
Filters the provided list to retain only the elements that are divisible by the given divisor without any remainder.
Arg... |
evol_instruct_66k | 43,059 | Write a Python function to format a given numeric value to have precisely two decimal places. The function should handle both positive and negative numbers, as well as numbers with fewer than two decimal places. The formatted number should always display two decimal places, even if they are zeros.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
def format_to_two_decimal_places(number: float) -> str:
"""
Formats a given numeric value to have precisely two decimal places.
Args:
number (float): The numeric value to be formatted.
Returns:
str: The... |
evol_instruct_66k | 43,075 | Write a Python function to count the number of non-overlapping occurrences of a specific subsequence within a given sequence of characters. The function should be efficient and handle cases where the subsequence might overlap within the sequence.
The code should start with:
```python
def count_subsequence(seq: str, su... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_subsequence(seq: str, sub: str) -> int:
"""
Counts the number of non-overlapping occurrences of a specific subsequence within a given sequence of characters.
Args:
seq (str): The sequence of characters in ... |
evol_instruct_66k | 43,079 | Write a Python function to remove all extra whitespace from a given string, ensuring that only single spaces remain between words. The function should handle leading, trailing, and multiple internal spaces.
The code should start with:
```python
def remove_extra_whitespace(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_extra_whitespace(text: str) -> str:
"""
Removes all extra whitespace from a given string, ensuring that only single spaces remain between words.
Args:
text (str): The input string from which extra whitesp... |
evol_instruct_66k | 43,085 | Write a Python function to remove duplicate elements from a given list of integers while preserving the order of the first occurrence of each element. The function should return a new list with all duplicate elements removed.
The code should start with:
```python
from typing import List
def remove_duplicates(arr: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates(arr: List[int]) -> List[int]:
"""
Removes duplicate elements from the given list of integers while preserving the order of the first occurrence of each element.
Args:
a... |
evol_instruct_66k | 43,093 | Write a Python function to generate a lyrical composition consisting of four distinct lines based on a given theme. The function should ensure that the lines are distinct and maintain a cohesive theme. The function should also handle exceptions appropriately and scale well with larger inputs. The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
import random
def generate_poem(theme: str) -> str:
"""
Generates a lyrical composition consisting of four distinct lines based on a given theme.
Args:
theme (str): The theme for the p... |
evol_instruct_66k | 43,102 | Write a Python function to determine if a given string consists solely of numerical characters using a regular expression. The function should return `True` if the string contains only digits, and `False` otherwise. The code should start with:
```python
import re
def is_numeric_string(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_numeric_string(s: str) -> bool:
"""
Determine if the given string consists solely of numerical characters.
Args:
s (str): The string to be checked.
Returns:
bool: True if the string co... |
evol_instruct_66k | 43,104 | Write a Python function to determine if a given number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors, excluding itself. The function should return `True` if the number is perfect and `False` otherwise. The code should start with:
```python
def is_perfect_num... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_perfect_number(n: int) -> bool:
"""
Determine if the given number is a perfect number.
A perfect number is a positive integer that is equal to the sum of its proper divisors, excluding itself.
Args:
n (i... |
evol_instruct_66k | 43,111 | Write a Python function to calculate the product of all elements in a given list of integers. The function should handle an empty list by returning 1, as the product of no numbers is defined as 1. The code should start with:
```python
from typing import List
def product_of_list(arr: 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(arr: List[int]) -> int:
"""
Calculate the product of all elements in a given list of integers.
Args:
arr (List[int]): The list of integers whose product is to be calculat... |
evol_instruct_66k | 43,135 | Write a Python function to calculate the Fibonacci sequence up to the nth term using memoization to optimize the time complexity. The function should handle larger Fibonacci numbers (over 100th term) without leading to stack overflow. Additionally, the function should return all Fibonacci numbers up to the nth term.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import sys
def fibonacci_sequence(n: int) -> List[int]:
"""
Calculate the Fibonacci sequence up to the nth term using memoization.
Args:
n (int): The term up to which the Fibonacci sequence ... |
evol_instruct_66k | 43,139 | Write a Python function to compute the cumulative sum of the individual digits of a given positive natural number. The function should handle only positive integers and should return the sum of the digits.
The code should start with:
```python
def cumulative_sum_of_digits(number: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def cumulative_sum_of_digits(number: int) -> int:
"""
Compute the cumulative sum of the individual digits of a given positive natural number.
Args:
number (int): The positive natural number whose digits' sum is to b... |
evol_instruct_66k | 43,140 | Write a Python function to reverse a given string without using any built-in functions or methods that directly reverse a string or list (e.g., `str.reverse()`, `str[::-1]`, `reversed()`, `''.join()`, etc.). The function should use a two-pointer approach to swap characters from the beginning and end of the string until... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(s: str) -> str:
"""
Reverses a given string using a two-pointer approach without using built-in reverse functions.
Args:
s (str): The input string to be reversed.
Returns:
str: The re... |
evol_instruct_66k | 43,152 | Write a Python function to extract and return the values associated with the `name` and `message` attributes from a given dictionary data structure. The function should handle cases where the dictionary might not contain the required keys by returning `None` for those missing keys. The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Optional, Tuple
def extract_name_message(data: Dict[str, str]) -> Tuple[Optional[str], Optional[str]]:
"""
Extracts and returns the values associated with the 'name' and 'message' attributes from the gi... |
evol_instruct_66k | 43,153 | Write a Python function to generate and manage multiple system variables in a thread-safe manner. The function should support multithreading and demonstrate this with a practical example. The function should start with:
```python
from threading import Lock, Thread
from typing import Dict, Any
def manage_system_variabl... | Here is the Python code to solve the given problem in the markdown block:
```python
from threading import Lock, Thread
from typing import Dict, Any
def manage_system_variables(variables: Dict[str, Any], num_threads: int) -> Dict[str, Any]:
"""
Manages multiple system variables in a thread-safe manner using mul... |
evol_instruct_66k | 43,154 | Write a Python function to perform a shallow copy of a given list of lists and demonstrate the potential caveats of using a shallow copy. The function should return both the original list and the shallow copy. Additionally, provide a function to perform a deep copy and compare the results.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import copy
def shallow_copy_and_caveats(original: List[List[any]]) -> (List[List[any]], List[List[any]]):
"""
Perform a shallow copy of the given list of lists and return both the original and the shall... |
evol_instruct_66k | 43,167 | Write a Python function to sort a list of dictionaries by a specified numerical property. The function should take a list of dictionaries and a string representing the key of the numerical property to sort by. The function should return the sorted list of dictionaries.
The code should start with:
```python
from typing... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def sort_by_property(data: List[Dict[str, any]], property_key: str) -> List[Dict[str, any]]:
"""
Sorts a list of dictionaries by a specified numerical property.
Args:
data (List[Dict[s... |
evol_instruct_66k | 43,170 | Write a Python function to convert a dictionary into a tuple where each key-value pair in the dictionary is represented as a tuple within the main tuple. The function should ensure that the final output retains the tuple data structure. The code should start with:
```python
from typing import Dict, Tuple
def dict_to_t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def dict_to_tuple(dict_obj: Dict) -> Tuple[Tuple[str, int], ...]:
"""
Converts a dictionary into a tuple where each key-value pair in the dictionary
is represented as a tuple within the main t... |
evol_instruct_66k | 43,172 | Write a Python function to calculate the mean value of a collection of integers. The function should handle potential discrepancies in the input collection, such as non-integer values or missing elements, and ensure the collection size is not predetermined, potentially containing up to 1,000,000 elements. The mean shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def calculate_mean(collection: List[Union[int, float]]) -> float:
"""
Calculate the mean value of a collection of integers, handling discrepancies such as non-integer values or missing elements.
... |
evol_instruct_66k | 43,181 | 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
def unique_paths(m: int, n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def unique_paths(m: int, n: int) -> int:
"""
Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid.
Args:
m (int): The number of rows in the grid.
n ... |
evol_instruct_66k | 43,188 | Write a Python function to identify and verify occurrences of the word "phoenix" at the start of a paragraph, ensuring that "phoenix" is the only capitalized word at the start. The function should return `True` if both conditions are met, otherwise `False`.
The code should start with:
```python
import re
def verify_p... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def verify_phoenix_start(text: str) -> bool:
"""
Verifies if the word "phoenix" appears at the start of a paragraph and is the only capitalized word at the start.
Args:
text (str): The text to be verified... |
evol_instruct_66k | 43,193 | Write a Python function to determine if a given integer is an even number when represented in binary. The function should return `True` if the binary representation of the integer ends with '0', indicating that the number is even in binary, and `False` otherwise. The function should be named `is_num_even_in_binary`.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_num_even_in_binary(num: int) -> bool:
"""
Determines if a given integer is even when represented in binary.
Args:
num (int): The integer to check for evenness in binary.
Returns:
bool: True if th... |
evol_instruct_66k | 43,196 | Write a Python function to generate the mirror image of a given character sequence. The function should reverse the order of characters in the sequence and return the reversed sequence. The code should start with:
```python
def mirror_image(sequence: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def mirror_image(sequence: str) -> str:
"""
Generate the mirror image of a given character sequence by reversing the order of characters.
Args:
sequence (str): The input character sequence to be mirrored.
Retur... |
evol_instruct_66k | 43,198 | Write a Python function to sort a given list of integers in ascending order while removing any duplicates. The function should be optimized for efficiency, aiming for a time complexity of O(n log n) or better. The code should start with:
```python
from typing import List
def unique_sort(arr: List[int]) -> List[int]:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def unique_sort(arr: List[int]) -> List[int]:
"""
Sorts a given list of integers in ascending order while removing any duplicates.
Args:
arr (List[int]): The list of integers to be sorted an... |
evol_instruct_66k | 43,209 | Write a Python function to find the k-th smallest element in a given list of integers. The function should efficiently handle the task using a min-heap data structure. The code should start with:
```python
from typing import List
import heapq
def find_kth_smallest(nums: List[int], k: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import heapq
def find_kth_smallest(nums: List[int], k: int) -> int:
"""
Find the k-th smallest element in a given list of integers using a min-heap.
Args:
nums (List[int]): The list of int... |
evol_instruct_66k | 43,212 | Write a Python function to process an array of integers and return an array with the squares of each element, maintaining their original positions. For any negative numbers, square the absolute value. If duplicate values exist, keep the first occurrence and replace subsequent ones with zeros, while maintaining their or... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def square_and_deduplicate(arr: List[int]) -> List[int]:
"""
Processes an array of integers to return an array with the squares of each element,
maintaining their original positions. For negative num... |
evol_instruct_66k | 43,215 | Write a Python function to assemble a list of speech fragments into a single comprehensive sentence. Each fragment should be separated by a semicolon and a whitespace character. The function should handle an empty list by returning an empty string.
The code should start with:
```python
from typing import List
def ass... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def assemble_sentence(phrases: List[str]) -> str:
"""
Assembles a list of speech fragments into a single comprehensive sentence.
Each fragment is separated by a semicolon and a whitespace character.
... |
evol_instruct_66k | 43,235 | Write a Python function to determine if all elements in a given list of integers are either all positive or all negative. The function should return `True` if all elements share the same orientation (either all positive or all negative), and `False` otherwise. The function should handle an empty list by returning `True... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def check_same_orientation(lst: List[int]) -> bool:
"""
Determines if all elements in the given list are either all positive or all negative.
Args:
lst (List[int]): The list of integers to c... |
evol_instruct_66k | 43,280 | Write a Python function to determine if two given strings are a "dual couple". A dual couple is defined as two strings that have the same length and the same characters, but possibly in different orders. The function should return `True` if the strings are a dual couple, and `False` otherwise.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_dual_couple(str1: str, str2: str) -> bool:
"""
Determines if two given strings are a dual couple.
A dual couple is defined as two strings that have the same length and the same characters,
but possibly in differe... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.