source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 32,031 | Write a Python function to concatenate multiple text segments into a single string with a specified delimiter. The function should take a list of strings and a delimiter as input and return the concatenated string. The code should start with:
```python
from typing import List
def concatenate_text_segments(text_segment... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def concatenate_text_segments(text_segments: List[str], delimiter: str) -> str:
"""
Concatenates multiple text segments into a single string with the specified delimiter.
Args:
text_segmen... |
evol_instruct_66k | 32,034 | Write a Python function to calculate the factorial of numbers from 0 to a given positive integer `n` using a while loop. The function should return a list of tuples where each tuple contains a number and its factorial. The code should start with:
```python
from typing import List, Tuple
def calculate_factorials(n: int... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Tuple
def calculate_factorials(n: int) -> List[Tuple[int, int]]:
"""
Calculate the factorial of numbers from 0 to a given positive integer n.
Args:
n (int): The upper limit of the range f... |
evol_instruct_66k | 32,035 | Write a Python function to filter out and return a list of even numbers from a given list of integers. The function should efficiently handle lists of varying sizes and return an empty list if no even numbers are found.
The code should start with:
```python
from typing import List
def filter_even_numbers(numbers: Lis... | 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 | 32,050 | Write a Python function to find the most frequent integer(s) in a given array of integers and their corresponding frequency. If there is a tie for the most frequent integer, return all the most frequent integers in a list along with their frequencies. If the array is empty, return an empty list.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
from collections import defaultdict
def most_frequent_elements(arr: List[int]) -> List[Tuple[int, int]]:
"""
Find the most frequent integer(s) in the given array and their corresponding frequency.... |
evol_instruct_66k | 32,052 | Write a Python function to sort a given list of numerical values in ascending order using the merge sort algorithm. The merge sort algorithm is a divide-and-conquer algorithm that recursively divides the list into halves until each sublist contains a single element, then merges these sublists in a sorted manner.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of numerical values in ascending order using the merge sort algorithm.
Args:
arr (List[int]): The list of numerical values to be... |
evol_instruct_66k | 32,070 | Write a Python function to determine if a given sentence contains all the alphabets (a-z) at least once, ignoring case sensitivity and special characters. The function should return `True` if the sentence is a pangram (contains every letter of the alphabet at least once), and `False` otherwise.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_pangram(sentence: str) -> bool:
"""
Determine if a given sentence contains all the alphabets (a-z) at least once, ignoring case sensitivity and special characters.
Args:
sentence (str): The sentence to check.... |
evol_instruct_66k | 32,077 | Write a Python function to safely divide two integers, handling the case where the divisor is zero. If the divisor is zero, the function should return a specific error message. The function should start with:
```python
def safe_division(dividend: int, divisor: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def safe_division(dividend: int, divisor: int) -> str:
"""
Safely divides two integers and returns the result as a string.
If the divisor is zero, returns an error message instead.
Args:
dividend (int): The nu... |
evol_instruct_66k | 32,079 | Write a Python function to determine the position of the initial instance of a predetermined integer within a systematically organized array of positive integers. If the target integer is not found in the array, the function should return -1. The function should handle arrays with duplicate elements and should return t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_first_occurrence(arr: List[int], target: int) -> int:
"""
Determine the position of the initial instance of a predetermined integer within a systematically organized array of positive integers.
... |
evol_instruct_66k | 32,085 | Write a Python function to find all divisors of a given number, calculate the sum and product of these divisors, and compare these values for two given numbers. The function should return `True` if both the sum and product of the divisors of the first number are equal to the sum and product of the divisors of the secon... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_divisors(n: int) -> list:
"""
Find all divisors of a given number.
Args:
n (int): The number to find divisors for.
Returns:
list: A list of all divisors of the number.
"""
return [i for... |
evol_instruct_66k | 32,092 | Write a Python function to calculate the average of a list of numbers. The function should handle lists of any length, including empty lists. If the list is empty, the function should return `None`. The code should start with:
```python
from typing import List, Optional
def calculate_average(numbers: List[float]) -> O... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def calculate_average(numbers: List[float]) -> Optional[float]:
"""
Calculate the average of a list of numbers.
Args:
numbers (List[float]): A list of numbers for which to calculat... |
evol_instruct_66k | 32,093 | Write a Python function to generate a two-dimensional array of size n x m where each element is the product of the corresponding row and column indices. The first row and the first column should contain the numbers from 1 to m and 1 to n respectively. The function should start with:
```python
from typing import List
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_multiplication_table(n: int, m: int) -> List[List[int]]:
"""
Generate a two-dimensional array of size n x m where each element is the product of the corresponding row and column indices.
... |
evol_instruct_66k | 32,095 | Write a Python function to find the maximum value in a given list and return both the maximum value and its index. The function should handle edge cases such as an empty list and should be efficient. The code should start with:
```python
from typing import List, Tuple
def find_max_and_index(arr: List[int]) -> Tuple[in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Optional
def find_max_and_index(arr: List[int]) -> Optional[Tuple[int, int]]:
"""
Find the maximum value and its index in a given list of integers.
Args:
arr (List[int]): The list of... |
evol_instruct_66k | 32,096 | Write a Python function to sort a given list of integers in descending order. The function should take a list of integers as input and return a new list with the elements sorted in descending order. The original list should not be modified.
The code should start with:
```python
from typing import List
def sort_descen... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_descending(numbers: List[int]) -> List[int]:
"""
Sorts a given list of integers in descending order and returns the sorted list.
Args:
numbers (List[int]): The list of integers to b... |
evol_instruct_66k | 32,099 | Write a Python function to modify the integer present at the third index in a given array of integers. The modification should increment the integer at the third index by a specified value. If the third index does not exist in the array, the function should return the original array without any modifications.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def modify_third_index(arr: List[int], increment: int) -> List[int]:
"""
Modifies the integer present at the third index (index 2) in the given array by incrementing it by the specified value.
If the... |
evol_instruct_66k | 32,110 | Write a Python function to create a dictionary with predefined keys and values. The dictionary should include the keys "occupation", "birthday", and "hobby". The function should return the dictionary.
The code should start with:
```python
def create_personal_info_dict() -> dict:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def create_personal_info_dict() -> dict:
"""
Creates a dictionary with predefined keys and values.
Returns:
dict: A dictionary containing the keys "occupation", "birthday", and "hobby" with corresponding values.
... |
evol_instruct_66k | 32,113 | Write a Python function to find the highest and the lowest numbers in a given list of numbers that include negative numbers and decimals, without using built-in functions like `max()` and `min()`. The function should return a tuple containing the lowest and the highest numbers.
The code should start with:
```python
fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_min_max(numbers: List[float]) -> Tuple[float, float]:
"""
Find the highest and the lowest numbers in a given list of numbers without using built-in functions like max() and min().
Ar... |
evol_instruct_66k | 32,117 | Write a Python function to reverse both the order of elements in a list of strings and the individual strings themselves without using any built-in reverse methods. The function should start with:
```python
from typing import List
def reverse_list_and_strings(input_list: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_list_and_strings(input_list: List[str]) -> List[str]:
"""
Reverses both the order of elements in a list of strings and the individual strings themselves.
Args:
input_list (List[s... |
evol_instruct_66k | 32,121 | Write a Python function to find the greatest and smallest values in a given array of numbers. The function should return a list containing these two values in the order: smallest, greatest. The code should start with:
```python
from typing import List
def find_extremes(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 find_extremes(numbers: List[int]) -> List[int]:
"""
Finds the smallest and greatest values in a given list of numbers.
Args:
numbers (List[int]): A list of integers from which to find ... |
evol_instruct_66k | 32,127 | Write a Python function to transform a given list containing string elements into a corresponding list with integer values while maintaining the original order. The function should handle lists of varying lengths and ensure that each string element can be converted to an integer without raising an error. If any element... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def transform_to_integers(list_of_strings: List[str]) -> List[int]:
"""
Transforms a list of string elements into a corresponding list of integer values.
Elements that cannot be converted to integers... |
evol_instruct_66k | 32,133 | Write a Python function to generate two arrays with random integers within different specific ranges (from 50 to 100 and from 200 to 250) using the `random.randint()` function. After creating both arrays, implement an efficient sorting algorithm to sort all the values of both arrays in increasing order without using bu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def sort_random_arrays() -> List[int]:
"""
Generates two arrays with random integers within different specific ranges,
merges them, and sorts the merged array in increasing order using ... |
evol_instruct_66k | 32,138 | Write a Python function to find the position of the first occurrence of a given subsequence within a specified text string. The function should be case-insensitive and should return the position of the first character of the subsequence. If the subsequence is not found, the function should return -1.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_subsequence_position(text: str, subsequence: str) -> int:
"""
Find the position of the first occurrence of a given subsequence within a text string.
The search is case-insensitive.
Args:
text (str): The... |
evol_instruct_66k | 32,141 | Write a Python function to construct a hashtable (dictionary) where the keys are the unique elements from two given arrays, `arrayA` and `arrayB`, and the values are the aggregate counts of occurrences of each element in both arrays. The function should handle arrays of any length and any integer values.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def construct_hashtable(arrayA: List[int], arrayB: List[int]) -> Dict[int, int]:
"""
Constructs a hashtable (dictionary) where the keys are the unique elements from two given arrays,
and the va... |
evol_instruct_66k | 32,161 | Write a Python function to generate a dictionary that includes the elements from two given lists, `x` and `y`, with corresponding values being their occurrence frequency in both lists combined. The function should start with:
```python
from typing import List, Dict
def generate_frequency_dict(x: List[int], y: List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
from collections import Counter
def generate_frequency_dict(x: List[int], y: List[int]) -> Dict[int, int]:
"""
Generates a dictionary that includes the elements from two lists, x and y,
with co... |
evol_instruct_66k | 32,163 | Write a Python function to double each item in a given 2D array and return a new 2D array with the doubled values in a transposed order. The function should use nested list comprehensions instead of standard loops.
The code should start with:
```python
from typing import List
def double_and_transpose(arr: List[List[i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def double_and_transpose(arr: List[List[int]]) -> List[List[int]]:
"""
Doubles each item in the given 2D array and returns a new 2D array with the doubled values in a transposed order.
Args:
... |
evol_instruct_66k | 32,171 | Write a Python function to find and replace all occurrences of a specified word in a given text with a replacement word. The function should handle cases where the word to be replaced is a substring of another word (e.g., replacing "cat" in "category" should not occur). The function should also handle cases where the w... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def find_and_replace(text: str, word: str, replacement: str) -> str:
"""
Replaces all occurrences of a specified word in a given text with a replacement word.
The word is replaced only if it is a whole word and no... |
evol_instruct_66k | 32,173 | Write a Python function to reverse a given string in-place with optimal time and space complexity. The function should use a two-pointer approach to swap characters from the beginning and end of the string until the middle is reached. The code should start with:
```python
def reverse_string_in_place(s: str) -> str:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string_in_place(s: str) -> str:
"""
Reverses a given string in-place with optimal time and space complexity.
Args:
s (str): The input string to be reversed.
Returns:
str: The reversed string... |
evol_instruct_66k | 32,185 | Write a Python function to find and return a list of all numbers within a given inclusive range that are not evenly divisible by a specified divisor. The function should handle both positive and negative ranges and allow for any integer divisor. The code should start with:
```python
from typing import List
def find_no... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_non_divisible_numbers(start: int, end: int, divisor: int) -> List[int]:
"""
Find and return a list of all numbers within a given inclusive range that are not evenly divisible by a specified divi... |
evol_instruct_66k | 32,193 | Write a Python function that generates a numerical sequence from 1 to a given number `n`, but substitutes any integer that is a multiple of 5 with the string "Five". The function should return a list containing the sequence.
The code should start with:
```python
from typing import List
def generate_sequence(n: int) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_sequence(n: int) -> List[str]:
"""
Generates a sequence from 1 to n, substituting any integer that is a multiple of 5 with the string "Five".
Args:
n (int): The upper limit of t... |
evol_instruct_66k | 32,208 | Write a Python function to reduce a five-dimensional array to a two-dimensional matrix representation. The five-dimensional array is represented by its h blocks, t blocks, p layers, m horizontal lines, and n vertical lines. The function should flatten the five-dimensional array into a two-dimensional matrix where each ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reduce_5D_to_2D(fiveD_mat: List[List[List[List[List[int]]]]]) -> List[List[int]]:
"""
Reduces a five-dimensional array to a two-dimensional matrix representation.
Args:
fiveD_mat (List[L... |
evol_instruct_66k | 32,211 | Write a Python function to remove all whitespace characters from a given alphanumeric string. The function should return the modified string without any spaces.
The code should start with:
```python
def remove_whitespace(alphanumeric_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_whitespace(alphanumeric_string: str) -> str:
"""
Removes all whitespace characters from the given alphanumeric string.
Args:
alphanumeric_string (str): The input string containing alphanumeric characters ... |
evol_instruct_66k | 32,214 | Write a Python function to determine the recurrence frequency and the positions of a particular integer in a string composed of hexadecimal characters. The function should handle both uppercase and lowercase hexadecimal characters and return the count of occurrences and the indices where the integer appears.
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_integer_in_hex_string(hex_string: str, my_int: int) -> tuple[int, list[int]]:
"""
Determine the recurrence frequency and positions of a particular integer in a hexadecimal string.
Args:
hex_string (str): Th... |
evol_instruct_66k | 32,215 | Write a Python function to determine if a given integer lies within the inclusive range of 5 to 10. The function should return a boolean value indicating whether the integer is within the specified range.
The code should start with:
```python
def is_within_range(x: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_within_range(x: int) -> bool:
"""
Determines if the given integer lies within the inclusive range of 5 to 10.
Args:
x (int): The integer to check.
Returns:
bool: True if the integer is within the... |
evol_instruct_66k | 32,228 | Write a Python function to sort a list of complex numbers based on their magnitudes (absolute values) in ascending order. The function should take a list of complex numbers as input and return the sorted list. The code should start with:
```python
from typing import List
def sort_complex_numbers_by_magnitude(complex_n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_complex_numbers_by_magnitude(complex_numbers: List[complex]) -> List[complex]:
"""
Sorts a list of complex numbers based on their magnitudes (absolute values) in ascending order.
Args:
... |
evol_instruct_66k | 32,237 | Write a Python function to merge two sorted lists into a single sorted list without using built-in functions like `sorted()` or `list.sort()`. The function should efficiently combine the elements from both lists while maintaining the sorted order.
The code should start with:
```python
from typing import List
def merg... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two sorted lists into a single sorted list without using built-in functions.
Args:
list1 (List[int]): The f... |
evol_instruct_66k | 32,251 | Write a Python function to manage comprehensive personal contact records. Each contact record should consist of an individual's complete legal name, detailed electronic mailing address, and an operational cellular phone number. The function should allow adding a new contact, retrieving a contact by ID, and updating an ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Optional
def add_contact(contacts: Dict[str, Dict[str, str]], contact_id: str, name: str, email: str, phone: str) -> None:
"""
Add a new contact to the contacts dictionary.
Args:
contacts (... |
evol_instruct_66k | 32,263 | Write a Python function to convert a given temperature from Fahrenheit to Celsius. The function should take a single argument representing the temperature in Fahrenheit and return the equivalent temperature in Celsius. The code should start with:
```python
def fahrenheit_to_celsius(fahrenheit: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def fahrenheit_to_celsius(fahrenheit: float) -> float:
"""
Convert a given temperature from Fahrenheit to Celsius.
Args:
fahrenheit (float): The temperature in Fahrenheit to be converted.
Returns:
float... |
evol_instruct_66k | 32,274 | Write a Python function to calculate the Least Common Multiple (LCM) of three numbers (x, y, and z) using an optimized algorithm. The function should handle the constraints where the input values are integers within the range 1 to 10^9. The function should start with:
```python
def lcm_of_three(x: int, y: int, z: int) ... | Here is the Python code to solve the given problem in the markdown block:
```python
def gcd(a: int, b: int) -> int:
"""
Compute the greatest common divisor of two numbers using the Euclidean algorithm.
Args:
a (int): The first number.
b (int): The second number.
Returns:
int: T... |
evol_instruct_66k | 32,292 | Modify the given Python code to correctly scan through a two-dimensional array and output every alternate element of each inner list starting from the second element of the array. The original code returns an error due to incorrect indexing. The corrected 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 print_alternate_elements(lst: List[List[int]]) -> None:
"""
Prints every alternate element of each inner list starting from the second element.
Args:
lst (List[List[int]]): A two-dimensi... |
evol_instruct_66k | 32,310 | Write a Python function to iterate over a given dictionary and return a list of formatted strings, where each string contains a key-value pair from the dictionary. The function should handle dictionaries with various data types as values. The code should start with:
```python
from typing import Dict, List, Any
def for... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import Dict, List, Any
def format_dictionary(dictionary: Dict[str, Any]) -> List[str]:
"""
Formats each key-value pair in the given dictionary into a list of strings.
Args:
dictionary (Dict[str, Any])... |
evol_instruct_66k | 32,326 | Write a Python function to perform division of two large integers without using any inbuilt mathematical operators (`/`, `*`, `-`, `+`) or libraries. The function should handle both positive and negative integers and return the quotient as an integer.
The code should start with:
```python
def divide_large_integers(div... | Here is the Python code to solve the given problem in the markdown block:
```python
def divide_large_integers(dividend: int, divisor: int) -> int:
"""
Perform division of two large integers without using any inbuilt mathematical operators.
Args:
dividend (int): The number to be divided.
div... |
evol_instruct_66k | 32,347 | Write a Python function to compute the nth Fibonacci number efficiently using memoization. The function should start with:
```python
def fibonacci(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def fibonacci(n: int, memo: dict = {}) -> int:
"""
Compute the nth Fibonacci number using memoization to optimize performance.
Args:
n (int): The position in the Fibonacci sequence to compute.
memo (dict):... |
evol_instruct_66k | 32,352 | Write a Python function to compute the interval between the maximum and minimum elements in a given list of numerical values. The function should return the interval as an integer.
The code should start with:
```python
from typing import List
def compute_interval(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def compute_interval(numbers: List[int]) -> int:
"""
Computes the interval between the maximum and minimum elements in a given list of numerical values.
Args:
numbers (List[int]): A list of ... |
evol_instruct_66k | 32,356 | Write a Python function to create and manage a multi-dimensional array (tensor) of dimensions 8x64x64x64 with all elements initialized to a specified value. The function should allow for quick access and updating of individual elements in the 4D space. The code should start with:
```python
import numpy as np
def creat... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def create_and_update_tensor(initial_value: int) -> np.ndarray:
"""
Create a multi-dimensional array (tensor) of dimensions 8x64x64x64 with all elements initialized to a specified value.
Demonstrate quick... |
evol_instruct_66k | 32,358 | Write a Python function to convert a given angle from gradians to degrees. The function should take a single argument representing the angle in gradians and return the equivalent angle in degrees. The conversion factor from gradians to degrees is 0.9. The code should start with:
```python
def gradians_to_degrees(gradia... | Here is the Python code to solve the given problem in the markdown block:
:
```python
def gradians_to_degrees(gradians: float) -> float:
"""
Convert a given angle from gradians to degrees.
Args:
gradians (float): The angle in gradians to be converted.
Returns:
float: The equivalent ang... |
evol_instruct_66k | 32,369 | Write a Python function to calculate the average of two numbers. The function should take two parameters, `a` and `b`, and return the average of these two numbers. The code should start with:
```python
def calculate_average(a: float, b: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_average(a: float, b: float) -> float:
"""
Calculate the average of two numbers.
Args:
a (float): The first number.
b (float): The second number.
Returns:
float: The average of the ... |
evol_instruct_66k | 32,382 | Write a Python function to construct the largest possible positive whole number from an array of integer values. The function should ignore any negative numbers in the array. If the array contains only negative numbers, the function should return `None`. The code should start with:
```python
from typing import List, Op... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def construct_largest_number(nums: List[int]) -> Optional[int]:
"""
Constructs the largest possible positive whole number from an array of integer values.
Args:
nums (List[int]): T... |
evol_instruct_66k | 32,384 | Write a Python function to identify and return the binary values (0 and 1) from a given list of integers and boolean values. The function should handle both integers and boolean values correctly, treating `True` as `1` and `False` as `0`. The code should start with:
```python
from typing import List, Union
def identif... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def identify_binary_values(lst: List[Union[int, bool]]) -> List[int]:
"""
Identify and return the binary values (0 and 1) from a given list of integers and boolean values.
Args:
lst (... |
evol_instruct_66k | 32,386 | Write a Python function to validate an email address based on the following criteria:
1. The email address must contain only lowercase letters.
2. The email address must match a specific regex pattern.
3. The domain of the email address must be in a specified list of valid domains.
The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def validate_email(email: str, valid_domains: List[str]) -> bool:
"""
Validates an email address based on the following criteria:
1. The email address must contain only lowercase letters.
... |
evol_instruct_66k | 32,394 | Write a Python function to sort a list of integers in ascending order based on the digit length of the numbers. If two numbers have the same digit length, they should be sorted by their base ten (decimal) value. The function should handle both positive and negative integers.
The code should start with:
```python
from ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_by_digit_length(arr: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order based on the digit length of the numbers.
If two numbers have the same digit length, they are so... |
evol_instruct_66k | 32,395 | Write a Python function to calculate the sum of elements within a specific range in an array using a recursive method. Handle edge cases such as an empty array or a range that is outside the bounds of the array. The function should start with:
```python
from typing import List
def recursive_range_sum(arr: List[int], s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def recursive_range_sum(arr: List[int], start: int, end: int) -> int:
"""
Calculate the sum of elements within a specific range in an array using a recursive method.
Args:
arr (List[int]): T... |
evol_instruct_66k | 32,397 | Write a Python function to validate and extract phone numbers from a given string. The function should support both international and extension formats. The international format should be like `+1-800-888-8888`, and the extension format should be like `021-555-3119 ext 1234`. The function should return a list of valid ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def extract_phone_numbers(text: str) -> List[str]:
"""
Extracts and validates phone numbers from a given string.
Supports both international and extension formats.
Args:
text (... |
evol_instruct_66k | 32,404 | Write a Python function to convert a given decimal integer to its binary representation without using the built-in `bin()` function. The function should handle the conversion manually by repeatedly dividing the number by 2 and collecting the remainders. The code should start with:
```python
def decimal_to_binary(n: int... | Here is the Python code to solve the given problem in the markdown block:
:
```python
def decimal_to_binary(n: int) -> str:
"""
Converts a given decimal integer to its binary representation without using the built-in bin() function.
Args:
n (int): The decimal integer to be converted.
Returns:
... |
evol_instruct_66k | 32,415 | Write a Python function to add two numbers and return the result. The function should be reusable and should handle any two integers provided as input. The code should start with:
```python
def add_two_numbers(num1: int, num2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def add_two_numbers(num1: int, num2: int) -> int:
"""
Adds two integers and returns the result.
Args:
num1 (int): The first integer to be added.
num2 (int): The second integer to be added.
Returns:
... |
evol_instruct_66k | 32,418 | Write a Python function to find the shared elements between two given lists of integers. The function should return a list of unique shared elements in ascending order. The code should start with:
```python
from typing import List
def find_shared_elements(arr1: List[int], arr2: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_shared_elements(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Find the shared elements between two lists of integers and return them in ascending order.
Args:
arr1 (List[int])... |
evol_instruct_66k | 32,427 | Write a Python function to transform a given numerical value into a format that brings its decimal component to a predetermined decimal point magnitude. The function should accept a float number and an integer representing the desired number of decimal places. The function should return the transformed number as a stri... | Here is the Python code to solve the given problem in the markdown block:
```python
def format_decimal(num: float, decimal_places: int) -> str:
"""
Transforms a given numerical value into a format that brings its decimal component to a predetermined decimal point magnitude.
Args:
num (float): The n... |
evol_instruct_66k | 32,440 | Write a Python function to remove all occurrences of the alphabetic characters 'a', 'b', and 'c' from a given string of text. The function should return the modified string.
The code should start with:
```python
def remove_abc(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_abc(text: str) -> str:
"""
Removes all occurrences of the characters 'a', 'b', and 'c' from the given string.
Args:
text (str): The input string from which to remove the characters 'a', 'b', and 'c'.
... |
evol_instruct_66k | 32,441 | Write a Python function to generate a random string of exactly eight characters, consisting of a balanced mix of alphanumeric characters (half letters and half digits). The function should ensure that the resulting string is unique and well-balanced in terms of character types. The code should start with:
```python
imp... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
import string
def generate_balanced_string() -> str:
"""
Generates a random string of exactly eight characters, consisting of a balanced mix of alphanumeric characters.
Half of the characters are letters (both... |
evol_instruct_66k | 32,465 | Write a Python function to find the second largest number in a given list of integers. The function should handle edge cases such as an empty list or a list with only one element. The code should start with:
```python
from typing import List
def find_second_largest(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def find_second_largest(numbers: List[int]) -> int:
"""
Find the second largest number in a given list of integers.
Args:
numbers (List[int]): The list of integers from which to find the s... |
evol_instruct_66k | 32,466 | Write a Python function to find the index of a specified element in a given list. If the element is not found, return -1. The function should handle cases where the list is empty or the element is not present in the list.
The code should start with:
```python
from typing import List
def find_element_index(letters: Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_element_index(letters: List[str], target: str) -> int:
"""
Find the index of a specified element in a given list. If the element is not found, return -1.
Args:
letters (List[str]): ... |
evol_instruct_66k | 32,482 | Write a Python function to calculate the edit distance (also known as Levenshtein distance) between two strings using dynamic programming. The edit distance is the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_edit_distance(string1: str, string2: str) -> int:
"""
Calculate the edit distance (Levenshtein distance) between two strings using dynamic programming.
Args:
string1 (str): The first string.
st... |
evol_instruct_66k | 32,488 | Write a Python function to check if a given string contains both the substrings "hello" and "world" in any order. The function should use regular expressions to perform this check efficiently. The code should start with:
```python
import re
def contains_hello_and_world(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_hello_and_world(string: str) -> bool:
"""
Check if the given string contains both the substrings "hello" and "world" in any order.
Args:
string (str): The string to be checked.
Returns:
... |
evol_instruct_66k | 32,522 | Write a Python function to calculate the product of all elements in a given list of integers. The function should handle lists of any length, including empty lists. If the list is empty, the function should return 1. The code should start with:
```python
from typing import List
def product_of_elements(array: List[int]... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def product_of_elements(array: List[int]) -> int:
"""
Calculate the product of all elements in a given list of integers.
Args:
array (List[int]): The list of integers to calculate the prod... |
evol_instruct_66k | 32,533 | Write a Python function to sort a given list of integers using the Cocktail Shaker Sort algorithm. The Cocktail Shaker Sort is a variation of the Bubble Sort that sorts the list in both directions alternately, first from left to right and then from right to left. The function should return the sorted list.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cocktail_shaker_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the Cocktail Shaker Sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
R... |
evol_instruct_66k | 32,534 | Write a Python function to construct a multidimensional array with two dimensions, each dimension containing the numbers 1 through 10. In the second dimension, replace all even numbers with their square root. The function should return a NumPy array.
The code should start with:
```python
import numpy as np
from typing... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List
def construct_multidimensional_array() -> np.ndarray:
"""
Constructs a multidimensional array with two dimensions, each containing numbers 1 through 10.
In the second dimension, al... |
evol_instruct_66k | 32,538 | Write a Python function to flatten a nested list, remove duplicates, and sort the final list in descending order. The function should handle lists with arbitrary levels of nesting and ensure that the final list is sorted in descending order without any duplicates.
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
def flatten_and_sort(nested_list: List) -> List[int]:
"""
Flattens a nested list, removes duplicates, and sorts the final list in descending order.
Args:
nested_list (List): A nested list co... |
evol_instruct_66k | 32,560 | Write a Python function to transform a URL slug back to its original string format. A URL slug is a string where spaces are replaced with hyphens (`-`), and the string is typically in lowercase. The function should convert the hyphens back to spaces and capitalize the first letter of each word.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
def slug_to_string(slug: str) -> str:
"""
Transforms a URL slug back to its original string format.
Args:
slug (str): The URL slug to be transformed.
Returns:
str: The transformed string with spaces ins... |
evol_instruct_66k | 32,564 | Write a Python function to invert a given dictionary, where the original keys become the values and the original values become the keys. If duplicate values are found, the keys should be appended into a list instead of overwriting them, and the list should be sorted alphabetically.
The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Union
def invert_dictionary(original_dict: Dict[str, int]) -> Dict[int, List[str]]:
"""
Inverts a given dictionary where the original keys become the values and the original values become the keys... |
evol_instruct_66k | 32,577 | Write a Python function to implement the bubble sort algorithm to sort an array of floating point numbers in ascending order. The function should take a list of floating point numbers as input and return the sorted list. The code should start with:
```python
from typing import List
def bubble_sort(num_array: List[floa... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def bubble_sort(num_array: List[float]) -> List[float]:
"""
Sorts a list of floating point numbers in ascending order using the bubble sort algorithm.
Args:
num_array (List[float]): The li... |
evol_instruct_66k | 32,588 | Write a Python function to generate a sequence of unique random numbers within a specified range. The function should ensure that no number is repeated and should handle cases where the requested sequence length exceeds the range of available numbers.
The code should start with:
```python
from typing import List
impor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_unique_random_sequence(range_start: int, range_end: int, sequence_length: int) -> List[int]:
"""
Generates a sequence of unique random numbers within a specified range.
Ar... |
evol_instruct_66k | 32,595 | Write a Python function to convert a timestamp in the 24-hour military time format into its equivalent in the standardized 12-hour civilian time format. The input is a string representing the time in the format "HHMM" (e.g., "1730" for 5:30 PM). The output should be a string in the format "HH:MM AM/PM" (e.g., "05:30 PM... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_time_to_12_hour(time: str) -> str:
"""
Convert a timestamp in the 24-hour military time format into its equivalent in the 12-hour civilian time format.
Args:
time (str): A string representing the time in... |
evol_instruct_66k | 32,601 | Refactor the given Python code to adhere to PEP8 best practices and use the `enumerate` function. The original code uses a `while` loop to iterate over a list and print each element along with its index. The task is to rewrite this code using a `for` loop with `enumerate` to make it more Pythonic and readable.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_elements_with_index(arr):
"""
Prints each element of the list along with its index.
Args:
arr (list): The list of elements to be printed with their indices.
Returns:
None: This function does n... |
evol_instruct_66k | 32,616 | Write a Python function to find the second largest number from a given set of integers. The function should handle sets of any size, including sets with fewer than two elements. If the set has fewer than two elements, the function should return `None`.
The code should start with:
```python
from typing import Set, Opti... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set, Optional
def find_second_largest(numbers: Set[int]) -> Optional[int]:
"""
Find the second largest number from a given set of integers.
Args:
numbers (Set[int]): A set of integers from which ... |
evol_instruct_66k | 32,630 | Write a Python function to replace all punctuation marks in a given multi-sentence textual string with a predetermined symbol. The function should use regular expressions to identify and replace punctuation marks efficiently.
The code should start with:
```python
import re
from typing import List
def replace_punctuat... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def replace_punctuation(text: str, symbol: str) -> str:
"""
Replace all punctuation marks in the given text with the specified symbol.
Args:
text (str): The input text string conta... |
evol_instruct_66k | 32,642 | Write a Python function to verify the existence of a specific element within a given numerical array. The function should return `True` if the target element exists in the array, and `False` otherwise. The code should start with:
```python
from typing import List
def verify_element_existence(array: List[int], target: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def verify_element_existence(array: List[int], target: int) -> bool:
"""
Verifies the existence of a specific element within a given numerical array.
Args:
array (List[int]): The numerical a... |
evol_instruct_66k | 32,648 | Write a Python function to compute the sum of the first `n` even numbers. The function should take an integer `n` as input and return the sum of the first `n` even numbers. The code should start with:
```python
def sum_of_first_n_even_numbers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_first_n_even_numbers(n: int) -> int:
"""
Compute the sum of the first n even numbers.
Args:
n (int): The number of even numbers to sum.
Returns:
int: The sum of the first n even numbers.
... |
evol_instruct_66k | 32,655 | Write a Python function to reverse a given list and return the reversed list. The function should not modify the original list. 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 given list and returns the reversed list without modifying the original list.
Args:
arr (List[int]): The list to be reversed... |
evol_instruct_66k | 32,657 | Write a Python function to sum two floating-point numbers provided as input. The function should handle the input validation to ensure both inputs are floating-point numbers. If any input is not a floating-point number, the function should return `None`.
The code should start with:
```python
def sum_two_floats(a: floa... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_two_floats(a: float, b: float) -> float:
"""
Sums two floating-point numbers provided as input.
Args:
a (float): The first floating-point number.
b (float): The second floating-point number.
Ret... |
evol_instruct_66k | 32,660 | Write a Python function to implement the selection sort algorithm to sort a given list of integers in ascending order. The function should modify the input list in place and return the sorted list. The code should start with:
```python
from typing import List
def selection_sort(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 selection_sort(input_list: List[int]) -> List[int]:
"""
Sorts the input list of integers in ascending order using the selection sort algorithm.
Args:
input_list (List[int]): The list of ... |
evol_instruct_66k | 32,663 | Write a Python function to generate the first 'n' numbers in the Fibonacci sequence, where 'n' is an integer input by the user. Validate the input to ensure it's an integer greater than zero. The function should return a list containing the first 'n' Fibonacci numbers.
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 generate_fibonacci(n: int) -> List[int]:
"""
Generate the first 'n' numbers in the Fibonacci sequence.
Args:
n (int): The number of Fibonacci numbers to generate.
Returns:
L... |
evol_instruct_66k | 32,667 | Write a Python function to validate if a given string represents a numerical value with exactly three decimal places. The function should use a regular expression to ensure the precision of the decimal places is exactly three.
The code should start with:
```python
import re
def validate_three_decimal_places(value: st... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_three_decimal_places(value: str) -> bool:
"""
Validates if the given string represents a numerical value with exactly three decimal places.
Args:
value (str): The string to be validated.
... |
evol_instruct_66k | 32,672 | Write a Python function to convert a temperature from Fahrenheit to Celsius. The function should take a single argument representing the temperature in Fahrenheit and return the temperature in Celsius. The function should be able to handle floating-point numbers and should return the result rounded to two decimal place... | Here is the Python code to solve the given problem in the markdown block:
```python
def fahrenheit_to_celsius(temp_fahrenheit: float) -> float:
"""
Convert a temperature from Fahrenheit to Celsius.
Args:
temp_fahrenheit (float): The temperature in Fahrenheit.
Returns:
float: The temper... |
evol_instruct_66k | 32,694 | Write a Python function to convert a list of integers into a new string, where each integer is separated by a custom delimiter and surrounded by curly braces. The function should handle any list of integers and any custom delimiter provided as input.
The code should start with:
```python
from typing import List
def f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def format_list_to_string(numbers: List[int], delimiter: str) -> str:
"""
Converts a list of integers into a string where each integer is separated by a custom delimiter and surrounded by curly braces.
... |
evol_instruct_66k | 32,698 | Write a Python function to validate and encapsulate user information using closures and dictionaries. The function should create a user object that stores the user's email and date of birth. The data should not be directly accessible from outside the function. The function should include methods to validate the user's ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Callable
import re
from datetime import datetime
def create_user() -> Dict[str, Callable[[str], None]]:
"""
Creates a user object that encapsulates and validates user information.
Returns:
... |
evol_instruct_66k | 32,708 | Write a Python function to find the minimum number of intervals that need to be removed from a given collection of intervals to make the rest of the intervals non-overlapping. The intervals cannot be rearranged and must remain in their original order.
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 min_intervals_to_remove(intervals: List[List[int]]) -> int:
"""
Calculate the minimum number of intervals to remove to make the rest of the intervals non-overlapping.
Args:
intervals (Li... |
evol_instruct_66k | 32,713 | Write a Python function to identify all distinct alphabetical elements present in a couple of alphanumeric sequences. The function should return a sorted list of these distinct alphabetical elements. The function should handle both uppercase and lowercase letters, treating them as distinct.
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 find_distinct_alphabets(string1: str, string2: str) -> List[str]:
"""
Identify all distinct alphabetical elements present in two alphanumeric sequences.
Args:
string1 (str): The first al... |
evol_instruct_66k | 32,718 | Write a Python function to print the elements of a two-dimensional array in a zigzag (or snaking) manner. The function should take a 2D list as input and print the elements row by row, reversing the order of elements in every alternate row.
The code should start with:
```python
from typing import List
def print_zigza... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_zigzag_array(array: List[List[int]]) -> None:
"""
Prints the elements of a 2D array in a zigzag (or snaking) manner.
Args:
array (List[List[int]]): A 2D list of integers.
Retu... |
evol_instruct_66k | 32,720 | Write a Python function to determine if two given phrases contain the same set of unique words. The function should ignore the order of words and any duplicate words within each phrase. The function should return `True` if the phrases contain the same unique words, and `False` otherwise.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def compare_word_sets(phrase1: str, phrase2: str) -> bool:
"""
Determines if two phrases contain the same set of unique words.
Args:
phrase1 (str): The first phrase to compare.
phrase2 (str): The second phra... |
evol_instruct_66k | 32,745 | Write a Python function to determine if at least one element from the second array is present in the first array. The function should return `False` only if none of the elements in the second array are found in the first array. The code should start with:
```python
from typing import List
def contains_any_element(arra... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def contains_any_element(array1: List[int], array2: List[int]) -> bool:
"""
Determines if at least one element from the second array is present in the first array.
Args:
array1 (List[int]): ... |
evol_instruct_66k | 32,752 | Write a Python function to encode biographical and professional details into a JSON-LD schema associated with the `Person` class of the Schema.org vocabulary. The function should take in personal and professional details as parameters and return a JSON-LD schema as a dictionary. The schema should conform to standard co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_json_ld_schema(name: str, age: int, gender: str, job_title: str, years_of_experience: int, skills: List[str]) -> Dict:
"""
Encodes biographical and professional details into a JSON-LD sc... |
evol_instruct_66k | 32,754 | Write a Python function to calculate the average age of students in a given list of student records. Each student record is represented as a dictionary with keys 'name', 'age', and 'statistics'. The 'statistics' key maps to a list of numerical values. The function should ignore any student records where the 'age' is no... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Union
def calculate_average_age(students: List[Dict[str, Union[str, int, List[float]]]]) -> float:
"""
Calculate the average age of students in a given list of student records.
Args:
... |
evol_instruct_66k | 32,763 | Write a Python function to convert a given array of integers into their corresponding binary representation. Each integer in the array should be converted to its binary form without the '0b' prefix. The function should return a list of these binary strings.
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 convert_to_binary(arr: List[int]) -> List[str]:
"""
Converts a given array of integers into their corresponding binary representation.
Args:
arr (List[int]): The array of integers to be ... |
evol_instruct_66k | 32,768 | Write a Python function to calculate the combined total of three specific numerical values, and then increase the result by an additional five units. The function should take three integers as input and return the final result.
The code should start with:
```python
def calculate_total(a: int, b: int, c: int) -> int:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_total(a: int, b: int, c: int) -> int:
"""
Calculate the combined total of three specific numerical values, and then increase the result by an additional five units.
Args:
a (int): The first numerical v... |
evol_instruct_66k | 32,781 | Write a Python function to transform all the entities within a given list of animal names into uppercase letters. The function should handle any list of strings, not just animal names. The code should start with:
```python
from typing import List
def transform_to_uppercase(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 transform_to_uppercase(strings: List[str]) -> List[str]:
"""
Transforms all the strings in the given list to their uppercase equivalents.
Args:
strings (List[str]): A list of strings t... |
evol_instruct_66k | 32,782 | Write a Python function to return a random element from a given list of strings. The function should handle an empty list by returning `None`. The code should start with:
```python
from typing import List, Optional
import random
def get_random_element(elements: List[str]) -> Optional[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
import random
def get_random_element(elements: List[str]) -> Optional[str]:
"""
Returns a random element from the given list of strings.
Args:
elements (List[str]): The list of str... |
evol_instruct_66k | 32,786 | Write a Python function to determine if a given integer is even or odd. If the input is not an integer, raise a `ValueError` with an appropriate message. The function should return a string indicating whether the number is "even" or "odd".
The code should start with:
```python
def even_or_odd(number: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def even_or_odd(number: int) -> str:
"""
Determine if the given integer is even or odd.
Args:
number (int): The integer to be checked.
Returns:
str: A string indicating whether the number is "even" or "... |
evol_instruct_66k | 32,788 | Write a Python function to count the number of unique words in a given sentence, considering case insensitivity. The function should handle punctuation and multiple spaces gracefully.
The code should start with:
```python
from typing import List
def count_unique_words(sentence: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import string
def count_unique_words(sentence: str) -> int:
"""
Counts the number of unique words in a given sentence, considering case insensitivity and ignoring punctuation.
Args:
sentence... |
evol_instruct_66k | 32,794 | Write a Python function to remove all whitespace characters (spaces, tabs, and newline characters) from a given string. The function should be efficient and handle various types of whitespace characters. The code should start with:
```python
def remove_whitespace(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_whitespace(s: str) -> str:
"""
Removes all whitespace characters (spaces, tabs, and newline characters) from the given string.
Args:
s (str): The input string from which whitespace characters are to be re... |
evol_instruct_66k | 32,803 | Write a Python function to construct a nested dictionary structure from a list of key pairs. Each key pair consists of a primary key and a subordinate key. The function should create a nested dictionary where each primary key maps to a dictionary containing its corresponding subordinate key, which in turn maps to an em... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def construct_nested_dict(key_pairs: List[Tuple[str, str]]) -> Dict[str, Dict[str, Dict]]:
"""
Constructs a nested dictionary structure from a list of key pairs.
Args:
key_pairs... |
evol_instruct_66k | 32,804 | Write a Python function to calculate the sum of all elements in a given list of integers. The function should iterate through each element in the list and accumulate the sum. The code should start with:
```python
from typing import List
def calculate_sum(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def calculate_sum(arr: List[int]) -> int:
"""
Calculate the sum of all elements in a given list of integers.
Args:
arr (List[int]): The list of integers whose sum is to be calculated.
... |
evol_instruct_66k | 32,817 | Write a Python function to check if two given strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should return `True` if the strings are anagrams, and `False` otherwise. T... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(s: str, t: str) -> bool:
"""
Check if two strings are anagrams of each other.
Args:
s (str): The first string.
t (str): The second string.
Returns:
bool: True if the strings are... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.