source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 28,652 | Write a Python function to calculate the aggregate quantity of individual words in a provided literary excerpt, ignoring punctuation and case sensitivity. The function should return a dictionary where the keys are the words and the values are their respective counts.
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 Dict
import string
from collections import Counter
def word_count(text: str) -> Dict[str, int]:
"""
Calculate the aggregate quantity of individual words in a provided literary excerpt,
ignoring punctuatio... |
evol_instruct_66k | 28,659 | Write a Python function to convert a list of 15 distinct hexadecimal numbers into their corresponding octal representations. The function should handle the conversion of each hexadecimal number to its octal equivalent and return a list of these octal values. The code should start with:
```python
from typing import List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def hex_list_to_oct_list(hex_list: List[str]) -> List[str]:
"""
Converts a list of 15 distinct hexadecimal numbers into their corresponding octal representations.
Args:
hex_list (List[str]):... |
evol_instruct_66k | 28,662 | Write a Python function to convert an input number, represented as a string, of a specified base (integer) into its binary equivalent as a string. The base can be either 8 (indicating octal), 10 (indicating decimal), or 16 (for hexadecimal). The function should handle the conversion efficiently and return the binary re... | Here is the Python code to solve the given problem in the markdown block:
```python
def number_to_binary(x: str, base: int) -> str:
"""
Convert an input number, represented as a string, of a specified base (integer) into its binary equivalent as a string.
The base can be either 8 (indicating octal), 10 (ind... |
evol_instruct_66k | 28,670 | Write a Python function to find the maximum sum of a contiguous subarray within a given array of integers. The function should efficiently compute the maximum sum using an optimal algorithm.
The code should start with:
```python
from typing import List
def max_sum_subarray(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_sum_subarray(arr: List[int]) -> int:
"""
Find the maximum sum of a contiguous subarray within the given array.
Args:
arr (List[int]): The input array of integers.
Returns:
... |
evol_instruct_66k | 28,677 | Write a Python function to transform a given dictionary such that each alphanumeric key is prefixed with the string "cube_of_" and each corresponding value is the cube of the original value. If the cubic value is an even number, it should be replaced by -1. The function should use a single for loop to traverse the give... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def transform_dictionary(d: Dict[str, int]) -> Dict[str, int]:
"""
Transforms the given dictionary such that each alphanumeric key is prefixed with "cube_of_"
and each corresponding value is the cube... |
evol_instruct_66k | 28,693 | Write a Python function to find the maximum value in a given list of numerical entities. The function should handle lists of integers and floats. The code should start with:
```python
from typing import List, Union
def find_max_value(numbers: List[Union[int, float]]) -> Union[int, float]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Union
def find_max_value(numbers: List[Union[int, float]]) -> Union[int, float]:
"""
Find the maximum value in a list of numerical entities.
Args:
numbers (List[Union[int, float]]): A lis... |
evol_instruct_66k | 28,697 | Write a Python function to sort an array of fruit names in lexicographical (dictionary) order. The function should take a list of strings as input and return a new list with the strings sorted in lexicographical order. The code should start with:
```python
from typing import List
def sort_fruits_lexicographically(frui... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_fruits_lexicographically(fruits: List[str]) -> List[str]:
"""
Sorts an array of fruit names in lexicographical (dictionary) order.
Args:
fruits (List[str]): A list of fruit names to... |
evol_instruct_66k | 28,721 | Write a Python function to efficiently store and retrieve a large list of numbers, where the numbers may repeat and require efficient searching and insertion operations. The function should use a suitable data structure to achieve this. The code should start with:
```python
from typing import List, Union
def store_and... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def store_and_retrieve_numbers(numbers: List[int]) -> Union[str, None]:
"""
Efficiently stores a large list of numbers in a dictionary and retrieves the string representation of the first number.
... |
evol_instruct_66k | 28,722 | Write a Python function to construct a dictionary where each key-value pair from two provided lists is iteratively duplicated according to the numerical values specified in a third list. The key should reflect an item from the first list and its associated word, with repetition depending on its correspondingly indexed ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_duplicated_dict(word_list: List[str], key_list: List[str], num_list: List[int]) -> Dict[str, List[str]]:
"""
Constructs a dictionary where each key-value pair from two provided lists is ... |
evol_instruct_66k | 28,728 | Write a Python function to find the maximum value in a given list of distinct integers. The function should iterate through the list and keep track of the maximum value encountered. The code should start with:
```python
from typing import List
def find_max_value(nums: 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_value(nums: List[int]) -> int:
"""
Find the maximum value in a list of distinct integers.
Args:
nums (List[int]): A list of distinct integers.
Returns:
int: The m... |
evol_instruct_66k | 28,731 | Write a Python function to save a given list of integers into a binary format file with a `.npy` extension using NumPy. The function should take a list of integers and a filename as input and save the list as a NumPy array in the specified file.
The code should start with:
```python
from typing import List
import nump... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import numpy as np
def save_list_to_npy(data: List[int], filename: str) -> None:
"""
Saves a list of integers into a binary format file with a .npy extension.
Args:
data (List[int]): The lis... |
evol_instruct_66k | 28,736 | Write a Python function to remove all empty strings from a given list of strings. The function should return a new list that contains only the non-empty strings from the original list. The code should start with:
```python
from typing import List
def remove_empty_strings(strings: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def remove_empty_strings(strings: List[str]) -> List[str]:
"""
Removes all empty strings from the given list of strings.
Args:
strings (List[str]): The list of strings from which to remove... |
evol_instruct_66k | 28,757 | Write a Python function to determine if a given target substring exists within a specified parent string. The function should return a boolean value indicating whether the target substring is found in the parent string. The code should start with:
```python
def is_substring_in_parent(parent_string: str, target_substrin... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_substring_in_parent(parent_string: str, target_substring: str) -> bool:
"""
Determines if the target substring is present within the parent string.
Args:
parent_string (str): The string in which to search for... |
evol_instruct_66k | 28,758 | Write a Python function to identify the intersecting or common key-value pairs across all dictionaries in a given list of dictionaries. The function should efficiently handle the input and return a dictionary containing only the common key-value pairs.
The code should start with:
```python
from typing import List, Dic... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def find_common_kv_pairs(dicts: List[Dict]) -> Dict:
"""
Identify the intersecting or common key-value pairs across all dictionaries in a given list.
Args:
dicts (List[Dict]): A list o... |
evol_instruct_66k | 28,772 | Write a Python function to generate a list of student dictionaries, where each dictionary contains the same predefined student data. The function should take an integer `n` as input, which represents the number of student dictionaries to generate. The function should return a list of these dictionaries. Additionally, o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def generate_student_list(n: int) -> List[Dict[str, str]]:
"""
Generates a list of student dictionaries, each containing the same predefined student data.
Args:
n (int): The number of ... |
evol_instruct_66k | 28,796 | Write a Python function to simulate a multi-threaded program that prints "Hello World" from a user-defined number of threads. Each thread should have a unique ID, and the output should be in the following format: "Hello World from Thread: <Thread-ID>". Ensure that the usage of threads is synchronized to avoid race cond... | Here is the Python code to solve the given problem in the markdown block:
```python
from threading import Thread, Lock
def print_hello_world(num_threads: int) -> None:
"""
Simulates a multi-threaded program that prints "Hello World" from a user-defined number of threads.
Each thread has a unique ID, and th... |
evol_instruct_66k | 28,797 | Write a Python function that accepts two lists as input, computes their respective lengths, and determines the shared elements between them. The function should return a tuple containing the lengths of the two lists and a list of their shared elements. The code 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_shared_elements(list1: List[int], list2: List[int]) -> Tuple[int, int, List[int]]:
"""
Computes the lengths of two lists and finds their shared elements.
Args:
list1 (List[in... |
evol_instruct_66k | 28,804 | Write a Python function to generate an array of a specified length consisting exclusively of floating-point numbers chosen randomly. The function should ensure that each element in the array is a random floating-point number between 0 and 1. The code should start with:
```python
from typing import List
import random
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_random_float_array(length: int) -> List[float]:
"""
Generates an array of the specified length consisting exclusively of random floating-point numbers between 0 and 1.
Arg... |
evol_instruct_66k | 28,813 | Write a Python function to sort a given list of integers in ascending or descending order based on a boolean parameter. The function should use Python's built-in sorting functions for efficiency.
The code should start with:
```python
from typing import List
def sort_list(my_list: List[int], ascending: bool = True) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_list(my_list: List[int], ascending: bool = True) -> List[int]:
"""
Sorts a list of integers in ascending or descending order based on the boolean parameter.
Args:
my_list (List[int]... |
evol_instruct_66k | 28,828 | Write a Python function to calculate the sum of the squares of all even integers in a given list. The function should handle possible exceptions such as invalid input types and return the result. The code should start with:
```python
from typing import List
def sum_of_squared_evens(lst: 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_squared_evens(lst: List[int]) -> int:
"""
Calculate the sum of the squares of all even integers in the given list.
Args:
lst (List[int]): The list of integers to process.
Ret... |
evol_instruct_66k | 28,832 | Write a Python function to convert a given date and time string from one format to another. The input format is 'Day-Month-Year Hours:Minutes' (e.g., '19-03-2020 17:30'), and the output format should be 'Day-MonthName-Year and Hours:Minutes' (e.g., '19-March-2020 and 17:30'). The time should remain in a 24-hour format.... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def convert_datetime_format(date_time_str: str) -> str:
"""
Converts a given date and time string from 'Day-Month-Year Hours:Minutes' format to 'Day-MonthName-Year and Hours:Minutes' format.
A... |
evol_instruct_66k | 28,835 | Write a Python function to find the intersection and symmetric difference between two sets. The function should take two sets as input and return a tuple containing the intersection and the symmetric difference.
The code should start with:
```python
from typing import Set, Tuple
def set_operations(set_a: Set[int], se... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set, Tuple
def set_operations(set_a: Set[int], set_b: Set[int]) -> Tuple[Set[int], Set[int]]:
"""
Find the intersection and symmetric difference between two sets.
Args:
set_a (Set[int]): The firs... |
evol_instruct_66k | 28,846 | Write a Python function to convert a hexadecimal string into its corresponding binary string representation. The function should handle both uppercase and lowercase hexadecimal characters and should return the binary string without the '0b' prefix that Python's `bin()` function includes.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_binary(hex_str: str) -> str:
"""
Convert a hexadecimal string into its corresponding binary string representation.
Args:
hex_str (str): The hexadecimal string to be converted.
Returns:
str: T... |
evol_instruct_66k | 28,851 | Write a Python function to print even numbers from 0 to a given limit (inclusive) using a loop and conditional statements. The function should be able to handle the case where the limit is less than 0 by printing nothing. The function should start with:
```python
def print_even_numbers(limit: int) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def print_even_numbers(limit: int) -> None:
"""
Prints even numbers from 0 to the given limit (inclusive).
Args:
limit (int): The upper limit for the even numbers to be printed.
Returns:
None: This func... |
evol_instruct_66k | 28,855 | Write a Python function to safely append an element to a list without causing an index out of range error. The function should handle the case where the list is initially empty and ensure that the element is appended correctly. The code should start with:
```python
from typing import List, Any
def safe_append(lst: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def safe_append(lst: List[Any], element: Any) -> None:
"""
Safely appends an element to the end of a list.
Args:
lst (List[Any]): The list to which the element will be appended.
... |
evol_instruct_66k | 28,861 | Write a Python function to swap the elements of two given arrays of integers. The function should ensure that both arrays have the same length before performing the swap. If the arrays do not have the same length, the function should return an error message. 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, Tuple
def swap_elements(arr1: List[int], arr2: List[int]) -> Tuple[List[int], List[int]] or str:
"""
Swaps the elements of two given arrays of integers.
Args:
arr1 (List[int]): The first ar... |
evol_instruct_66k | 28,865 | Write a Python function to traverse the elements of a specified dictionary and return a list of formatted strings, where each string contains both the identifier and the corresponding data point. The dictionary for manipulation is provided. The function should start with:
```python
from typing import Dict, List
def tr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def traverse_dictionary(myinfo: Dict[str, str]) -> List[str]:
"""
Traverse the elements of a specified dictionary and return a list of formatted strings.
Args:
myinfo (Dict[str, str]):... |
evol_instruct_66k | 28,870 | Write a Python function to generate the first `n` prime numbers. The function should return a list of the first `n` prime numbers. The code should start with:
```python
from typing import List
def generate_first_n_primes(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_first_n_primes(n: int) -> List[int]:
"""
Generate the first n prime numbers.
Args:
n (int): The number of prime numbers to generate.
Returns:
List[int]: A list cont... |
evol_instruct_66k | 28,889 | Write a Python function to reverse the order of elements in a given list of integers. The function should return a new list with the elements in reverse order. The code should start with:
```python
from typing import List
def reverse_list(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def reverse_list(arr: List[int]) -> List[int]:
"""
Reverses the order of elements in a given list of integers.
Args:
arr (List[int]): The list of integers to be reversed.
Returns:
... |
evol_instruct_66k | 28,904 | Write a Python function to return an array with unique elements from a given array of integers, while preserving the order of their first appearance. The function should handle any size of input array and ensure that the output array contains only the first occurrence of each element.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def unique_elements_preserve_order(arr: List[int]) -> List[int]:
"""
Returns a list of unique elements from the given array, preserving the order of their first appearance.
Args:
arr (List[i... |
evol_instruct_66k | 28,905 | Write a Python function to calculate the total price of items in a shopping cart after applying a discount code. The function should handle the following operations:
1. Add items to the cart with their respective prices and quantities.
2. Apply a discount code to the cart, which reduces the total price by a specified p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Union
def calculate_total_price(cart: Dict[str, Dict[str, Union[int, float]]], discount_code: str = None) -> float:
"""
Calculate the total price of items in the shopping cart after applying a discount ... |
evol_instruct_66k | 28,910 | Write a Python function to perform matrix multiplication between two given 5x5 matrices composed of randomly generated real integers within the range of -100 to 100. The function should return the resultant matrix. If the matrix multiplication is not possible due to size constraints, the function should raise a `ValueE... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def matrix_multiplication(A: List[List[int]], B: List[List[int]]) -> List[List[int]]:
"""
Perform matrix multiplication between two 5x5 matrices composed of integers within the range of -10... |
evol_instruct_66k | 28,953 | Write a Python function to recursively sum all the numbers in a given list. The list may contain other numerical lists which also need to be added up. The function must effectively identify and ignore any non-numeric elements or lists containing non-numeric elements.
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, Union
def recursive_sum(lst: List[Union[int, float, List]]) -> Union[int, float]:
"""
Recursively sums all the numbers in a given list, including numbers in nested lists.
Non-numeric elements and li... |
evol_instruct_66k | 28,956 | Write a Python function to implement the Cocktail Sort algorithm, which is a variant of the Bubble Sort algorithm that sorts in both directions (bidirectional). Additionally, optimize the algorithm to skip unnecessary iterations by keeping track of the last swapped index. The function 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 cocktail_sort(arr: List[int]) -> List[int]:
"""
Sorts the given list using the Cocktail Sort algorithm, which is a bidirectional Bubble Sort.
The algorithm is optimized to skip unnecessary iterat... |
evol_instruct_66k | 28,960 | Write a Python function to reverse the order of elements in a given list without using any built-in utility functions like `reverse()` or `reversed()`. The function should iterate through the list and construct a new list with elements in the reverse order.
The code should start with:
```python
from typing import List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_list(seq: List[int]) -> List[int]:
"""
Reverses the order of elements in a given list without using built-in utility functions.
Args:
seq (List[int]): The list of integers to be ... |
evol_instruct_66k | 28,962 | Write a Python function to create a 2D array of specified dimensions filled with a specified numerical value using the NumPy module. The function should allow for both integer and floating-point values. The code should start with:
```python
import numpy as np
from typing import Union
def create_2d_array(rows: int, col... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import Union
def create_2d_array(rows: int, cols: int, value: Union[int, float]) -> np.ndarray:
"""
Create a 2D array of specified dimensions filled with a specified numerical value.
Args:
... |
evol_instruct_66k | 28,969 | Write a Python function to calculate the sum of all elements within a provided two-dimensional array. The function should traverse through both dimensions of the array to compute the sum. The code should start with:
```python
from typing import List
def sum_2d_array(array: List[List[int]]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_2d_array(array: List[List[int]]) -> int:
"""
Calculate the sum of all elements in a provided two-dimensional array.
Args:
array (List[List[int]]): A two-dimensional array (list of li... |
evol_instruct_66k | 28,974 | Write a Python function to reverse the characters in a given string. The function should take a string as input and return the reversed string. The code should start with:
```python
def reverse_string(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(text: str) -> str:
"""
Reverses the characters in the given string.
Args:
text (str): The input string to be reversed.
Returns:
str: The reversed string.
"""
# Use slicing to ... |
evol_instruct_66k | 28,987 | Write a Python function to reverse a given string if its length matches a specified length. If the length of the string does not match the specified length, the function should raise a `ValueError`.
The code should start with:
```python
def reverse_string_if_length_matches(s: str, length: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string_if_length_matches(s: str, length: int) -> str:
"""
Reverses the given string `s` if its length matches the specified `length`.
If the length of the string does not match the specified length, raises a Valu... |
evol_instruct_66k | 28,992 | Write a Python function to determine if two given phrases contain completely identical sets of words, considering both the word order and frequency. The function should return `True` if the phrases are identical in terms of word sequences and frequencies, and `False` otherwise.
The code should start with:
```python
de... | Here is the Python code to solve the given problem in the markdown block:
```python
def compare_word_sets_frequency_order(phrase1: str, phrase2: str) -> bool:
"""
Determine if two input phrases contain identical sequences of words with the same word frequency and order.
Args:
phrase1 (str): The fir... |
evol_instruct_66k | 28,994 | Write a Python function to filter and return a list of even numbers from a given list of integers. The function should iterate over the list and include only the even numbers in the result. 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 and returns a list of even numbers from the given list of integers.
Args:
numbers (List[int]): The list of integers to f... |
evol_instruct_66k | 29,015 | Write a Python function to determine if a given list contains at least one decimal number (float). The function should return `True` if there is at least one float in the list, otherwise it should return `False`.
The code should start with:
```python
from typing import List, Union
def contains_decimal(seq: List[Union... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def contains_decimal(seq: List[Union[int, float, str]]) -> bool:
"""
Determines if a given list contains at least one decimal number (float).
Args:
seq (List[Union[int, float, str]]):... |
evol_instruct_66k | 29,029 | Write a Python function to calculate the minimum value in a 2D list (list of lists) without using external libraries like NumPy. The function should iterate through the 2D list and find the minimum value efficiently.
The code should start with:
```python
from typing import List
def find_min_in_2d_list(array: List[Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_min_in_2d_list(array: List[List[int]]) -> int:
"""
Calculate the minimum value in a 2D list (list of lists).
Args:
array (List[List[int]]): A 2D list containing integers.
Retur... |
evol_instruct_66k | 29,043 | Write a Python function to divide a given list of integers into two separate lists: one containing the elements at even indices and the other containing the elements at odd indices. The original order of the elements should be preserved in both lists after the split. The function should start with:
```python
from typin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def split_array_by_indices(arr: List[int]) -> Tuple[List[int], List[int]]:
"""
Splits a list of integers into two lists: one containing elements at even indices and the other containing elements a... |
evol_instruct_66k | 29,080 | Write a Python function to extract the latitude and longitude from a given geographical data dictionary. The dictionary contains various geographical information, including a nested dictionary for coordinates. The function should return a tuple containing the latitude and longitude.
The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def extract_coordinates(geographical_data: Dict) -> Tuple[float, float]:
"""
Extracts the latitude and longitude from a given geographical data dictionary.
Args:
geographical_data (di... |
evol_instruct_66k | 29,085 | Write a Python function to find the kth largest element in a given list of integers efficiently. The function should handle edge cases such as an empty list or k being out of bounds. The code should start with:
```python
from typing import List
def find_kth_largest(arr: 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_largest(arr: List[int], k: int) -> int:
"""
Find the kth largest element in a given list of integers.
Args:
arr (List[int]): The list of integers from which to fi... |
evol_instruct_66k | 29,094 | Write a Python function to calculate the sum of the per-digit XOR operation between two hexadecimal numbers. Each digit in the hexadecimal numbers should be XORed with the corresponding digit in the other number, and the results should be summed. The function should handle hexadecimal numbers of different lengths by pa... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_xor_per_digit(hex_num1: str, hex_num2: str) -> int:
"""
Calculate the sum of the per-digit XOR operation between two hexadecimal numbers.
Args:
hex_num1 (str): The first hexadecimal number as a string.
... |
evol_instruct_66k | 29,121 | Write a Python function to sort a list of dictionaries containing musical notes and their frequencies in descending order based on the frequency values. Each dictionary in the list has two keys: `'note'` (a string representing the musical note) and `'frequency'` (a float representing the frequency of the note). The fun... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def sort_musical_notes(notes: List[Dict[str, float]]) -> List[Dict[str, float]]:
"""
Sorts a list of dictionaries containing musical notes and their frequencies in descending order based on the fre... |
evol_instruct_66k | 29,128 | Write a Python function to sort a given numerical dataset in ascending order using the Bubble Sort algorithm. The function should return the sorted array. The code should start with:
```python
from typing import List
def bubble_sort(array: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(array: List[int]) -> List[int]:
"""
Sorts a given numerical dataset in ascending order using the Bubble Sort algorithm.
Args:
array (List[int]): The numerical dataset to be s... |
evol_instruct_66k | 29,136 | Write a Python function to find the median of a list of five unique integers. The function should sort the list and then compute the median. The code should start with:
```python
from typing import List
def find_median_of_five(values: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_median_of_five(values: List[int]) -> int:
"""
Finds the median of a list of exactly five unique integers.
Args:
values (List[int]): A list of exactly five unique integers.
Retu... |
evol_instruct_66k | 29,140 | Write a Python function to construct a regular expression pattern that exclusively matches the words "apple" and "match". The function should return the compiled regular expression pattern. The code should start with:
```python
import re
def construct_regex_pattern() -> re.Pattern:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def construct_regex_pattern() -> re.Pattern:
"""
Constructs a regular expression pattern that exclusively matches the words "apple" and "match".
Returns:
re.Pattern: A compiled regular expression pattern ... |
evol_instruct_66k | 29,145 | Write a Python function to correct and print a given string variable with the value "Hello World". The function should take a string as input, correct any spelling mistakes, and print the corrected string. The code should start with:
```python
def correct_and_print_string(input_string: str) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def correct_and_print_string(input_string: str) -> None:
"""
Corrects any spelling mistakes in the input string to match "Hello World" and prints the corrected string.
Args:
input_string (str): The input string to... |
evol_instruct_66k | 29,153 | Write a Python function to convert a string of digits to the corresponding integer value without using built-in functions like `int()` or `atoi()`. The function should handle potential edge cases, such as invalid characters in the input string. The code should start with:
```python
def string_to_int(string: str) -> int... | Here is the Python code to solve the given problem in the markdown block:
```python
def string_to_int(string: str) -> int:
"""
Converts a string of digits to the corresponding integer value without using built-in functions like int() or atoi().
Args:
string (str): The string of digits to be convert... |
evol_instruct_66k | 29,165 | Write a Python function to merge two alphanumeric strings while maintaining the original character order. The function should handle any potential error cases, such as non-string inputs. The merged string should be stored in a variable and returned.
The code should start with:
```python
def merge_alphanumeric_strings(... | Here is the Python code to solve the given problem in the markdown block:
```python
def merge_alphanumeric_strings(str1: str, str2: str) -> str:
"""
Merges two alphanumeric strings while maintaining their original character order.
Args:
str1 (str): The first alphanumeric string.
str2 (str):... |
evol_instruct_66k | 29,167 | Write a Python function to compute the absolute difference between two integers. The function should handle both positive and negative integers, ensuring that the result is always non-negative. The code should start with:
```python
def compute_absolute_difference(int1: int, int2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def compute_absolute_difference(int1: int, int2: int) -> int:
"""
Computes the absolute difference between two integers.
Args:
int1 (int): The first integer.
int2 (int): The second integer.
Returns:
... |
evol_instruct_66k | 29,168 | Write a Python function to analyze a list of sentences and return a dictionary of unique words (case-insensitive) along with their occurrences, excluding predefined stopwords and punctuation marks. The function should start with:
```python
from typing import List, Dict
def analyze_sentences(sentences: List[str], stopw... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
from collections import Counter
import string
def analyze_sentences(sentences: List[str], stopwords: List[str]) -> Dict[str, int]:
"""
Analyzes a list of sentences and returns a dictionary of uniqu... |
evol_instruct_66k | 29,174 | Write a Python function to check if the variable `x` equals 10 and the variable `y` equals 20. Additionally, the function should check if either `x` is greater than 5 or `y` is less than 30. Lastly, the function should ensure that `x` is not equal to `y`. The function should return `True` if all conditions are met, oth... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_conditions(x: int, y: int) -> bool:
"""
Check if the given conditions are met for the variables x and y.
Args:
x (int): The first integer to check.
y (int): The second integer to check.
Return... |
evol_instruct_66k | 29,184 | Write a Python function to determine if two singly linked data structures share any common elements. The function should take two lists as input and return a boolean value indicating whether there is at least one common element between the two lists. The code should start with:
```python
from typing import List
def do... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def do_lists_share_common_elements(list1: List[int], list2: List[int]) -> bool:
"""
Determines if two singly linked data structures share any common elements.
Args:
list1 (List[int]): The fi... |
evol_instruct_66k | 29,191 | Write a Python function to determine the minimum number of non-overlapping intervals needed to cover the entire range of a given set of intervals. The intervals can include fractional numbers and can have the same start and end points. The function should handle an empty list of intervals by returning 0.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def min_intervals_to_cover_range(intervals: List[List[float]]) -> int:
"""
Determine the minimum number of non-overlapping intervals needed to cover the entire range of a given set of intervals.
Arg... |
evol_instruct_66k | 29,223 | Write a Python function to sort a list of users based on their last names in reverse alphabetical order. If two users have the same last name, sort them by their age in ascending order (youngest to oldest). The function should take a list of dictionaries, where each dictionary represents a user with keys 'last_name' an... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def sort_users(users: List[Dict[str, any]]) -> List[Dict[str, any]]:
"""
Sorts a list of users based on their last names in reverse alphabetical order.
If two users have the same last name, the... |
evol_instruct_66k | 29,244 | Write a Python function to find the first negative number in each sub-array of a given 2D list. If a sub-array does not contain any negative numbers, the function should return `None` for that sub-array. The function should demonstrate the use of a "do-while" loop emulation pattern and compare it with a traditional "fo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_first_negative_do_while(arr: List[List[int]]) -> List[Optional[int]]:
"""
Find the first negative number in each sub-array of a given 2D list using a "do-while" loop emulation pattern.... |
evol_instruct_66k | 29,249 | Write a Python function to count the number of definitions for each word in a given dictionary. The dictionary is structured such that each key is a word, and its value is a list of definitions. The function should return a new dictionary where each key is a word from the input dictionary, and its value is the number o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def count_definitions(dictionary: Dict[str, List[str]]) -> Dict[str, int]:
"""
Counts the number of definitions for each word in the given dictionary.
Args:
dictionary (Dict[str, List[... |
evol_instruct_66k | 29,253 | Write a Python function to convert an RGB color to its HEX representation and its closest complementary color in HEX.
The function should start with:
```python
from typing import Tuple
def rgb_to_hex_and_complementary(rgb: Tuple[int, int, int]) -> Tuple[str, str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def rgb_to_hex_and_complementary(rgb: Tuple[int, int, int]) -> Tuple[str, str]:
"""
Converts an RGB color to its HEX representation and its closest complementary color in HEX.
Args:
rgb (Tu... |
evol_instruct_66k | 29,257 | Write a Python decorator function `check_negative` that checks if a value is negative before passing it to the decorated function. If the value is negative, the decorator should raise a `ValueError` with the message "Negative value not allowed". If the value is non-negative, the decorator should return the result of th... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_negative(func):
"""
A decorator that checks if a value is negative before passing it to the decorated function.
If the value is negative, it raises a ValueError. Otherwise, it returns the result of the
decorate... |
evol_instruct_66k | 29,269 | Write a Python function to reverse the characters of a given input text while removing any punctuation and converting all uppercase letters to lowercase. The function should start with:
```python
from typing import List
import string
def reverse_and_clean_text(input_text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import string
def reverse_and_clean_text(input_text: str) -> str:
"""
Reverses the characters of the given input text while removing any punctuation and converting all uppercase letters to lowercase.
... |
evol_instruct_66k | 29,273 | Write a Python function to generate a sequence of exactly `n` discrete characters from a given set of characters. The function should ensure that the sequence is unpredictable by using a random selection method. The code should start with:
```python
from typing import List
import random
import string
def generate_unpr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
import string
def generate_unpredictable_sequence(n: int, character_set: List[str]) -> str:
"""
Generates a sequence of exactly `n` discrete characters from a given set of characters.
... |
evol_instruct_66k | 29,277 | Write a Python function to generate the mirror reflection of a given string of characters containing both letters and numbers. The mirror reflection should reverse the order of characters in the string while maintaining the case of each letter. The function should handle any combination of letters and numbers.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
def mirror_string(s: str) -> str:
"""
Generate the mirror reflection of a given string of characters containing both letters and numbers.
Args:
s (str): The input string containing a mix of letters and numbers.
... |
evol_instruct_66k | 29,283 | Write a Python function to sort a given list in ascending order without modifying the original list. The function should return a new list that contains the elements of the original list in sorted order.
The code should start with:
```python
from typing import List
def sort_list_preserve_original(my_list: List[int]) ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_list_preserve_original(my_list: List[int]) -> List[int]:
"""
Sorts the given list in ascending order without modifying the original list.
Args:
my_list (List[int]): The list of inte... |
evol_instruct_66k | 29,284 | Write a Python function to sort a list of integers using an optimized bubble sort algorithm. The function should allow sorting in both ascending and descending order. The function should start with:
```python
from typing import List
def optimized_bubble_sort(nums: List[int], order: str) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def optimized_bubble_sort(nums: List[int], order: str) -> List[int]:
"""
Sorts a list of integers using an optimized bubble sort algorithm.
Args:
nums (List[int]): The list of integers to be... |
evol_instruct_66k | 29,285 | Write a Python function to find all distinct factors of a given integer efficiently. The function should return a sorted list of all unique factors of the integer. The code should start with:
```python
from typing import List
def find_all_factors(num: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_all_factors(num: int) -> List[int]:
"""
Find all distinct factors of a given integer efficiently.
Args:
num (int): The integer for which to find the factors.
Returns:
L... |
evol_instruct_66k | 29,309 | Write a Python function to remove all vowels from a given string. The function should handle both uppercase and lowercase vowels. The code should start with:
```python
def remove_vowels(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def remove_vowels(s: str) -> str:
"""
Removes all vowels (both uppercase and lowercase) from the given string.
Args:
s (str): The input string from which vowels are to be removed.
Returns:
str: The st... |
evol_instruct_66k | 29,312 | Write a Python function to transform a list of dictionaries into a dictionary where each key is the value of the `id` field from the original dictionaries, and the value is the corresponding dictionary. The input list contains dictionaries with unique `id` fields.
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 transform_to_dict(arr: List[Dict[str, any]]) -> Dict[int, Dict[str, any]]:
"""
Transforms a list of dictionaries into a dictionary where each key is the value of the 'id' field from the origina... |
evol_instruct_66k | 29,321 | Write a Python function to perform a binary search on a sorted array of integers to find the index of a target value. If the target value is not found in the array, the function should return -1. The function should be efficient and utilize the binary search algorithm.
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 binary_search(arr: List[int], target: int) -> int:
"""
Perform a binary search on a sorted array to find the index of a target value.
Args:
arr (List[int]): A sorted list of integers.
... |
evol_instruct_66k | 29,329 | Write a Python function to replace the last non-zero element in a given list with another specified element. The function should handle both sequence and non-sequence lists. The function should start with:
```python
from typing import List
def replace_last_non_zero_element(lst: List[int], element: int) -> List[int]:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def replace_last_non_zero_element(lst: List[int], element: int) -> List[int]:
"""
Replaces the last non-zero element in the given list with the specified element.
Args:
lst (List[int]): The ... |
evol_instruct_66k | 29,333 | Write a Python function to find the lengthiest shared subsequence of characters within three distinct textual strings. The function should not use any libraries, built-in functions, or packages for string comparison or subsequence identification. You need to create all the functions from scratch. The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
def longest_common_subsequence(X: str, Y: str, Z: str) -> int:
"""
Calculate the length of the longest common subsequence of three distinct textual strings.
Args:
X (str): The first string.
Y (str): The seco... |
evol_instruct_66k | 29,335 | Write a Python function to filter out and return a list of even numbers from a given list of integers. The function should iterate through the list and check each number to see if it is divisible by 2 without leaving a remainder. If a number meets this condition, it should be included in the result list.
The code shou... | 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 integers ... |
evol_instruct_66k | 29,337 | Write a Python function to filter a given list of integers, returning only the elements that are not less than a specified threshold value. The function should be efficient and should handle various edge cases, such as an empty list or a list with all elements below the threshold.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_elements_above_threshold(arr: List[int], threshold: int) -> List[int]:
"""
Filters a list of integers to return only the elements that are not less than a specified threshold.
Args:
... |
evol_instruct_66k | 29,338 | Write a Python function to retrieve a substring from a given string based on two input indices representing the beginning and ending positions. The function should handle cases where the indices are out of bounds by adjusting them to the nearest valid positions. The code should start with:
```python
def get_substring(s... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_substring(s: str, start_index: int, end_index: int) -> str:
"""
Retrieves a substring from a given string based on the provided start and end indices.
If the indices are out of bounds, they are adjusted to the neares... |
evol_instruct_66k | 29,351 | Write a Python function to perform element-wise addition of two lists and return the result as a new list. The function should handle lists of different lengths by padding the shorter list with zeros. The code should start with:
```python
from typing import List
def element_wise_addition(list_a: List[int], list_b: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def element_wise_addition(list_a: List[int], list_b: List[int]) -> List[int]:
"""
Perform element-wise addition of two lists and return the result as a new list.
If the lists are of different lengths... |
evol_instruct_66k | 29,380 | Write a Python function to eliminate recurring elements from a given numerical array while preserving the initial order of distinct elements. The function should not use any built-in array or list manipulation functions or libraries. The array may contain negative numbers and floating point values.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def eliminate_duplicates(arr: List[float]) -> List[float]:
"""
Eliminates recurring elements from a given numerical array while preserving the initial order of distinct elements.
Args:
arr (... |
evol_instruct_66k | 29,381 | Write a Python function to create a 2D Numpy array with a specified number of rows and columns, filled with incrementing integers starting from 0. The function should take two parameters: the number of rows (`n`) and the number of columns (`m`). The function should return the created 2D array.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def create_2d_array(n: int, m: int) -> np.ndarray:
"""
Create a 2D Numpy array with n rows and m columns, filled with incrementing integers starting from 0.
Args:
n (int): The number of rows in t... |
evol_instruct_66k | 29,384 | Write a Python function to find the nth number in the Fibonacci sequence using a recursive algorithm with memoization to optimize runtime performance. The function should handle edge cases such as negative inputs and return the correct Fibonacci number for non-negative integers.
The code should start with:
```python
d... | Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci_memoized(n: int) -> int:
"""
Calculate the nth Fibonacci number using a recursive algorithm with memoization.
Args:
n (int): The position in the Fibonacci sequence to calculate.
Returns:
i... |
evol_instruct_66k | 29,394 | Write a Python function to determine the primality and parity of a given number, and if the number is composite, return its prime factors. The function should return a tuple containing three elements: a string indicating whether the number is "Prime" or "Composite", a string indicating whether the number is "Even" or "... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_number_properties(n: int) -> tuple:
"""
Determine the primality and parity of a given number, and if the number is composite, return its prime factors.
Args:
n (int): The number to be checked.
Returns... |
evol_instruct_66k | 29,395 | Write a Python function to calculate the number of trailing zeros in the factorial of a given number `n`. The factorial of a number `n` is the product of all positive integers less than or equal to `n`. Trailing zeros are created by factors of 10 in the number, which are in turn created by pairs of 2 and 5. Since there... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_trailing_zeros_in_factorial(n: int) -> int:
"""
Calculate the number of trailing zeros in the factorial of a given number n.
Args:
n (int): The number for which to calculate the factorial and count trailin... |
evol_instruct_66k | 29,399 | Write a Python function to create a dictionary where each character in a given string acts as the key and its corresponding ASCII value acts as the value. The function should handle any non-empty string input and return a dictionary with characters as keys and their ASCII values as values.
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 create_ascii_dict(s: str) -> Dict[str, int]:
"""
Creates a dictionary where each character in the given string acts as the key and its corresponding ASCII value acts as the value.
Args:
... |
evol_instruct_66k | 29,415 | Write a Python function to extract all email addresses from a given text where the domain ends with the extension ".com". The function should use a regular expression to efficiently find and return these email addresses. The code should start with:
```python
import re
from typing import List
def extract_com_emails(tex... | Here is the Python code to solve the given problem in the markdown block:
:
```python
import re
from typing import List
def extract_com_emails(text: str) -> List[str]:
"""
Extracts all email addresses from the given text where the domain ends with the extension ".com".
Args:
text (str): The text f... |
evol_instruct_66k | 29,420 | Write a Python function to generate a set of `n` unique random hexadecimal numbers, each with a length of 8 characters (32 bits). Ensure that there are no duplicates among the generated numbers. Additionally, implement a function to verify that the generated hexadecimal numbers are valid 32-bit numbers.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_hex_numbers(n: int) -> set:
"""
Generate a set of n unique random hexadecimal numbers, each with a length of 8 characters (32 bits).
Args:
n (int): The number of unique hexadecimal number... |
evol_instruct_66k | 29,424 | Write a Python function to find all prime numbers less than a given number `n` using an efficient algorithm. The function should return a list of all prime numbers up to but not including `n`.
The code should start with:
```python
from typing import List
def find_primes_below(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def find_primes_below(n: int) -> List[int]:
"""
Find all prime numbers less than a given number n using the Sieve of Eratosthenes algorithm.
Args:
n (int): The upper limit (exclu... |
evol_instruct_66k | 29,426 | Write a Python function to find all distinct sentences in a given text that start with the phrase "I like" and end with a period. The function should use a regular expression to identify these sentences and return them as a list. The code should start with:
```python
import re
from typing import List
def find_i_like_s... | Here is the Python code to solve the given problem in the markdown block:
:
```python
import re
from typing import List
def find_i_like_sentences(text: str) -> List[str]:
"""
Find all distinct sentences in the given text that start with "I like" and end with a period.
Args:
text (str): The text to... |
evol_instruct_66k | 29,427 | Write a Python function to generate an array of `n` random numbers between `a` and `b`, where `a` and `b` are the lower and upper bounds of the range, respectively. The function should return the generated array. The code should start with:
```python
from typing import List
import numpy as np
def generate_random_numbe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import numpy as np
def generate_random_numbers(n: int, a: float, b: float) -> List[float]:
"""
Generates an array of n random numbers between a and b.
Args:
n (int): The number of random num... |
evol_instruct_66k | 29,428 | Write a Python function to rotate a given 2D numpy array 90 degrees counterclockwise. The function should handle any size of the 2D array and should return the rotated array. The code should start with:
```python
import numpy as np
def rotate_90_counterclockwise(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 rotate_90_counterclockwise(arr: np.ndarray) -> np.ndarray:
"""
Rotates a given 2D numpy array 90 degrees counterclockwise.
Args:
arr (np.ndarray): The 2D numpy array to be rotated.
Ret... |
evol_instruct_66k | 29,432 | Write a Python function to build a multi-level dictionary from provided keys and associate them with the corresponding values. The keys and values are presented in separate lists of nested tuples. Each tuple in the keys list represents a path in the dictionary, and each tuple in the values list represents the correspon... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Any
def build_multi_level_dict(keys: List[Tuple[Tuple[str, str], Tuple[str, str]]], values: List[Tuple[Tuple[Any, Any], Tuple[Any, Any]]]) -> dict:
"""
Build a multi-level dictionary from provide... |
evol_instruct_66k | 29,458 | Write a Python function to find the sum of the three smallest numbers in a given list of integers. The function must have a time complexity less than O(n log n). The code should start with:
```python
from typing import List
def sum_of_three_smallest(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_three_smallest(arr: List[int]) -> int:
"""
Calculate the sum of the three smallest numbers in a given list of integers.
Args:
arr (List[int]): The list of integers from which to f... |
evol_instruct_66k | 29,464 | Write a Python function to classify numbers within a given range based on their divisibility by 2 and 3. The function should iterate through the range and print a message for each number indicating whether it is even, odd and divisible by 3, or just odd. The function should start with:
```python
def classify_numbers(st... | Here is the Python code to solve the given problem in the markdown block:
```python
def classify_numbers(start: int, end: int) -> None:
"""
Classify numbers within a given range based on their divisibility by 2 and 3.
Args:
start (int): The starting number of the range (inclusive).
end (int... |
evol_instruct_66k | 29,465 | Write a Python function to count the occurrences of each word in a given text. The function should be case-insensitive and should treat punctuation as part of the word. The function should return a dictionary where the keys are the words and the values are the counts of those words in the text.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_word_occurrences(text: str) -> Dict[str, int]:
"""
Counts the occurrences of each word in the given text.
Args:
text (str): The input text to analyze.
Returns:
Dict[st... |
evol_instruct_66k | 29,478 | Write a Python function to iterate over a given numerical array and return a list of tuples where each tuple contains the index and the corresponding element from the array. The function should handle arrays of any length and ensure that the output list maintains the order of elements as they appear in the input array.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def indexed_elements(arr: List[int]) -> List[Tuple[int, int]]:
"""
Returns a list of tuples where each tuple contains the index and the corresponding element from the input array.
Args:
... |
evol_instruct_66k | 29,490 | Write a Python function to convert a list of digit strings into a list of unbroken integers and compute the sequential accumulation of their values. The function should take a list of strings as input and return a list of integers representing the accumulated values.
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 sequential_accumulation(digit_strings: List[str]) -> List[int]:
"""
Convert a list of digit strings into a list of unbroken integers and compute the sequential accumulation of their values.
Args... |
evol_instruct_66k | 29,518 | Write a Python function to reverse the order of words in a given string while maintaining the original character sequence of each word. The function should handle strings with multiple spaces between words and leading/trailing spaces. The code should start with:
```python
def reverse_words_in_string(text: str) -> str:
... | Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_words_in_string(text: str) -> str:
"""
Reverses the order of words in a given string while maintaining the original character sequence of each word.
Args:
text (str): The input string containing words ... |
evol_instruct_66k | 29,544 | Write a Python function to find the most frequent elements in a given list. If there are multiple elements with the same highest frequency, the function should return all of them. The function should handle lists with any type of elements, including integers, strings, and other data types.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def most_frequent_elements(arr: List[Any]) -> List[Any]:
"""
Find the most frequent elements in a given list.
Args:
arr (List[Any]): The list of elements to analyze.
Returns:
... |
evol_instruct_66k | 29,546 | Write a Python function to classify the elements of a given list of integers into two separate lists: one for even numbers and one for odd numbers. The function should return a tuple containing the two lists. The code should start with:
```python
from typing import List, Tuple
def classify_numbers(array: List[int]) ->... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Tuple
def classify_numbers(array: List[int]) -> Tuple[List[int], List[int]]:
"""
Classify the elements of a given list of integers into even and odd numbers.
Args:
array (List[int]): The ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.