source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 46,674 | Write a Python function to generate a Fibonacci sequence of a given length `n`. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the two preceding ones. The function should return a list containing the first `n` terms of the Fibonacci sequence.
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 generate_fibonacci(n: int) -> List[int]:
"""
Generate a Fibonacci sequence of length n.
The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the two preceding one... |
evol_instruct_66k | 46,675 | Write a Python function to determine if a given integer is even or odd. The function should return a string "Yes, this is an even number" if the number is even, and "No, this is not an even number" if the number is odd. The code should start with:
```python
def check_even_or_odd(number: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def check_even_or_odd(number: int) -> str:
"""
Determines if the given integer is even or odd and returns an appropriate message.
Args:
number (int): The integer to be checked.
Returns:
str: A string ... |
evol_instruct_66k | 46,691 | Write a Python function to process a numerical array by first identifying and removing any recurring elements, and then sorting the resultant array in ascending order without using any direct array sorting functions or helpers. The function should start with:
```python
from typing import List
def process_array(arr: Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def process_array(arr: List[int]) -> List[int]:
"""
Processes a numerical array by removing recurring elements and sorting the resultant array in ascending order.
Args:
arr (List[int]): The ... |
evol_instruct_66k | 46,696 | Write a Python function to convert a Pantone color code into its corresponding CMYK color format. The function should handle both single Pantone codes and a list of Pantone codes. If a Pantone code is invalid, the function should return an error message for that code. The function should start with:
```python
from typi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Union
def pantone_to_cmyk(codes: Union[str, List[str]]) -> Dict[str, Union[List[Dict[str, str]], List[str]]]:
"""
Converts Pantone color codes to their corresponding CMYK color format.
Args:
... |
evol_instruct_66k | 46,703 | Write a Python function to convert a binary string to its octal equivalent. The function should take a binary string as input and return a string representing the octal equivalent. The conversion should be efficient and handle various lengths of binary strings.
The code should start with:
```python
def binary_to_octal... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_octal(bin_str: str) -> str:
"""
Converts a binary string to its octal equivalent.
Args:
bin_str (str): The binary string to be converted.
Returns:
str: The octal string representation of t... |
evol_instruct_66k | 46,706 | Write a Python function to find the most frequently occurring item in a given array. If there are multiple items with the same highest frequency, return the first one encountered in the array. The function should handle arrays with any type of elements, including integers, strings, and other data types.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def most_frequent_item(array: List[Any]) -> Any:
"""
Find the most frequently occurring item in a given array.
Args:
array (List[Any]): The array from which to find the most frequent it... |
evol_instruct_66k | 46,715 | Write a Python function to generate a hashmap from a given sequence of contiguous characters, where each distinct word corresponds to a key and its frequency of appearance as the value. The hashmap should be sorted by the keys in lexicographical order. For words with equal frequency, their order should be preserved as ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import re
from collections import Counter
def generate_hashmap(s: str) -> Dict[str, int]:
"""
Generates a hashmap from a given string where each distinct word corresponds to a key and its frequency of ap... |
evol_instruct_66k | 46,717 | Write a Python function to determine the positions of each character in a given string and return a dictionary where the keys are the characters and the values are lists of their positions in the string.
The code should start with:
```python
from typing import Dict, List
def character_positions(text: str) -> Dict[str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def character_positions(text: str) -> Dict[str, List[int]]:
"""
Determine the positions of each character in the given string and return a dictionary.
Args:
text (str): The input strin... |
evol_instruct_66k | 46,740 | Write a Python function to sort a dictionary of dictionaries in descending order based on a custom comparison function. The function should be flexible enough to allow sorting based on individual keys and derived attributes. For example, you should be able to sort the dictionary not only based on 'age' and 'name', but ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Callable
def sort_dict_of_dicts(d: Dict[str, Dict[str, any]], key_func: Callable[[Dict[str, any]], any]) -> Dict[str, Dict[str, any]]:
"""
Sorts a dictionary of dictionaries in descending order based on... |
evol_instruct_66k | 46,747 | Write a Python function to calculate the difference between the highest and lowest values in a given list of integers. The function should handle lists of any length, including empty lists, and return `None` for empty lists. The code should start with:
```python
from typing import List, Optional
def find_difference(ar... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_difference(arr: List[int]) -> Optional[int]:
"""
Calculate the difference between the highest and lowest values in a list of integers.
Args:
arr (List[int]): A list of int... |
evol_instruct_66k | 46,755 | Write a Python function to validate an IP address according to the Internet Protocol (IP) version 4 (IPv4) standards. The function should check if the input string is a valid IPv4 address by ensuring it meets the following criteria:
1. The IP address must be composed of exactly four decimal numbers separated by dots (`... | Here is the Python code to solve the given problem in the markdown block:
```python
def validate_IP(ip: str) -> str:
"""
Validates an IPv4 address according to the Internet Protocol (IP) version 4 (IPv4) standards.
Args:
ip (str): The IP address string to be validated.
Returns:
str: "V... |
evol_instruct_66k | 46,776 | Write a Python function to count the number of vowels in a given string. The function should be case-insensitive and should consider both uppercase and lowercase vowels. The code should start with:
```python
def count_vowels(string: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def count_vowels(string: str) -> int:
"""
Counts the number of vowels in a given string.
Args:
string (str): The input string to count vowels from.
Returns:
int: The total number of vowels in the stri... |
evol_instruct_66k | 46,780 | Write a Python function to filter a dictionary and return a new dictionary containing only the key-value pairs where the value is above a specified limit. The function should use dictionary comprehension for this purpose.
The code should start with:
```python
from typing import Dict
def filter_dict_above_limit(d: Dic... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def filter_dict_above_limit(d: Dict[str, int], limit: int) -> Dict[str, int]:
"""
Filters a dictionary and returns a new dictionary containing only the key-value pairs
where the value is above a spec... |
evol_instruct_66k | 46,781 | Write a Python function to convert a date string in the format 'day-month-year' (e.g., '01 Jan 2018') into a tuple containing the day, the full month name, and the year. The function should handle the conversion and dissection of the date string efficiently.
The code should start with:
```python
from datetime import d... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def convert_and_dissect_date(date_string: str) -> tuple:
"""
Converts a date string in the format 'day-month-year' (e.g., '01 Jan 2018') into a tuple containing the day, the full month name, and th... |
evol_instruct_66k | 46,791 | Write a Python function to implement the Shell Sort algorithm, which is an optimization of the Insertion Sort algorithm. The function should sort a given list of integers in ascending order. The Shell Sort algorithm works by sorting pairs of elements far apart from each other, then progressively reducing the gap betwee... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def shell_sort(lst: List[int]) -> List[int]:
"""
Sorts a list of integers using the Shell Sort algorithm.
Args:
lst (List[int]): The list of integers to be sorted.
Returns:
List... |
evol_instruct_66k | 46,797 | Write a Python function to convert an array of decimal numbers (ranging from 0 to 255) to their corresponding hexadecimal representation without using any built-in hexadecimal conversion functions. The function should return a list of hexadecimal 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 dec_array_to_hex_array(arr: List[int]) -> List[str]:
"""
Converts an array of decimal numbers (0-255) to their corresponding hexadecimal representation.
Args:
arr (List[int]): The array ... |
evol_instruct_66k | 46,802 | Write a Python function to find the index of a specified character in a given string. If the character is not found, the function should return -1. The function should handle case sensitivity and should not use the built-in `find` method.
The code should start with:
```python
def find_character_index(phrase: str, char... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_character_index(phrase: str, char: str) -> int:
"""
Find the index of a specified character in a given string.
Args:
phrase (str): The string in which to search for the character.
char (str): The ch... |
evol_instruct_66k | 46,804 | Write a Python function to count the occurrences of a given number in a list efficiently. The function should use a dictionary to store the counts of each number in the list, and then return the count of the specified number. The code should start with:
```python
from typing import List, Dict
def count_occurrences(lst... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_occurrences(lst: List[int], num: int) -> int:
"""
Counts the occurrences of a given number in a list.
Args:
lst (List[int]): The list of integers in which to count occurrence... |
evol_instruct_66k | 46,836 | Write a Python function to extract all integer elements from a nested list structure. The function should handle lists that may contain other lists, dictionaries, or any combination of these data types. The function should return a list of all integers found in the nested structure.
The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def extract_integers(nested_structure: Any) -> List[int]:
"""
Extracts all integer elements from a nested list structure.
Args:
nested_structure (Any): The nested structure to extract i... |
evol_instruct_66k | 46,840 | Write a Python function that takes a list of integers as input and returns a list of strings where each string consists of the number followed by "Even" if the number is even, and "Odd" if the number is odd. The function should handle lists of any length, including empty lists.
The code should start with:
```python
fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def classify_numbers(numbers: List[int]) -> List[str]:
"""
Classify each number in the input list as "Even" or "Odd" and return a list of strings.
Args:
numbers (List[int]): A list of intege... |
evol_instruct_66k | 46,846 | Write a Python function to sort the first `n` elements of a given array of integers in ascending order, while leaving the remaining elements of the array unchanged. The function should return the modified array.
The code should start with:
```python
from typing import List
def sort_first_n_elements(arr: List[int], n:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_first_n_elements(arr: List[int], n: int) -> List[int]:
"""
Sorts the first n elements of the given array in ascending order, while leaving the remaining elements unchanged.
Args:
ar... |
evol_instruct_66k | 46,849 | Write a Python function to calculate the cumulative sum of elements in a given list of integers. The cumulative sum at each position `i` in the list should be the sum of all elements from the start of the list up to and including the element at position `i`.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_sum(arr: List[int]) -> List[int]:
"""
Calculate the cumulative sum of elements in a given list of integers.
Args:
arr (List[int]): The list of integers for which to calculate ... |
evol_instruct_66k | 46,854 | Write a Python function to find the indices of all occurrences of a specified number in a given two-dimensional matrix. The function should return a list of tuples, where each tuple represents the row and column indices of an occurrence of the specified number.
The code should start with:
```python
from typing import ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_all_occurrences(matrix: List[List[int]], target: int) -> List[Tuple[int, int]]:
"""
Find the indices of all occurrences of a specified number in a two-dimensional matrix.
Args:
... |
evol_instruct_66k | 46,855 | Write a Python function to find the top 'n' keys that appear most frequently in a given dictionary. If there are more than 'n' keys with the same highest frequency, return them in lexicographical order (alphabetical order). The output should be a dictionary where the key is the key from the given dictionary, and the va... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
from collections import Counter
import operator
def top_n_frequent_keys(dictionary: Dict[str, int], n: int) -> Dict[str, int]:
"""
Find the top 'n' keys that appear most frequently in the given dic... |
evol_instruct_66k | 46,873 | Write a Python function to calculate the product of all elements in a given list of integers. The function should handle an empty list by returning 1, as the product of no numbers is defined as 1. The code should start with:
```python
from typing import List
def product_of_elements(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def product_of_elements(arr: List[int]) -> int:
"""
Calculate the product of all elements in a given list of integers.
Args:
arr (List[int]): The list of integers whose product needs to be... |
evol_instruct_66k | 46,881 | Write a Python function to perform a binary search on a sorted list of integers to determine if a specific integer is present in the list. The function should return `True` if the integer is found, and `False` otherwise. The code should start with:
```python
from typing import List
def binary_search(array: List[int], ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(array: List[int], target: int) -> bool:
"""
Perform a binary search on a sorted list of integers to determine if a specific integer is present.
Args:
array (List[int]): A s... |
evol_instruct_66k | 46,886 | Write a Python function that takes a string as input and returns a new string where each character in the input string is doubled. For example, if the input string is "Hello", the output should be "HHeelllloo". The function should handle any string, including those with spaces and special characters.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
def double_each_character(input_string: str) -> str:
"""
Returns a new string where each character in the input string is doubled.
Args:
input_string (str): The input string to be processed.
Returns:
st... |
evol_instruct_66k | 46,897 | Write a Python function to calculate the product of all elements in a given list using a while loop. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def calculate_product(num_list: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def calculate_product(num_list: List[int]) -> int:
"""
Calculate the product of all elements in a given list using a while loop.
Args:
num_list (List[int]): The list of integers whose prod... |
evol_instruct_66k | 46,902 | Write a Python function to iterate through a given dictionary and return a list of values corresponding to the keys in a specified order. The function should accept a dictionary and a list of keys, and it should return a list of values from the dictionary based on the order of the keys in the list. If a key in the list... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Any
def get_values_in_order(dictionary: Dict[Any, Any], keys: List[Any]) -> List[Any]:
"""
Returns a list of values from the dictionary based on the order of the keys in the provided list.
Ar... |
evol_instruct_66k | 46,903 | Write a Python function to find the intersection of two lists, maintaining the order of elements as they appear in the first list. The lists may contain duplicates, and the intersecting list should reflect the count of common elements. The function should not use built-in functions like `set.intersection` or `collectio... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def intersect_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Find the intersection of two lists, maintaining the order of elements as they appear in the first list.
The lists may contain... |
evol_instruct_66k | 46,908 | Write a Python function to generate an associative data structure (dictionary) from two tuples of identical length. Each entry in the first tuple should be linked to the corresponding entry in the second tuple. The function should handle cases where the tuples are not of identical length by returning an empty dictionar... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict
def create_dictionary_from_tuples(tuple1: Tuple[str], tuple2: Tuple[str]) -> Dict[str, str]:
"""
Generates an associative data structure (dictionary) from two tuples of identical length.
Each ... |
evol_instruct_66k | 46,910 | Write a Python function to create a NumPy array that incorporates an equal distribution of specified elements with their respective counts. The function should take two lists as input: one for the values and another for the counts of those values. The function should return a NumPy array with the specified distribution... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List
def create_distribution_array(values: List[int], counts: List[int]) -> np.ndarray:
"""
Creates a NumPy array with a specified distribution of elements.
Args:
values (List[... |
evol_instruct_66k | 46,915 | Write a Python function to implement the Quick Sort algorithm from scratch. The function should avoid using any built-in Python sorting functions and should be optimized for performance. The code should start with:
```python
from typing import List
def quick_sort(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def quick_sort(arr: List[int]) -> List[int]:
"""
Sorts the given list of integers using the Quick Sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
... |
evol_instruct_66k | 46,924 | Write a Python function to compute an array where each element is the product of all the elements in the input array except the one at the corresponding index. The function should handle arrays of any length, including empty arrays. The code should start with:
```python
from typing import List
def product_of_all_excep... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def product_of_all_except_self(arr: List[int]) -> List[int]:
"""
Compute an array where each element is the product of all elements in the input array except the one at the corresponding index.
Args... |
evol_instruct_66k | 46,933 | Write a Python function to normalize the spacing in a given string by converting all instances of multiple consecutive spaces into a single space. The function should handle strings with varying numbers of consecutive spaces and should not use regular expressions.
The code should start with:
```python
def normalize_sp... | Here is the Python code to solve the given problem in the markdown block:
```python
def normalize_spacing(text: str) -> str:
"""
Normalizes the spacing in a given string by converting all instances of multiple consecutive spaces into a single space.
Args:
text (str): The input string with potential... |
evol_instruct_66k | 46,934 | Write a Python function to implement the bubble sort algorithm for a given array of integers. The function should sort the array in ascending order. The code should start with:
```python
from typing import List
def bubble_sort(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def bubble_sort(arr: List[int]) -> List[int]:
"""
Sorts the given array of integers using the bubble sort algorithm.
Args:
arr (List[int]): The array of integers to be sorted.
Returns... |
evol_instruct_66k | 46,961 | Write a Python function to calculate the sum of all integer components in a given list of integers. The function should handle an empty list by returning 0.
The code should start with:
```python
from typing import List
def sum_of_integers(my_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_of_integers(my_list: List[int]) -> int:
"""
Calculate the sum of all integer components in a given list of integers.
Args:
my_list (List[int]): A list of integers.
Returns:
... |
evol_instruct_66k | 46,962 | Write a Python function to trim only the leading and trailing whitespace from a given string, while preserving the whitespace between words. The function should use the `re` module to achieve this.
The code should start with:
```python
import re
def trim_whitespace(my_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def trim_whitespace(my_string: str) -> str:
"""
Trims only the leading and trailing whitespace from a given string, preserving the whitespace between words.
Args:
my_string (str): The input string from wh... |
evol_instruct_66k | 46,964 | Write a Python function to insert a given numerical value at the end of a provided numerical array. The function should modify the original array in place and return the modified array. The code should start with:
```python
from typing import List
def insert_value_at_end(array: List[int], value: int) -> List[int]:
```... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def insert_value_at_end(array: List[int], value: int) -> List[int]:
"""
Inserts a given numerical value at the end of a provided numerical array.
Args:
array (List[int]): The numerical arr... |
evol_instruct_66k | 46,967 | Write a Python function to retrieve the name of a user given their user ID from a dictionary. If the user ID does not exist in the dictionary, return a default message indicating that the user was not found. The function should handle the case where the user ID is not present in the dictionary gracefully.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Union
def get_user_name(user_id: int, user_info: Dict[int, str]) -> Union[str, None]:
"""
Retrieve the name of a user given their user ID from a dictionary.
If the user ID does not exist in the dict... |
evol_instruct_66k | 46,972 | Write a Python function to generate a frequency dictionary from an array of alphanumeric symbols. The dictionary should have unique English alphabets as keys and their respective counts (frequency) in the input array as values. The function should be case-insensitive, meaning 'A' and 'a' should be treated as the same c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def generate_frequency_dict(array: List[str]) -> Dict[str, int]:
"""
Generates a frequency dictionary from an array of alphanumeric symbols.
Args:
array (List[str]): The array of alpha... |
evol_instruct_66k | 46,974 | Write a Python function to evaluate a given mathematical expression string according to the order of operations (PEMDAS) and return the result as an integer. The function should handle basic arithmetic operations: addition (+), subtraction (-), multiplication (*), and division (/). The expression string will contain on... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def evaluate_expression(expression: str) -> int:
"""
Evaluate a given mathematical expression string according to the order of operations (PEMDAS) and return the result as an integer.
Args:
expression (st... |
evol_instruct_66k | 46,984 | Write a Python function to remove all empty strings from a given list in-place and in one pass without using any additional memory for a new list or any pre-defined functions like `filter()`. The function should modify the original list and return it.
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 remove_empty_strings(lst: List[str]) -> List[str]:
"""
Removes all empty strings from the given list in-place and in one pass without using any additional memory.
Args:
lst (List[str]): ... |
evol_instruct_66k | 47,009 | Write a Python function to convert a given string into its hexadecimal representation, where each byte is separated by a colon. The function should handle any string input and return the corresponding hexadecimal string.
The code should start with:
```python
def string_to_hex(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def string_to_hex(input_string: str) -> str:
"""
Converts a given string into its hexadecimal representation, with each byte separated by a colon.
Args:
input_string (str): The input string to be converted.
Ret... |
evol_instruct_66k | 47,012 | Write a Python function that swaps the initial and terminal elements in an array. Additionally, the function should also swap the penultimate element with the second one, the antepenultimate with the third one, and so forth. The function should be capable of managing arrays of arbitrary length and diverse data types. T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def swap_elements(arr: List[Any]) -> List[Any]:
"""
Swaps the initial and terminal elements in an array, and concurrently swaps the penultimate element with the second one, the antepenultimate with ... |
evol_instruct_66k | 47,013 | Write a Python function to remove all sub-directories from a given list of directories and return the remaining directories in any sequence. A directory is considered a sub-directory if it is located within another directory in the list. The structure of a path is one or more concatenated strings of the form: `/` follo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_subdirectories(directories: List[str]) -> List[str]:
"""
Removes all sub-directories from the given list of directories and returns the remaining directories.
Args:
directories (L... |
evol_instruct_66k | 47,021 | Write a Python function to trim extraneous whitespace characters from both the beginning and the end of a given string. The function should handle various types of whitespace characters, including spaces, tabs, and newlines. The function should return the trimmed string.
The code should start with:
```python
def trim_... | Here is the Python code to solve the given problem in the markdown block:
```python
def trim_whitespace(s: str) -> str:
"""
Trims extraneous whitespace characters from both the beginning and the end of a given string.
Args:
s (str): The input string from which to remove leading and trailing whitesp... |
evol_instruct_66k | 47,029 | Write a Python function that performs an insertion sort on a list of integers using a binary search method to find the correct insertion position for each element. This approach should maintain optimal performance and efficiency by reducing the number of comparisons needed during the insertion process.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from bisect import bisect_left
def binary_insertion_sort(arr: List[int]) -> List[int]:
"""
Perform an insertion sort on a list of integers using binary search to find the correct insertion position.
... |
evol_instruct_66k | 47,035 | Write a Python function to convert a given time from Central Daylight Time (CDT) to Eastern Standard Time (EST). The input time is provided in the format "HH:MM" and should be returned in the same format. The function should handle the time zone conversion by adding 1 hour to the given CDT time.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime, timedelta
def convert_cdt_to_est(cdt_time: str) -> str:
"""
Converts a given time from Central Daylight Time (CDT) to Eastern Standard Time (EST).
Args:
cdt_time (str): The time in Ce... |
evol_instruct_66k | 47,044 | Write a Python function to remove all occurrences of a specified integer from a given list. The function should return a new list with all instances of the specified integer removed. The original list should remain unchanged.
The code should start with:
```python
from typing import List
def remove_all_occurrences(lst... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_all_occurrences(lst: List[int], value: int) -> List[int]:
"""
Removes all occurrences of a specified integer from a given list and returns a new list.
Args:
lst (List[int]): The l... |
evol_instruct_66k | 47,049 | Write a Python function to calculate the sum of squares of all numbers in a given list of integers. The function should take a list of integers as input and return the sum of their squares. The code should start with:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
"""
Calculate the sum of squares of all numbers in the given list.
Args:
numbers (List[int]): A list of integers for which the sum of squares... |
evol_instruct_66k | 47,070 | Write a Python function to generate a string transformation where the final character sequence mirrors the original string's, effectively reversing its initial order. The function should handle strings of varying lengths, including empty strings. The code should start with:
```python
def reverse_string(original_string:... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(original_string: str) -> str:
"""
Reverses the input string.
Args:
original_string (str): The string to be reversed.
Returns:
str: The reversed string.
"""
# Use slicing to re... |
evol_instruct_66k | 47,071 | Write a Python function to find all duplicate elements in a given list of integers efficiently. The function should return a set of integers that appear more than once in the list. The code should start with:
```python
from typing import List, Set
def find_duplicates(nums: List[int]) -> Set[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Set
def find_duplicates(nums: List[int]) -> Set[int]:
"""
Find all duplicate elements in a given list of integers.
Args:
nums (List[int]): The list of integers to check for duplicates.
... |
evol_instruct_66k | 47,077 | Write a Python function to convert a list of integers into a comma-separated string. The list should be sorted in descending order, and any negative or zero values should be excluded from the final string.
The code should start with:
```python
from typing import List
def list_to_sorted_string(my_list: List[int]) -> s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def list_to_sorted_string(my_list: List[int]) -> str:
"""
Converts a list of integers into a comma-separated string.
The list is sorted in descending order, and any negative or zero values are exclud... |
evol_instruct_66k | 47,078 | Write a Python function to swap the elements at two specified index positions in a given list. The function should modify the list in place and return the modified list. The code should start with:
```python
from typing import List
def swap_elements(arr: List[int], i: int, j: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def swap_elements(arr: List[int], i: int, j: int) -> List[int]:
"""
Swaps the elements at the specified index positions i and j in the given list.
Args:
arr (List[int]): The list in which ... |
evol_instruct_66k | 47,083 | Write a Python function to perform a linear search on a given list of integers to find the index of a specified element. If the element is not found, the function should return -1. The function should be efficient and handle various edge cases, such as an empty list or the element not being present in the list.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def linear_search(arr: List[int], x: int) -> int:
"""
Perform a linear search on a list of integers to find the index of a specified element.
Args:
arr (List[int]): The list of integers to s... |
evol_instruct_66k | 47,085 | Write a Python function to determine if a given string is a pangram. A pangram is a sentence that contains every letter of the English alphabet at least once. The function should ignore non-alphabetic characters and be case-insensitive.
The code should start with:
```python
def is_pangram(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_pangram(s: str) -> bool:
"""
Determine if a given string is a pangram.
A pangram is a sentence that contains every letter of the English alphabet at least once.
This function is case-insensitive and ignores non-a... |
evol_instruct_66k | 47,111 | Write a Python function to validate the symmetry of parentheses in a given input string. The function should ensure that each opening parenthesis has a corresponding closing parenthesis and vice versa. The function should return `True` if the parentheses are balanced and `False` otherwise. The code should start with:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_parentheses_balanced(s: str) -> bool:
"""
Validates the symmetry of parentheses in a given string.
Args:
s (str): The input string containing parentheses to be validated.
Returns:
bool: True if t... |
evol_instruct_66k | 47,121 | Write a Python function to calculate the area of a circle given its radius. The function should use the `math` module to compute the value of π (pi) and perform the necessary mathematical operations. The code should start with:
```python
import math
def calculate_circle_area(radius: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_circle_area(radius: float) -> float:
"""
Calculate the area of a circle given its radius.
Args:
radius (float): The radius of the circle.
Returns:
float: The area of the circl... |
evol_instruct_66k | 47,126 | Write a Python function to calculate the sum of the first `n` natural numbers using an efficient approach. The function should avoid using a loop and instead use a mathematical formula to achieve the result. The code should start with:
```python
def sum_of_natural_numbers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_natural_numbers(n: int) -> int:
"""
Calculate the sum of the first n natural numbers using a mathematical formula.
Args:
n (int): The number of natural numbers to sum.
Returns:
int: The sum o... |
evol_instruct_66k | 47,141 | Write a Python function to convert an HTML string, where all characters are in uppercase, into its lowercase equivalent while preserving the structure and content of the HTML. The function should handle any HTML tags and their attributes, ensuring that the entire string is converted to lowercase.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_html_to_lowercase(html_string: str) -> str:
"""
Converts an HTML string, where all characters are in uppercase, into its lowercase equivalent.
Args:
html_string (str): The HTML string to be converted.
... |
evol_instruct_66k | 47,147 | Write a Python function to generate a unique 17-character string using a base-32 encoding scheme. The string should be composed of uppercase letters and the digits '2' to '7'. The function should ensure that the generated string is unique by checking against a list of previously generated strings. If a collision is det... | 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_unique_base32_string(previous_strings: List[str] = None, length: int = 17) -> str:
"""
Generates a unique 17-character string using a base-32 encoding scheme.
... |
evol_instruct_66k | 47,178 | Write a Python function to generate a list of `n` random numbers between a given range `[min_value, max_value]`. The function should ensure that the generated numbers are unique and sorted in ascending order. The code should start with:
```python
from typing import List
import random
def generate_unique_random_numbers... | 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_numbers(n: int, min_value: int, max_value: int) -> List[int]:
"""
Generates a list of `n` unique random numbers between `min_value` and `max_value` (inclusive) an... |
evol_instruct_66k | 47,181 | Write a Python function to generate a probabilistic sequence of 'n' individual elements using exclusively the lowercase letters from the English alphabet. The function should ensure that each letter has an equal probability of being chosen. The code should start with:
```python
from typing import List
import random
imp... | 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_probabilistic_sequence(n: int) -> List[str]:
"""
Generates a probabilistic sequence of 'n' individual elements using exclusively the lowercase letters from the En... |
evol_instruct_66k | 47,193 | Write a Python function to encapsulate the numerical value representing the age of a Homo sapien in the context of elapsed years, and subsequently construct a correlating articulate linguistic assertion. The function should take an integer representing the age as input and return a string that describes the age in a hu... | Here is the Python code to solve the given problem in the markdown block:
```python
def describe_age(age: int) -> str:
"""
Encapsulates the numerical value representing the age of a Homo sapien in the context of elapsed years,
and constructs a correlating articulate linguistic assertion.
Args:
... |
evol_instruct_66k | 47,194 | Write a Python function to create an array with the given elements in a specified order. The elements are 13, 29, 37, and 42. The function should return the array in the order provided.
The code should start with:
```python
from typing import List
def create_array() -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_array() -> List[int]:
"""
Creates an array with the elements 13, 29, 37, and 42 in the specified order.
Returns:
List[int]: A list containing the elements [13, 29, 37, 42].
""... |
evol_instruct_66k | 47,202 | Write a Python function to determine the minimum and maximum elements present within a given array of integers. The function should return a tuple containing the minimum and maximum values. The code should start with:
```python
from typing import List, Tuple
def find_min_max(numbers: List[int]) -> Tuple[int, int]:
```... | 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[int]) -> Tuple[int, int]:
"""
Determine the minimum and maximum elements present within a given array of integers.
Args:
numbers (List[int]): The array ... |
evol_instruct_66k | 47,206 | Write a Python function to reverse the words in a given string while preserving the order of spaces between words and handling leading/trailing spaces. The function should correctly handle multiple spaces between words and ensure that the reversed string maintains the original spacing structure.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_words_in_string(s: str) -> str:
"""
Reverses the words in a given string while preserving the order of spaces between words and handling leading/trailing spaces.
Args:
s (str): The input string containin... |
evol_instruct_66k | 47,218 | Write a Python function to search for a specified term in a provided text sequence and return the index of the term if found. The search should be case-insensitive and should handle potential punctuation marks. If the term is not found, the function should return -1.
The code should start with:
```python
import re
de... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def search_term_in_text(text: str, term: str) -> int:
"""
Searches for a specified term in a provided text sequence and returns the index of the term if found.
The search is case-insensitive and handles potential ... |
evol_instruct_66k | 47,222 | Write a Python function to convert a given time in London Time (GMT) to New Zealand Standard Time (NZST) and handle Daylight Saving Time (DST). The function should be able to handle the case where the time passes midnight (24:00) and adjust for DST if necessary. The function should not use any libraries specifically de... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_time_to_nzst(london_time: str, is_dst: bool = False) -> str:
"""
Converts a given time in London Time (GMT) to New Zealand Standard Time (NZST) and handles Daylight Saving Time (DST).
Args:
london_time (... |
evol_instruct_66k | 47,236 | Write a Python function to return a list of distinct strings from a given list of strings, sorted in alphabetical order. The function should handle an empty list and ensure that the output list contains only unique strings in ascending order.
The code should start with:
```python
from typing import List
def distinct_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def distinct_sorted_strings(arr: List[str]) -> List[str]:
"""
Returns a list of distinct strings from the given list, sorted in alphabetical order.
Args:
arr (List[str]): A list of strings f... |
evol_instruct_66k | 47,265 | Write a Python function to generate a list of pairs from a dictionary based on a given list of keys. Each pair should contain a key from the list and its corresponding value from the dictionary. If a key from the list does not exist in the dictionary, the value part of the pair should be the string "Not found". The fun... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def get_pairs_from_dict(dictionary: Dict[int, str], keys: List[int]) -> List[Tuple[int, str]]:
"""
Generates a list of pairs from a dictionary based on a given list of keys.
Args:
... |
evol_instruct_66k | 47,296 | Write a Python function to validate if a given string contains only the English alphabet (both uppercase and lowercase letters) and no other characters. The function should return `True` if the string is valid and `False` otherwise. The code should start with:
```python
import re
def is_valid_english_alphabet_string(s... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_english_alphabet_string(s: str) -> bool:
"""
Validates if the given string contains only the English alphabet (both uppercase and lowercase letters) and no other characters.
Args:
s (str): Th... |
evol_instruct_66k | 47,298 | Write a Python function to generate the first `n` Fibonacci numbers and return them along with their corresponding indices in a list of tuples. Each tuple should contain the index and the Fibonacci number at that index. The function should handle the case where `n` is less than or equal to 0 by returning an empty list.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def generate_fibonacci_with_indices(n: int) -> List[Tuple[int, int]]:
"""
Generate the first n Fibonacci numbers along with their indices.
Args:
n (int): The number of Fibonacci numbe... |
evol_instruct_66k | 47,303 | Write a Python function to determine the alphabetical grade of a student based on their numerical score using a ternary operator. The function should accept a numerical score as input and return the corresponding alphabetical grade. The grading scale is as follows:
- A: 90 and above
- B: 80 to 89
- C: 70 to 79
- D: 60 ... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_alphabetical_grade(numerical_score: int) -> str:
"""
Determine the alphabetical grade based on the given numerical score using a ternary operator.
Args:
numerical_score (int): The numerical score of the stud... |
evol_instruct_66k | 47,321 | Write a Python function to compute the Euclidean Distance between two points in an n-dimensional space. The coordinates of the points are provided as lists, where the length of each list corresponds to the number of dimensions. The function should adhere to the fundamental principles of the Pythagorean theorem and shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def euclidean_distance(point1: List[float], point2: List[float]) -> float:
"""
Computes the Euclidean Distance between two points in an n-dimensional space.
Args:
point1 (List[float]): The c... |
evol_instruct_66k | 47,349 | Write a Python function to recursively compute the square of each element in a nested list of integers. The function should handle any level of nested lists and return a new nested list with the same structure, but with each element squared.
The code should start with:
```python
from typing import List, Union
def squ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def square_nested_list(lst: Union[List, int]) -> Union[List, int]:
"""
Recursively computes the square of each element in a nested list of integers.
Args:
lst (Union[List, int]): A ne... |
evol_instruct_66k | 47,352 | Write a Python function to sort a list of tuples based on the second component of each tuple in descending order. The function should handle lists of tuples where each tuple contains exactly two integers.
The code should start with:
```python
from typing import List, Tuple
def sort_tuples_by_second_component(tuples: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_tuples_by_second_component(tuples: List[Tuple[int, int]]) -> List[Tuple[int, int]]:
"""
Sorts a list of tuples based on the second component of each tuple in descending order.
Args:
... |
evol_instruct_66k | 47,354 | Write a Python function to validate and format a given employee record according to a predefined schema. The schema includes the following fields: `employee_name`, `employee_id`, `email`, and `work_station_location`. The function should ensure that each field is present, non-empty, and formatted correctly. The `employe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Optional, Dict
import re
def validate_and_format_employee_record(record: Dict[str, str]) -> Optional[Dict[str, str]]:
"""
Validates and formats an employee record according to a predefined schema.
Args:
... |
evol_instruct_66k | 47,355 | Write a Python function to build a nested dictionary using three lists where the third list elements are the keys of the main dictionary, and the values of the first two lists are nested within these keys. The first list elements will be the keys of the nested dictionaries, and the second list elements will be their co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def build_nested_dict(l1: List[str], l2: List[int], l3: List[str]) -> Dict[str, Dict[str, int]]:
"""
Builds a nested dictionary using three lists.
Args:
l1 (List[str]): List of keys fo... |
evol_instruct_66k | 47,366 | Write a Python function to determine if a given string contains the alphabetic character "u" (case insensitive). The function should return `True` if the character "u" is present in the string, and `False` otherwise. The code should start with:
```python
def contains_u(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def contains_u(s: str) -> bool:
"""
Determines if the character "u" (case insensitive) is present in the given string.
Args:
s (str): The input string to check for the presence of the character "u".
Returns:
... |
evol_instruct_66k | 47,382 | Write a Python function to convert a list of atmospheric temperatures from Fahrenheit to Celsius. The function should handle possible exceptions and errors such as non-numeric inputs. The function should return a dictionary where the keys are the original Fahrenheit temperatures and the values are the corresponding Cel... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def convert_temperatures(temp_list: List[str]) -> Dict[float, float]:
"""
Converts a list of atmospheric temperatures from Fahrenheit to Celsius.
Args:
temp_list (List[str]): A list of... |
evol_instruct_66k | 47,405 | Write a Python function to find and return the smallest number in a given list of integers efficiently. The function should handle edge cases such as an empty list and should be optimized for large datasets. The code should start with:
```python
from typing import List, Optional
def find_min(numbers: List[int]) -> Opt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_min(numbers: List[int]) -> Optional[int]:
"""
Find and return the smallest number in a given list of integers.
Args:
numbers (List[int]): The list of integers from which t... |
evol_instruct_66k | 47,408 | Write a Python function to replace all occurrences of the numeric character '1' with the symbol '@' in a given two-dimensional grid of alphanumeric elements. The grid is represented as a list of lists, where each sublist represents a row in the grid.
The code should start with:
```python
from typing import List
def r... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def replace_ones_with_at_symbol(grid: List[List[str]]) -> List[List[str]]:
"""
Replaces all occurrences of the numeric character '1' with the symbol '@' in a given two-dimensional grid.
Args:
... |
evol_instruct_66k | 47,420 | Write a Python function to combine two lists into a single list, ensuring that the elements from both lists are interleaved. If one list is longer than the other, the remaining elements of the longer list should be appended at the end of the combined list.
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 interleave_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Interleaves two lists into a single list. If one list is longer than the other,
the remaining elements of the longer list ar... |
evol_instruct_66k | 47,422 | Write a Python function to perform binary search on a sorted list and return the index of the target element if it exists in the list. If the target element is not found, return the string "Not Found". The function should be efficient and should handle edge cases such as an empty list or a target that is not in the lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def binary_search(arr: List[int], target: int) -> Union[int, str]:
"""
Perform a binary search on a sorted list to find the index of the target element.
Args:
arr (List[int]): A sorte... |
evol_instruct_66k | 47,429 | Write a Python function to generate a specified number of lists, each containing a specified number of random integers within a given range. The function should minimize redundancy and enhance succinctness by using list comprehensions and avoiding repetitive code.
The code should start with:
```python
import random
fr... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
from typing import List
def generate_random_lists(num_lists: int, num_elements: int, lower_bound: int, upper_bound: int) -> List[List[int]]:
"""
Generates a specified number of lists, each containing a specified n... |
evol_instruct_66k | 47,437 | Write a Python function to find all customers from a given list that have the same age and email domain as a specified customer, and calculate their average account balance. The specified customer should be excluded from the results. The function should start with:
```python
from typing import List, Tuple
def find_sim... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_similar_customers_and_average_balance(customers: List[Tuple[str, int, str, float]], given_customer: Tuple[str, int, str]) -> float:
"""
Finds all customers with the same age and email dom... |
evol_instruct_66k | 47,439 | Write a Python function to simulate the functioning of a NAND gate using bitwise operations. The NAND gate takes two boolean inputs and returns the negation of their logical AND operation. The function should accept two boolean values as input and return a boolean value as output.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
def nand_gate(a: bool, b: bool) -> bool:
"""
Simulates the functioning of a NAND gate using bitwise operations.
Args:
a (bool): The first boolean input.
b (bool): The second boolean input.
Returns:
... |
evol_instruct_66k | 47,447 | Write a Python function to generate a list of `n` random integers within a specified range `[min_value, max_value]`. The function should ensure that the generated list contains exactly `n` integers, all within the specified range. The code should start with:
```python
from typing import List
import random
def generate... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_random_numbers(n: int, min_value: int, max_value: int) -> List[int]:
"""
Generate a list of `n` random integers within the specified range `[min_value, max_value]`.
Args:
... |
evol_instruct_66k | 47,453 | Write a Python function to cleanse a list by removing elements that appear two or more times. The function should return a new list containing only the elements that appear less than two times in the original list.
The code should start with:
```python
from typing import List
def cleanse_list(input_list: List[int]) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cleanse_list(input_list: List[int]) -> List[int]:
"""
Cleanses a list by removing elements that appear two or more times.
Args:
input_list (List[int]): The list of integers to be cleanse... |
evol_instruct_66k | 47,454 | Write a Python function that takes an integer `x` as input and returns a value based on the following rules:
- If `x` is greater than 5, return `x` multiplied by 2.
- If `x` is less than or equal to 5, return `x` multiplied by 3.
The function should handle both positive and negative integers, as well as zero. The code... | Here is the Python code to solve the given problem in the markdown block:
```python
def my_fun(x: int) -> int:
"""
Returns a value based on the input integer x.
If x is greater than 5, the function returns x multiplied by 2.
If x is less than or equal to 5, the function returns x multiplied by 3.
... |
evol_instruct_66k | 47,467 | Write a Python function to repeat each element in a given array of strings `digits` a number of times specified by the corresponding element in another array `multipliers`. The function should handle irregularities such as null, undefined, or non-numeric values in the arrays. 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 repeat_elements(digits: List[str], multipliers: List[int]) -> List[str]:
"""
Repeats each element in the 'digits' array a number of times specified by the corresponding element in the 'multipliers' a... |
evol_instruct_66k | 47,472 | Write a Python function to extract and return all even numbers from a given sequential dataset in the form of a text string that enumerates integers delineated by commas. The function should handle the input string, split it into individual numbers, filter out the even numbers, and return them as a list of integers.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def extract_even_numbers(data: str) -> List[int]:
"""
Extracts and returns all even numbers from a given sequential dataset in the form of a text string.
Args:
data (str): A text string that... |
evol_instruct_66k | 47,473 | Write a Python function to calculate the lowest common multiple (LCM) of two positive integers `x` and `y`, handling edge cases where either `x` or `y` is zero. The function should use the greatest common divisor (GCD) to compute the LCM efficiently.
The code should start with:
```python
def lowest_common_multiple(x: ... | Here is the Python code to solve the given problem in the markdown block:
```python
def gcd(x: int, y: int) -> int:
"""
Calculate the greatest common divisor (GCD) of two positive integers x and y.
Args:
x (int): The first positive integer.
y (int): The second positive integer.
Returns... |
evol_instruct_66k | 47,483 | Write a Python function to find the largest number in a given list without using built-in Python functions like `max()`. Additionally, implement this function using a single pass through the list. The function should handle an empty list by returning `None`.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_largest_number(my_list: List[int]) -> Optional[int]:
"""
Find the largest number in a given list without using built-in Python functions like max().
The function uses a single pass... |
evol_instruct_66k | 47,484 | Write a Python function to determine if two input strings are isomorphic. Two strings are considered isomorphic if there is a one-to-one mapping between every character in the first string and every character in the second string. This must be done without using any predefined or inbuilt functions such as `isdigit()` o... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_isomorphic(str1: str, str2: str) -> bool:
"""
Determine if two input strings are isomorphic.
Two strings are considered isomorphic if there is a one-to-one mapping between every character in the first string and eve... |
evol_instruct_66k | 47,486 | Write a Python function to reverse the order of elements in a given array of integers. The function should handle arrays of any length, including empty arrays. The code should start with:
```python
from typing import List
def reverse_array(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 reverse_array(array: List[int]) -> List[int]:
"""
Reverses the order of elements in a given array of integers.
Args:
array (List[int]): The array of integers to be reversed.
Retur... |
evol_instruct_66k | 47,487 | Write a Python function to implement an XOR gate using only NAND gates. The XOR gate should take two boolean inputs and return the result of the XOR operation. The function should be implemented using the provided `NAND` function.
The code should start with:
```python
def XOR(a: bool, b: bool) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def NAND(a: bool, b: bool) -> bool:
"""
Returns the result of a NAND operation on two boolean inputs.
Args:
a (bool): The first boolean input.
b (bool): The second boolean input.
Returns:
bool: ... |
evol_instruct_66k | 47,489 | Write a Python function to flatten a given four-dimensional array into a one-dimensional list. The four-dimensional array is characterized by its `t` blocks, `p` layers, `m` horizontal lines, and `n` vertical lines. The function should return a list containing all the elements of the four-dimensional array in a linear ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def flatten_4D_array(array_4D: List[List[List[List[int]]]]) -> List[int]:
"""
Flattens a given four-dimensional array into a one-dimensional list.
Args:
array_4D (List[List[List[List[int]]]]... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.