source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 8,924 | Write a Python function to compute the Hamming distance between two strings of equal length. The Hamming distance is defined as the number of positions at which the corresponding characters in the two strings are different. The function should raise a `ValueError` if the input strings are not of the same length.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
def hamming_distance(string1: str, string2: str) -> int:
"""
Compute the Hamming distance between two strings of equal length.
The Hamming distance is the number of positions at which the corresponding
characters in the... |
evol_instruct_66k | 8,927 | Write a Python function to print the squares of numbers in a given range, handling potential errors gracefully. The function should start with an integer `j` and increment it by 2 until it exceeds a specified upper limit. The function should handle cases where `j` is not an integer, changes to a non-integer type during... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_squares_in_range(j: int, upper_limit: int) -> None:
"""
Print the squares of numbers starting from `j` and incrementing by 2 until the upper limit.
Handle potential errors such as non-integer values for `j` or over... |
evol_instruct_66k | 8,929 | Write a Python function to count the number of prime numbers from 1 to n (inclusive) using the Sieve of Eratosthenes algorithm. The function should handle cases where n is less than 2 by returning 0. The code should start with:
```python
def count_primes(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_primes(n: int) -> int:
"""
Counts the number of prime numbers from 1 to n (inclusive) using the Sieve of Eratosthenes algorithm.
Args:
n (int): The upper limit of the range to count primes.
Returns:
... |
evol_instruct_66k | 8,934 | Write a Python function to determine the shared characters between two given strings, ignoring case, and count the number of occurrences of each shared character. The function should handle special characters and numbers. The code should start with:
```python
from typing import Dict
def shared_chars_count(str1: str, s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def shared_chars_count(str1: str, str2: str) -> Dict[str, int]:
"""
Determines the shared characters between two given strings, ignoring case, and counts the number of occurrences of each shared characte... |
evol_instruct_66k | 8,935 | Write a Python function to check if two strings are anagrams, considering the following requirements:
1. The function should be case-insensitive.
2. The function should consider special characters and numbers.
3. The function should handle large strings efficiently.
4. The function should remove leading and trailing sp... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(string1: str, string2: str) -> bool:
"""
Check if two strings are anagrams, considering case insensitivity, special characters, and numbers.
Args:
string1 (str): The first string to compare.
... |
evol_instruct_66k | 8,937 | Write a Python function to safely calculate the sum of two numeric strings. The function should handle cases where the input strings are not convertible to integers by returning a default value of 0. The code should start with:
```python
def safe_sum_of_strings(x: str, y: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def safe_sum_of_strings(x: str, y: str) -> int:
"""
Safely calculates the sum of two numeric strings. If either string is not convertible to an integer, returns 0.
Args:
x (str): The first numeric string.
y ... |
evol_instruct_66k | 8,941 | Write a Python function to generate a list of integers within a specified range, excluding a specific integer. The function should take three parameters: the start of the range, the end of the range (inclusive), and the integer to exclude. The function should return a list of integers that fall within the specified ran... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_range_excluding_integer(start: int, end: int, exclude: int) -> List[int]:
"""
Generates a list of integers within a specified range, excluding a specific integer.
Args:
start (i... |
evol_instruct_66k | 8,944 | Write a Python function to find all prime numbers within a given range of integers. Additionally, implement a lambda function to achieve the same result and apply memoization to optimize for repeated inputs.
The code should start with:
```python
from typing import List
from functools import lru_cache
def find_primes_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from functools import lru_cache
def find_primes_in_range(start: int, end: int) -> List[int]:
"""
Find all prime numbers within a given range [start, end].
Args:
start (int): The start of the... |
evol_instruct_66k | 8,945 | Write a Python function that validates scholar data using advanced Python coding techniques such as decorators and generator expressions. The function should validate the scholar data against a set of predetermined rules, such as regular expressions or algorithms, and handle large amounts of data efficiently. The funct... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
import re
def validate_scholar_data(scholar_data: Dict[int, Dict[str, Any]]) -> Dict[int, bool]:
"""
Validates scholar data against a set of predetermined rules and returns a dictionary indicating t... |
evol_instruct_66k | 8,977 | Write a Python function to compute the cumulative sum of the first n even numbers. The function should use a while loop to iterate through numbers, check for evenness, and accumulate the sum until the required number of even numbers is collected.
The code should start with:
```python
def cumulative_sum_of_first_n_even... | Here is the Python code to solve the given problem in the markdown block:
```python
def cumulative_sum_of_first_n_evens(n: int) -> int:
"""
Computes the cumulative sum of the first n even numbers.
Args:
n (int): The number of even numbers to sum.
Returns:
int: The cumulative sum of the... |
evol_instruct_66k | 8,987 | Write a Python function to calculate and compare the cumulative sum of individual digits for a list of integers. The function should handle negative numbers by preserving their negative sign in the sum. The function should return the sum for each integer, as well as the integers with the highest and lowest aggregate su... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def calculate_digit_sums(nums: List[int]) -> Tuple[Dict[int, int], List[int], List[int]]:
"""
Calculate the cumulative sum of individual digits for each integer in the list.
Handle negat... |
evol_instruct_66k | 8,990 | Write a Python function to generate a random numeric measurement within a specified range, ensuring that the measurement falls within the designated parameter range. The function should handle both floating-point and integer measurements based on a provided flag.
The code should start with:
```python
import random
de... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_random_measurement(lower_boundary: float, upper_boundary: float, is_integer: bool = False) -> float:
"""
Generates a random numeric measurement within the specified range.
Args:
lower_bou... |
evol_instruct_66k | 9,013 | Write a Python function to validate an International Mobile Equipment Identity (IMEI) number using a regular expression pattern. The function should check if the given IMEI number is valid based on the following criteria:
1. The IMEI number must be composed of exactly 15 digits.
2. The IMEI number must not contain any ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_imei(imei: str) -> bool:
"""
Validates an International Mobile Equipment Identity (IMEI) number using a regular expression pattern.
Args:
imei (str): The IMEI number to validate.
Returns... |
evol_instruct_66k | 9,030 | Write a Python function to calculate the lowest common multiple (LCM) of two given integer inputs, `x` and `y`. The function should use the greatest common divisor (GCD) to compute the LCM efficiently. The code should start with:
```python
import math
def lowest_common_multiple(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def lowest_common_multiple(x: int, y: int) -> int:
"""
Calculate the lowest common multiple (LCM) of two integers x and y.
Args:
x (int): The first integer.
y (int): The second integer.
Ret... |
evol_instruct_66k | 9,037 | Write a Python function to find the common elements of three sets without using Python's set operations. The function should ensure that the mutual elements, excluding repetitions, are returned in numeric order. The function should start with:
```python
from typing import List, Set
def three_set_intersection(s1: Set[i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Set
def three_set_intersection(s1: Set[int], s2: Set[int], s3: Set[int]) -> List[int]:
"""
Find the common elements of three sets without using Python's set operations and return them in numeric order.
... |
evol_instruct_66k | 9,041 | Write a Python function to generate a random alphanumeric string of a specified length. The string should consist of both alphabetic letters (uppercase and lowercase) and numeric digits, and should not follow any discernable pattern. The function should ensure that the generated string is truly random and does not favo... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
import string
def generate_random_alphanumeric_string(length: int) -> str:
"""
Generates a random alphanumeric string of the specified length.
The string consists of both alphabetic letters (uppercase and low... |
evol_instruct_66k | 9,043 | Write a Python function to sort an array using the Bubble Sort algorithm. The function should correctly handle the sorting process and return the sorted array. The code should start with:
```python
from typing import List
def bubble_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 bubble_sort(arr: List[int]) -> List[int]:
"""
Sorts an array using the Bubble Sort algorithm.
Args:
arr (List[int]): The array to be sorted.
Returns:
List[int]: The sorted a... |
evol_instruct_66k | 9,054 | Write a Python function to convert any given hexadecimal number to its binary representation without using in-built or library functions. Ensure your solution handles both uppercase and lowercase letters, and invalid inputs. The function should return the binary representation as a string or an error message if the inp... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_bin(hex_num: str) -> str:
"""
Converts a given hexadecimal number to its binary representation without using in-built or library functions.
Args:
hex_num (str): The hexadecimal number to be converted. It ... |
evol_instruct_66k | 9,060 | Write a Python function to eliminate repetitive elements from a given list of integers and return the remaining elements in descending order. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def eliminate_repetitions_and_sort_descendin... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def eliminate_repetitions_and_sort_descending(arr: List[int]) -> List[int]:
"""
Eliminates repetitive elements from a list of integers and returns the remaining elements in descending order.
Args:... |
evol_instruct_66k | 9,084 | Write a Python function to sort a mixed list of integers and strings in ascending order using an optimized bubble sort algorithm. The function should segregate the integers and strings into separate lists, sort each list individually, and then concatenate the sorted lists. The function should not use any built-in sort ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def optimized_bubble_sort(input_list: List[Union[int, str]]) -> List[Union[int, str]]:
"""
Sorts a mixed list of integers and strings in ascending order using an optimized bubble sort algorithm.
... |
evol_instruct_66k | 9,102 | Write a Python function to sort a list of fruit names in lexicographical order and return a single string with the sorted fruit names separated by commas. The function should handle an empty list by returning an empty string.
The code should start with:
```python
from typing import List
def sort_fruits(fruit_list: Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_fruits(fruit_list: List[str]) -> str:
"""
Sorts a list of fruit names in lexicographical order and returns a single string with the sorted fruit names separated by commas.
Args:
fru... |
evol_instruct_66k | 9,107 | Write a Python function to compute the Levenshtein distance between two strings using the Wagner-Fisher algorithm. The Levenshtein distance is the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other. The function should start with:
```python
de... | Here is the Python code to solve the given problem in the markdown block:
```python
def levenshtein_distance(s1: str, s2: str) -> int:
"""
Compute the Levenshtein distance between two strings using the Wagner-Fisher algorithm.
Args:
s1 (str): The first string.
s2 (str): The second string.
... |
evol_instruct_66k | 9,112 | Write a Python function to reverse the words in a given string while maintaining the order of the words. For example, if the input string is "Hello World!", the output should be "World! Hello". The function should handle strings with multiple spaces between words and leading/trailing spaces.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_words_in_string(s: str) -> str:
"""
Reverses the words in a given string while maintaining the order of the words.
Args:
s (str): The input string to reverse the words in.
Returns:
str: A ... |
evol_instruct_66k | 9,116 | Write a Python function to generate the first `n` components of the Fibonacci series. The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones, starting from 0 and 1. The function should return a list containing the first `n` Fibonacci numbers.
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 generate_fibonacci(n: int) -> List[int]:
"""
Generate the first n components of the Fibonacci series.
The Fibonacci series is a sequence of numbers where each number is the sum of the two preced... |
evol_instruct_66k | 9,119 | Write a Python function to sort a list of strings in alphabetical order, considering both case-sensitive and case-insensitive sorting. The function should return a tuple containing two lists: the first list sorted in a case-sensitive manner, and the second list sorted in a case-insensitive manner.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_strings(list_of_strings: List[str]) -> Tuple[List[str], List[str]]:
"""
Sorts a list of strings in both case-sensitive and case-insensitive manners.
Args:
list_of_strings (Li... |
evol_instruct_66k | 9,126 | Write a Python function to convert a hierarchical JSON object representing an HTML structure into an HTML string. The JSON object will have a specific structure where each node can have a `tag`, optional `text`, and optional `childs` which is a list of child nodes. The function should recursively traverse the JSON obje... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def json_to_html(json_obj: Dict[str, Any]) -> str:
"""
Converts a hierarchical JSON object representing an HTML structure into an HTML string.
Args:
json_obj (Dict[str, Any]): A diction... |
evol_instruct_66k | 9,136 | Write a Python function to generate a decrementing series from a given integer `x` down to 0, and return the series as a list. The function should handle any non-negative integer input for `x`.
The code should start with:
```python
from typing import List
def decrementing_series(x: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def decrementing_series(x: int) -> List[int]:
"""
Generates a decrementing series from the given integer `x` down to 0.
Args:
x (int): The starting integer for the decrementing series.
... |
evol_instruct_66k | 9,153 | Write a Python function to calculate the sum of the squares of all even numbers in a given list of integers. The function should iterate through the list, identify the even numbers, square each of them, and then return the sum of these squared values.
The code should start with:
```python
from typing import List
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_squared_evens(lst: List[int]) -> int:
"""
Calculate the sum of the squares of all even numbers in the given list.
Args:
lst (List[int]): A list of integers.
Returns:
... |
evol_instruct_66k | 9,154 | Write a Python function to find the position of the last occurrence of a target integer in a given list of integers. If the target integer is not found, the function should return -1. The function should be implemented without using any in-built Python functions or libraries.
The code should start with:
```python
from... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_last_occurrence(my_list: List[int], target: int) -> int:
"""
Find the position of the last occurrence of a target integer in a given list.
Args:
my_list (List[int]): The list of int... |
evol_instruct_66k | 9,155 | Write a Python function to reverse the order of words in a given sentence and capitalize each word. The function should handle special characters and white spaces correctly. The code should start with:
```python
def reverse_capitalize_sentence(sentence: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_capitalize_sentence(sentence: str) -> str:
"""
Reverses the order of words in a given sentence and capitalizes each word.
Args:
sentence (str): The input sentence to be processed.
Returns:
s... |
evol_instruct_66k | 9,158 | Write a Python function to convert every character within a given text string into its lowercase equivalent. The function should handle any string input, including strings with special characters and numbers, and should return the lowercase version of the input string.
The code should start with:
```python
def convert... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_lowercase(input_string: str) -> str:
"""
Converts every character within a given text string into its lowercase equivalent.
Args:
input_string (str): The input string to be converted to lowercase.
... |
evol_instruct_66k | 9,167 | Write a Python function to append a new item to a list and return the updated list. The function should handle the case where the append operation does not return a new list but modifies the original list in place.
The code should start with:
```python
from typing import List, Any
def append_and_return(lst: List[Any]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def append_and_return(lst: List[Any], item: Any) -> List[Any]:
"""
Appends an item to a list and returns the updated list.
Args:
lst (List[Any]): The list to which the item will be appe... |
evol_instruct_66k | 9,176 | Write a Python function to duplicate a given string `n` times, where `n` is a positive integer. The function should return the duplicated string. If `n` is not a positive integer, the function should return the original string without any duplication.
The code should start with:
```python
def duplicate_string(input_st... | Here is the Python code to solve the given problem in the markdown block:
```python
def duplicate_string(input_string: str, n: int) -> str:
"""
Duplicates the given string `n` times if `n` is a positive integer.
If `n` is not a positive integer, returns the original string without any duplication.
Args... |
evol_instruct_66k | 9,218 | Write a Python function to recursively calculate the sum of all integer values in a multi-tiered dictionary. The dictionary may contain nested dictionaries, and the function should traverse through all levels to find and sum all integer values.
The code should start with:
```python
from typing import Dict
def sum_nes... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sum_nested_dict(dictionary: Dict) -> int:
"""
Recursively calculates the sum of all integer values in a multi-tiered dictionary.
Args:
dictionary (Dict): The dictionary to traverse and s... |
evol_instruct_66k | 9,227 | Write a Python function to clean a given string by removing all whitespace characters and non-alphanumeric characters (such as punctuation marks and symbols). The function should return the cleaned string. Additionally, provide a corrected version of a flawed function that attempts to solve the same problem but fails d... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def clean_string(input_string: str) -> str:
"""
Clean the input string by removing all whitespace characters and non-alphanumeric characters.
Args:
input_string (str): The input string to be cleaned.
... |
evol_instruct_66k | 9,230 | Write a Python function to reverse a given list while preserving the original list's order. 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_preserve_original(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_preserve_original(input_list: List[int]) -> List[int]:
"""
Reverses a given list while preserving the original list's order.
Args:
input_list (List[int]): The list to be revers... |
evol_instruct_66k | 9,231 | Write a Python function to calculate the sum of all the cubed numbers of odd integers from 1 to 19, ensuring that the sum does not exceed 20. Implement error handling to catch potential issues. The function should start with:
```python
def sum_of_cubed_odds_before_20() -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_cubed_odds_before_20() -> int:
"""
Calculate the sum of all the cubed numbers of odd integers from 1 to 19, ensuring that the sum does not exceed 20.
Returns:
int: The sum of the cubed numbers of odd inte... |
evol_instruct_66k | 9,235 | Write a Python function to apply a logarithmic transformation to a given set of numerical data. The function should handle both positive and zero values in the dataset. For zero values, the function should return a predefined constant value (e.g., 0). The code should start with:
```python
from typing import List
import... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def log_transform(data: List[float], zero_value: float = 0.0) -> List[float]:
"""
Applies a logarithmic transformation to a given set of numerical data.
Args:
data (List[float]):... |
evol_instruct_66k | 9,242 | Write a Python function to create a dictionary that maps each name in a list of names to their corresponding birth date from a list of birth dates. The function should ensure that the two lists are of the same length and handle cases where the lists are empty.
The code should start with:
```python
from typing import L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_birth_date_map(names: List[str], birth_dates: List[str]) -> Dict[str, str]:
"""
Creates a dictionary that maps each name in the list of names to their corresponding birth date from the l... |
evol_instruct_66k | 9,246 | Write a Python function to determine if a given numerical value resides within the bounds of 5 and 10 (inclusive). The function should return `True` if the number is within the bounds and `False` otherwise. The code should start with:
```python
def is_within_bounds(number: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_within_bounds(number: int) -> bool:
"""
Determines if a given numerical value resides within the bounds of 5 and 10 (inclusive).
Args:
number (int): The numerical value to check.
Returns:
bool: T... |
evol_instruct_66k | 9,247 | Write a Python function to extract and return the values from a given dictionary. The function should handle dictionaries with various types of keys and values. The code should start with:
```python
from typing import Dict, Any, List
def extract_values(dictionary: Dict[Any, Any]) -> List[Any]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import Dict, Any, List
def extract_values(dictionary: Dict[Any, Any]) -> List[Any]:
"""
Extracts and returns the values from a given dictionary.
Args:
dictionary (Dict[Any, Any]): The dictionary from ... |
evol_instruct_66k | 9,248 | Write a Python function to count the occurrences of each word in a given list of words and return a dictionary where the keys are the words and the values are the counts of their occurrences. The function should handle case-sensitive words and should not use any external libraries.
The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_word_occurrences(words: List[str]) -> Dict[str, int]:
"""
Counts the occurrences of each word in a given list of words.
Args:
words (List[str]): A list of words to count.
... |
evol_instruct_66k | 9,256 | Write a Python function to determine if a given string is a valid palindrome considering only alphanumeric characters and ignoring cases. The function should return `True` if the string is a valid palindrome, otherwise `False`.
The code should start with:
```python
def is_valid_palindrome(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_palindrome(s: str) -> bool:
"""
Determine if a given string is a valid palindrome considering only alphanumeric characters and ignoring cases.
Args:
s (str): The input string to be checked.
Returns... |
evol_instruct_66k | 9,258 | Write a Python function to compute the factorial of a given non-negative integer using an iterative approach. The function should handle edge cases such as zero and large numbers efficiently. The code should start with:
```python
def factorial(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int:
"""
Compute the factorial of a given non-negative integer using an iterative approach.
Args:
n (int): The non-negative integer for which to compute the factorial.
Returns:
... |
evol_instruct_66k | 9,283 | Write a Python function to determine if two given strings are isomorphic. Two strings are isomorphic if there is a one-to-one mapping possible for every character of the first string to every character of the second string. The function should handle edge cases such as strings of different lengths and ensure that no tw... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_isomorphic(string1: str, string2: str) -> bool:
"""
Determine if two strings are isomorphic.
Two strings are isomorphic if there is a one-to-one mapping possible for every character
of the first string to every ... |
evol_instruct_66k | 9,290 | Write a Python function to find the index of the highest integer in a given list of numerical values. The function should return the index of the first occurrence of the highest integer. The code should start with:
```python
from typing import List
def find_max_index(lst: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def find_max_index(lst: List[int]) -> int:
"""
Find the index of the highest integer in a given list of numerical values.
Args:
lst (List[int]): The list of numerical values.
Returns:... |
evol_instruct_66k | 9,299 | Write a Python function to merge a list of countries with their corresponding populations into a dictionary. The function should ensure that the countries and populations are correctly paired and that the resulting dictionary is sorted by the population in descending order.
The code should start with:
```python
from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def merge_and_sort_populations(nations: List[str], populations: List[int]) -> Dict[str, int]:
"""
Merges a list of countries with their corresponding populations into a dictionary
and sorts the... |
evol_instruct_66k | 9,304 | Write a Python function to construct an array by integrating a list of specified elements while preserving their particular ordering. The function should accept a list of integers as input and return a new list with the elements added in the specified order.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def construct_array(elements: List[int]) -> List[int]:
"""
Constructs an array by integrating a list of specified elements while preserving their particular ordering.
Args:
elements (List[in... |
evol_instruct_66k | 9,310 | Write a Python function to extract the recurring elements from a given numerical sequence. A recurring element is defined as an element that appears more than once in the sequence. The function should return a list of these recurring elements in ascending order.
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 find_recurring_elements(sequence: List[int]) -> List[int]:
"""
Extracts the recurring elements from a given numerical sequence and returns them in ascending order.
Args:
sequence (List[i... |
evol_instruct_66k | 9,313 | Write a Python function that converts a tuple of two floats into a complex number. The function should include type hinting for the function arguments and return value, following Python's best practices. The function should be named `tuple_to_complex` and should accept a single argument, which is a tuple containing exa... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def tuple_to_complex(numbers: Tuple[float, float]) -> complex:
"""
Converts a tuple of two floats into a complex number.
Args:
numbers (Tuple[float, float]): A tuple containing exactly two ... |
evol_instruct_66k | 9,327 | Write a Python function to find the highest numerical value in a given array of integers. The function should return the maximum value present in the array. The code should start with:
```python
from typing import List
def find_highest_value(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def find_highest_value(arr: List[int]) -> int:
"""
Find the highest numerical value in a given array of integers.
Args:
arr (List[int]): The array of integers from which to find the highes... |
evol_instruct_66k | 9,340 | Write a Python function to find the largest number in a given array using a multi-step process. The function should iterate through the array and keep track of the largest number found so far. The code should start with:
```python
from typing import List
def find_largest_number(array: 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(array: List[int]) -> int:
"""
Finds the largest number in a given array using a multi-step process.
Args:
array (List[int]): The array of integers from which to find ... |
evol_instruct_66k | 9,354 | Write a Python function to merge two dictionaries into a single dictionary. If both dictionaries have the same key, the value from the second dictionary should overwrite the value from the first dictionary. The function should handle cases where the input dictionaries are empty or contain duplicate keys.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_dictionaries(dict1: Dict[str, str], dict2: Dict[str, str]) -> Dict[str, str]:
"""
Merge two dictionaries into a single dictionary. If both dictionaries have the same key,
the value from the... |
evol_instruct_66k | 9,365 | Write two Python functions to sort the keys of a dictionary in an increasing sequence. The first function should ignore special characters when sorting, while the second function should include special characters in sorting. If the value is an integer, it should be listed first before alphabetical ordering. The functio... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
import re
def sort_dict_ignore_special_chars(dictionary: Dict[str, int]) -> List[Tuple[str, int]]:
"""
Sorts the keys of a dictionary in increasing sequence, ignoring special characters.
... |
evol_instruct_66k | 9,375 | Write a Python function to find all occurrences of a designated integral multiple within a specified interval. The function should return a list of all numbers within the interval that are multiples of the given number.
The code should start with:
```python
from typing import List
def find_multiples_in_interval(n: in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_multiples_in_interval(n: int, start: int, end: int) -> List[int]:
"""
Find all multiples of a given number `n` within the interval `[start, end]`.
Args:
n (int): The number whose mu... |
evol_instruct_66k | 9,388 | Write a Python function to generate a SQL query that fetches the top 3 books with the most reviews from a library database. The query should also fetch the average rating of each book and list them primarily from categories with the least number of book entries. Only consider books that have a review count of 10 or mor... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_top_books_query() -> str:
"""
Generates a SQL query to fetch the top 3 books with the most reviews from a library database.
The query also fetches the average rating of each book and lists them primarily from ca... |
evol_instruct_66k | 9,389 | Write a Python function to extract and return a list of all numerical values from a given dictionary where each key is an alphabetical character and the corresponding value is a list of distinct numerical figures. The function should handle dictionaries with varying lengths of lists and different keys.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def extract_numbers_from_dict(dictionary: Dict[str, List[int]]) -> List[int]:
"""
Extracts and returns a list of all numerical values from a given dictionary where each key is an alphabetical chara... |
evol_instruct_66k | 9,394 | Write a Python function to censor non-duplicated string elements in a given list. The function should replace each string that appears only once with the string 'xxxx'. The list is composed of Python string elements.
The code should start with:
```python
from typing import List
def censor_non_duplicated(mylist: List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def censor_non_duplicated(mylist: List[str]) -> List[str]:
"""
Censors non-duplicated string elements in the given list by replacing them with 'xxxx'.
Args:
mylist (List[str]): The list of s... |
evol_instruct_66k | 9,429 | Write a Python function to systematically distinguish and isolate all lexical elements (words and numbers) from a given string using Regular Expressions (RegEx). The function should return a list of these lexical elements.
The code should start with:
```python
from typing import List
import re
def extract_lexical_ele... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def extract_lexical_elements(input_string: str) -> List[str]:
"""
Extracts all lexical elements (words and numbers) from a given string using Regular Expressions (RegEx).
Args:
inp... |
evol_instruct_66k | 9,433 | Write a Python function to find the maximum and second maximum elements in an unsorted array of integers. The function should handle possible duplicates efficiently. The code should start with:
```python
from typing import List
def find_max_and_second_max(arr: List[int]) -> (int, int):
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def find_max_and_second_max(arr: List[int]) -> (int, int):
"""
Find the maximum and second maximum elements in an unsorted array of integers.
Args:
arr (List[int]): The unsorted array of i... |
evol_instruct_66k | 9,437 | Write a Python function to invert the sequence of elements within a provided numerical array and return the array with its elements in reverse order. The function should handle arrays of any length, including empty arrays. The code should start with:
```python
from typing import List
def invert_array(arr: List[int]) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def invert_array(arr: List[int]) -> List[int]:
"""
Inverts the sequence of elements within a provided numerical array and returns the array with its elements in reverse order.
Args:
arr (Lis... |
evol_instruct_66k | 9,447 | Write a Python function to calculate the mean value of nodes at each level in a binary tree. The function should take the root of the binary tree as input and return a list of mean values, where each element in the list corresponds to the mean value of nodes at a specific level. The mean values should be accurate to wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def average_of_levels(root: Optional[TreeNode]) -> List... |
evol_instruct_66k | 9,450 | Write a Python function to convert all characters of a given string to uppercase. The function should handle strings with any combination of characters, including letters, numbers, and special characters. The function should return the modified string with all characters in uppercase.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_uppercase(input_string: str) -> str:
"""
Converts all characters in the input string to uppercase.
Args:
input_string (str): The string to be converted to uppercase.
Returns:
str: The inp... |
evol_instruct_66k | 9,454 | Write a Python function to determine if a given list of integers is strictly increasing. A list is considered strictly increasing if each element is greater than the previous element. The function should return `True` if the list is strictly increasing and `False` otherwise.
The code should start with:
```python
from ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_strictly_increasing(arr: List[int]) -> bool:
"""
Determines if a given list of integers is strictly increasing.
Args:
arr (List[int]): The list of integers to check.
Returns:
... |
evol_instruct_66k | 9,459 | Write a Python function to convert a given numerical score into a corresponding grade level based on the following grading scale:
- 90 and above: 'A'
- 80 to 89: 'B'
- 70 to 79: 'C'
- 60 to 69: 'D'
- Below 60: 'F'
The function should take a single integer score as input and return the corresponding grade as a string.
... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_score_to_grade(score: int) -> str:
"""
Convert a given numerical score into a corresponding grade level.
Args:
score (int): The numerical score to be converted.
Returns:
str: The correspondi... |
evol_instruct_66k | 9,472 | Write a Python function to create a dictionary where the keys are elements from a given tuple and the values are their corresponding indices in the tuple. The function should handle tuples of any length and ensure that the dictionary is correctly constructed.
The code should start with:
```python
from typing import Tu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict
def tuple_to_dict(my_tuple: Tuple[int]) -> Dict[int, int]:
"""
Converts a tuple into a dictionary where each element of the tuple becomes a key
and its index becomes the corresponding value.
... |
evol_instruct_66k | 9,485 | Write a Python function to check if a specified integer exists in a given list of integers. The function should return `True` if the integer is found in the list, and `False` otherwise. The code should start with:
```python
from typing import List
def element_exists_in_list(arr: List[int], element: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def element_exists_in_list(arr: List[int], element: int) -> bool:
"""
Check if a specified integer exists in a given list of integers.
Args:
arr (List[int]): The list of integers to search i... |
evol_instruct_66k | 9,493 | Write a Python function to calculate the arithmetic summation of all numerical values in a given list of integers. The function should handle lists of varying lengths, including empty lists. The code should start with:
```python
from typing import List
def arithmetic_summation(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def arithmetic_summation(numbers: List[int]) -> int:
"""
Calculate the arithmetic summation of all numerical values in a given list of integers.
Args:
numbers (List[int]): The list of intege... |
evol_instruct_66k | 9,495 | Write a Python function to count the frequency of each unique alphabetical character in a given string. The function should return a dictionary where the keys are the lowercase alphabetical characters and the values are their respective counts. Non-alphabetical characters should be ignored.
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 count_alphabetical_chars(text: str) -> Dict[str, int]:
"""
Counts the frequency of each unique alphabetical character in the given string.
Args:
text (str): The input string from which t... |
evol_instruct_66k | 9,503 | Write a Python function to count the frequency of each word in a given text sequence and return the result as a dictionary. The function should handle various edge cases, such as empty strings, strings with only whitespace, and strings with punctuation. The code should start with:
```python
from typing import Dict
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import string
def word_frequency(text: str) -> Dict[str, int]:
"""
Count the frequency of each word in the given text sequence and return the result as a dictionary.
Args:
text (str): The in... |
evol_instruct_66k | 9,510 | Write a Python function to compute the cumulative sum of integers ranging from 1 to a given positive integer `n` (including both extremes). The function should ensure that the solution requires multiple steps to address, such as initializing a variable to hold the cumulative sum, iterating over the range, and updating ... | Here is the Python code to solve the given problem in the markdown block:
```python
def cumulative_sum(n: int) -> int:
"""
Compute the cumulative sum of integers ranging from 1 to n (inclusive).
Args:
n (int): The upper limit of the range (inclusive).
Returns:
int: The cumulative sum o... |
evol_instruct_66k | 9,523 | Write a Python function to extract and return a list of values corresponding to specified keys from a given dictionary. The function should handle cases where the keys might not exist in the dictionary by returning `None` for such keys.
The code should start with:
```python
from typing import Dict, List, Optional
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Optional
def extract_values(dictionary: Dict[str, any], keys: List[str]) -> List[Optional[any]]:
"""
Extracts values from a dictionary based on a list of keys. If a key does not exist in the dicti... |
evol_instruct_66k | 9,537 | Write a Python function to count the frequency of each unique character in a given text string. The function should return a dictionary where the keys are the characters and the values are the counts of those characters in the string. The function should handle any string input, including empty strings.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_character_frequencies(text: str) -> Dict[str, int]:
"""
Counts the frequency of each unique character in the given text string.
Args:
text (str): The input string for which charact... |
evol_instruct_66k | 9,544 | Write a Python function to find the maximum squared value among four given numbers and append it to a specified list. The function should take four integers as input and a list to which the maximum squared value will be appended. The code should start with:
```python
from typing import List
def append_max_squared(num1... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def append_max_squared(num1: int, num2: int, num3: int, num4: int, result_list: List[int]) -> None:
"""
Appends the maximum squared value among four given numbers to a specified list.
Args:
... |
evol_instruct_66k | 9,550 | Write a Python function to calculate the frequency of each element in a given integer array. The function should return a dictionary where the keys are the elements of the array and the values are their respective frequencies.
The code should start with:
```python
from typing import List, Dict
def calculate_frequenci... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def calculate_frequencies(arr: List[int]) -> Dict[int, int]:
"""
Calculate the frequency of each element in a given integer array.
Args:
arr (List[int]): The array of integers for whic... |
evol_instruct_66k | 9,554 | Write a Python function to identify the programming language of a given code snippet and provide a brief explanation of why specific features of the code belong to that language. Additionally, suggest an alternative programming language that could yield the same output. The function should return a tuple containing the... | Here is the Python code to solve the given problem in the markdown block:
```python
def identify_language(code_snippet: str) -> tuple:
"""
Identify the programming language of a given code snippet and suggest an alternative language.
Args:
code_snippet (str): The code snippet to analyze.
Retur... |
evol_instruct_66k | 9,556 | Write a Python function to sort a sequence of real numbers in descending order. The function should take a list of real numbers as input and return a new list with the numbers sorted in descending order. The original list should not be modified.
The code should start with:
```python
from typing import List
def sort_d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_descending(sequence: List[float]) -> List[float]:
"""
Sorts a sequence of real numbers in descending order.
Args:
sequence (List[float]): The list of real numbers to be sorted.
... |
evol_instruct_66k | 9,557 | Write a Python function to find the position (row and column index) of the first occurrence of a specified integer value in a given 2D numerical array. If the value is not found, return `(-1, -1)`. The function should be efficient in terms of both time and space complexity.
The code should start with:
```python
from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_first_occurrence(data: List[List[int]], value: int) -> Tuple[int, int]:
"""
Find the position (row and column index) of the first occurrence of a specified integer value in a 2D numerical... |
evol_instruct_66k | 9,568 | Write a Python function to find the indexes of two distinct target numbers within a given matrix of unique numbers. If a target number is not present in the matrix, return `-1` for that number. The function should return a list containing the indexes of the first target number followed by the indexes of the second targ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_target_indexes(matrix: List[List[int]], target1: int, target2: int) -> List[Tuple[int, int]]:
"""
Find the indexes of two distinct target numbers within a given matrix of unique numbers.
... |
evol_instruct_66k | 9,572 | Write a Python function to find the longest palindromic substring within a given non-empty string. The function should efficiently identify the longest palindromic structure using dynamic programming.
The code should start with:
```python
def longest_palindromic_substring(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def longest_palindromic_substring(input_string: str) -> str:
"""
Finds the longest palindromic substring within the given input string.
Args:
input_string (str): The non-empty string in which to find the longest pal... |
evol_instruct_66k | 9,573 | Write a Python function to flip a given 2D numpy array diagonally from the top-left to the bottom-right. The function should take a 2D numpy array as input and return the flipped array. The code should start with:
```python
import numpy as np
def flip_array_diagonally(arr: np.ndarray) -> np.ndarray:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def flip_array_diagonally(arr: np.ndarray) -> np.ndarray:
"""
Flips the given 2D numpy array diagonally from the top-left to the bottom-right.
Args:
arr (np.ndarray): The 2D numpy array to be fli... |
evol_instruct_66k | 9,585 | Write a Python function to find the shared elements between two lists and return them in ascending order. The function must adhere to an O(nlogn) time complexity or better and should not use Python's intrinsic list methods for sorting or removing duplicates. The function 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
import heapq
def shared_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Find the shared elements between two lists and return them in ascending order.
Args:
list1 (List[int]):... |
evol_instruct_66k | 9,587 | Write a Python function that takes a list of integers and returns a new list where each element is the sum of the original element and the next element in the list. If the element is the last one in the list, it should be added to itself. The function should start with:
```python
from typing import List
def sum_with_n... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def sum_with_next(numbers: List[int]) -> List[int]:
"""
Returns a new list where each element is the sum of the original element and the next element in the list.
If the element is the last one in ... |
evol_instruct_66k | 9,598 | Write a Python function to move all the zeros to the end of a given list while maintaining the relative order of the non-zero elements. The function should return the modified list. The code should start with:
```python
from typing import List
def move_zeros(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 move_zeros(arr: List[int]) -> List[int]:
"""
Moves all zeros to the end of the given list while maintaining the relative order of the non-zero elements.
Args:
arr (List[int]): The list o... |
evol_instruct_66k | 9,599 | Write a Python function to multiply two integers without using the built-in multiplication operator (`*`) and calculate the product recursively. The function should handle both positive and negative integers. The code should start with:
```python
def multiply_recursive(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def multiply_recursive(a: int, b: int) -> int:
"""
Recursively multiplies two integers without using the built-in multiplication operator (*).
Args:
a (int): The first integer.
b (int): The second integer.
... |
evol_instruct_66k | 9,607 | Write a Python function to calculate the mean of a given list of real numbers. The function should handle lists of varying lengths, including empty lists, and return `None` for empty lists. The code should start with:
```python
from typing import List, Optional
def calculate_mean(numbers: List[float]) -> Optional[floa... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def calculate_mean(numbers: List[float]) -> Optional[float]:
"""
Calculate the mean of a list of real numbers.
Args:
numbers (List[float]): A list of real numbers.
Returns:
... |
evol_instruct_66k | 9,608 | Write a Python function to calculate the minimum edit distance between two DNA sequences, considering the cost of different operations: substitutions cost 2, and insertions and deletions cost 1. The function should use dynamic programming to determine the minimum number of operations required to transform one DNA seque... | Here is the Python code to solve the given problem in the markdown block:
```python
def min_edit_distance(s1: str, s2: str) -> int:
"""
Calculate the minimum edit distance between two DNA sequences.
Args:
s1 (str): The first DNA sequence.
s2 (str): The second DNA sequence.
Returns:
... |
evol_instruct_66k | 9,609 | Write a Python function to remove all whitespace characters from a given string. The function should handle various types of whitespace characters, including spaces, tabs, and newlines. The code should start with:
```python
def remove_all_whitespace(input_str: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def remove_all_whitespace(input_str: str) -> str:
"""
Removes all whitespace characters from the given string.
Args:
input_str (str): The input string from which to remove whitespace characters.
Retu... |
evol_instruct_66k | 9,634 | Write a Python function to find the minimum integer in a given triplet of integers. The function should accept a tuple of three integers as input and return the smallest integer among them. The code should start with:
```python
from typing import Tuple
def find_minimum_in_triplet(triplet: Tuple[int, int, int]) -> int:... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import Tuple
def find_minimum_in_triplet(triplet: Tuple[int, int, int]) -> int:
"""
Find the minimum integer in a given triplet of integers.
Args:
triplet (Tuple[int, int, int]): A tuple containing ex... |
evol_instruct_66k | 9,648 | Write a Python function to perform a binary search on a sorted list to find the index of a target element. If the target element is not found, return `None`. The function should be efficient and handle edge cases such as an empty list or a target element that is not present in the 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, Optional
def binary_search(arr: List[int], x: int) -> Optional[int]:
"""
Perform a binary search on a sorted list to find the index of a target element.
Args:
arr (List[int]): A sorted list... |
evol_instruct_66k | 9,659 | Write a Python function to calculate the sum of all values in a given dictionary where each key maps to a list of integers. The function should return a dictionary where each key maps to the sum of its corresponding list of integers.
The code should start with:
```python
from typing import Dict, List
def sum_values_i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def sum_values_in_dict(data: Dict[str, List[int]]) -> Dict[str, int]:
"""
Calculate the sum of all values in a dictionary where each key maps to a list of integers.
Args:
data (Dict[st... |
evol_instruct_66k | 9,674 | Write a Python function to iterate over a list of integers and collect the halved values of even numbers into a new list. The function should start with:
```python
from typing import List
def halve_even_numbers(nums: List[int]) -> List[float]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def halve_even_numbers(nums: List[int]) -> List[float]:
"""
Iterates over a list of integers and collects the halved values of even numbers into a new list.
Args:
nums (List[int]): A list of... |
evol_instruct_66k | 9,677 | Write a Python function to sort a given list of strings in alphabetical order. The function should handle lists of varying lengths and should be able to sort strings in both ascending and descending order based on a provided boolean flag.
The code should start with:
```python
from typing import List
def sort_strings(... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_strings(strings: List[str], ascending: bool = True) -> List[str]:
"""
Sorts a given list of strings in alphabetical order.
Args:
strings (List[str]): The list of strings to be sorte... |
evol_instruct_66k | 9,685 | Write a Python function that generates the factorial of each number in a given list of integers using a generator expression. The function should return the generator object.
The code should start with:
```python
from typing import List, Generator
import math
def generate_factorials(numbers: List[int]) -> Generator[i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Generator
import math
def generate_factorials(numbers: List[int]) -> Generator[int, None, None]:
"""
Generates the factorial of each number in the given list of integers using a generator expression.
... |
evol_instruct_66k | 9,695 | Write a Python function to find the k closest points to the origin (0, 0) from a given list of points. Each point is represented as a tuple of two integers (x, y). The function should return a list of the k closest points, sorted by their distance to the origin in ascending order. If two points have the same distance, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import math
def find_k_closest_points(points: List[Tuple[int, int]], k: int) -> List[Tuple[int, int]]:
"""
Find the k closest points to the origin (0, 0) from a given list of points.
Args:
... |
evol_instruct_66k | 9,699 | Write a Python function to transform specific punctuations ('.', ',', '!', '?') within a given textual content into their respective textual representations. The function should replace each punctuation mark with a space followed by its textual representation (e.g., '.' should be replaced with ' DOT'). The function sho... | Here is the Python code to solve the given problem in the markdown block:
```python
def transform_punctuation(text: str) -> str:
"""
Transforms specific punctuations ('.', ',', '!', '?') within the provided textual content into their respective textual representations.
Args:
text (str): The input t... |
evol_instruct_66k | 9,721 | Write a Python function to simulate the behavior of the JavaScript function described in the given code snippet. The function should take a list of colors and a list of items, and cycle through the colors for each item when called. The function should return the updated list of items with their new colors.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cycle_colors(colors: List[str], items: List[str]) -> List[str]:
"""
Cycles through a list of colors for each item in a list of items and returns the updated list of items with their new colors.
... |
evol_instruct_66k | 9,725 | Write a Python function to count the frequency of each unique number in a given list of integers and return the result as a dictionary. The dictionary should map each unique number to its corresponding frequency of occurrence. The function should handle any list of integers, including empty lists.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_frequencies(nums: List[int]) -> Dict[int, int]:
"""
Counts the frequency of each unique number in the given list of integers.
Args:
nums (List[int]): The list of integers to ... |
evol_instruct_66k | 9,745 | Write a Python function to remove duplicate elements from a given list while preserving the order of the first occurrence of each element. The function should be efficient and handle various edge cases, such as an empty list or a list with all elements being the same.
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 remove_duplicates(array: List[int]) -> List[int]:
"""
Removes duplicate elements from the given list while preserving the order of the first occurrence of each element.
Args:
array (List... |
evol_instruct_66k | 9,769 | Write a Python function to generate all unique combinations of a given list of integers, taken k at a time, using the `itertools` module. The function should return a list of tuples, where each tuple represents a unique combination.
The code should start with:
```python
from typing import List, Tuple
from itertools im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
from itertools import combinations
def generate_combinations(dataset: List[int], k: int) -> List[Tuple[int, ...]]:
"""
Generate all unique combinations of a given list of integers, taken k at a ti... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.