source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 7,015 | Write a Python function to generate a list of `n` distinct fruit names. The function should ensure that the fruit names are unique and are randomly selected from a predefined list of 20 fruit names. The function should also handle cases where `n` is greater than the number of available fruit names, returning all availa... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_fruit_list(n: int) -> List[str]:
"""
Generates a list of `n` distinct fruit names randomly selected from a predefined list of 20 fruit names.
Args:
n (int): The nu... |
evol_instruct_66k | 7,036 | Write a Python function to calculate the number of unique diagonal elements in a given square matrix. A square matrix is a matrix where the number of rows is equal to the number of columns. The diagonal elements of a matrix are those elements that lie on the main diagonal, i.e., elements where the row index is equal to... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_unique_diagonal_elements(matrix: List[List[int]]) -> int:
"""
Calculate the number of unique diagonal elements in a given square matrix.
Args:
matrix (List[List[int]]): A square ma... |
evol_instruct_66k | 7,042 | Write a Python function to count the number of unique employees for a given company in a list of companies and their employees. The list contains sublists where the first element is the company name and the subsequent elements are employee names. Employees may work in multiple companies, and company and employee names ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_unique_employees(company_list: List[List[str]], company_name: str) -> int:
"""
Count the number of unique employees for a given company in a list of companies and their employees.
Ar... |
evol_instruct_66k | 7,043 | Write a Python function to determine if a given integer is an even number. The function should return `True` if the number is even and `False` otherwise. The code should start with:
```python
def is_even(num: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_even(num: int) -> bool:
"""
Determines if a given integer is an even number.
Args:
num (int): The integer to be checked for evenness.
Returns:
bool: True if the number is even, False otherwise.
... |
evol_instruct_66k | 7,054 | Write a Python function to calculate the cumulative sum of numeric elements in a given list. The function should iterate over the list using a `for` loop and accumulate the sum of the elements. The code should start with:
```python
from typing import List
def cumulative_sum(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_sum(numbers: List[int]) -> int:
"""
Calculate the cumulative sum of numeric elements in a given list.
Args:
numbers (List[int]): A list of integers for which the cumulative su... |
evol_instruct_66k | 7,070 | Write a Python function to filter elements from a given list based on a specified condition. The function should accept a list of integers and a function that defines the filtering condition. The function should return a new list containing only the elements that satisfy the condition.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable
def filter_elements(arr: List[int], condition: Callable[[int], bool]) -> List[int]:
"""
Filters elements from the given list based on the specified condition.
Args:
arr (List[int])... |
evol_instruct_66k | 7,092 | Write a Python function to generate an array of `n` distinct integers, where each integer resides within a specified numerical range `[min_value, max_value]`, utilizing randomness in its selection methodology. The function should ensure that the generated integers are unique and within the specified range.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_distinct_random_numbers(n: int, min_value: int, max_value: int) -> List[int]:
"""
Generates an array of n distinct integers within the specified range [min_value, max_value].
... |
evol_instruct_66k | 7,097 | Write a Python function to determine the least common multiple (LCM) of three given integers. The function should be able to handle any positive integers and should return the LCM of the three numbers. The code should start with:
```python
def lcm_of_three(x: int, y: int, z: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def gcd(a: int, b: int) -> int:
"""
Calculate the greatest common divisor (GCD) of two integers.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
int: The GCD of the two i... |
evol_instruct_66k | 7,098 | Write a Python function to calculate the total sales made by each salesman in a given list of sales transactions. Each transaction is represented as a tuple containing the `sale_id`, `salesman_id`, and `sale_amount`. The function should return a dictionary where the keys are `salesman_id` and the values are the total s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def calculate_total_sales(transactions: List[Tuple[int, int, float]]) -> Dict[int, float]:
"""
Calculate the total sales made by each salesman from a list of sales transactions.
Args:
... |
evol_instruct_66k | 7,100 | Write a Python function to check if a given input is an integer within a specified range efficiently. The function should handle large inputs and non-integer inputs gracefully. The code should start with:
```python
def is_integer_in_range(n, r) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_integer_in_range(n, r) -> bool:
"""
Check if the given input is an integer within the specified range.
Args:
n: The input to check.
r: A tuple representing the range (lower_bound, upper_bound).
R... |
evol_instruct_66k | 7,101 | Write a Python function to check if a given string is a palindrome. The function should be efficient and handle various edge cases, such as non-string inputs, empty strings, and strings with special characters. The function should return `True` if the string is a palindrome and `False` otherwise. The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_palindrome(s: str) -> bool:
"""
Check if the given string is a palindrome.
This function normalizes the string by removing non-alphanumeric characters
and converting it to lowercase before checking if it reads th... |
evol_instruct_66k | 7,111 | Write a Python function to merge two or more strings into a single string without using the `+` operator. The function should accept a variable number of string arguments and return the merged string. The code should start with:
```python
from typing import List
def merge_strings(*args: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_strings(*args: str) -> str:
"""
Merges multiple strings into a single string without using the `+` operator.
Args:
*args (str): Variable number of string arguments to be merged.
... |
evol_instruct_66k | 7,112 | Write a Python function to reverse a given string sequence in an inverse or reversed manner. The function should handle strings of varying lengths, including empty strings. The code should start with:
```python
def reverse_string(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(input_string: str) -> str:
"""
Reverses the given string sequence.
Args:
input_string (str): The string to be reversed.
Returns:
str: The reversed string.
"""
# Use slicing to... |
evol_instruct_66k | 7,117 | Write a Python function to compute the factorial of a given positive integer using recursion with memoization. The function should include error checking to ensure that the input is a positive integer. If the input is not a positive integer, the function should raise an appropriate exception. The function should also b... | Here is the Python code to solve the given problem in the markdown block:
```python
def factorial_memoized(n: int, memo: dict = {}) -> int:
"""
Compute the factorial of a given positive integer using recursion with memoization.
Args:
n (int): The positive integer for which to compute the factorial.... |
evol_instruct_66k | 7,123 | Write a Python function to count the frequency of each unique character in a given mixed string. The string can contain any combination of alphabetic characters (both uppercase and lowercase) and digits. The function should return a dictionary where the keys are the characters and the values are their respective counts... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_character_frequencies(mixed_string: str) -> Dict[str, int]:
"""
Counts the frequency of each unique character in a given mixed string.
Args:
mixed_string (str): The string containi... |
evol_instruct_66k | 7,156 | Write a Python function to insert a given numerical value at the end of a pre-existing numerical array. The function should take two parameters: a list of integers (the array) and an integer (the value to be inserted). The function should return the modified array with the value appended at the end.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def append_value_to_array(array: List[int], value: int) -> List[int]:
"""
Appends a given numerical value to the end of a pre-existing numerical array.
Args:
array (List[int]): The pre-exist... |
evol_instruct_66k | 7,181 | Write a Python function to transform a given chronology annotation into a specialized format of `mm/dd/yyyy`. The input is a string representing a date in the format `Month Day, Year`, such as `April 14, 2021`. The function should convert this date into the format `mm/dd/yyyy`.
The code should start with:
```python
de... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_date_format(date_str: str) -> str:
"""
Converts a date string from the format 'Month Day, Year' to 'mm/dd/yyyy'.
Args:
date_str (str): The input date string in the format 'Month Day, Year'.
Returns:... |
evol_instruct_66k | 7,186 | Write a Python function to compare two lists of strings representing animal classes and determine if they contain the same elements, regardless of their order. The function should return `True` if the two lists contain the same elements, and `False` otherwise. The code should start with:
```python
from typing import Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def compare_collections(list1: List[str], list2: List[str]) -> bool:
"""
Compares two lists of strings to determine if they contain the same elements, regardless of order.
Args:
list1 (List[... |
evol_instruct_66k | 7,202 | Write a Python function that takes in a number and an array of numbers as arguments. The function should use a correctly named identifier to store the number, then find and return the sum of the number and all the numbers in the array. The identifier must start with an underscore followed by the letter 'a'.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_values(num: int, num_array: List[int]) -> int:
"""
Calculate the sum of a given number and all numbers in a given array.
Args:
num (int): The number to be added to the sum of the arr... |
evol_instruct_66k | 7,210 | Write a Python function to perform element-wise multiplication of two 1D arrays. If the arrays are not of the same length, the function should return a list of tuples where each tuple contains the corresponding elements from both arrays, followed by their product. The code should start with:
```python
from typing impor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def element_wise_multiplication(arr1: List[int], arr2: List[int]) -> List[Tuple[int, int, int]]:
"""
Perform element-wise multiplication of two 1D arrays.
If the arrays are of the same length... |
evol_instruct_66k | 7,232 | Write a Python function to create a three-dimensional matrix with specified dimensions and populate every element with a given numerical value. The function should return the created matrix.
The code should start with:
```python
from typing import List
def create_3d_matrix(dimensions: List[int], value: int) -> List[L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_3d_matrix(dimensions: List[int], value: int) -> List[List[List[int]]]:
"""
Creates a three-dimensional matrix with the specified dimensions and populates each element with the given value.
... |
evol_instruct_66k | 7,233 | Write a Python function to find the greatest whole number in a given list of integers. The function should handle lists of any size, 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 find_greatest_number(numbers:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_greatest_number(numbers: List[int]) -> Optional[int]:
"""
Find the greatest whole number in a given list of integers.
Args:
numbers (List[int]): A list of integers.
R... |
evol_instruct_66k | 7,234 | Write a Python function to filter and return a list of unique numbers less than 50 from a given list of integers. The function should be optimized for efficiency by using a set to track unique numbers and a list to maintain the order of insertion.
The code should start with:
```python
from typing import List
def filt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_unique_less_than_50(lst: List[int]) -> List[int]:
"""
Filters and returns a list of unique numbers less than 50 from the given list.
Args:
lst (List[int]): The list of integers to... |
evol_instruct_66k | 7,242 | Write a Python function to validate an email address using a regular expression that supports multiple email formats, including different domain extensions and sub-domains. Additionally, implement a function to check if the email domain is in a list of approved domains. 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
import re
def is_valid_email(email: str) -> bool:
"""
Validate an email address using a regular expression.
Args:
email (str): The email address to validate.
Returns:
bool: True... |
evol_instruct_66k | 7,257 | Write a Python function to find the maximum subarray sum in a given list of integers. The function should return the maximum sum of any contiguous subarray within the list. The code should start with:
```python
from typing import List
def max_subarray_sum(nums: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def max_subarray_sum(nums: List[int]) -> int:
"""
Find the maximum sum of any contiguous subarray within the given list of integers.
Args:
nums (List[int]): The list of integers from which... |
evol_instruct_66k | 7,273 | Write a Python function to count the occurrences of each word in a given sentence, considering case sensitivity and treating punctuation as separate entities. The function should return a dictionary where the keys are the words (including punctuation) and the values are the counts of those words in the sentence.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import re
def count_word_occurrences(sentence: str) -> Dict[str, int]:
"""
Counts the occurrences of each word and punctuation mark in a given sentence,
considering case sensitivity and treating punc... |
evol_instruct_66k | 7,280 | Write a Python function to count the occurrences of each vowel (a, e, i, o, u) and each letter in a given string, considering case sensitivity. The function should return a dictionary with three keys: "total", "vowels", and "consonants". The "total" key should map to a dictionary containing the frequency of each letter... | Here is the Python code to solve the given problem in the markdown block:
```python
def letter_frequency(string: str) -> dict:
"""
Counts the occurrences of each vowel and each letter in a given string, considering case sensitivity.
Args:
string (str): The input string to analyze.
Returns:
... |
evol_instruct_66k | 7,285 | Write a Python function to determine if two strings have the same perimeter, where the perimeter of a string is defined as the sum of the lengths of the string and its reverse. The function should take two strings as input and return a boolean indicating whether their perimeters are identical.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_same_perimeter(string1: str, string2: str) -> bool:
"""
Determines if two strings have the same perimeter.
The perimeter of a string is defined as the sum of its length and the length of its reverse.
Args:
... |
evol_instruct_66k | 7,288 | Write a Python function to initialize an array with ten integer components, each set to the value zero, and then return the array. The function should ensure that the array is correctly initialized and returned without printing any values. The code should start with:
```python
from typing import List
def initialize_ze... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def initialize_zero_array() -> List[int]:
"""
Initializes an array with ten integer components, each set to the value zero.
Returns:
List[int]: A list containing ten integer components, all ... |
evol_instruct_66k | 7,294 | Write a Python function to extract the character from a given string that corresponds to the third place in the English alphabetical order. The function should take a string as input and return the character that is the third letter in the alphabet. If the string does not contain at least three characters, the function... | Here is the Python code to solve the given problem in the markdown block:
```python
def extract_third_alphabet_char(string: str) -> str:
"""
Extracts the character from the given string that corresponds to the third place in the English alphabetical order.
Args:
string (str): The input string from ... |
evol_instruct_66k | 7,315 | Write a Python function to generate the first `n` terms of the sequence of powers of two, starting from 1 onwards. The function should return a list of these terms. The code should start with:
```python
from typing import List
def generate_powers_of_two(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_powers_of_two(n: int) -> List[int]:
"""
Generate the first n terms of the sequence of powers of two, starting from 1 onwards.
Args:
n (int): The number of terms to generate.
... |
evol_instruct_66k | 7,321 | Write a Python function to generate a sequence of numbers within a specified range and print each number in the sequence. The function should be efficient and avoid unnecessary operations. The code should start with:
```python
def generate_and_print_sequence(start: int, end: int) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def generate_and_print_sequence(start: int, end: int) -> None:
"""
Generates and prints a sequence of numbers from start to end (exclusive).
Args:
start (int): The starting number of the sequence.
end (int... |
evol_instruct_66k | 7,325 | Write a Python function to generate an Elasticsearch query that limits the number of search results for a given keyword and field name. The function should accept three parameters: the maximum number of results (`size`), the field name (`field_name`), and the keyword (`keyword`). The function should return a dictionary... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def generate_search_query(size: int, field_name: str, keyword: str) -> Dict:
"""
Generates an Elasticsearch query to limit the number of search results for a given keyword and field name.
Args:
... |
evol_instruct_66k | 7,328 | Write a Python function to identify the unique elements that are present in two given non-sequenced arrays of integers and count the number of these unique elements. The function should return both the count and the set of unique elements.
The code should start with:
```python
from typing import List, Set, Tuple
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Set, Tuple
def count_unique_elements(list1: List[int], list2: List[int]) -> Tuple[int, Set[int]]:
"""
Identify and count the unique elements present in two given non-sequenced arrays of integers.
A... |
evol_instruct_66k | 7,330 | Write a Python function to find all occurrences of a given string `y` in a collection of lists `info`. The function should return a list of tuples where each tuple represents the index positions of the occurrences of `y` in the format `(row, index)`. If `y` appears more than once in the same list, the tuples should be ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_str(info: List[List[str]], y: str) -> List[Tuple[int, int]]:
"""
Find all occurrences of a given string `y` in a collection of lists `info`.
Args:
info (List[List[str]]): A c... |
evol_instruct_66k | 7,341 | Write a Python function to convert a given three-dimensional NumPy array into a two-dimensional matrix. The resulting matrix should have the same number of columns as the innermost dimension of the original three-dimensional array.
The code should start with:
```python
import numpy as np
from typing import List
def f... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List
def flatten_3d_to_2d(three_dimensional_array: np.ndarray) -> np.ndarray:
"""
Converts a given three-dimensional NumPy array into a two-dimensional matrix.
Args:
three_dime... |
evol_instruct_66k | 7,353 | Write a Python function to calculate the aggregate sum of solitary digits in a given integer value. The function should handle both positive and negative integers. The code should start with:
```python
def aggregate_sum_of_digits(number: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def aggregate_sum_of_digits(number: int) -> int:
"""
Calculate the aggregate sum of solitary digits in a given integer value.
Args:
number (int): The integer value from which to calculate the sum of digits.
Ret... |
evol_instruct_66k | 7,363 | Write a Python function to convert a given binary string into its corresponding hexadecimal string. The function should handle binary strings of any length and return the hexadecimal representation in lowercase letters. The code should start with:
```python
def binary_to_hexadecimal(binary_str: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_hexadecimal(binary_str: str) -> str:
"""
Converts a given binary string to its corresponding hexadecimal string.
Args:
binary_str (str): The binary string to be converted.
Returns:
str: Th... |
evol_instruct_66k | 7,401 | Write a Python function to count the number of distinct numerical elements in a multi-dimensional array of integers. The function should correctly handle nested arrays and return the count of unique elements across all layers of arrays. The provided erroneous code needs to be rectified to achieve this.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_distinct_elements(arr: List[List[int]]) -> int:
"""
Count the number of distinct numerical elements in a multi-dimensional array of integers.
Args:
arr (List[List[int]]): A multi-d... |
evol_instruct_66k | 7,442 | Write a Python function to rotate a given 3x3 2D matrix counterclockwise by 90 degrees. The function should take a 2D list as input and return the rotated matrix. The code should start with:
```python
from typing import List
def rotate_matrix_counterclockwise(matrix: List[List[int]]) -> List[List[int]]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def rotate_matrix_counterclockwise(matrix: List[List[int]]) -> List[List[int]]:
"""
Rotates a given 3x3 2D matrix counterclockwise by 90 degrees.
Args:
matrix (List[List[int]]): A 3x3 2D lis... |
evol_instruct_66k | 7,452 | Write a Python function to generate a new list where each element is the square of the corresponding element in a given list. The function should use list comprehension for this purpose.
The code should start with:
```python
from typing import List
def square_elements(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 square_elements(input_list: List[int]) -> List[int]:
"""
Generates a new list where each element is the square of the corresponding element in the input list.
Args:
input_list (List[int]... |
evol_instruct_66k | 7,456 | Write a Python function to find the first occurrence of a target element in a sorted list and return its index. If the target element is not found, return -1. The function should use a binary search algorithm to efficiently locate the target element. The code should start with:
```python
from typing import List
def fi... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def find_first_occurrence(sorted_list: List[int], target: int) -> int:
"""
Find the first occurrence of a target element in a sorted list using binary search.
Args:
sorted_list (List[int])... |
evol_instruct_66k | 7,471 | Write a Python function to compare three numbers and print distinct success messages based on the comparison of the values. The function should handle the following scenarios:
- If `num1` is greater than both `num2` and `num3`, print "Num1 is the greatest."
- If `num2` is greater than both `num1` and `num3`, print "Num... | Here is the Python code to solve the given problem in the markdown block:
```python
def compare_numbers(num1: int, num2: int, num3: int) -> None:
"""
Compare three numbers and print distinct success messages based on the comparison.
Args:
num1 (int): The first number to compare.
num2 (int):... |
evol_instruct_66k | 7,478 | Write a Python function to format a given date in a human-readable format. The function should accept a date object and return a string formatted as "Month day, year".
The code should start with:
```python
from datetime import date
def format_date_to_human_readable(input_date: date) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import date
def format_date_to_human_readable(input_date: date) -> str:
"""
Formats a given date object into a human-readable string.
Args:
input_date (date): The date object to be formatted.
Ret... |
evol_instruct_66k | 7,482 | Write a Python function that uses regular expressions to find and replace all instances of IP addresses in a given text with the term "IP_ADDRESS". The function should be able to handle various valid IP address formats, including those with leading zeros and within the range of 0.0.0.0 to 255.255.255.255.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def replace_ip_addresses(text: str) -> str:
"""
Replaces all instances of IP addresses in the given text with the term "IP_ADDRESS".
Args:
text (str): The input text in which to replace IP addresses.
... |
evol_instruct_66k | 7,485 | Write a Python function to sort a list of numbers using the Insertion Sort algorithm. 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 insertion_sort(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 insertion_sort(numbers: List[int]) -> List[int]:
"""
Sorts a list of numbers using the Insertion Sort algorithm.
Args:
numbers (List[int]): The list of numbers to be sorted.
Returns... |
evol_instruct_66k | 7,494 | Write a Python function to check each element in a given list and determine whether its type corresponds to a string data format or not. The function should return a list of tuples where each tuple contains the element and a boolean value indicating whether the element is a string (`True`) or not (`False`).
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def check_string_types(array: List[any]) -> List[Tuple[any, bool]]:
"""
Checks each element in the given list to determine if it is a string.
Args:
array (List[any]): The list of elem... |
evol_instruct_66k | 7,500 | Write a Python function to calculate the difference between two timestamps in seconds, considering leap years. The function should handle timestamps in the format "YYYY-MM-DD HH:MM:SS". The code should start with:
```python
from datetime import datetime
def timestamp_difference_seconds(timestamp1: str, timestamp2: str... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def timestamp_difference_seconds(timestamp1: str, timestamp2: str) -> int:
"""
Calculate the difference between two timestamps in seconds, considering leap years.
Args:
timestamp1 (str... |
evol_instruct_66k | 7,501 | Write a Python function to calculate the product of two given integers `x` and `y` and return the result. The function should handle any integer inputs and return their product. The code should start with:
```python
def multiply_integers(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def multiply_integers(x: int, y: int) -> int:
"""
Calculate the product of two integers.
Args:
x (int): The first integer.
y (int): The second integer.
Returns:
int: The product of the two integ... |
evol_instruct_66k | 7,503 | Write a Python function that removes leading and trailing whitespace from a given string and reduces multiple consecutive whitespace characters within the string to a single whitespace. The function should not use Python's built-in functions such as `strip()`, `split()`, or `join()`. Instead, implement the solution man... | Here is the Python code to solve the given problem in the markdown block:
```python
def clean_text(text: str) -> str:
"""
Removes leading and trailing whitespace from the given text and reduces multiple consecutive
whitespace characters within the text to a single whitespace.
Args:
text (str): ... |
evol_instruct_66k | 7,507 | Write a Python function to find all occurrences of a specific character in a given string and return their indices. The function should handle cases where the character is not found in the string by returning an empty list. The code should start with:
```python
from typing import List
def find_character_indices(s: str... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def find_character_indices(s: str, ch: str) -> List[int]:
"""
Find all occurrences of a specific character in a given string and return their indices.
Args:
s (str): The input string to se... |
evol_instruct_66k | 7,524 | Write a Python function to calculate the sum of squares of all the numbers from 1 to N. The function should take an integer N as input and return the sum of squares of all integers from 1 to N. The code should start with:
```python
def sum_of_squares(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def sum_of_squares(n: int) -> int:
"""
Calculate the sum of squares of all integers from 1 to n.
Args:
n (int): The upper limit of the range (inclusive) for which to calculate the sum of squares.
Returns:
... |
evol_instruct_66k | 7,532 | Write a Python function to calculate the sum of a given number `a` and the product of two other numbers `b` and `c`. The function should adhere to PEP 8 style guidelines for improved readability and maintainability. The code should start with:
```python
def calculate_sum(a: int, b: int, c: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def calculate_sum(a: int, b: int, c: int) -> int:
"""
Calculate the sum of a given number `a` and the product of two other numbers `b` and `c`.
Args:
a (int): The first number to be added.
b (int): The fir... |
evol_instruct_66k | 7,538 | Write a Python function to remove duplicate elements from a given list while preserving the order of the first occurrence of each element. The function should handle lists of integers and return a new list with duplicates removed.
The code should start with:
```python
from typing import List
def remove_duplicates(lst... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates(lst: List[int]) -> List[int]:
"""
Removes duplicate elements from the given list while preserving the order of the first occurrence of each element.
Args:
lst (List[int... |
evol_instruct_66k | 7,541 | Write a Python function to convert a given 32-bit binary string to its hexadecimal representation. The function should handle both positive and negative binary numbers (represented in 2's complement) correctly. Additionally, the function should validate the input to ensure it is a valid 32-bit binary number and raise a... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_hex(binary_str: str) -> str:
"""
Converts a given 32-bit binary string to its hexadecimal representation.
Handles both positive and negative binary numbers (represented in 2's complement).
Args:
bi... |
evol_instruct_66k | 7,562 | Write a Python function to append a given distinct numerical value to the end of the last list in a given matrix, ensuring the matrix structure is preserved and the list synchronization is maintained. The function should handle matrices of varying dimensions and ensure the value is only appended to the last list.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def append_to_last_list(matrix: List[List[int]], value: int) -> List[List[int]]:
"""
Appends a given distinct numerical value to the end of the last list in a given matrix.
Args:
matrix (Lis... |
evol_instruct_66k | 7,564 | Write a Python function to find the largest number among three given numerical parameters. The function should be able to handle integers, floats, and any other numerical types. The code should start with:
```python
def find_max_number(a: float, b: float, c: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def find_max_number(a: float, b: float, c: float) -> float:
"""
Find the largest number among three given numerical parameters.
Args:
a (float): The first numerical parameter.
b (float): The second numeric... |
evol_instruct_66k | 7,589 | Write a Python function to compute the product of all elements in a given multidimensional array of integers. The array can be up to three dimensions. The function should handle arrays of varying dimensions and sizes.
The code should start with:
```python
from typing import List
def product_of_elements(arr: 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(arr: List[int]) -> int:
"""
Compute the product of all elements in a given multidimensional array of integers.
Args:
arr (List[int]): The multidimensional array of in... |
evol_instruct_66k | 7,590 | Write a Python function to perform a binary search on a sorted array and return the index of the target item if it exists in the array, or -1 if it does not. The function should be efficient and implement the binary search algorithm.
The code should start with:
```python
from typing import List
def binary_search(arr:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(arr: List[int], item: int) -> int:
"""
Perform a binary search on a sorted array to find the index of the target item.
Args:
arr (List[int]): A sorted list of integers.
... |
evol_instruct_66k | 7,604 | Write a Python function to concatenate elements from a list of textual elements into a single string without using built-in concatenation or join functions. The function should also accept an optional list of indices. If provided, only the elements at those indices should be concatenated. If no indices are provided, al... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def fuse_text(arr: List[str], indices: Optional[List[int]] = None) -> str:
"""
Concatenates elements from a list of textual elements into a single string.
If indices are provided, only the ... |
evol_instruct_66k | 7,611 | Write a Python function to generate a roster of individual attributes isolated from a given list of elements, organized in alphabetical order. The function should handle lists with duplicate elements and return a sorted list of unique elements.
The code should start with:
```python
from typing import List
def generat... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_roster(elements: List[str]) -> List[str]:
"""
Generates a roster of individual attributes isolated from a given list of elements, organized in alphabetical order.
Args:
elements... |
evol_instruct_66k | 7,630 | Write a Python function to count the number of times a given two-word phrase appears together in a document. The function should take a phrase and a document as input and return the count of occurrences of the phrase in the document. The document is a string where words are separated by spaces. The phrase consists of e... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_phrase_occurrences(phrase: str, document: str) -> int:
"""
Counts the number of times a given two-word phrase appears together in a document.
Args:
phrase (str): The two-word phrase to search for in the do... |
evol_instruct_66k | 7,631 | Write a Python function to calculate the output value of a mathematical expression structured in the pattern `a * (b + c)`, where the operators `*` and `+` denote multiplication and addition, respectively. The function should accept three integers `a`, `b`, and `c` as input parameters and return the result of the expre... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_expression(a: int, b: int, c: int) -> int:
"""
Calculate the value of the mathematical expression a * (b + c).
Args:
a (int): The first integer value.
b (int): The second integer value.
... |
evol_instruct_66k | 7,637 | Write a Python function to create and populate a fixed-size array with a predefined capacity of 10 elements. The array should be populated in a strictly monotonic increasing order starting from 1 and ending at 10. The function should return the populated array.
The code should start with:
```python
from typing import ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_and_populate_array() -> List[int]:
"""
Creates and populates a fixed-size array with a predefined capacity of 10 elements.
The array is populated in a strictly monotonic increasing order s... |
evol_instruct_66k | 7,661 | Write a Python function to perform element-wise multiplication on two given NumPy arrays. The function should take two NumPy arrays as input and return a new NumPy array containing the result of the element-wise multiplication. The code should start with:
```python
import numpy as np
from typing import List
def elemen... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List
def element_wise_multiplication(array1: List[int], array2: List[int]) -> np.ndarray:
"""
Perform element-wise multiplication on two given NumPy arrays.
Args:
array1 (List[... |
evol_instruct_66k | 7,664 | Write a Python function to sort a list of numerical values using the Quick Sort algorithm. The function should be able to handle lists of integers and floats. The code should start with:
```python
from typing import List
def quick_sort(arr: List[float]) -> List[float]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def quick_sort(arr: List[float]) -> List[float]:
"""
Sorts a list of numerical values using the Quick Sort algorithm.
Args:
arr (List[float]): The list of numerical values to be sorted.
... |
evol_instruct_66k | 7,679 | Write a Python function to calculate the median value of a given list of scores. The median is the middle value of a dataset when it is ordered. If the dataset has an even number of elements, the median is the average of the two middle values. The function should handle lists of any length, including empty lists.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def median_score(scores: List[int]) -> float:
"""
Calculate the median value of a given list of scores.
Args:
scores (List[int]): A list of integers representing the scores.
Returns:
... |
evol_instruct_66k | 7,680 | Write a Python function to append a new element to an existing array and return the modified array. The function should handle the case where the input array is `None` by initializing it as an empty list before appending the new element.
The code should start with:
```python
from typing import List, Optional
def appe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def append_to_array(array: Optional[List[int]], new_element: int) -> List[int]:
"""
Appends a new element to an existing array and returns the modified array.
If the input array is None, it... |
evol_instruct_66k | 7,684 | Write a Python function to convert a list of 7-segment display codes into their corresponding binary and hexadecimal representations. The function should handle potential punctuation characters that could exist in the 7-segment display (such as period, comma, colon, semi-colon, etc.). If an invalid 7-segment code is en... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def convert_seven_segment(seven_segment_codes: List[str]) -> List[Tuple[str, str]]:
"""
Convert a list of 7-segment display codes into their corresponding binary and hexadecimal representations.
... |
evol_instruct_66k | 7,688 | Write a Python function to merge two dictionaries into a single dictionary where values are merged based on keys. If the same key is present in both dictionaries, then increment the value of the key in the merged dictionary with the values from both dictionaries. The function should start with:
```python
from typing im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_dicts(dictA: Dict[str, int], dictB: Dict[str, int]) -> Dict[str, int]:
"""
Merge two dictionaries where values are merged based on keys. If the same key is present in both dictionaries,
the... |
evol_instruct_66k | 7,696 | Write a Python function to join two strings using a given separator such that every character of each string is separated by the separator. Additionally, insert a new separator between the characters of the first and second strings after each operation. The function should also validate if the separator strings contain... | Here is the Python code to solve the given problem in the markdown block:
```python
def process_and_validate_strings(str1: str, str2: str, sep1: str, sep2: str) -> str:
"""
Joins two strings using a given separator and validates the separators.
Args:
str1 (str): The first string to be processed.
... |
evol_instruct_66k | 7,702 | Write a Python function to determine the letter grade of a student based on the inputted numerical grade using a ternary operator. The function should return the letter grade as a string. The grading scale is as follows:
- A: 90 and above
- B: 80 to 89
- C: 70 to 79
- D: 60 to 69
- F: below 60
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
def determine_letter_grade(numerical_grade: int) -> str:
"""
Determine the letter grade of a student based on the inputted numerical grade.
Args:
numerical_grade (int): The numerical grade of the student.
Retur... |
evol_instruct_66k | 7,707 | Write a Python function to calculate the frequency of each word in a given piece of text. The function should handle case insensitivity by converting all words to lowercase. The text may contain punctuation marks, which should be ignored when counting word frequencies. 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 Dict
import string
def word_frequency(text: str) -> Dict[str, int]:
"""
Calculate the frequency of each word in a given piece of text.
Args:
text (str): The input text from which to calculate wor... |
evol_instruct_66k | 7,718 | Write a Python function to sort a list using an optimized version of bubble sort and compare its performance with a standard bubble sort implementation. The function should return a tuple containing the sorted list and a boolean indicating whether the list was sorted using the optimized version or not.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_list_with_optimization(arr: List[int]) -> Tuple[List[int], bool]:
"""
Sorts the given list using an optimized version of bubble sort and returns the sorted list along with a boolean indic... |
evol_instruct_66k | 7,725 | Write a Python function to analyze multiple alphanumeric sequences and identify all distinct alphabetical elements present in these sequences. The function should also count the frequencies of each distinct alphabetical element and track their locations/indices in the sequences. The function should return a dictionary ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
def analyze_sequences(sequences: List[str]) -> Dict[str, Dict[str, int or List[Tuple[int, int]]]]:
"""
Analyze multiple alphanumeric sequences to identify all distinct alphabetical elements,... |
evol_instruct_66k | 7,743 | Write a Python function to count the occurrences of each alphabetic character in a given string. The function should return a dictionary where the keys are the characters and the values are their respective counts. The function should handle edge cases where the input string is `None` or consists only of special charac... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_characters(input_string: str) -> Dict[str, int]:
"""
Counts the occurrences of each alphabetic character in the given string.
Args:
input_string (str): The string to count characte... |
evol_instruct_66k | 7,758 | Write a Python function to find the frequency of each unique element in a given list. The function should return a dictionary where the keys are the unique elements from the list and the values are their respective frequencies.
The code should start with:
```python
from typing import List, Dict
def find_frequency(lst... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def find_frequency(lst: List[int]) -> Dict[int, int]:
"""
Find the frequency of each unique element in a given list.
Args:
lst (List[int]): The list of integers for which to find the f... |
evol_instruct_66k | 7,761 | Write a Python function to calculate the volume of distinct elements in a given list of integer values. The volume is defined as the sum of the absolute values of the distinct elements. The function should handle negative integers and zero.
The code should start with:
```python
from typing import List
def calculate_v... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_volume_of_distinct_elements(arr: List[int]) -> int:
"""
Calculate the volume of distinct elements in a given list of integer values.
The volume is defined as the sum of the absolute val... |
evol_instruct_66k | 7,765 | Write a Python function to perform binary search on a sorted array to find the index of a target element. If the target element is not found, return -1. The function should be efficient and correctly handle edge cases such as an empty array or a target that is not present in the array.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(input_array: List[int], target: int) -> int:
"""
Perform binary search on a sorted array to find the index of a target element.
Args:
input_array (List[int]): A sorted list... |
evol_instruct_66k | 7,787 | Write a Python function to generate a sequence of numbers using either a `while` loop or a `for` loop, based on a given starting number, ending number, and step size. The function should return a list of numbers that fall within the specified range, inclusive of the starting number and exclusive of the ending number. T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_sequence(start: int, end: int, step: int) -> List[int]:
"""
Generate a sequence of numbers from start to end (exclusive) with the given step size.
Args:
start (int): The startin... |
evol_instruct_66k | 7,790 | Write a Python function to determine if the current time falls within a specified period, from 20:00 hours to 08:00 hours, based on the system's internal clock. The function should return a boolean value indicating whether the current time is within the specified period.
The code should start with:
```python
from date... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def is_within_time_period() -> bool:
"""
Determine if the current time falls within the period from 20:00 to 08:00.
Returns:
bool: True if the current time is within the specified peri... |
evol_instruct_66k | 7,793 | Write a Python function to implement a ternary search in a sorted array. The function should return the index of the target element if it exists in the array, otherwise return -1. The function should be recursive and should handle the base case where the search range is invalid.
The code should start with:
```python
f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def ternary_search(arr: List[int], l: int, r: int, x: int) -> int:
"""
Perform a ternary search to find the index of the target element in a sorted array.
Args:
arr (List[int]): The sorted a... |
evol_instruct_66k | 7,797 | Write a Python function to sort an array of integers in ascending order using the Insertion Sort algorithm and then implement a binary search to determine if a specified integer is present in the sorted array. The sorting function should not use any built-in sorting methods. The binary search function should return `Tr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def insertion_sort(arr: List[int]) -> List[int]:
"""
Sort the array in ascending order using Insertion Sort.
Args:
arr (List[int]): The unsorted array of integers.
Returns:
List... |
evol_instruct_66k | 7,798 | Write a Python function to find the largest numeric value in a list, while handling potential errors for non-numeric inputs. The function should ignore any non-numeric elements and return the largest numeric value found in the list. If the list contains no numeric values, the function should return `None`.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_largest_numeric(arr: List[object]) -> Optional[int]:
"""
Find the largest numeric value in a list, ignoring non-numeric inputs.
Args:
arr (List[object]): The list of items... |
evol_instruct_66k | 7,801 | Write a Python function to compute the first 25 values of the Catalan sequence efficiently using dynamic programming. The Catalan sequence is defined by the recursive formula:
\[ C(n) = \sum_{i=0}^{n-1} C(i) \times C(n-i-1) \]
where \( C(0) = 1 \).
The code should start with:
```python
from typing import List
def cat... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def catalan_sequence(n: int) -> List[int]:
"""
Compute the first n+1 Catalan numbers efficiently using dynamic programming.
Args:
n (int): The number of Catalan numbers to compute.
Retu... |
evol_instruct_66k | 7,803 | Write a Python function to calculate the sum of an array of integers. The function should take a list of integers as input and return the sum of the integers. The code should start with:
```python
from typing import List
def calculate_sum(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_sum(numbers: List[int]) -> int:
"""
Calculate the sum of an array of integers.
Args:
numbers (List[int]): A list of integers.
Returns:
int: The sum of the integers... |
evol_instruct_66k | 7,813 | Write a Python function to display the elements of a bi-dimensional matrix in a spiral order. The matrix is represented as a list of lists, where each inner list represents a row of the matrix. The function should print the elements in a spiral order starting from the top-left corner and moving right, down, left, and u... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def display_spiral_matrix(matrix: List[List[int]]) -> None:
"""
Displays the elements of a bi-dimensional matrix in a spiral order.
Args:
matrix (List[List[int]]): The bi-dimensional matrix ... |
evol_instruct_66k | 7,817 | Write a Python function to extract the smallest trio of numerical values from a given array of integers without using any pre-existing or built-in functions. The function should return the three smallest values in ascending order.
The code should start with:
```python
from typing import List
def find_smallest_trio(ar... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_smallest_trio(array: List[int]) -> List[int]:
"""
Extracts the smallest trio of numerical values from a given array of integers without using built-in functions.
Args:
array (List[i... |
evol_instruct_66k | 7,823 | Write a Python function that takes a string as input and returns a modified version of the string using lambda functions and list comprehension. The function should append the phrase ", world!" to the input string and ensure the output is in the format "Hi, world!".
The code should start with:
```python
def modify_str... | Here is the Python code to solve the given problem in the markdown block:
```python
def modify_string(input_str: str) -> str:
"""
Modifies the input string by appending ", world!" to it and returns the result.
Args:
input_str (str): The input string to be modified.
Returns:
str: The mo... |
evol_instruct_66k | 7,824 | Write a Python function to convert a given binary number represented as a string into its equivalent decimal number. The function should handle binary numbers with or without a fractional part. The binary number can be either positive or negative.
The code should start with:
```python
def binary_to_decimal(binary_str:... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_decimal(binary_str: str) -> float:
"""
Converts a binary number represented as a string to its equivalent decimal number.
Args:
binary_str (str): The binary number to convert, represented as a string.
... |
evol_instruct_66k | 7,825 | Write a Python function to generate all prime numbers between 1 and a given integer `n` using the Sieve of Eratosthenes algorithm. The function should be optimized to reduce time complexity, making it efficient for larger ranges. The code should start with:
```python
from typing import List
def generate_primes(n: int)... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_primes(n: int) -> List[int]:
"""
Generate all prime numbers between 1 and n using the Sieve of Eratosthenes algorithm.
Args:
n (int): The upper limit to find all prime numbers.
... |
evol_instruct_66k | 7,843 | Write a Python function to iterate through a given list and return a new list containing the elements in reverse order without using the standard `reversed()` function or the `reverse()` method. The function should start with:
```python
from typing import List
def reverse_list(array: 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(array: List[str]) -> List[str]:
"""
Returns a new list containing the elements of the input list in reverse order.
Args:
array (List[str]): The input list of strings to be r... |
evol_instruct_66k | 7,860 | Write a Python function to extract and return the values from a given dictionary. The dictionary contains key-value pairs where the keys are strings representing attributes and the values can be of any type. The function should return a list containing all the values from the dictionary.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Any
def extract_values(dictionary: Dict[str, Any]) -> List[Any]:
"""
Extracts and returns the values from a given dictionary.
Args:
dictionary (Dict[str, Any]): The dictionary from wh... |
evol_instruct_66k | 7,861 | Write a Python function to simplify the given conditional logic that determines the value of `result` based on the value of `x`. The original logic contains redundant conditions that can be merged or eliminated. The function should handle the following cases:
- If `x` is less than or equal to 0, `result` should be 0.
-... | Here is the Python code to solve the given problem in the markdown block:
```python
def simplify_conditional(x: int) -> int:
"""
Simplifies the given conditional logic to determine the value of `result` based on the value of `x`.
Args:
x (int): The input value to determine the result.
Returns:... |
evol_instruct_66k | 7,864 | Write a Python function to find the largest element in a given dataset. The dataset is a list of integers. The function should return the largest integer in the list. The code should start with:
```python
from typing import List
def find_largest_element(dataset: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_largest_element(dataset: List[int]) -> int:
"""
Finds the largest element in the given dataset.
Args:
dataset (List[int]): The dataset from which to find the largest element.
R... |
evol_instruct_66k | 7,877 | Write a Python function to calculate the Euclidean distance between two given coordinate tuples in a 2D plane. The function should handle tuples of integers or floats. The code should start with:
```python
from typing import Tuple
import math
def euclidean_distance(coord1: Tuple[float, float], coord2: Tuple[float, flo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
import math
def euclidean_distance(coord1: Tuple[float, float], coord2: Tuple[float, float]) -> float:
"""
Calculate the Euclidean distance between two points in a 2D plane.
Args:
coord1 (T... |
evol_instruct_66k | 7,887 | Write a Python function to perform a ternary search for a specific element in a pre-sorted numerical array. The function should return the index of the element if it is found, otherwise it should return -1. The code should start with:
```python
from typing import List
def ternary_search(arr: List[int], key: int) -> in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def ternary_search(arr: List[int], key: int) -> int:
"""
Perform a ternary search to find the index of a specific element in a pre-sorted numerical array.
Args:
arr (List[int]): The pre-sort... |
evol_instruct_66k | 7,907 | Write a Python function to convert a given hexadecimal numeral, represented as a string, into its corresponding decimal notation. The function should handle both uppercase and lowercase hexadecimal characters and should return the decimal value as an integer.
The code should start with:
```python
def hex_to_decimal(he... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_decimal(hex_value: str) -> int:
"""
Convert a given hexadecimal numeral, represented as a string, into its corresponding decimal notation.
Args:
hex_value (str): The hexadecimal numeral to be converted, r... |
evol_instruct_66k | 7,919 | Write a Python function to determine the type of a given variable. The function should take a variable as input and return its type as a string. The code should start with:
```python
def get_variable_type(variable) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_variable_type(variable) -> str:
"""
Determine the type of a given variable and return it as a string.
Args:
variable: The variable whose type needs to be determined.
Returns:
str: The type of th... |
evol_instruct_66k | 7,940 | Write a Python function to validate if all elements in a given numeric array are prime numbers. Each element in the array is guaranteed to be greater than 2 and less than 106. The function should use an iterative loop and avoid using any prime-checking built-in functions. The solution should aim for a time complexity l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(num: int) -> bool:
"""
Check if a given number is prime.
Args:
num (int): The number to check for primality.
Returns:
bool: True if the number is prime, False other... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.