source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 24,277 | Write a Python function to safely and efficiently erase a key-value pair from a dictionary, including handling nested dictionaries. The function should ensure that the key is removed from all levels of nested dictionaries if it exists. The function should also handle the case where the key does not exist in the diction... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_key_from_dict(d: dict, key: str) -> dict:
"""
Safely removes a key-value pair from the dictionary and any nested dictionaries.
Args:
d (dict): The dictionary from which to remove the key.
key (str... |
evol_instruct_66k | 24,283 | 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 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:
```python
from typing impo... | 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 | 24,292 | Write a Python function to calculate the least common multiple (LCM) and the greatest common divisor (GCD) for each distinct pair of numbers in a given list. The list can contain up to 100 numbers. The function should return a dictionary where the keys are tuples representing each distinct pair of numbers, and the valu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
import math
from itertools import combinations
def calculate_lcm_gcd_pairs(numbers: List[int]) -> Dict[Tuple[int, int], Tuple[int, int]]:
"""
Calculate the least common multiple (LCM) and gr... |
evol_instruct_66k | 24,294 | Write a Python function to convert a list of digit-centric character strings into their corresponding integer counterparts and determine the progressive accumulation of their sums. The function should return a list of these progressive sums.
The code should start with:
```python
from typing import List
def progressiv... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def progressive_sum_of_digits(lst: List[str]) -> List[int]:
"""
Converts a list of digit-centric character strings into their integer counterparts and calculates the progressive accumulation of their sum... |
evol_instruct_66k | 24,300 | Write a Python function to efficiently merge two pre-sorted lists into a single sorted list. The function should avoid using the built-in `sort()` method and instead use a two-pointer technique to achieve the merge. The code should start with:
```python
from typing import List
def merge_sorted_lists(lst1: List[int], l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_lists(lst1: List[int], lst2: List[int]) -> List[int]:
"""
Merges two pre-sorted lists into a single sorted list using a two-pointer technique.
Args:
lst1 (List[int]): The fi... |
evol_instruct_66k | 24,304 | Write a Python function to calculate the absolute difference between two given numbers. The function should take two integers as input and return the absolute difference as an integer.
The code should start with:
```python
def absolute_difference(num1: int, num2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def absolute_difference(num1: int, num2: int) -> int:
"""
Calculate the absolute difference between two given numbers.
Args:
num1 (int): The first number.
num2 (int): The second number.
Returns:
... |
evol_instruct_66k | 24,312 | Write a Python function to create a dictionary where each element of a given tuple is the key, and its corresponding position (index) in the tuple is the value. The function should handle tuples of any length and ensure that the dictionary is correctly constructed.
The code should start with:
```python
from typing imp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict
def tuple_to_index_dict(t: Tuple) -> Dict:
"""
Converts a tuple into a dictionary where each element of the tuple is the key,
and its corresponding index in the tuple is the value.
Args:
... |
evol_instruct_66k | 24,321 | Write a Python function to find and return all distinct elements from a given list while preserving their original order of first appearance. The function should handle lists of any length, including empty lists.
The code should start with:
```python
from typing import List
def unique_elements_preserving_order(lst: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def unique_elements_preserving_order(lst: List[int]) -> List[int]:
"""
Returns a list of all distinct elements from the given list, preserving the order of their first appearance.
Args:
lst ... |
evol_instruct_66k | 24,340 | Write a Python function to create a detailed dictionary structure for a scholar, including nominal data, years alive, academic scores, and the anticipated year of leaving academia. The function should handle cases where some information is unknown (e.g., the scholar is still alive or the year of leaving academia is not... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def create_scholar_profile(first_name: str, last_name: str, birth_year: int, death_year: Optional[int], academic_scores: List[int], year_leaving_academia: Optional[int]) -> dict:
"""
Create a d... |
evol_instruct_66k | 24,364 | Write a Python function to determine if there are any duplicate elements within a given list of integers such that the indices of these duplicates are within a specified distance `k` from each other. The function should return `True` if such duplicates exist, otherwise `False`.
The code should start with:
```python
fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def contains_nearby_duplicate(nums: List[int], k: int) -> bool:
"""
Determines if there are any duplicate elements in the list such that the indices of these duplicates
are within a specified distanc... |
evol_instruct_66k | 24,365 | Write a Python function to flatten a nested list, which is comprised of multiple individual lists, into a single flat list. The function should handle any level of nested lists, including lists within lists, and should return a single list containing all the elements in a flat structure.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def flatten_list(nested_list: List[Any]) -> List[Any]:
"""
Flattens a nested list into a single flat list.
Args:
nested_list (List[Any]): The nested list to be flattened.
Returns:
... |
evol_instruct_66k | 24,392 | Write a Python function to remove all numbers from a given list that are divisible by 5. The function should return a new list containing only the numbers that are not divisible by 5. The code should start with:
```python
from typing import List
def remove_divisible_by_five(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 remove_divisible_by_five(numbers: List[int]) -> List[int]:
"""
Removes all numbers from the given list that are divisible by 5.
Args:
numbers (List[int]): The list of integers from whi... |
evol_instruct_66k | 24,422 | Write a Python function to determine if a given phrase is a pangram. A pangram is a sentence that contains every letter of the alphabet at least once. The function should be case-insensitive and should ignore non-alphabetic characters.
The code should start with:
```python
def is_pangram(phrase: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_pangram(phrase: str) -> bool:
"""
Determine if the given phrase is a pangram.
A pangram is a sentence that contains every letter of the alphabet at least once.
This function is case-insensitive and ignores non-al... |
evol_instruct_66k | 24,426 | Write a Python function to edit a given list by replacing an existing element with a new value. The replacement should only be performed if the length of the new value is greater than the length of the old value. If the new value has the same or shorter length, the replacement should not be performed. The function shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def replace_element_conditionally(mylist: List[str], old_value: str, new_value: str) -> List[str]:
"""
Replaces an existing element in the list with a new value if the length of the new value is greater ... |
evol_instruct_66k | 24,427 | Write a Python function to extract all numerical values from a given text using a regular expression pattern. The function should be able to detect and isolate numerical values that include integers, floating-point numbers, and scientific notation.
The code should start with:
```python
import re
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def extract_numbers(text: str) -> List[str]:
"""
Extracts all numerical values from the given text using a regular expression pattern.
Args:
text (str): The input text from which t... |
evol_instruct_66k | 24,433 | Write a Python function to create and populate a dictionary with exactly five key-value pairs. The keys should be strings representing different types of vehicles, and the values should be strings representing the brand names of those vehicles. The function should return the populated dictionary.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def create_vehicle_dictionary() -> Dict[str, str]:
"""
Creates and populates a dictionary with exactly five key-value pairs.
The keys represent different types of vehicles, and the values represent t... |
evol_instruct_66k | 24,452 | Write a Python function to find the symmetric difference between two sets of integers. The symmetric difference of two sets is the set of elements which are in either of the sets but not in their intersection. Additionally, ensure that the function handles cases where the input sets might be empty.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def symmetric_difference_of_sets(set1: Set[int], set2: Set[int]) -> Set[int]:
"""
Calculate the symmetric difference between two sets of integers.
The symmetric difference of two sets is the set of e... |
evol_instruct_66k | 24,464 | Write a Python function to remove duplicate strings from a given list and return the sorted list in alphabetical order. The comparison for duplicates should be case-insensitive.
The code should start with:
```python
from typing import List
def remove_duplicates_and_sort(strings: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def remove_duplicates_and_sort(strings: List[str]) -> List[str]:
"""
Removes duplicate strings from the given list and returns the sorted list in alphabetical order.
The comparison for duplicates i... |
evol_instruct_66k | 24,477 | Write a Python function to count the occurrences of each unique element in a given array and return the result as a dictionary where the keys are the unique elements and the values are their respective counts. The function should handle any iterable data type, including lists, tuples, and sets.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Iterable
def count_occurrences(arr: Iterable) -> Dict[str, int]:
"""
Counts the occurrences of each unique element in the given iterable.
Args:
arr (Iterable): The iterable containing the e... |
evol_instruct_66k | 24,487 | Write a Python function to swap the case of each character in a given string without using built-in Python string and char functions such as `str.lower()`, `str.upper()`, and `char.isupper()`. The function should handle both uppercase and lowercase alphabetic characters and leave non-alphabetic characters unchanged.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
def swap_case(s: str) -> str:
"""
Swaps the case of each character in the given string without using built-in string and char functions.
Args:
s (str): The input string whose case needs to be swapped.
Returns:
... |
evol_instruct_66k | 24,500 | Write a Python function to determine 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 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 rows ... |
evol_instruct_66k | 24,513 | Write a Python function to generate the squares of the first n natural numbers using a generator expression. The function should return the generator object.
The code should start with:
```python
def generate_squares(n: int) -> 'generator':
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def generate_squares(n: int) -> 'generator':
"""
Generates the squares of the first n natural numbers using a generator expression.
Args:
n (int): The number of natural numbers to square.
Returns:
gener... |
evol_instruct_66k | 24,514 | Write a Python function to generate an n x n identity matrix using the NumPy library. The function should take an integer `n` as input and return a 2D NumPy array representing the identity matrix.
The code should start with:
```python
import numpy as np
def generate_identity_matrix(n: int) -> np.ndarray:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def generate_identity_matrix(n: int) -> np.ndarray:
"""
Generate an n x n identity matrix using the NumPy library.
Args:
n (int): The size of the identity matrix.
Returns:
np.ndarray... |
evol_instruct_66k | 24,517 | Write a Python function to compute the factorial of a given non-negative integer. The function should handle edge cases such as negative numbers and non-integer inputs by returning appropriate error messages. The function should not use external libraries or modules like `math.factorial()` to perform the computation.
... | Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int or str:
"""
Compute the factorial of a given non-negative integer.
Args:
n (int): The non-negative integer for which to compute the factorial.
Returns:
int or str: The facto... |
evol_instruct_66k | 24,526 | Write a Python function to calculate the median of three given humidity levels. The function should accept three integers as input and return the median value. The median is the middle value in a sorted list of numbers. If the list has an odd number of elements, the median is the middle element. If the list has an even... | Here is the Python code to solve the given problem in the markdown block:
```python
def median_of_three(humidity1: int, humidity2: int, humidity3: int) -> int:
"""
Calculate the median of three given humidity levels.
Args:
humidity1 (int): The first humidity level.
humidity2 (int): The seco... |
evol_instruct_66k | 24,528 | Write a Python function to identify and return all valid email addresses in a given text string using a regular expression. The function should handle various email formats and return a list of all valid email addresses found in the input string.
The code should start with:
```python
from typing import List
import re
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def find_emails(text: str) -> List[str]:
"""
Identify and return all valid email addresses in the given text string.
Args:
text (str): The input text string to search for email add... |
evol_instruct_66k | 24,545 | Write a Python function to efficiently store and retrieve personal monikers and their corresponding residence locations using a suitable data structure. The function should allow adding new monikers and locations, updating existing locations, and retrieving locations based on monikers. The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Optional
def manage_monikers(monikers: Dict[str, str], operation: str, moniker: Optional[str] = None, location: Optional[str] = None) -> Optional[str]:
"""
Manages personal monikers and their correspond... |
evol_instruct_66k | 24,558 | Write a Python function to generate the square transformation of every individual element in a given list of integers. The function should return a new list containing the squared values of the original list. The code should start with:
```python
from typing import List
def square_elements(arr: List[int]) -> List[int]... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def square_elements(arr: List[int]) -> List[int]:
"""
Generates the square transformation of every individual element in the given list of integers.
Args:
arr (List[int]): The list of inte... |
evol_instruct_66k | 24,564 | Write a Python function to perform Breadth-First Search (BFS) traversal on a given tree represented as an adjacency list. The function should return the order of nodes visited during the BFS traversal starting from a specified root node.
The code should start with:
```python
from typing import List, Dict
from collecti... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
from collections import deque
def bfs_traversal(tree: Dict[int, List[int]], root: int) -> List[int]:
"""
Perform a Breadth-First Search (BFS) traversal on a tree represented as an adjacency list.
... |
evol_instruct_66k | 24,577 | Write a Python function to identify and retrieve the index and value of the element in a given tuple that matches a specified denomination. If the denomination is not found in the tuple, the function should return `None` for both the index and value.
The code should start with:
```python
from typing import Tuple, Opti... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Optional
def find_denomination(fruit_tuple: Tuple[str], denomination: str) -> Tuple[Optional[int], Optional[str]]:
"""
Identify and retrieve the index and value of the element in the given tuple that m... |
evol_instruct_66k | 24,588 | Write a Python function to calculate the product of all the numbers in a given list. The function should handle lists of integers and floating-point numbers. The code should start with:
```python
from typing import List
def product_of_list(arr: List[float]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def product_of_list(arr: List[float]) -> float:
"""
Calculate the product of all numbers in the given list.
Args:
arr (List[float]): The list of numbers (integers or floating-point numbers) ... |
evol_instruct_66k | 24,590 | Write a Python function to create a dictionary that maps each continent to its aggregate landmass in square kilometers. The function should take a list of continents and a list of corresponding landmasses as input and return a dictionary. The code should start with:
```python
from typing import List, Dict
def create_l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_landmass_dict(continents: List[str], landmasses: List[int]) -> Dict[str, int]:
"""
Creates a dictionary that maps each continent to its aggregate landmass in square kilometers.
Args... |
evol_instruct_66k | 24,594 | Write a Python function to compute the factorial of a given non-negative integer `n` using an iterative approach to ensure efficiency. The function should handle large values of `n` efficiently and should not use recursion or any external libraries like `functools`.
The code should start with:
```python
def factorial_... | Here is the Python code to solve the given problem in the markdown block:
```python
def factorial_iterative(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.
Ret... |
evol_instruct_66k | 24,604 | Write a Python function to create a product array where each element at the i-th position is the product of all the elements in the input array except the one at the i-th position. The function should handle arrays of integers and should be efficient.
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 product_array(numbers: List[int]) -> List[int]:
"""
Creates a product array where each element at the i-th position is the product of all elements in the input array except the one at the i-th positi... |
evol_instruct_66k | 24,610 | Write a Python function to sort a list of numerical values based on their divisibility characteristics with a specific numeral. The function should return a list of numbers that are divisible by the given `divisible_number` from the provided `dataset`.
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 sort_by_divisibility(dataset: List[int], divisible_number: int) -> List[int]:
"""
Returns a list of numbers from the dataset that are divisible by the given divisible_number.
Args:
datas... |
evol_instruct_66k | 24,654 | Write a Python function to determine if two given strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should ignore spaces and be case-insensitive.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(str1: str, str2: str) -> bool:
"""
Determine if two strings are anagrams of each other.
Args:
str1 (str): The first string to compare.
str2 (str): The second string to compare.
Returns:... |
evol_instruct_66k | 24,656 | Write a Python function to transform a binary tree into a doubly-linked list (DLL) in-place. The DLL should be in the order of an in-order traversal of the binary tree. The function should return the head of the DLL.
The code should start with:
```python
class TreeNode:
def __init__(self, value=0, left=None, right... | Here is the Python code to solve the given problem in the markdown block:
```python
class TreeNode:
def __init__(self, value=0, left=None, right=None):
self.value = value
self.left = left
self.right = right
def binary_tree_to_dll(root: TreeNode) -> TreeNode:
"""
Transforms a binary ... |
evol_instruct_66k | 24,658 | Write a Python function to sort a collection of floating-point values in ascending order using the merge sort algorithm. The merge sort algorithm should be implemented from scratch without using Python's built-in sorting functions.
The code should start with:
```python
from typing import List
def merge_sort_floats(nu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort_floats(numbers: List[float]) -> List[float]:
"""
Sorts a collection of floating-point values in ascending order using the merge sort algorithm.
Args:
numbers (List[float]): Th... |
evol_instruct_66k | 24,661 | Write a Python function to find the smallest number in a given list of integers. The function should be efficient and handle edge cases such as an empty list or a list with a single element. The code should start with:
```python
from typing import List
def find_smallest_number(int_list: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_smallest_number(int_list: List[int]) -> int:
"""
Find the smallest number in a given list of integers.
Args:
int_list (List[int]): The list of integers from which to find the smalle... |
evol_instruct_66k | 24,663 | Write a Python function to calculate the cumulative sum of all numerical values contained within a provided list of tuples. The function should be capable of navigating nested tuple structures and disregarding any non-numeric entities. Additionally, the function should handle complex numbers, extracting their real part... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Union
def cumulative_sum(tuples: List[Union[Tuple, int, float, complex]]) -> float:
"""
Calculate the cumulative sum of all numerical values contained within a provided list of tuples.
This f... |
evol_instruct_66k | 24,680 | Write a Python function to implement the Bubble Sort algorithm to sort a list of integers in ascending order. The function should return the sorted list. The code should start with:
```python
from typing import List
def bubble_sort(unsorted_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 bubble_sort(unsorted_list: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order using the Bubble Sort algorithm.
Args:
unsorted_list (List[int]): The list of integers... |
evol_instruct_66k | 24,682 | Write a Python function to retrieve the last element and the second last element from a given list without using built-in functions like `len()`, `[-1]`, or `[-2]`. The function should handle lists of any length, including empty lists and lists with fewer than two elements.
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, Tuple, Optional
def get_last_and_second_last_elements(arr: List[int]) -> Tuple[Optional[int], Optional[int]]:
"""
Retrieves the last and second last elements from a given list without using built-in fun... |
evol_instruct_66k | 24,696 | Write a Python function to find the prime factors of a given number `N` efficiently, ensuring that the solution does not exceed a time complexity of O(sqrt(N)). Additionally, the solution should return a dictionary where the keys are the prime factors and the values are their respective powers in the factorization of `... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import math
def prime_factors(n: int) -> Dict[int, int]:
"""
Find the prime factors of a given number `n` and return them as a dictionary
where the keys are the prime factors and the values are their... |
evol_instruct_66k | 24,703 | Write a Python function to count the number of occurrences of a given word in an array of strings and the number of words that are anagrams of the given word. An anagram is a word formed by rearranging the letters of a different word, using all the original letters exactly once.
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, Tuple
def count_occurrences_and_anagrams(words: List[str], target_word: str) -> Tuple[int, int]:
"""
Count the number of occurrences of a given word in an array of strings and the number of words that a... |
evol_instruct_66k | 24,741 | Write a Python function to recursively calculate the cumulative total of all numerical elements within a multi-dimensional array. The array may contain sub-arrays of various depths and configurations, and each sub-array may contain a mix of numerical elements and further sub-arrays. The function should handle edge case... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union, List
def recursive_sum(input_array: Union[List, int, float]) -> float:
"""
Recursively calculates the cumulative total of all numerical elements within a multi-dimensional array.
Args:
inp... |
evol_instruct_66k | 24,756 | Write a Python function to evaluate a mathematical proposition involving two double integers `x` and `y`. The proposition should be a logical expression that evaluates to `True` if `x` is equal to 4 and `y` is equal to 8, and `False` otherwise. The function should return the result of this logical expression.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
def evaluate_proposition(x: int, y: int) -> bool:
"""
Evaluates a mathematical proposition involving two double integers x and y.
The proposition is True if x is equal to 4 and y is equal to 8, and False otherwise.
Args... |
evol_instruct_66k | 24,770 | Write a Python function to convert a given sequence of characters into its equivalent hexadecimal notation. Each character in the sequence should be converted to its corresponding hexadecimal value, and the results should be concatenated into a single string. The function should handle any sequence of characters, inclu... | Here is the Python code to solve the given problem in the markdown block:
```python
def text_to_hex(text: str) -> str:
"""
Converts a given sequence of characters into its equivalent hexadecimal notation.
Args:
text (str): The input sequence of characters to be converted.
Returns:
str:... |
evol_instruct_66k | 24,780 | Write a Python function to generate a matrix of size `m x n` with a specified value. If no value is provided, the matrix should be initialized with zeros. 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, Optional
def gen... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def generate_matrix(m: int, n: int, value: Optional[int] = None) -> List[List[int]]:
"""
Generate a matrix of size m x n with a specified value. If no value is provided, the matrix is initializ... |
evol_instruct_66k | 24,787 | Write a Python function to perform a binary search on a sorted list of numbers to find the index of a given element. The function should not use any built-in Python functions or libraries for the search operation. The function should return the index of the element if found, otherwise return -1.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_search(nums: list, x: int) -> int:
"""
Perform a binary search on a sorted list to find the index of a given element.
Args:
nums (list): A sorted list of integers.
x (int): The integer to search f... |
evol_instruct_66k | 24,794 | Write a Python function to determine if a given target integer is present in a list of integers. The function should return a boolean value indicating whether the target is found in the list. The code should start with:
```python
from typing import List
def is_target_in_list(nums: List[int], target: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def is_target_in_list(nums: List[int], target: int) -> bool:
"""
Determines if the target integer is present in the given list of integers.
Args:
nums (List[int]): A list of integers to se... |
evol_instruct_66k | 24,812 | Write a Python function to find the length of the longest continuous sequence of unique characters in a given string. The function should efficiently track the longest substring without repeating characters.
The code should start with:
```python
def longest_unique_substring_length(s: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def longest_unique_substring_length(s: str) -> int:
"""
Calculate the length of the longest substring without repeating characters.
Args:
s (str): The input string to analyze.
Returns:
int: The length o... |
evol_instruct_66k | 24,825 | Write a Python function to calculate the sum of all elements in two lists `A` and `B`, and also find the cross sum of elements at the same index position in both lists. The cross sum is defined as the sum of the products of corresponding elements in `A` and `B`. Ensure the function handles potential overflow errors by ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_sums(A: List[int], B: List[int]) -> (int, int, int):
"""
Calculate the sum of all elements in two lists A and B, and the cross sum of elements at the same index position in both lists.
... |
evol_instruct_66k | 24,828 | Write a Python function to create a new list where each element is the factorial of the corresponding element in the given input list. The input list contains non-negative integers.
The code should start with:
```python
from typing import List
import math
def factorial_sequence(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
import math
def factorial_sequence(input_list: List[int]) -> List[int]:
"""
Creates a new list where each element is the factorial of the corresponding element in the given input list.
Args:
... |
evol_instruct_66k | 24,834 | Write a Python function to calculate the square and cube of a given number. The function should return a tuple containing the square and cube of the number. Additionally, ensure that the function handles input validation to accept only numeric values (integers or floats). If the input is not numeric, the function shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_square_and_cube(number):
"""
Calculate the square and cube of a given number.
Args:
number: A numeric value (integer or float) for which to calculate the square and cube.
Returns:
tuple: A... |
evol_instruct_66k | 24,835 | Write a Python function to find the minimum value and the index of the minimum value in a given list of numbers. Additionally, identify and explain a piece of erroneous code that should not be used to solve the problem. The function should start with:
```python
from typing import List, Tuple
def find_min_value_and_ind... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_min_value_and_index(numbers: List[int]) -> Tuple[int, int]:
"""
Find the minimum value and its index in a given list of numbers.
Args:
numbers (List[int]): The list of number... |
evol_instruct_66k | 24,848 | Write a Python function to calculate the frequency of unique case-sensitive alphabetic characters within a given sentence. The function should ignore all non-alphabetic characters and return a dictionary where the keys are the characters and the values are their respective frequencies.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
from collections import Counter
def calculate_character_frequency(sentence: str) -> Dict[str, int]:
"""
Calculate the frequency of unique case-sensitive alphabetic characters in a given sentence.
Ar... |
evol_instruct_66k | 24,859 | Write a Python function to compute the cumulative total of the cubed values of all whole numbers within the range of 1 through to and including `n` using a mathematical formula. The function should be efficient and avoid the use of loops.
The code should start with:
```python
def cumulative_total_of_cubes(n: int) -> i... | Here is the Python code to solve the given problem in the markdown block:
```python
def cumulative_total_of_cubes(n: int) -> int:
"""
Compute the cumulative total of the cubed values of all whole numbers from 1 to n using a mathematical formula.
Args:
n (int): The upper limit of the range (inclusiv... |
evol_instruct_66k | 24,864 | Write a Python function to invert the order of elements in a given list without modifying the original list. The function should return a new list with the elements in reverse order.
The code should start with:
```python
from typing import List
def reverse_list(original_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 reverse_list(original_list: List[int]) -> List[int]:
"""
Returns a new list with the elements of the original list in reverse order.
Args:
original_list (List[int]): The list to be rever... |
evol_instruct_66k | 24,867 | Write a Python function to calculate the compound interest using Principal, Rate, and Time, considering different compounding periods such as yearly, quarterly, and monthly. The interest rate should follow a Gaussian distribution with a given mean and standard deviation. The function should return a dictionary containi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import random
import math
def calculate_compound_interest(principal: float, mean_rate: float, std_dev_rate: float, time: float) -> Dict[str, float]:
"""
Calculate the compound interest for different comp... |
evol_instruct_66k | 24,870 | Write a Python function to perform a linear search on a given list of integers to find the index of a specified target element. If the target element is not found, the function should return -1. The function should be robust and handle various types of input, including empty lists, lists with duplicate elements, and li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def linear_search(arr: List[int], target: int) -> int:
"""
Perform a linear search on a list of integers to find the index of a specified target element.
Args:
arr (List[int]): The list of i... |
evol_instruct_66k | 24,883 | Write a Python function to print all keys and values from a dictionary, handling both simple and nested dictionaries. The function should be optimized for computational efficiency and should correctly handle the case where the dictionary values are nested dictionaries.
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, Any
def print_dictionary(dictionary: Dict[str, Any]) -> None:
"""
Prints all keys and values from a dictionary, handling nested dictionaries.
Args:
dictionary (Dict[str, Any]): The dictiona... |
evol_instruct_66k | 24,887 | Write a Python function to find the second, third, and fourth smallest numbers in a given multidimensional array and return them in ascending order. The function should handle duplicate values and edge cases where the array has less than 4 unique numbers. If there are fewer than 4 unique numbers, the function should re... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_smallest_numbers(array: List[List[int]]) -> List[int]:
"""
Finds the second, third, and fourth smallest numbers in a given multidimensional array and returns them in ascending order.
Handles... |
evol_instruct_66k | 24,892 | Write a Python function to filter and recommend movies based on a given genre and a minimum rating threshold. The function should return a list of movie titles that match the specified genre and have a rating greater than or equal to the given threshold.
The code should start with:
```python
from typing import List, D... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def recommend_movies(movies: List[Dict[str, str]], genre: str, min_rating: float) -> List[str]:
"""
Recommends movies based on a given genre and a minimum rating threshold.
Args:
movie... |
evol_instruct_66k | 24,893 | Write a Python function to sort a given array of integers in ascending order and validate if the sorted array forms an arithmetic sequence. If the array after sorting is an arithmetic sequence, the function should return `True`, otherwise `False`. The function should start with:
```python
from typing import List
def i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_arithmetic_sequence(arr: List[int]) -> bool:
"""
Sorts the given array of integers in ascending order and checks if the sorted array forms an arithmetic sequence.
Args:
arr (List[int]... |
evol_instruct_66k | 24,902 | Write a Python function to find the second largest value in a given list of integers. The function should handle lists with duplicate values and should be efficient in terms of both time and space complexity. The code should start with:
```python
from typing import List
def find_second_largest(numbers: List[int]) -> i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_second_largest(numbers: List[int]) -> int:
"""
Find the second largest value in a given list of integers.
Args:
numbers (List[int]): The list of integers from which to find the seco... |
evol_instruct_66k | 24,924 | Write a Python function to compute the factorial of each numerical entity within a given array and return a transformed array. The function should handle erroneous inputs and edge scenarios by raising a custom exception if the array contains non-integer or negative entities. Additionally, identify and correct the inacc... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from math import factorial
def factorial_array(input_array: List[int]) -> List[int]:
"""
Computes the factorial of each numerical entity within a given array and returns a transformed array.
Args:
... |
evol_instruct_66k | 24,936 | Write a Python function to construct an SQL query that extracts records of staff members whose tenure exceeds a duration of 5 years in the organization. The results should be sorted by department, and within each department, by position level. Additionally, include the most recent project involvement and the performanc... | Here is the Python code to solve the given problem in the markdown block:
```python
def construct_sql_query(current_date: str) -> str:
"""
Constructs an SQL query to extract records of staff members whose tenure exceeds 5 years.
The results are sorted by department and within each department by position lev... |
evol_instruct_66k | 24,944 | Write a Python function to implement a Fibonacci Search algorithm that searches for a specific number in a provided Fibonacci sequence of numbers and identifies and corrects erroneous elements within that sequence. The function should handle potential edge cases, such as a missing Fibonacci number or the target number ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def fibonacci_search_and_fix(sequence: List[int], target_num: int) -> int:
"""
Searches for a target number in a provided Fibonacci sequence and corrects any erroneous elements.
Args:
sequen... |
evol_instruct_66k | 24,950 | Write a Python function to generate a unique, case-insensitive ID for a given string. The ID should remain the same despite changing the case of input characters. The function should start with:
```python
def generate_case_insensitive_id(s: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def generate_case_insensitive_id(s: str) -> int:
"""
Generate a unique, case-insensitive ID for a given string.
Args:
s (str): The input string for which to generate the ID.
Returns:
int: A unique ID ... |
evol_instruct_66k | 24,959 | Write a Python function to compute the factorial of a given non-negative integer `n` using memoization to optimize the time complexity. The function should cache previously computed factorial values to avoid redundant calculations.
The code should start with:
```python
def factorial(n: int) -> int:
```
| 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 memoization.
Args:
n (int): The non-negative integer for which to compute the factorial.
Returns:
int: T... |
evol_instruct_66k | 24,969 | Write a Python function to find the character with the highest frequency in a given string. If there are multiple characters with the same highest frequency, return the one that appears first in the string. The function should be case-insensitive, meaning 'A' and 'a' should be considered the same character.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
def most_frequent_char(s: str) -> str:
"""
Find the character with the highest frequency in the given string.
If there are multiple characters with the same highest frequency,
return the one that appears first in the str... |
evol_instruct_66k | 24,970 | Write a Python function to reverse the characters in a given string. The function should handle strings of varying lengths, including empty strings. 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 characters in a given string.
Args:
s (str): The input string to be reversed.
Returns:
str: The reversed string.
"""
# Use slicing to revers... |
evol_instruct_66k | 24,971 | Write a Python function to generate the reflection or mirror inversion of a specified alphanumeric string. The reflection should reverse the order of words in the string while maintaining the individual characters in each word in their original order. The function should handle any alphanumeric string input.
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
def reflect_string(s: str) -> str:
"""
Generates the reflection or mirror inversion of a specified alphanumeric string.
The reflection reverses the order of words in the string while maintaining the
individual character... |
evol_instruct_66k | 24,976 | Write a Python function to generate a random sequence of 15 characters containing at least 5 unique characters without repeating any character consecutively, as well as having no more than 3 occurrences of any single character. The function should return the generated sequence as a string.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
import string
def generate_random_sequence() -> str:
"""
Generates a random sequence of 15 characters containing at least 5 unique characters.
No character is repeated consecutively, and no character appears m... |
evol_instruct_66k | 24,986 | Write a Python function to create a hierarchical dictionary from two given lists, where the first list contains keys and the second list contains values. The hierarchical dictionary should have the structure where each key from the first list points to a dictionary that contains the corresponding value from the second ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_hierarchical_dict(keys: List[str], values: List[int]) -> Dict[str, Dict[str, int]]:
"""
Creates a hierarchical dictionary from two lists.
Args:
keys (List[str]): A list of k... |
evol_instruct_66k | 25,001 | Write a Python function to randomly select 'n' items from a given list without replacement. The function should ensure that the selection is random and that it handles cases where 'n' is greater than the length of the list by selecting all items in the list. The code should start with:
```python
from typing import List... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import random
def select_random_elements(lst: List[int], n: int) -> List[int]:
"""
Randomly selects 'n' items from the given list without replacement.
Args:
lst (List[int]): The list from ... |
evol_instruct_66k | 25,002 | Write a Python function to increment an initial score by a specified odd number and then set a final score to the incremented initial score. The function should ensure that the increment value is always an odd number. If an even number is provided, it should be converted to the next odd number before performing the inc... | Here is the Python code to solve the given problem in the markdown block:
```python
def increment_score_by_odd(initial_score: int, increment: int) -> int:
"""
Increments the initial score by a specified odd number and returns the final score.
Args:
initial_score (int): The initial score to be incre... |
evol_instruct_66k | 25,003 | Write a Python function to sort a list of strings alphabetically in ascending order. The function should handle lists of varying lengths and should not modify the original list. The code should start with:
```python
from typing import List
def sort_strings_alphabetically(strings: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_strings_alphabetically(strings: List[str]) -> List[str]:
"""
Sorts a list of strings alphabetically in ascending order without modifying the original list.
Args:
strings (List[str])... |
evol_instruct_66k | 25,013 | Write a Python function to construct a NumPy array with a specified number of negative twos and threes. The function should take two integers as input: the number of negative twos and the number of threes. The function should return a NumPy array containing the specified number of negative twos followed by the specifie... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def construct_array(num_neg_twos: int, num_threes: int) -> np.ndarray:
"""
Constructs a NumPy array with a specified number of negative twos followed by a specified number of threes.
Args:
num_ne... |
evol_instruct_66k | 25,032 | Write a Python function to construct a valid URL with the given domain, endpoint, and parameters. The function should handle erroneous inputs by ensuring that all parameters are properly encoded and converted to strings if necessary. The function should also handle cases where the parameters might be missing or contain... | Here is the Python code to solve the given problem in the markdown block:
```python
from urllib.parse import urlencode
def build_url(domain: str, endpoint: str, params: dict) -> str:
"""
Constructs a valid URL with the given domain, endpoint, and parameters.
Args:
domain (str): The domain of the U... |
evol_instruct_66k | 25,043 | Write a Python function that demonstrates the concept of higher-order functions. The function should take another function and a list of integers as arguments, and apply the given function to each element of the list, returning a new list with the results. The code should start with:
```python
from typing import Callab... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Callable, List
def apply_function_to_list(func: Callable[[int], int], lst: List[int]) -> List[int]:
"""
Applies the given function to each element of the list and returns a new list with the results.
Arg... |
evol_instruct_66k | 25,052 | Write a Python function to determine if a specific key `k` is present within a nested tuple structure. The function should recursively search through all levels of the nested tuple to find the key.
The code should start with:
```python
def find_key_in_tuple(tuple_input: tuple, k: any) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_key_in_tuple(tuple_input: tuple, k: any) -> bool:
"""
Recursively searches for a key `k` within a nested tuple structure.
Args:
tuple_input (tuple): The nested tuple structure to search within.
k (a... |
evol_instruct_66k | 25,061 | Write a Python function to implement the quicksort algorithm for sorting an array of integers. The function should follow the principles of partitioning inherent to quicksort, ensuring that the array is sorted in-place. The code should start with:
```python
from typing import List
def quicksort(arr: List[int], low: in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def quicksort(arr: List[int], low: int, high: int) -> None:
"""
Sorts the given array of integers in-place using the quicksort algorithm.
Args:
arr (List[int]): The array of integers to be s... |
evol_instruct_66k | 25,076 | Write a Python function to convert a binary number represented as a string to its decimal equivalent. The function should handle binary numbers of any length, including those with leading zeros. The code should start with:
```python
def binary_to_decimal(binary: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_decimal(binary: str) -> int:
"""
Converts a binary number represented as a string to its decimal equivalent.
Args:
binary (str): The binary number to convert, represented as a string.
Returns:
... |
evol_instruct_66k | 25,083 | Write a Python function to generate a list of standard base-10 integers within the range from 0 (inclusive) to a specified upper limit (exclusive). The function should efficiently handle large ranges and return the list of integers.
The code should start with:
```python
from typing import List
def generate_integers(u... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_integers(upper_limit: int) -> List[int]:
"""
Generate a list of standard base-10 integers from 0 (inclusive) to the specified upper limit (exclusive).
Args:
upper_limit (int): T... |
evol_instruct_66k | 25,088 | Write a Python function to sort a 3D numeric matrix using the Quick Sort algorithm. The matrix is a 2x2x5 array of floating-point numbers. The function should flatten the matrix, sort it using Quick Sort, and then reshape it back to its original 3D form.
The code should start with:
```python
import numpy as np
from ty... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List, Tuple
def quick_sort_3d_matrix(matrix: np.ndarray) -> np.ndarray:
"""
Sorts a 3D numeric matrix using the Quick Sort algorithm.
Args:
matrix (np.ndarray): A 3D numpy arra... |
evol_instruct_66k | 25,092 | Write a Python function to safely iterate through a range of numbers and print each number, while handling any potential `ArithmeticError` that might occur during the iteration. The function should start with:
```python
def safe_iteration(start: int, end: int) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def safe_iteration(start: int, end: int) -> None:
"""
Safely iterates through a range of numbers from start to end (inclusive) and prints each number,
while handling any potential ArithmeticError that might occur during the ... |
evol_instruct_66k | 25,114 | Write a Python function to extract all email addresses from a given text using a regular expression. The function should be able to handle various email address formats and domain variations. The code should start with:
```python
import re
from typing import List
def extract_emails(text: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
import re
from typing import List
def extract_emails(text: str) -> List[str]:
"""
Extracts all email addresses from the given text using a regular expression.
Args:
text (str): The text from which to extract emai... |
evol_instruct_66k | 25,120 | Write a Python function to find the position of a specified fruit in a given 2-dimensional matrix of arrays. Each sub-array represents a different type of fruit. The function should return the row and column indices of the specified fruit in a tuple. If the fruit is not found in the matrix, the function should return '... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Union
def find_fruit_position(food_matrix: List[List[str]], fruit_name: str) -> Union[Tuple[int, int], str]:
"""
Find the position of a specified fruit in a 2-dimensional matrix of arrays.
A... |
evol_instruct_66k | 25,130 | Write a Python function to sort a list of n distinct integers 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(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def insertion_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of n distinct integers using the insertion sort algorithm.
Args:
arr (List[int]): The list of distinct integers to be sort... |
evol_instruct_66k | 25,140 | Write a Python function to filter even numbers from a given list, square them, and return the length of the updated list. The function should start with:
```python
from typing import List
def filter_even_square_length(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_even_square_length(arr: List[int]) -> int:
"""
Filters even numbers from the given list, squares them, and returns the length of the updated list.
Args:
arr (List[int]): The list ... |
evol_instruct_66k | 25,162 | Write a Python function to remove all duplicate elements from a given list and return the result in descending order. The function should not use any pre-built functions except for basic list operations and the `print` function for displaying the result. 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 remove_duplicates_and_sort_descending(lst: List[int]) -> List[int]:
"""
Removes all duplicate elements from the given list and returns the result in descending order.
Args:
lst (List[int... |
evol_instruct_66k | 25,163 | Write a Python function to find all sequences in a given text that match a specific pattern. The pattern should start with a lowercase alphabetic character 'a', contain at least one numeric digit in the middle, at least one special character, and end with an uppercase alphabetic character 'Z'. The function should use R... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def find_sequences(text: str) -> List[str]:
"""
Find all sequences in the given text that match the specified pattern.
The pattern requires the sequence to start with 'a', contain at least ... |
evol_instruct_66k | 25,196 | Write a Python function to validate and categorize MAC addresses based on their first 3 bytes (Organizationally Unique Identifier or OUI) into different manufacturers. The function should handle a large collection of MAC addresses efficiently. The MAC addresses can be in either colon-separated or hyphen-separated forma... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
import re
def categorize_mac_addresses(mac_addresses: List[str]) -> Dict[str, List[str]]:
"""
Validates and categorizes MAC addresses based on their first 3 bytes (OUI) into different manufacturers... |
evol_instruct_66k | 25,206 | Write a Python function to calculate the product of all elements in a given list of integers. The function should handle an empty list by returning 1, as the product of no numbers is defined as 1. The code should start with:
```python
from typing import List
def product_of_elements(input_array: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def product_of_elements(input_array: List[int]) -> int:
"""
Calculate the product of all elements in a given list of integers.
Args:
input_array (List[int]): The list of integers for which... |
evol_instruct_66k | 25,211 | Write a Python function to determine and print the type of each element in a given list. The function should correctly identify and print "integer", "string", or "float" for each element in the list. The code should start with:
```python
from typing import List
def print_element_types(elements: List[int | str | float]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_element_types(elements: List[int | str | float]) -> None:
"""
Prints the type of each element in the given list.
Args:
elements (List[int | str | float]): A list containing element... |
evol_instruct_66k | 25,213 | Rewrite the given code to use a dictionary and nested for-loops to achieve the same functionality as the original code, which uses nested lists and multiple if-else statements. The goal is to enhance the complexity and performance of the code. The input is a nested list `nested_list` and a list `y`. The output should b... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Any
def process_nested_list(nested_list: List[List[Any]], y: List[Any]) -> List[Any]:
"""
Process a nested list to find elements from another list and return a list of found elements or None.
... |
evol_instruct_66k | 25,221 | Write a Python function to find the complex numbers with the smallest and largest magnitudes from a given array of complex numbers. If there are multiple complex numbers with the same magnitude, the function should return all of them. The function should start with:
```python
from typing import List, Tuple
def find_mi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_min_max_magnitudes(array: List[complex]) -> Tuple[List[complex], List[complex]]:
"""
Find the complex numbers with the smallest and largest magnitudes from a given array of complex number... |
evol_instruct_66k | 25,227 | Write a Python function to remove consecutive repeated characters from a given string. The function should return a new string where each sequence of repeated characters is reduced to a single character.
The code should start with:
```python
def remove_consecutive_duplicates(string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_consecutive_duplicates(string: str) -> str:
"""
Removes consecutive repeated characters from the given string.
Args:
string (str): The input string from which consecutive duplicates are to be removed.
... |
evol_instruct_66k | 25,245 | Write a Python function to calculate the factorial of a given integer using an iterative approach. The function should handle non-negative integers and return the factorial of the input number. The code should start with:
```python
def factorial(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int:
"""
Calculate the factorial of a given non-negative integer.
Args:
n (int): The non-negative integer for which to calculate the factorial.
Returns:
int: The factorial of th... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.