source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 34,519 | Write a Python function to create and fill a homogeneous one-dimensional array (list) with a predetermined size accommodating `n` elements, and sequentially fill it up with consecutive integers starting from 1 and ending at `n`. The function should return the filled list.
The code should start with:
```python
from typ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_and_fill_array(n: int) -> List[int]:
"""
Creates and fills a one-dimensional array with consecutive integers from 1 to n.
Args:
n (int): The size of the array and the last integer... |
evol_instruct_66k | 34,542 | Write a Python function to generate a random string of a specified length composed exclusively of lowercase alphabetic characters. The function should ensure that each character in the string is chosen randomly to enhance unpredictability. The code should start with:
```python
import random
import string
def generate_... | Here is the Python code to solve the given problem in the markdown block:
:
```python
import random
import string
def generate_random_string(length: int) -> str:
"""
Generates a random string of the specified length composed exclusively of lowercase alphabetic characters.
Args:
length (int): The l... |
evol_instruct_66k | 34,583 | Write a Python function to sort a given list of integers in ascending order using the merge sort algorithm. The function should be able to handle lists of any length, including empty lists. The merge sort algorithm should be implemented from scratch without using Python's built-in `sort()` or `sorted()` functions.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order using the merge sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Re... |
evol_instruct_66k | 34,588 | Write a Python function to find and return the second smallest numerical value within a provided list. The function should handle lists with duplicate values and ensure that the second smallest value is correctly identified. The code should start with:
```python
from typing import List
def find_second_smallest(numbers... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def find_second_smallest(numbers: List[int]) -> int:
"""
Find and return the second smallest numerical value within a provided list.
Args:
numbers (List[int]): A list of integers from whic... |
evol_instruct_66k | 34,601 | Write a Python function to replicate the elements of a given list a specified number of times. The function should return a new list containing each element of the original list repeated the specified number of times. The code should start with:
```python
from typing import List
def replicate_elements(original_list: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def replicate_elements(original_list: List[str], times: int) -> List[str]:
"""
Replicates each element of the original list a specified number of times.
Args:
original_list (List[str]): The ... |
evol_instruct_66k | 34,609 | Write a Python function to count the frequency of each unique integer in a given list of integers and return the count of distinct integers along with a dictionary containing the frequency of each unique integer. The function should validate the input to ensure all elements are integers and handle any potential excepti... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_frequency(array: List[int]) -> Dict[int, int]:
"""
Counts the frequency of each unique integer in the given list and returns a dictionary with the frequency of each unique integer.
A... |
evol_instruct_66k | 34,611 | Write a Python function to generate an Elasticsearch query that searches for all records containing a "location" field with a value of "Los Angeles" and a "category" field with a value of "Technology". The function should also include options for pagination and sorting by a specified field in ascending or descending or... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Optional
def generate_elasticsearch_query(location: str, category: str, page: int = 1, page_size: int = 10, sort_field: Optional[str] = None, sort_order: str = "asc") -> Dict:
"""
Generates an Elasticse... |
evol_instruct_66k | 34,627 | Write a Python function `checkNumber` that takes two arguments: `number` and `factor`. The function should check if the given `number` is divisible by the `factor` and return `True` if it is, otherwise return `False`. The function should handle cases where `factor` is zero by returning `False`.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
def checkNumber(number: int, factor: int) -> bool:
"""
Check if the given number is divisible by the given factor.
Args:
number (int): The number to be checked for divisibility.
factor (int): The factor to c... |
evol_instruct_66k | 34,632 | Write a Python function to count the frequency of each character in a given multi-dimensional array. The function should return a dictionary where the keys are characters and the values are their respective counts.
The code should start with:
```python
from typing import List, Dict
def count_character_frequencies(mul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_character_frequencies(multi_array: List[List[str]]) -> Dict[str, int]:
"""
Counts the frequency of each character in a given multi-dimensional array.
Args:
multi_array (List[... |
evol_instruct_66k | 34,637 | Write a Python function to consolidate a given list of discrete alphabetic entities into a consolidated, uninterrupted textual representation. The function should take a list of characters as input and return a single string that concatenates all the characters in the list.
The code should start with:
```python
from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def consolidate_characters(characters: List[str]) -> str:
"""
Consolidates a given list of discrete alphabetic entities into a consolidated, uninterrupted textual representation.
Args:
chara... |
evol_instruct_66k | 34,648 | Write a Python function to calculate the average of all elements in a given list of integers. The function should handle the case where the list is empty by returning 0. The code should start with:
```python
from typing import List
def calculate_average(arr: List[int]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def calculate_average(arr: List[int]) -> float:
"""
Calculate the average of all elements in a given list of integers.
If the list is empty, return 0.
Args:
arr (List[int]): The list o... |
evol_instruct_66k | 34,654 | Write a Python function to randomize the elements of a given list. The function should return a new list with the elements in a randomized order. The original list should not be modified.
The code should start with:
```python
from typing import List
import random
def randomize_list(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def randomize_list(arr: List[int]) -> List[int]:
"""
Randomizes the elements of a given list and returns a new list with the elements in a randomized order.
Args:
arr (List[int... |
evol_instruct_66k | 34,688 | Write a Python function to generate the Collatz sequence for a given integer `n`. The Collatz sequence is defined as follows:
- Start with an integer `n`.
- If `n` is even, the next number is `n / 2`.
- If `n` is odd, the next number is `3 * n + 1`.
- Repeat the process until `n` becomes 1.
The function should return ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def collatz_sequence(n: int) -> List[int]:
"""
Generate the Collatz sequence for a given integer `n`.
The Collatz sequence is defined as follows:
- Start with an integer `n`.
- If `n` is eve... |
evol_instruct_66k | 34,694 | Write a Python function to implement the Bubble Sort algorithm. The function should take a list of integers as input and return the sorted list. The code should start with:
```python
from typing import List
def bubble_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 bubble_sort(numbers: List[int]) -> List[int]:
"""
Sorts a list of integers using the Bubble Sort algorithm.
Args:
numbers (List[int]): The list of integers to be sorted.
Returns:
... |
evol_instruct_66k | 34,697 | Write a Python function to perform a linear search on a given list of integers to determine if a specified target integer is present. If the target is found, return a message indicating its position in the list. If the target is not found, return a message indicating its absence.
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 linear_search(lst: List[int], target: int) -> str:
"""
Perform a linear search on a list of integers to find the specified target integer.
Args:
lst (List[int]): The list of integers to ... |
evol_instruct_66k | 34,698 | Write a Python function to convert a given phrase into snake_case format. The function should handle multiple spaces, leading and trailing spaces, and special characters by replacing them with underscores. The function should also convert all characters to lowercase.
The code should start with:
```python
def convert_t... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_snake_case(phrase: str) -> str:
"""
Converts a given phrase into snake_case format.
Args:
phrase (str): The input phrase to be converted.
Returns:
str: The phrase converted to snake_case ... |
evol_instruct_66k | 34,701 | Write a Python function to remove an item from a tuple by converting it to a list, removing the item, and then converting it back to a tuple. The function should handle cases where the item to be removed does not exist in the tuple.
The code should start with:
```python
from typing import Tuple, Any
def remove_item_f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Any
def remove_item_from_tuple(t: Tuple[Any], item_to_remove: Any) -> Tuple[Any]:
"""
Removes an item from a tuple by converting it to a list, removing the item, and then converting it back to a tuple.... |
evol_instruct_66k | 34,713 | Write a Python function to create an innovative array by traversing each component of a given vector and incorporating each individual element into the innovative array. The function should handle vectors of any length and return the innovative array.
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 create_innovative_array(vector: List[int]) -> List[int]:
"""
Creates an innovative array by traversing each component of the given vector and incorporating each individual element into the innovative... |
evol_instruct_66k | 34,717 | Write a Python function to find all unique pairs of integers within a given range `[0, n-1]` that sum up to a specified value `k`. The function should return a list of tuples, where each tuple represents a pair of integers that satisfy the condition. The pairs should be unique, meaning that `(i, j)` and `(j, i)` should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_unique_pairs(n: int, k: int) -> List[Tuple[int, int]]:
"""
Find all unique pairs of integers within the range [0, n-1] that sum up to a specified value k.
Args:
n (int): The ... |
evol_instruct_66k | 34,724 | Write a Python function to sort a list of tuples based on their second element. If two tuples have the same second element, sort those tuples according to their first element. Assume all first elements are single digits. The function should handle the sorting efficiently and correctly.
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, Tuple
def sort_tuples_by_second_element(list_of_tuples: List[Tuple[str, int]]) -> List[Tuple[str, int]]:
"""
Sorts a list of tuples based on their second element. If two tuples have the same second elem... |
evol_instruct_66k | 34,728 | Write a Python function to transform a given sequence of numerical values into a corresponding dictionary structure. The resultant dictionary should use these numeric quantities as keys, matched to equivalent values in the form of associated characters. The function should handle cases where the lengths of the numeric ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def transform_to_dict(num_list: List[int], char_list: List[str]) -> Dict[int, str]:
"""
Transforms a given sequence of numerical values into a corresponding dictionary structure.
The resultant ... |
evol_instruct_66k | 34,729 | Write a Python function to remove all leading and trailing whitespace characters from a given string. The function should handle various types of whitespace characters, including spaces, tabs, and newlines. The code should start with:
```python
def remove_whitespace(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_whitespace(text: str) -> str:
"""
Removes all leading and trailing whitespace characters from the given string.
Args:
text (str): The input string from which to remove whitespace characters.
Returns:... |
evol_instruct_66k | 34,749 | Write a Python function to extract and return a list of keys from a given dictionary. The function should handle dictionaries with various types of keys and values. The code should start with:
```python
from typing import Dict, List
def get_keys_from_dict(dictionary: Dict) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def get_keys_from_dict(dictionary: Dict) -> List[str]:
"""
Extracts and returns a list of keys from a given dictionary.
Args:
dictionary (Dict): The dictionary from which to extract th... |
evol_instruct_66k | 34,755 | Write a Python function to safely convert two string inputs to integers and return their sum. If either of the inputs cannot be converted to an integer, the function should return `None`. The function should handle potential `ValueError` exceptions gracefully.
The code should start with:
```python
def safe_sum_of_stri... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_sum_of_strings(x: str, y: str) -> int:
"""
Safely converts two string inputs to integers and returns their sum.
If either of the inputs cannot be converted to an integer, returns None.
Args:
x (str): Th... |
evol_instruct_66k | 34,758 | Write a Python function to find the highest value in a given list of integers without using the built-in `max` function. The function should handle an empty list by returning `None`. The code should start with:
```python
from typing import List, Optional
def find_highest_value(nums: List[int]) -> Optional[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_highest_value(nums: List[int]) -> Optional[int]:
"""
Find the highest value in a given list of integers without using the built-in 'max' function.
Args:
nums (List[int]): ... |
evol_instruct_66k | 34,760 | Write a Python function to perform a linear search on a given list to find the index of a specified target element. If the target element is not found in the list, the function should return `None`. The function should handle cases where the list is empty or the target is not present in the list.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def linear_search(target: int, lst: List[int]) -> Optional[int]:
"""
Perform a linear search on a list to find the index of a specified target element.
Args:
target (int): The elem... |
evol_instruct_66k | 34,762 | Write a Python function to transform an array of individual text elements into a unified, singular textual entity. The function should handle cases where the string elements may carry unique identifiers or special characters. The function should allow for customization of the separator used to join the elements.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def combine_text_elements(text_elements: List[str], separator: str = "") -> str:
"""
Combines an array of individual text elements into a unified, singular textual entity.
Args:
text_element... |
evol_instruct_66k | 34,767 | Write a Python function to compute the nth Catalan number from the sequence. The Catalan numbers are a sequence of natural numbers that appear in various combinatorial problems. The nth Catalan number can be computed using the formula:
\[ C_n = \frac{(2n)!}{(n+1)!n!} \]
The code should start with:
```python
def catal... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def catalan_number(n: int) -> int:
"""
Compute the nth Catalan number from the sequence.
The nth Catalan number is computed using the formula:
C_n = (2n)! / ((n+1)! * n!)
Args:
n (int): The pos... |
evol_instruct_66k | 34,769 | Write a Python function to create a three-dimensional array of size `4x3x3` with all elements set to 0, and then populate it with sequential integers starting from 1. The integers should only occupy even positions in the third dimension (i.e., positions where the third index is even).
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def populate_3d_array() -> np.ndarray:
"""
Create a 4x3x3 three-dimensional array with all elements set to 0,
and populate it with sequential integers starting from 1,
ensuring integers only occupy ev... |
evol_instruct_66k | 34,772 | Write a Python function to find the longest repeating pattern in a stream of numbers that appears at least three times. The function should return the starting index and the length of the pattern. If no such pattern exists, the function should return `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, Tuple, Optional
def find_longest_repeating_pattern(stream: List[int]) -> Optional[Tuple[int, int]]:
"""
Finds the longest repeating pattern in a stream of numbers that appears at least three times.
... |
evol_instruct_66k | 34,775 | Write a Python function to calculate the transpose of a given n-dimensional array without using any in-built transpose functions. The function should be able to handle arrays of any dimensionality. The code should start with:
```python
import numpy as np
from typing import List
def custom_transpose(arr: np.ndarray) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List
def custom_transpose(arr: np.ndarray) -> np.ndarray:
"""
Calculate the transpose of a given n-dimensional array without using in-built transpose functions.
Args:
arr (np.n... |
evol_instruct_66k | 34,776 | Write a Python function to invert an integer without converting it to a string, preserving its numerical properties. The function should handle both positive and negative integers. The code should start with:
```python
def invert_integer(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def invert_integer(n: int) -> int:
"""
Inverts an integer without converting it to a string, preserving its numerical properties.
Args:
n (int): The integer to be inverted.
Returns:
int: The inverted ... |
evol_instruct_66k | 34,792 | Write a Python function to generate a list of the cubes of the first n odd numbers, where n is a positive integer. The function should return the list of these cubes.
The code should start with:
```python
from typing import List
def generate_odd_cubes(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_odd_cubes(n: int) -> List[int]:
"""
Generate a list of the cubes of the first n odd numbers.
Args:
n (int): The number of odd numbers to consider.
Returns:
List[int... |
evol_instruct_66k | 34,794 | Write a Python function to calculate the total sales across all regions from a given list of sales data. Each item in the list is a dictionary containing the region and the corresponding sales amount. The function should sum up all the sales amounts and return the total.
The code 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
def calculate_total_sales(sales_data: List[Dict[str, int]]) -> int:
"""
Calculate the total sales across all regions from a given list of sales data.
Args:
sales_data (List[Dict[str, i... |
evol_instruct_66k | 34,797 | Write a Python function to create a list of N dictionaries, where each dictionary has a unique identifier as a key and the value being another dictionary with a specific structure. The structure of the inner dictionary should include keys "name", "age", and "email", each initialized to an empty string.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_dict_list(N: int) -> List[dict]:
"""
Creates a list of N dictionaries, each with a unique identifier as a key and the value being another dictionary with specific keys.
Args:
N (i... |
evol_instruct_66k | 34,803 | Write a Python function to find and return the elements in an array of integers that have their permutation or ordinal enumeration (i.e., their index in the array) greater than or equal to a given integer barrier. The array is 0-indexed.
The code should start with:
```python
from typing import List
def elements_after... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def elements_after_barrier(array: List[int], barrier: int) -> List[int]:
"""
Returns the elements in the array whose indices are greater than or equal to the given barrier.
Args:
array (List... |
evol_instruct_66k | 34,812 | Write a Python function to parse a string, remove all special characters, and return the new string in reverse order. The function should not use any built-in string functions or the `re` module. The code should start with:
```python
def clean_and_reverse(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def clean_and_reverse(s: str) -> str:
"""
Parses a string, removes all special characters, and returns the new string in reverse order.
Args:
s (str): The input string to be cleaned and reversed.
Returns:
... |
evol_instruct_66k | 34,813 | Write a Python function to convert angle measurements between degrees and radians based on user input. The function should handle both single values and lists of values. If the input is a list, the function should return a list of converted values. The function should also include error handling for invalid inputs.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union, List
import math
def convert_angle(value: Union[float, List[float]], to_unit: str) -> Union[float, List[float]]:
"""
Convert angle measurements between degrees and radians based on user input.
Arg... |
evol_instruct_66k | 34,817 | Write a Python function to determine the cumulative count of unique elements in a multidimensional array, considering that the nested lists can go up to 3 levels deep. The function should also return a dictionary with the count of each unique element.
The code should start with:
```python
from typing import List, Dict... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
from collections import Counter
def flatten(array: List) -> List:
"""
Recursively flattens a multidimensional array up to 3 levels deep.
Args:
array (List): The multidimensional array ... |
evol_instruct_66k | 34,824 | Write a Python function to convert a given text to uppercase and eliminate all numeric characters. The function should take a string as input and return a string with all characters converted to uppercase and all numeric characters removed.
The code should start with:
```python
def convert_text(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def convert_text(text: str) -> str:
"""
Converts the given text to uppercase and removes all numeric characters.
Args:
text (str): The input text to be processed.
Returns:
str: The processed text with a... |
evol_instruct_66k | 34,841 | Write a Python function to determine the number exceeding the value of 100 that recurs with the highest frequency within a given list of numeric elements. The function should handle potential errors due to different data types in the list and efficiently deal with large lists. The function should start with:
```python
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def most_frequent_over_100(numbers: List[int]) -> int:
"""
Determine the number exceeding 100 that recurs with the highest frequency in the given list.
Args:
numbers (List[int]): A list of n... |
evol_instruct_66k | 34,842 | Write a Python function to calculate the maximum profit that can be made by buying and selling a stock given a list of stock prices on different days. The function should determine the best day to buy and the best day to sell to maximize the profit. The code should start with:
```python
from typing import List
def max... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_profit(prices: List[int]) -> int:
"""
Calculate the maximum profit that can be made by buying and selling a stock.
Args:
prices (List[int]): A list of stock prices on different days.... |
evol_instruct_66k | 34,847 | Write a Python function to generate a matrix of increasing numbers beginning from 1 and of dimensions `m` by `n`. The matrix should be filled such that the numbers increase sequentially from left to right and top to bottom. The function should return the generated matrix.
The code should start with:
```python
from typ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_increasing_matrix(m: int, n: int) -> List[List[int]]:
"""
Generate a matrix of increasing numbers beginning from 1 and of dimensions m by n.
Args:
m (int): The number of rows in... |
evol_instruct_66k | 34,853 | Write a Python function to sort a dictionary by its values in ascending order. If two keys have the same value, their original order should be preserved. The function should return the sorted dictionary.
The code should start with:
```python
from typing import Dict
def sort_dictionary_by_value(my_dict: Dict[str, int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dictionary_by_value(my_dict: Dict[str, int]) -> Dict[str, int]:
"""
Sorts a dictionary by its values in ascending order. If two keys have the same value, their original order is preserved.
... |
evol_instruct_66k | 34,862 | Write a Python function to generate a meticulously ordered catalog (list) of continuous, whole numerical values starting from a given integer `start` and ending at a given integer `end` (inclusive). The function should ensure that the catalog is ordered in ascending order.
The code should start with:
```python
from ty... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_catalog(start: int, end: int) -> List[int]:
"""
Generates a meticulously ordered catalog (list) of continuous, whole numerical values
starting from the given integer `start` and ending a... |
evol_instruct_66k | 34,863 | Write a Python function to compute the factorial of a given non-negative integer `n` using an iterative approach for better performance. The function should handle large values of `n` efficiently and avoid the pitfalls of recursion, such as stack overflow for large `n`.
The code should start with:
```python
def factor... | Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int:
"""
Compute the factorial of a given non-negative integer `n` using an iterative approach.
Args:
n (int): The non-negative integer for which to compute the factorial.
Returns:
... |
evol_instruct_66k | 34,880 | Write a Python function to count the number of odd numbers within a given range from 1 to n (exclusive). The function should be efficient and bug-free. The code should start with:
```python
def count_odd_numbers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_odd_numbers(n: int) -> int:
"""
Count the number of odd numbers within the range from 1 to n (exclusive).
Args:
n (int): The upper limit of the range (exclusive).
Returns:
int: The number of o... |
evol_instruct_66k | 34,885 | Write a Python function to determine if there exist any two distinct elements in a given array that sum up to a specified target sum. The function should return `True` if such a pair exists, otherwise `False`.
The code should start with:
```python
from typing import List
def has_pair_with_sum(array: List[int], target... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def has_pair_with_sum(array: List[int], target_sum: int) -> bool:
"""
Determines if there exist any two distinct elements in the given array that sum up to the specified target sum.
Args:
ar... |
evol_instruct_66k | 34,898 | Write a Python function that prints the string "Hello World!" to the console. The function should be named `print_hello_world`. The function should not take any arguments and should not return any value. The code should start with:
```python
def print_hello_world():
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def print_hello_world():
"""
Prints the string "Hello World!" to the console.
This function does not take any arguments and does not return any value.
It simply prints the string "Hello World!" to the console when calle... |
evol_instruct_66k | 34,899 | Write a Python function to evaluate a given mathematical expression string, taking into account the order of operations (PEMDAS), handling fractional results, and dealing with potential arithmetic exceptions. The function should return the result of the expression as a float.
The code should start with:
```python
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
def evaluate_expression(expression: str) -> float:
"""
Evaluates a given mathematical expression string, respecting the order of operations (PEMDAS),
handling fractional results, and dealing with potential arithmetic excepti... |
evol_instruct_66k | 34,901 | Write a Python function to search for a given number in a 2D array where each sub-array can have varying lengths. If the number is found, return the indices of the number in the 2D array as a tuple. If the number is not found, return -1.
The code should start with:
```python
from typing import List, Tuple, Union
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Union
def search_2D_array(arr: List[List[int]], num: int) -> Union[Tuple[int, int], int]:
"""
Searches for a given number in a 2D array where each sub-array can have varying lengths.
Args:
... |
evol_instruct_66k | 34,912 | Write a Python function to generate a Unix shell script that periodically executes a given command at a specified interval. The function should accept the command to be executed and the interval in minutes as input parameters. The generated script should be returned as a string.
The code should start with:
```python
d... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_periodic_script(command: str, interval_minutes: int) -> str:
"""
Generates a Unix shell script that periodically executes a given command at a specified interval.
Args:
command (str): The command to be ... |
evol_instruct_66k | 34,916 | Write a Python function to calculate the least common multiple (LCM) of three distinct positive integers efficiently. The function should use the greatest common divisor (GCD) to optimize the computation.
The code should start with:
```python
import math
def least_common_multiple(x: int, y: int, z: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def least_common_multiple(x: int, y: int, z: int) -> int:
"""
Calculate the least common multiple (LCM) of three distinct positive integers.
Args:
x (int): The first positive integer.
y (int): T... |
evol_instruct_66k | 34,935 | Write a Python function to merge two lists into a single unified list. The function should handle lists of any length and should not modify the original lists. The merged list should contain all elements from both input lists, maintaining the order of elements as they appear in the original lists.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_lists(list1: List[str], list2: List[str]) -> List[str]:
"""
Merges two lists into a single unified list without modifying the original lists.
Args:
list1 (List[str]): The first lis... |
evol_instruct_66k | 34,936 | Write a Python function to validate the lengths of two input lists and then merge them into a dictionary. If the lengths of the lists are not the same, the function should return an error message. The function should start with:
```python
from typing import List, Dict, Union
def merge_lists_to_dict(list1: List[str], l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Union
def merge_lists_to_dict(list1: List[str], list2: List[int]) -> Union[Dict[str, int], str]:
"""
Validates the lengths of two input lists and merges them into a dictionary.
Args:
... |
evol_instruct_66k | 34,952 | Write a Python function to determine if all elements at odd indices in a given list are odd numbers. The function should return `True` if all elements at odd indices are odd, and `False` otherwise. The code should start with:
```python
from typing import List
def check_odd_indices_elements(input_list: List[int]) -> bo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def check_odd_indices_elements(input_list: List[int]) -> bool:
"""
Determines if all elements at odd indices in the given list are odd numbers.
Args:
input_list (List[int]): The list of inte... |
evol_instruct_66k | 34,961 | Write a Python function to find the maximum sum of a contiguous subarray within a given array of integers. The function should efficiently handle both positive and negative integers. The code should start with:
```python
from typing import List
def max_sum_subarray(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_sum_subarray(arr: List[int]) -> int:
"""
Find the maximum sum of a contiguous subarray within the given array of integers.
Args:
arr (List[int]): The array of integers.
Returns:... |
evol_instruct_66k | 34,983 | Write a Python function to convert a given string into its corresponding binary representation. Each character in the string should be converted to its 8-bit binary equivalent. The function should return a single string containing the concatenated binary representations of all characters in the input string.
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
def text_to_binary(text: str) -> str:
"""
Converts a given string into its corresponding binary representation.
Each character in the input string is converted to its 8-bit binary equivalent,
and the binary strings are ... |
evol_instruct_66k | 34,993 | Write a Python function to remove all occurrences of a specified item from a given list while preserving the order of the remaining elements. The function should handle lists with multiple occurrences of the item and lists that do not contain the item. 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_item(items: List[str], item_to_remove: str) -> List[str]:
"""
Removes all occurrences of a specified item from a given list while preserving the order of the remaining elements.
Args:
... |
evol_instruct_66k | 35,007 | Write a Python function to reverse a given string. The function should take a string as input and return the reversed string. The code should start with:
```python
def reverse_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_string(s: str) -> str:
"""
Reverses the given string.
Args:
s (str): The string to be reversed.
Returns:
str: The reversed string.
"""
# Use slicing to reverse the string
retur... |
evol_instruct_66k | 35,010 | Write a Python function to determine if all characters in a given string are unique, adhering to a Big O notation of O(n), where n is the length of the string. The function should ignore spaces and be case-insensitive. The code should start with:
```python
def are_characters_unique(in_str: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def are_characters_unique(in_str: str) -> bool:
"""
Determines if all characters in the given string are unique, ignoring spaces and case.
Args:
in_str (str): The input string to check for unique characters.
Re... |
evol_instruct_66k | 35,011 | Write a Python function to find the common elements within a specified range from two given lists of integers. The function should accept two lists and a tuple representing the range as parameters. The function should return a list of integers that are present in both input lists and fall within the specified range.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def get_common_numbers_in_range(list1: List[int], list2: List[int], range_values: Tuple[int, int]) -> List[int]:
"""
Find the common elements within a specified range from two given lists of integ... |
evol_instruct_66k | 35,031 | Write a Python function to count the total number of words in a given string. The function should handle various edge cases, such as strings with multiple spaces, leading/trailing spaces, and empty strings. The code should start with:
```python
def count_words(s: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_words(s: str) -> int:
"""
Counts the total number of words in a given string.
Args:
s (str): The input string to count words from.
Returns:
int: The total number of words in the string.
""... |
evol_instruct_66k | 35,037 | Write a Python function to compute the magnitude of a vector in three-dimensional space given its components (x, y, z). The function should return the magnitude as a floating-point number. The code should start with:
```python
import math
def compute_vector_magnitude(x: float, y: float, z: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def compute_vector_magnitude(x: float, y: float, z: float) -> float:
"""
Computes the magnitude of a vector in three-dimensional space given its components (x, y, z).
Args:
x (float): The x-component of... |
evol_instruct_66k | 35,038 | Write a Python function to invert a given character sequence. The function should take a string as input and return the string with its characters reversed. The code should start with:
```python
def invert_sequence(sequence: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def invert_sequence(sequence: str) -> str:
"""
Inverts the given character sequence by reversing the order of its characters.
Args:
sequence (str): The input string to be inverted.
Returns:
str: The i... |
evol_instruct_66k | 35,040 | Write a Python function to sort an array of floating point numbers from largest to smallest. The function should take a list of floating point numbers as input and return a new list with the numbers sorted in descending order.
The code should start with:
```python
from typing import List
def sort_floats_descending(nu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_floats_descending(nums: List[float]) -> List[float]:
"""
Sorts an array of floating point numbers from largest to smallest.
Args:
nums (List[float]): The list of floating point numb... |
evol_instruct_66k | 35,042 | Write a Python function to calculate the sum of all odd integers within a given range [l, r], where both l and r are positive integers and not fractions. The function should handle cases where l is greater than r by swapping their values to ensure the range is valid.
The code should start with:
```python
def sum_of_od... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_odds_in_range(l: int, r: int) -> int:
"""
Calculate the sum of all odd integers within the range [l, r].
Args:
l (int): The lower limit of the range (inclusive).
r (int): The upper limit of the ra... |
evol_instruct_66k | 35,050 | Write a Python function to find the first index of a given character in a string, considering the search to be case-insensitive. If the character does not appear in the string, the function should return -1. The function should start with:
```python
def find_case_insensitive_index(input_string: str, char: str) -> int:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_case_insensitive_index(input_string: str, char: str) -> int:
"""
Find the first index of a given character in a string, considering the search to be case-insensitive.
Args:
input_string (str): The string in... |
evol_instruct_66k | 35,051 | Write a Python function to construct an array of objects, where each object represents a distinct numerical value sourced from a given array of numbers. The function should take an array of integers as input and return a list of dictionaries, where each dictionary contains a single key-value pair with the key being `'v... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def construct_objects_array(arr: List[int]) -> List[Dict[str, int]]:
"""
Constructs an array of objects from a given array of integers.
Args:
arr (List[int]): The input array of intege... |
evol_instruct_66k | 35,059 | Write a Python function to search for a specific integer within a collection of integers represented as an array. The function should return the index of the first occurrence of the target integer if it exists in the array, otherwise it should return -1. The code should start with:
```python
from typing import List
de... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def search_integer(array: List[int], target: int) -> int:
"""
Searches for the first occurrence of a target integer in an array and returns its index.
If the target integer is not found, returns -1... |
evol_instruct_66k | 35,108 | Write a Python function to iterate over each item in a nested dictionary and perform the following tasks:
1. Compute and return the square of each value in the dictionary.
2. Keep a cumulative sum of the values and return the total sum once completed.
3. At each step, check if the value is an even number. If it is, sto... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def process_nested_dict(nested_dict: Dict[str, Dict[str, int]]) -> Tuple[Dict[str, Dict[str, int]], int, List[int]]:
"""
Processes a nested dictionary to compute the square of each value, ke... |
evol_instruct_66k | 35,120 | Write a Python function to juxtapose two text strings and output a dictionary containing individual alphabetical characters that are present at identical indices in both strings, along with their corresponding repetition counts. The function should ignore non-alphabetical characters and case sensitivity.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def juxtapose_strings(sentence1: str, sentence2: str) -> Dict[str, int]:
"""
Juxtaposes two text strings and returns a dictionary containing individual alphabetical characters
that are present at ide... |
evol_instruct_66k | 35,133 | Write a Python function to find the length of the longest continuously ascending subsequence in a given numerical array. The subsequence should not include any duplicate numbers, and the function should handle negative numbers and zeros. The code should start with:
```python
from typing import List
def longest_continu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_continuous_ascending_subsequence(sequence: List[int]) -> int:
"""
Calculate the length of the longest continuously ascending subsequence in a given numerical array.
The subsequence should... |
evol_instruct_66k | 35,137 | Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move either down or right at any point in time. The function should start with:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
"""
Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid.
Args:
m (int): The number of row... |
evol_instruct_66k | 35,149 | Write a Python function to compute the product of the absolute values of a list of numeric entities, truncating any fractional part to zero if present. The function should omit from calculations any figures exceeding 100. The code should start with:
```python
from typing import List
def multiply_abs_values(lst: List[f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_abs_values(lst: List[float]) -> int:
"""
Compute the product of the absolute values of a list of numeric entities, truncating any fractional part to zero if present.
Omit from calculatio... |
evol_instruct_66k | 35,159 | Write a Python function to determine if two given strings are permutations of each other. A permutation is a rearrangement of the characters in a string. The function should return `True` if the two strings are permutations of each other, and `False` otherwise. The function should handle strings of different lengths by... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import Counter
def are_permutations(s1: str, s2: str) -> bool:
"""
Determine if two strings are permutations of each other.
Args:
s1 (str): The first string to compare.
s2 (str): The second... |
evol_instruct_66k | 35,161 | Write a Python function to compute the arithmetic mean of the elements within a given list of integers. The function should handle empty lists by returning `None` instead of raising an error. The code should start with:
```python
from typing import List, Optional
def compute_arithmetic_mean(array: List[int]) -> Option... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Optional
def compute_arithmetic_mean(array: List[int]) -> Optional[float]:
"""
Computes the arithmetic mean of the elements within a given list of integers.
Args:
array (List[int]): The l... |
evol_instruct_66k | 35,170 | Write a Python function that takes a list of numerical entities and returns a generator expression that yields the square of each number in the list. The function should be designed to handle any list of integers or floats. The code should start with:
```python
from typing import List, Generator
def generate_squared_n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Generator
def generate_squared_numbers(numbers: List[float]) -> Generator[float, None, None]:
"""
Generates the squares of each number in the given list.
Args:
numbers (List[float]): A list... |
evol_instruct_66k | 35,191 | Write a Python function to encode and decode a given string using the ROT13 substitution cipher method. The function should handle both alphabetic characters (both uppercase and lowercase) and numeric characters. Special characters should remain unchanged. The function should be able to encode and decode the string cor... | Here is the Python code to solve the given problem in the markdown block:
```python
def rot13_cipher(text: str) -> str:
"""
Encodes or decodes the given string using the ROT13 substitution cipher.
This function handles both alphabetic characters (uppercase and lowercase)
and numeric characters. Special ... |
evol_instruct_66k | 35,200 | Write a Python function to replace each item in a given list with a random integer within a specified range. The function should modify the list in place and return the modified list. The code should start with:
```python
from typing import List
import random
def replace_with_random(my_list: List[int], lower_bound: in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def replace_with_random(my_list: List[int], lower_bound: int, upper_bound: int) -> List[int]:
"""
Replaces each item in the given list with a random integer within the specified range.
... |
evol_instruct_66k | 35,201 | Write a Python function to initialize a 2D list (matrix) with a given value. The matrix should have `m` rows and `n` columns. The function should handle cases where `m` or `n` is zero, returning an empty list. The code should start with:
```python
from typing import List
def initialize_matrix(m: int, n: int, value: in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def initialize_matrix(m: int, n: int, value: int) -> List[List[int]]:
"""
Initializes a 2D list (matrix) with the specified number of rows and columns,
and sets each element to the given value.
... |
evol_instruct_66k | 35,204 | Write a Python function to split a given string based on multiple delimiters. The function should accept a string and a list of delimiters, and return a list of words obtained by splitting the string at any of the specified delimiters. The function should handle edge cases such as empty strings, empty delimiters list, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def split_string_by_delimiters(s: str, delimiters: List[str]) -> List[str]:
"""
Splits a given string based on multiple delimiters and returns a list of words.
Args:
s (str): The i... |
evol_instruct_66k | 35,209 | Write a Python function to truncate a given string to its first `n` characters. If the length of the string is less than `n`, return the string as is. The function should handle cases where `n` is greater than the length of the string, and where `n` is less than or equal to zero. The code should start with:
```python
d... | Here is the Python code to solve the given problem in the markdown block:
```python
def truncate_string(string: str, n: int) -> str:
"""
Truncates the given string to its first `n` characters.
Args:
string (str): The string to be truncated.
n (int): The number of characters to keep from the... |
evol_instruct_66k | 35,217 | Write a Python function to concatenate a list of textual elements into a single string with a specified delimiter. The function should handle an empty list by returning an empty string. The code should start with:
```python
from typing import List
def concatenate_with_delimiter(elements: List[str], delimiter: str = ''... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def concatenate_with_delimiter(elements: List[str], delimiter: str = '') -> str:
"""
Concatenates a list of textual elements into a single string with a specified delimiter.
Args:
elements (... |
evol_instruct_66k | 35,222 | Write a Python function to extract values from a given list at specified ordinal positions, considering that ordinal positions start at 1. The function should handle cases where the specified positions are out of the list's bounds by returning `None` for those positions.
The code 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, Optional
def extract_values_at_positions(num_list: List[int], positions: List[int]) -> List[Optional[int]]:
"""
Extracts values from a list at specified ordinal positions, considering that ordinal posit... |
evol_instruct_66k | 35,265 | Write a Python function to iterate through a given array and print each element in reverse order without using built-in reverse functions. Additionally, implement a check for negative numbers and return an error message if any negative number is found.
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 print_reverse_with_check(arr: List[int]) -> None:
"""
Iterates through the given array and prints each element in reverse order without using built-in reverse functions.
If any negative number is... |
evol_instruct_66k | 35,267 | Write a Python function that takes a list of integers as input and returns a list of the squares of the even numbers from the input list. The function should use a `while` loop instead of a `for` loop and should handle any potential errors gracefully using exception handling.
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 get_squared_evens(nums: List[int]) -> List[int]:
"""
Returns a list of the squares of the even numbers from the input list.
Args:
nums (List[int]): A list of integers.
Returns:
... |
evol_instruct_66k | 35,273 | Write a Python function to merge two nested dictionaries. The function should ensure that all elements from both dictionaries are retained in the merged result, even if there are overlapping keys. If a key exists in both dictionaries and both values are dictionaries, the function should recursively merge these nested d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def deep_merge_dicts(dict1: Dict, dict2: Dict) -> Dict:
"""
Merges two nested dictionaries recursively. If a key exists in both dictionaries and both values are dictionaries,
the function recursively... |
evol_instruct_66k | 35,276 | Write a Python function to sort a list of floating-point numbers in descending order. The function should take a list of floating-point numbers as input and return a new list with the numbers sorted in descending order. The original list should not be modified.
The code should start with:
```python
from typing import ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_descending(numbers: List[float]) -> List[float]:
"""
Sorts a list of floating-point numbers in descending order.
Args:
numbers (List[float]): The list of floating-point numbers to b... |
evol_instruct_66k | 35,298 | Write a Python function to determine if two given strings are permutations of each other. A permutation of a string is another string that contains the same characters, only the order of characters can be different. The function should return a boolean value indicating whether the two strings are permutations of each o... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import Dict
def are_permutations(str1: str, str2: str) -> bool:
"""
Determines if two given strings are permutations of each other.
Args:
str1 (str): The first string to compare.
str2 (str): T... |
evol_instruct_66k | 35,299 | Write a Python function to validate email addresses using a regular expression. The function should determine if a given email address conforms to a standard email format. The code should start with:
```python
import re
def validate_email(email: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_email(email: str) -> bool:
"""
Validate an email address using a regular expression.
Args:
email (str): The email address to validate.
Returns:
bool: True if the email is valid, ... |
evol_instruct_66k | 35,320 | Write a Python function to add two matrices and return the result as a new matrix. The function should handle sparse matrices efficiently, meaning it should only perform addition on non-zero elements to optimize performance. The matrices `a` and `b` are guaranteed to have the same dimensions.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def add_matrices(a: List[List[int]], b: List[List[int]]) -> List[List[int]]:
"""
Adds two matrices and returns the result as a new matrix.
The function handles sparse matrices efficiently by only per... |
evol_instruct_66k | 35,325 | Write a Python function to compute the centroid of a triangle given its vertices. The vertices are provided as a list of tuples, where each tuple represents the coordinates of a vertex in a 2D plane. The function should return the centroid as a tuple of two floating-point numbers representing the x and y coordinates of... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def compute_centroid(vertices: List[Tuple[float, float]]) -> Tuple[float, float]:
"""
Compute the centroid of a triangle given its vertices.
Args:
vertices (List[Tuple[float, float]])... |
evol_instruct_66k | 35,328 | Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should handle edge cases such as a 0x0 grid or a grid with only one row or column.
The code should start with:
```python
from typing ... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
"""
Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid.
Args:
m (int): The number of row... |
evol_instruct_66k | 35,337 | Write a Python function to find the common elements between two lists of numerical values. The function should efficiently determine the intersection of the two lists and return the result as a sorted list. The code should start with:
```python
from typing import List
def find_common_elements(list1: List[int], list2: ... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def find_common_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Find the common elements between two lists of numerical values and return them as a sorted list.
Args:
list1 ... |
evol_instruct_66k | 35,340 | Write a Python function to count the frequency of each character in a given string. The function should return a dictionary where the keys are characters from the string and the values are the counts of those characters. The code should start with:
```python
from typing import Dict
def count_characters(str1: str) -> D... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import Dict
def count_characters(str1: str) -> Dict[str, int]:
"""
Count the frequency of each character in the given string.
Args:
str1 (str): The input string to count characters from.
Returns:... |
evol_instruct_66k | 35,353 | Write a Python function to validate a hexadecimal color code using a regular expression. The hexadecimal color code should be in the format `#RRGGBB`, where `RR`, `GG`, and `BB` are two-digit hexadecimal numbers representing the red, green, and blue components of the color, respectively. The function should return `Tru... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_hex_color(code: str) -> bool:
"""
Validate if the given string is a valid hexadecimal color code in the format #RRGGBB.
Args:
code (str): The string to be validated as a hexadecimal color cod... |
evol_instruct_66k | 35,362 | Write a Python function to determine if any of the tuples in a given list of tuples contains the character 'k'. The function should return `True` if at least one tuple contains 'k', otherwise it should return `False`.
The code should start with:
```python
from typing import List, Tuple
def contains_k(tuples: List[Tup... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def contains_k(tuples: List[Tuple[str]]) -> bool:
"""
Determines if any of the tuples in the provided list contains the character 'k'.
Args:
tuples (List[Tuple[str]]): A list of tuple... |
evol_instruct_66k | 35,388 | Write a Python function to analyze and report on the contents of a given dictionary. The function should return a dictionary containing the following information:
1. The total number of keys in the input dictionary.
2. A count of each data type present in the dictionary values.
3. The number of keys with empty values (... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def analyze_dictionary(d: Dict[str, Any]) -> Dict[str, Any]:
"""
Analyzes the contents of a given dictionary and returns a report containing:
1. The total number of keys.
2. A count of each ... |
evol_instruct_66k | 35,406 | Write a Python function to count the number of unique elements in a given list of integers. The function should efficiently handle large lists and return the count of unique elements.
The code should start with:
```python
from typing import List
def count_unique_elements(elements: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_unique_elements(elements: List[int]) -> int:
"""
Counts the number of unique elements in a given list of integers.
Args:
elements (List[int]): The list of integers from which to co... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.