source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 12,290 | Write a Python function to identify and return all narcissistic numbers that are less than or equal to a given integer input. A narcissistic number (also known as a pluperfect number, an Armstrong number, or a plus perfect number) is a number that is the sum of its own digits each raised to the power of the number of d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_narcissistic_numbers(n: int) -> List[int]:
"""
Identifies and returns all narcissistic numbers that are less than or equal to a given integer input.
Args:
n (int): The upper limit t... |
evol_instruct_66k | 12,291 | Write a Python function to transform a dataset based on a list of transformation rules. The dataset is represented as a list of dictionaries, where each dictionary represents an individual record. The transformation rules are tuples of the form `(action, column, value)`, where `action` can be one of the following: `'ad... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
def transform_dataset(data: List[Dict[str, any]], rules: List[Tuple[str, str, any]]) -> List[Dict[str, any]]:
"""
Transforms a dataset based on a list of transformation rules.
Args:
... |
evol_instruct_66k | 12,292 | Write a Python function to solve the 0/1 Knapsack problem using dynamic programming. The function should take a list of item weights, a list of item values, and a maximum weight capacity as inputs, and return the maximum value that can be obtained without exceeding the weight capacity.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def knapsack(weights: List[int], values: List[int], max_weight: int) -> int:
"""
Solves the 0/1 Knapsack problem using dynamic programming.
Args:
weights (List[int]): A list of weights of th... |
evol_instruct_66k | 12,297 | Write a Python function to calculate the Least Common Multiple (LCM) of two integers `x` and `y` using an enhanced algorithm that takes into account the constraints `1 <= x, y <= 10^9`. The function should be efficient and avoid overflow issues.
The code should start with:
```python
def lcm(x: int, y: int) -> int:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
def lcm(x: int, y: int) -> int:
"""
Calculate the Least Common Multiple (LCM) of two integers x and y using an enhanced algorithm.
Args:
x (int): The first integer, where 1 <= x <= 10^9.
y (int): The second ... |
evol_instruct_66k | 12,333 | Write a Python function to sort the values of a given dictionary in descending order based on their values. The function should return a new dictionary with the same keys but with the values sorted in descending order.
The code should start with:
```python
from typing import Dict
def sort_dict_by_value_desc(input_dic... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_value_desc(input_dict: Dict[str, int]) -> Dict[str, int]:
"""
Sorts the values of a given dictionary in descending order based on their values.
Args:
input_dict (Dict[str, i... |
evol_instruct_66k | 12,340 | Write a Python function to count the number of times a given character appears in a sentence, considering both uppercase and lowercase versions of the character as the same. The function should be case-insensitive.
The code should start with:
```python
def count_character_occurrences(sentence: str, character: str) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_character_occurrences(sentence: str, character: str) -> int:
"""
Counts the number of times a given character appears in a sentence, ignoring case differences.
Args:
sentence (str): The sentence in which t... |
evol_instruct_66k | 12,345 | Write a Python function to find the youngest customers who have made at least 3 purchases and live in either New York or California from a given dataset. The dataset is a list of dictionaries, where each dictionary represents a customer with keys `'id'`, `'name'`, `'age'`, `'location'`, and `'purchases'`. The `'purchas... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def find_youngest_qualified_customers(customers: List[Dict[str, any]]) -> List[Dict[str, any]]:
"""
Finds the youngest customers who have made at least 3 purchases and live in either New York or Ca... |
evol_instruct_66k | 12,347 | Write a Python function to swap the positions of two elements in an array, ensuring that the function can handle an array of any length and data type. The function should also be able to handle cases where the array contains duplicate values. The function should raise an `IndexError` if either of the positions is out o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def swap_elements(arr: List[Any], position1: int, position2: int) -> List[Any]:
"""
Swap the positions of two elements in an array.
Args:
arr (List[Any]): The array in which to swap ele... |
evol_instruct_66k | 12,360 | Write a Python function to generate a sequence of integers from a given two-dimensional array in a clockwise spiral order. The function should take a 2D list of integers as input and return a list of integers representing the spiral order traversal of the matrix.
The code should start with:
```python
from typing impor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def spiral_order(matrix: List[List[int]]) -> List[int]:
"""
Generate a sequence of integers from a given 2D array in a clockwise spiral order.
Args:
matrix (List[List[int]]): A 2D list of in... |
evol_instruct_66k | 12,362 | Write a Python function to generate a list of squares of numbers from 0 up to a given number `n`. The function should return a list where each element is the square of the corresponding number in the range from 0 to `n`.
The code should start with:
```python
from typing import List
def generate_squares(n: int) -> Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_squares(n: int) -> List[int]:
"""
Generate a list of squares of numbers from 0 to the given number n.
Args:
n (int): The upper limit (inclusive) for generating squares.
Ret... |
evol_instruct_66k | 12,368 | Write a Python function to find the highest and lowest values within a list of integers, and also calculate the sum and average of all the integers. The function should avoid using built-in functions like `max`, `min`, and `sum`. The code should start with:
```python
from typing import List, Tuple
def find_stats(lst: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_stats(lst: List[int]) -> Tuple[int, int, int, float]:
"""
Find the highest and lowest values within a list of integers, and also calculate the sum and average of all the integers.
Ar... |
evol_instruct_66k | 12,370 | Write a Python function to find the maximum sum of any two distinct elements in a given list of integers. The function should be optimized for performance, avoiding unnecessary computations.
The code should start with:
```python
from typing import List
def max_sum_of_two_distinct_elements(list_numbers: List[int]) -> ... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def max_sum_of_two_distinct_elements(list_numbers: List[int]) -> int:
"""
Find the maximum sum of any two distinct elements in the given list of integers.
Args:
list_numbers (List[int]): T... |
evol_instruct_66k | 12,379 | Write a Python function to convert a given string into Morse code. The function should handle both uppercase and lowercase letters, digits, and spaces. The Morse code for each character should be separated by a space, and words should be separated by a slash ('/'). 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
def string_to_morse(text: str) -> str:
"""
Converts a given string into Morse code.
Args:
text (str): The input string to be converted into Morse code.
Returns:
str: The M... |
evol_instruct_66k | 12,382 | Write a Python function to calculate the square root of a given number without using any built-in functions or standard operations for square root calculation. The function should use an iterative method to approximate the square root to a high degree of accuracy.
The code should start with:
```python
def calculate_sq... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_square_root(n: float) -> float:
"""
Calculate the square root of a given number using an iterative method.
Args:
n (float): The number for which to calculate the square root.
Returns:
floa... |
evol_instruct_66k | 12,385 | Write a Python function to generate a list of multiples of a given integer `k` within a specified range `[start, end]`. The function should return a list of these multiples.
The code should start with:
```python
from typing import List
def multiples_in_range(k: int, start: int, end: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiples_in_range(k: int, start: int, end: int) -> List[int]:
"""
Generate a list of multiples of a given integer `k` within the specified range `[start, end]`.
Args:
k (int): The integ... |
evol_instruct_66k | 12,387 | Write a Python function to find the highest numerical value in a given list of integers. The function should iterate through the list and update the highest value found during the iteration. The code should start with:
```python
from typing import List
def find_highest_value(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_highest_value(numbers: List[int]) -> int:
"""
Find the highest numerical value in a given list of integers.
Args:
numbers (List[int]): A list of integers from which to find the high... |
evol_instruct_66k | 12,388 | Write a Python function to calculate the greatest common divisor (GCD) of two given integers using the Euclidean algorithm. The function should be able to handle both positive and negative integers. The code should start with:
```python
def gcd(num1: int, num2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def gcd(num1: int, num2: int) -> int:
"""
Calculate the greatest common divisor (GCD) of two integers using the Euclidean algorithm.
Args:
num1 (int): The first integer.
num2 (int): The second integer.
... |
evol_instruct_66k | 12,390 | Write a Python function to create a dictionary from two given lists, where the first list serves as the keys and the second list serves as the corresponding values. Ensure that the function handles cases where the lists are of different lengths by ignoring the extra elements in the longer list. The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def lists_to_dict(keys: List[str], values: List[int]) -> Dict[str, int]:
"""
Creates a dictionary from two lists, where the first list serves as the keys and the second list serves as the correspon... |
evol_instruct_66k | 12,403 | Write a Python function to replace all punctuation marks in a given string with a specified symbol, except for apostrophes. The function should handle multiple sentences and various punctuation marks efficiently.
The code should start with:
```python
import string
def replace_punctuation_except_apostrophe(text_string... | Here is the Python code to solve the given problem in the markdown block:
```python
import string
def replace_punctuation_except_apostrophe(text_string: str, symbol: str) -> str:
"""
Replaces all punctuation marks in the given string with the specified symbol, except for apostrophes.
Args:
text_st... |
evol_instruct_66k | 12,404 | Write a Python function to sort an array of integers in ascending order and return the sorted array. The function should handle any array of integers, including an empty array. The code should start with:
```python
from typing import List
def sort_array(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 sort_array(arr: List[int]) -> List[int]:
"""
Sorts an array of integers in ascending order and returns the sorted array.
Args:
arr (List[int]): The array of integers to be sorted.
R... |
evol_instruct_66k | 12,412 | Write a Python function to determine whether each digit in a given number is even or odd. The function should return a list of boolean values where `True` indicates that the corresponding digit is even and `False` indicates that the digit is odd. The function should handle both positive and negative integers.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def detect_even_odd_digits(number: int) -> List[bool]:
"""
Determines whether each digit in the given number is even or odd.
Args:
number (int): The number to analyze.
Returns:
... |
evol_instruct_66k | 12,424 | 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, the function should return `None`. The function should handle both unsorted and sorted lists.
The code should start with:
```python
from typing import List, Optional
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def linear_search(lst: List[int], target: int) -> Optional[int]:
"""
Perform a linear search on a list to find the index of a specified target element.
Args:
lst (List[int]): The l... |
evol_instruct_66k | 12,441 | Write a Python function to determine if a specific integer value exists within a given array of integer elements. The function should return `True` if the value is found in the array, and `False` otherwise. The code should start with:
```python
from typing import List
def value_exists_in_array(array: List[int], value:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def value_exists_in_array(array: List[int], value: int) -> bool:
"""
Determines if a specific integer value exists within a given array of integer elements.
Args:
array (List[int]): The arra... |
evol_instruct_66k | 12,448 | Write a Python function to flatten a deeply nested dictionary. The function should take a dictionary as input and return a new dictionary where all nested keys are flattened into a single level. The keys in the flattened dictionary should be constructed by concatenating the keys from the original dictionary using a spe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def flatten_nested_dict(nested_dict: Dict, separator: str = '.') -> Dict:
"""
Flattens a deeply nested dictionary into a single-level dictionary.
Args:
nested_dict (Dict): The nested diction... |
evol_instruct_66k | 12,451 | Write a Python function to compute the sum of the values of a given dictionary. The dictionary contains string keys and integer values. The function should handle dictionaries with varying numbers of key-value pairs and ensure that the sum is computed correctly.
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 Dict
def sum_of_values(dictionary: Dict[str, int]) -> int:
"""
Compute the sum of the values in a given dictionary.
Args:
dictionary (Dict[str, int]): A dictionary with string keys and integer va... |
evol_instruct_66k | 12,456 | Write a Python function to compute the N-th number in the Tribonacci Sequence. The Tribonacci Sequence is defined as follows: T0 is 0, T1 and T2 are both 1, and for any n greater than or equal to 0, Tn+3 is the sum of Tn, Tn+1, and Tn+2. The function should take an integer `n` as input and return the value of Tn.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
def tribonacci(n: int) -> int:
"""
Compute the N-th number in the Tribonacci Sequence.
The Tribonacci Sequence is defined as follows:
T0 = 0, T1 = 1, T2 = 1, and for n >= 0, Tn+3 = Tn + Tn+1 + Tn+2.
Args:
n... |
evol_instruct_66k | 12,459 | Write a Python function to calculate the product of all odd integers in a given list. The function should handle lists of any length, including empty lists. If the list contains no odd integers, the function should return 1.
The code should start with:
```python
from typing import List
def product_of_odds(arr: List[i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def product_of_odds(arr: List[int]) -> int:
"""
Calculate the product of all odd integers in the given list.
Args:
arr (List[int]): The list of integers to process.
Returns:
int... |
evol_instruct_66k | 12,464 | Write a Python function to find the position of the last occurrence of a target integer in a given list of integers. The function should traverse the list from the end to the beginning to efficiently find the last occurrence. If the target integer is not found in the list, the function should return -1.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_last_occurrence(lst: List[int], target: int) -> int:
"""
Find the position of the last occurrence of a target integer in a list.
Args:
lst (List[int]): The list of integers to searc... |
evol_instruct_66k | 12,471 | Write a Python function to remove the last item from a given list of alphabet characters and return the updated list. The function should handle cases where the list is empty by returning the empty list without any errors. The code should start with:
```python
from typing import List
def remove_last_item(lst: List[str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_last_item(lst: List[str]) -> List[str]:
"""
Removes the last item from a given list of strings and returns the updated list.
Args:
lst (List[str]): The list of strings from wh... |
evol_instruct_66k | 12,472 | Write a Python function to count the number of times a particular number is repeated in a two-dimensional array. The arrays may not be of equal length. The function should start with:
```python
from typing import List
def count_occurrences(two_d_array: List[List[int]], target: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_occurrences(two_d_array: List[List[int]], target: int) -> int:
"""
Counts the number of times a particular number is repeated in a two-dimensional array.
Args:
two_d_array (List[Li... |
evol_instruct_66k | 12,476 | Write a Python function to reverse the order of keys in a given dictionary. The function should return a new dictionary with the keys in the reversed order while maintaining the same key-value pairs. The code should start with:
```python
from typing import Dict
def reverse_keys(dictionary: Dict[str, int]) -> Dict[str,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def reverse_keys(dictionary: Dict[str, int]) -> Dict[str, int]:
"""
Reverses the order of keys in the given dictionary while maintaining the same key-value pairs.
Args:
dictionary (Dict[str,... |
evol_instruct_66k | 12,481 | Write a Python function to compute the transpose of a given 3x3 bi-dimensional matrix and validate the input to ensure it is a perfect square matrix. The function should return the transposed matrix if the input is valid; otherwise, it should return an appropriate error message.
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, Union
def transpose_3x3_matrix(matrix: List[List[int]]) -> Union[List[List[int]], str]:
"""
Computes the transpose of a given 3x3 bi-dimensional matrix and validates the input.
Args:
matrix... |
evol_instruct_66k | 12,510 | Write a Python function to rearrange the elements in a given tuple so that they are sorted in descending order. Additionally, the largest even number should be at the beginning and the largest odd number at the end. The function should return the rearranged tuple.
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 Tuple
def rearrange_tuple(input_tuple: Tuple[int]) -> Tuple[int]:
"""
Rearranges the elements in the given tuple so that they are sorted in descending order.
The largest even number is placed at the begin... |
evol_instruct_66k | 12,532 | Write a Python function to convert a given binary number into its equivalent octal number. The function should handle the conversion by grouping the binary digits into sets of three, converting each group to its octal equivalent, and then concatenating the results. The function should also handle padding the binary num... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_octal(binary_num: str) -> str:
"""
Converts a given binary number to its equivalent octal number.
Args:
binary_num (str): The binary number to be converted, represented as a string.
Returns:
... |
evol_instruct_66k | 12,535 | Write a Python function to reshape a given 1D list into a 2D list with specified dimensions. The function should ensure that the reshaped matrix has the correct number of elements as in the original list. If the reshape operation is not possible due to mismatch in the number of elements, the function should return `Non... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def reshape_list(vector: List[int], rows: int, cols: int) -> Optional[List[List[int]]]:
"""
Reshape a given 1D list into a 2D list with specified dimensions.
Args:
vector (List[int... |
evol_instruct_66k | 12,542 | Write a Python function to merge two dictionaries and convert the resulting dictionary's keys into a set, ensuring that the set contains only unique keys. The function should handle cases where the dictionaries have overlapping keys, and the resulting set should reflect the uniqueness of the keys.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Set
def merge_dicts_to_set(dict1: Dict[str, int], dict2: Dict[str, int]) -> Set[str]:
"""
Merges two dictionaries and returns a set of unique keys from the merged dictionary.
Args:
dict1 (D... |
evol_instruct_66k | 12,568 | Write a Python function to implement a linear search algorithm that locates a specific element within a one-dimensional list. The list may contain a mix of integers, strings, lists, and dictionaries. The function should return the index of the target element if found, otherwise return -1. The solution must ensure a tim... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, List
def linear_search(arr: List[Any], target: Any) -> int:
"""
Perform a linear search to locate a specific element within a one-dimensional list.
Args:
arr (List[Any]): The list to search ... |
evol_instruct_66k | 12,582 | Write a Python function to determine the appropriate classification category for a given hexadecimal representation within the paradigm of data types. The function should accept a hexadecimal string as input and return the corresponding data type as a string.
The code should start with:
```python
def classify_hexadeci... | Here is the Python code to solve the given problem in the markdown block:
```python
def classify_hexadecimal(hex_str: str) -> str:
"""
Determine the appropriate classification category for a given hexadecimal representation.
Args:
hex_str (str): The hexadecimal string to classify.
Returns:
... |
evol_instruct_66k | 12,584 | Write a Python function to filter and sort a list of user documents based on specific criteria. Each user document is represented as a dictionary with keys 'name', 'creationDate', and 'address'. The 'address' field is itself a dictionary containing 'city' and 'state'. The function should return the first 5 user documen... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def filter_and_sort_users(users: List[Dict]) -> List[Dict]:
"""
Filters and sorts a list of user documents based on specific criteria.
Args:
users (List[Dict]): A list of user document... |
evol_instruct_66k | 12,588 | Write a Python function to estimate the occurrence count and relative proportion of a specific value within a given list. The function should return both the count of the value and its proportion relative to the total number of elements in the list. The code should start with:
```python
from typing import List, Tuple
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def estimate_value(lst: List[int], value: int) -> Tuple[int, float]:
"""
Estimate the occurrence count and relative proportion of a specific value within a given list.
Args:
lst (List... |
evol_instruct_66k | 12,589 | Write a Python function to compute the sum of the harmonic series up to the N-th term. The harmonic series is defined as the sum of the reciprocals of the first N natural numbers. The function should take an integer N as input and return the sum of the series.
The code should start with:
```python
def harmonic_series_... | Here is the Python code to solve the given problem in the markdown block:
```python
def harmonic_series_sum(N: int) -> float:
"""
Compute the sum of the harmonic series up to the N-th term.
The harmonic series is defined as the sum of the reciprocals of the first N natural numbers:
H_N = 1/1 + 1/2 + 1/... |
evol_instruct_66k | 12,598 | Write a Python function to find the maximum value in a given list of integers using the `numpy` library. The function should return the maximum value. The code should start with:
```python
from typing import List
import numpy as np
def find_max_value(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import numpy as np
def find_max_value(numbers: List[int]) -> int:
"""
Find the maximum value in a given list of integers using the numpy library.
Args:
numbers (List[int]): A list of integer... |
evol_instruct_66k | 12,601 | Write a Python function to convert a Roman numeral string to its corresponding decimal (integer) value. The Roman numeral system uses symbols to represent values as follows: 'I' (1), 'V' (5), 'X' (10), 'L' (50), 'C' (100), 'D' (500), 'M' (1000). Roman numerals are usually written from largest to smallest from left to r... | Here is the Python code to solve the given problem in the markdown block:
```python
def roman_to_decimal(roman: str) -> int:
"""
Convert a Roman numeral string to its corresponding decimal (integer) value.
Args:
roman (str): The Roman numeral string to be converted.
Returns:
int: The d... |
evol_instruct_66k | 12,604 | Write a Python function to convert a range of decimal numbers to their ternary (base 3) representation. The function should take two integers, `start` and `end`, and return a list of ternary strings representing the decimal numbers in the given range, inclusive.
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 decimal_to_ternary(decimal_num: int) -> str:
"""
Converts a single decimal number to its ternary (base 3) representation.
Args:
decimal_num (int): The decimal number to convert.
Ret... |
evol_instruct_66k | 12,609 | Write a Python function that demonstrates the functionality of the `break` statement within a `for` loop. The function should iterate over a range of numbers and print each number until a specific condition is met, at which point the loop should terminate using the `break` statement. The function should also return the... | Here is the Python code to solve the given problem in the markdown block:
```python
def break_example(condition: int) -> int:
"""
Demonstrates the functionality of the break statement within a for loop.
The loop iterates over a range of numbers and prints each number until the
specified condition is met... |
evol_instruct_66k | 12,618 | Write a Python function to convert a list of dictionaries, where each dictionary contains a unique `username` key, into a dictionary where the keys are the `username` values and the values are the corresponding dictionaries from the list. The function should handle lists of any length and ensure that the resulting dict... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def convert_list_to_dict(users_list: List[Dict[str, any]]) -> Dict[str, Dict[str, any]]:
"""
Converts a list of dictionaries into a dictionary where the keys are the 'username' values from the dict... |
evol_instruct_66k | 12,625 | Write a Python function to obtain the inverse of a given array using slicing. The function should take a list of integers as input and return a new list that is the inverse of the input list. The function should not modify the original list.
The code should start with:
```python
from typing import List
def inverse_ar... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def inverse_array(arr: List[int]) -> List[int]:
"""
Returns the inverse of the given array using slicing.
Args:
arr (List[int]): The input array of integers.
Returns:
List[int]:... |
evol_instruct_66k | 12,634 | Write a Python function to convert a given integer into its Roman numeral representation. The function should handle integers in the range from 1 to 3999. The code should start with:
```python
def int_to_roman(input: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def int_to_roman(input: int) -> str:
"""
Convert an integer into its Roman numeral representation.
Args:
input (int): The integer to be converted, must be between 1 and 3999.
Returns:
str: The Roman num... |
evol_instruct_66k | 12,644 | Write a Python function to perform a binary search on a sorted list of strings to find a target word. The function should handle cases where the target word is not found and should be efficient for large datasets.
The code should start with:
```python
from typing import List, Optional
def binary_search(sorted_list: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def binary_search(sorted_list: List[str], target: str) -> Optional[int]:
"""
Perform a binary search on a sorted list of strings to find the index of a target word.
Args:
sorted_li... |
evol_instruct_66k | 12,660 | Write a Python function to generate a list of random floating-point numbers within a specified range and length. The function should allow customization of both the range and the length of the list. The code should start with:
```python
from typing import List
import random
def generate_random_floats(length: int, lowe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_random_floats(length: int, lower_bound: float, upper_bound: float) -> List[float]:
"""
Generates a list of random floating-point numbers within a specified range and length.
... |
evol_instruct_66k | 12,663 | Write a Python function to arrange a collection of whole numbers into two nested lists: one containing exclusively even numbers and the other containing exclusively odd numbers. The function should return a list of two lists, where the first list contains all even numbers and the second list contains all odd numbers.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def organize_numbers(nums: List[int]) -> List[List[int]]:
"""
Arrange a collection of whole numbers into two nested lists: one containing exclusively even numbers and the other containing exclusively odd... |
evol_instruct_66k | 12,669 | Write a Python function to find the largest number in a list using recursion. The function should not use any loops or built-in functions that directly solve the problem. The code should start with:
```python
from typing import List
def find_largest_recursive(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_largest_recursive(numbers: List[int]) -> int:
"""
Find the largest number in a list using recursion.
Args:
numbers (List[int]): The list of integers from which to find the largest n... |
evol_instruct_66k | 12,681 | Write a Python function to simulate a basic chatbot interaction. The function should take a user's input as a string, process it using a simplified natural language processing (NLP) logic, and return the bot's response as a string. The NLP logic should include basic keyword matching and predefined responses.
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
def chatbot_response(user_input: str) -> str:
"""
Simulate a basic chatbot interaction by processing the user's input and returning a bot's response.
Args:
user_input (str): The user's input message.
Returns:
... |
evol_instruct_66k | 12,685 | Write a Python function to generate a Fibonacci series of a given length `n`. The Fibonacci series is a sequence where each number is the sum of the two preceding ones, typically starting with 0 and 1. The function should return a list containing the first `n` elements of the Fibonacci series.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci_series(n: int) -> List[int]:
"""
Generate a Fibonacci series of length `n`.
The Fibonacci series is a sequence where each number is the sum of the two preceding ones,
typi... |
evol_instruct_66k | 12,686 | Write a Python function to find the intersection of two sets, `groupA` and `groupB`. The function should return a new set containing elements that are present in both sets. The code should start with:
```python
from typing import Set
def find_intersection(groupA: Set[int], groupB: Set[int]) -> Set[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def find_intersection(groupA: Set[int], groupB: Set[int]) -> Set[int]:
"""
Find the intersection of two sets, groupA and groupB.
Args:
groupA (Set[int]): The first set of integers.
gr... |
evol_instruct_66k | 12,689 | Write a Python function to determine the smallest possible number of rabbits that could inhabit the forest based on the given responses from a group of rabbits. Each rabbit provides information about the number of other rabbits that share its color. The function 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
import collections
import math
def min_rabbits_in_forest(answers: List[int]) -> int:
"""
Calculate the smallest possible number of rabbits in the forest based on their responses.
Args:
answe... |
evol_instruct_66k | 12,694 | Write a Python function to determine if a given variable is `None` or not. The function should return `True` if the variable is `None`, and `False` otherwise. Additionally, provide a detailed explanation of the implications of using `None` in Python, including how it behaves in conditional statements and potential pitf... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_none(variable) -> bool:
"""
Determine if the given variable is None.
Args:
variable: The variable to check.
Returns:
bool: True if the variable is None, False otherwise.
"""
return variab... |
evol_instruct_66k | 12,698 | Write a Python function to compute the aggregate sum of the individual numerical digits within a specified integer value. The function should handle both positive and negative integers. The code should start with:
```python
def sum_of_digits(number: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_digits(number: int) -> int:
"""
Compute the aggregate sum of the individual numerical digits within a specified integer value.
Args:
number (int): The integer value whose digits are to be summed.
Ret... |
evol_instruct_66k | 12,710 | Write a Python function to initialize and populate a list with the first n multiples of a given integer x. The function should return the populated list. The code should start with:
```python
from typing import List
def initialize_and_populate_list(x: int, n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def initialize_and_populate_list(x: int, n: int) -> List[int]:
"""
Initializes and populates a list with the first n multiples of a given integer x.
Args:
x (int): The integer whose multip... |
evol_instruct_66k | 12,711 | Write a Python function to partition distinct special characters from a given string. Special characters are defined as any characters that are neither alphanumeric nor whitespace. The function should return a set of these distinct special characters.
The code should start with:
```python
from typing import Set
def p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def partition_special_characters(text: str) -> Set[str]:
"""
Partitions distinct special characters from the given string.
Special characters are defined as any characters that are neither alphanumer... |
evol_instruct_66k | 12,715 | Write a Python function to calculate the Euclidean distance between two points in a 2D plane using the Pythagorean theorem. The function should take four parameters representing the coordinates of the two points and return the distance as a floating-point number.
The code should start with:
```python
import math
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def euclidean_distance(x1: float, y1: float, x2: float, y2: float) -> float:
"""
Calculate the Euclidean distance between two points (x1, y1) and (x2, y2) in a 2D plane.
Args:
x1 (float): The x-coordina... |
evol_instruct_66k | 12,731 | Write a Python function to retrieve the third string from each sub-array within a given main array. The main array is a list of lists, where each sub-array contains exactly three strings. The function should return a list containing the third string from each sub-array.
The code should start with:
```python
from typin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_third_strings(main_array: List[List[str]]) -> List[str]:
"""
Retrieves the third string from each sub-array within the given main array.
Args:
main_array (List[List[str]]): A list of... |
evol_instruct_66k | 12,739 | Write a Python function to replace all the vowels in a given string with the character '$'. The function should be case-insensitive, meaning both uppercase and lowercase vowels should be replaced. The code should start with:
```python
def replace_vowels_with_dollar(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def replace_vowels_with_dollar(s: str) -> str:
"""
Replace all vowels (both uppercase and lowercase) in the given string with the character '$'.
Args:
s (str): The input string in which vowels need to be replaced.
... |
evol_instruct_66k | 12,749 | Write a Python function to merge two lists into a single list, where each element from the first list is followed by the corresponding element from the second list. If one list is longer than the other, the remaining elements of the longer list should be appended to the end of the merged list.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from itertools import zip_longest
def merge_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Merges two lists such that each element from the first list is followed by the corresponding elemen... |
evol_instruct_66k | 12,751 | Write a Python function to detect and return the first occurrence of a negative number in a given array of numbers, along with its index. If no negative number is found, return a specific message indicating that no negative numbers were found. The function should handle edge cases where the array is empty or contains n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Union
def find_first_negative(numbers: List[int]) -> Union[Tuple[int, int], str]:
"""
Detects and returns the first occurrence of a negative number in the given list of integers, along with its i... |
evol_instruct_66k | 12,776 | Write a Python function to concatenate two lists and handle potential errors such as different data types. The function should return an error message if the provided inputs are not lists. The code should start with:
```python
from typing import List, Union
def concatenate_lists(list1: Union[List, None], list2: Union[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def concatenate_lists(list1: Union[List, None], list2: Union[List, None]) -> Union[List, str]:
"""
Concatenate two lists and handle potential errors such as different data types.
Args:
... |
evol_instruct_66k | 12,781 | Write a Python function to calculate the product of the first n natural numbers using a while loop. The function should handle edge cases such as n being zero or negative, and ensure that the product is calculated correctly. The code should start with:
```python
def product_of_first_n_natural_numbers(n: int) -> int:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def product_of_first_n_natural_numbers(n: int) -> int:
"""
Calculate the product of the first n natural numbers.
Args:
n (int): The number of natural numbers to include in the product.
Returns:
int: The... |
evol_instruct_66k | 12,790 | Write a Python function to analyze a given sequence of characters and return a dictionary containing the frequency of each distinct alphabet character in the input string. Additionally, the dictionary should include two special keys: 'vowels' and 'consonants', which represent the cumulative frequency of all vowel chara... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def analyze_character_frequency(input_str: str) -> Dict[str, int]:
"""
Analyzes the frequency of each distinct alphabet character in the input string and categorizes them into vowels and consonants.
... |
evol_instruct_66k | 12,792 | Write a Python function to find the n smallest unique numbers from a given dataset. The dataset is a list of integers, and the function should ignore any repeated numbers. The function should return a list of the n smallest unique numbers in ascending order.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_n_smallest_unique_numbers(dataset: List[int], n: int) -> List[int]:
"""
Returns the n smallest unique numbers from the given dataset.
Args:
dataset (List[int]): The dataset from whic... |
evol_instruct_66k | 12,802 | Write a Python function to generate the first `n` numbers in the Lucas sequence. The Lucas sequence is similar to the Fibonacci sequence but starts with 2 and 1 instead of 0 and 1. The function should handle boundary conditions where `n` is less than 1 and return an empty list in such cases. The function should also re... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_lucas_sequence(n: int) -> List[int]:
"""
Generate the first n numbers in the Lucas sequence.
The Lucas sequence is similar to the Fibonacci sequence but starts with 2 and 1.
Each su... |
evol_instruct_66k | 12,806 | Write a Python function to calculate the number of structurally distinct Binary Search Trees (BSTs) that can be formed with `n` nodes, where each node has a unique value ranging from `1` to `n`. The function should adhere to the constraints that `n` is an integer between 1 and 19, inclusive.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_unique_bst(n: int) -> int:
"""
Calculate the number of structurally distinct Binary Search Trees (BSTs) that can be formed with `n` nodes.
Args:
n (int): The number of nodes in the BST. Must be between 1 a... |
evol_instruct_66k | 12,807 | Write a Python function to find the nearest whole number in a given numeric sequence to a specified target number. The function should return the closest number from the list, and if there are multiple numbers that are equally close, it should return the smallest one.
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 find_nearest_number(num_list: List[int], target_num: int) -> int:
"""
Find the nearest whole number in a given numeric sequence to a specified target number.
Args:
num_list (List[int]): ... |
evol_instruct_66k | 12,809 | Write a Python function that generates and yields the first N numbers from the Fibonacci sequence using a generator. The function should be designed to yield each Fibonacci number one at a time, rather than returning a list of all numbers at once. The function should start with:
```python
def generate_fibonacci(n: int)... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_fibonacci(n: int):
"""
Generates the first N numbers from the Fibonacci sequence using a generator.
Args:
n (int): The number of Fibonacci numbers to generate.
Yields:
int: The next Fibonac... |
evol_instruct_66k | 12,811 | Write a Python function to convert a given string into a sequence of binary numbers, each corresponding to the ASCII characters of the string. The binary numbers should be 8 bits long, and the sequence should be space-separated.
The code should start with:
```python
def string_to_binary(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def string_to_binary(s: str) -> str:
"""
Converts a given string into a sequence of 8-bit binary numbers, each corresponding to the ASCII characters of the string.
Args:
s (str): The input string to be converted.
... |
evol_instruct_66k | 12,814 | Write a Python function to calculate the sum of the first `n` natural numbers efficiently. The function should use a mathematical formula to achieve this, reducing the execution time compared to a loop-based approach.
The code should start with:
```python
def sum_of_first_n(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_first_n(n: int) -> int:
"""
Calculate the sum of the first n natural numbers using a mathematical formula.
Args:
n (int): The number of natural numbers to sum.
Returns:
int: The sum of the fi... |
evol_instruct_66k | 12,816 | Write a Python function to sort an array of integers using the insertion 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 insertion_sort(array: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def insertion_sort(array: List[int]) -> List[int]:
"""
Sorts an array of integers using the insertion sort algorithm.
Args:
array (List[int]): The array of integers to be sorted.
Retu... |
evol_instruct_66k | 12,823 | Write a Python function to convert an array of binary string representations into an array of octal integer equivalents. The function should handle erroneous binary strings and return an error message for those. The function should start with:
```python
from typing import List
def convert_binary_to_octal(binary_string... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_binary_to_octal(binary_strings: List[str]) -> List[str]:
"""
Converts an array of binary string representations into an array of octal integer equivalents.
If a binary string is invalid, ... |
evol_instruct_66k | 12,837 | Write a Python function to update and retrieve information about the number of known moons for planets in our solar system. The function should allow adding new planets and updating the number of moons for existing planets. The function should also be able to retrieve the number of moons for a given planet.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Union
def update_planet_moons(planets_with_moons: Dict[str, int], planet: str, moons: int) -> None:
"""
Update the number of moons for a given planet in the dictionary.
If the planet does not exist ... |
evol_instruct_66k | 12,838 | Write a Python function that uses the "Walrus operator" to efficiently find and return the first occurrence of a substring in a given string. The function should return the substring if found, otherwise return `None`. The code should start with:
```python
def find_substring(substring: str, text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
import re
def find_substring(substring: str, text: str) -> str:
"""
Finds the first occurrence of a substring in a given text using the Walrus operator.
Args:
substring (str): The substring to search for.
... |
evol_instruct_66k | 12,862 | Write a Python function to find the longest string within a specified length range from a given list of textual elements. The function should accept an array of textual elements and two numeric parameters `k1` and `k2` which define the inclusive range of string lengths to consider. The function should return the longes... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
import heapq
def longest_string_in_range(text_arr: List[str], k1: int, k2: int) -> Optional[str]:
"""
Find the longest string within a specified length range from a given list of textual elemen... |
evol_instruct_66k | 12,863 | Write a Python function to remove all empty strings from a given list of strings. The function should return a new list that contains only the non-empty strings from the original list. The code should start with:
```python
from typing import List
def remove_empty_strings(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_empty_strings(strings: List[str]) -> List[str]:
"""
Removes all empty strings from the given list of strings.
Args:
strings (List[str]): The list of strings from which to remove e... |
evol_instruct_66k | 12,885 | Write a Python function to iterate over a given nested list, calculate the average of each sublist, and return a sorted list of these averages in descending order. The function should handle the case where any of the sublists are empty. For empty sublists, consider their average as 0.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sorted_averages_descending(arr: List[List[int]]) -> List[float]:
"""
Calculate the average of each sublist in the given nested list and return a sorted list of these averages in descending order.
... |
evol_instruct_66k | 12,895 | Write a Python function to generate a random letter from a given string, excluding whitespace characters and ensuring equal probability for each character. The function should handle any string input and return a single random character.
The code should start with:
```python
import random
from typing import List
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
from typing import List
def get_random_letter(string: str) -> str:
"""
Generates a random letter from the given string, excluding whitespace characters.
Args:
string (str): The input string from which... |
evol_instruct_66k | 12,900 | Write a Python function to generate a SQL query that displays the employee name, city, and the average salary of their department (rounded to two decimal points) for a particular employee ID. The output should be sorted in descending order and include only those records where the department has more than 5 employees. T... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_sql_query(employee_id: int) -> str:
"""
Generate a SQL query to display the employee name, city, and the average salary of their department
(rounded to two decimal points) for a particular employee ID. The outpu... |
evol_instruct_66k | 12,910 | Write a Python function to calculate the sum of the first `n` even numbers. The function should be efficient and should handle any non-negative integer `n`. The code should start with:
```python
def sum_of_first_n_even_numbers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_first_n_even_numbers(n: int) -> int:
"""
Calculate the sum of the first n even numbers.
Args:
n (int): The number of even numbers to sum.
Returns:
int: The sum of the first n even numbers.
... |
evol_instruct_66k | 12,917 | Write a Python function to demonstrate four different ways to loop through a dictionary and print its keys and values. Additionally, provide commentary on the time complexity of each method and situations where one method may be preferable over others. The function should accept a dictionary as input and print the keys... | Here is the Python code to solve the given problem in the markdown block:
```python
def loop_through_dictionary(dic: dict) -> None:
"""
Demonstrates four different ways to loop through a dictionary and print its keys and values.
Args:
dic (dict): The dictionary to loop through.
Returns:
... |
evol_instruct_66k | 12,920 | Write a Python function to arrange a given list of strings in lexicographic (dictionary) order. The function should take a list of strings as input and return the sorted list. The code should start with:
```python
from typing import List
def sort_lexicographically(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_lexicographically(strings: List[str]) -> List[str]:
"""
Sorts a list of strings in lexicographic (dictionary) order.
Args:
strings (List[str]): The list of strings to be sorted.
... |
evol_instruct_66k | 12,924 | Write a Python function to count the number of occurrences of a specific character within a given string. The function should be case-sensitive and should handle any string input, including empty strings. The code should start with:
```python
def count_character(text: str, character: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_character(text: str, character: str) -> int:
"""
Counts the number of occurrences of a specific character in a given string.
Args:
text (str): The string in which to count the character occurrences.
... |
evol_instruct_66k | 12,931 | Write a Python function to obfuscate specific lexemes within a given block of textual content. The function should replace each occurrence of the specified lexemes with a fixed string (e.g., '***'). The function should handle case sensitivity and ensure that only whole words are replaced, not substrings.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def obfuscate_text(input_text: str, lexemes_to_obfuscate: List[str]) -> str:
"""
Obfuscates specific lexemes within a given block of textual content.
Args:
input_text (str): The or... |
evol_instruct_66k | 12,932 | 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 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 | 12,942 | Write a Python function to compute all prime numbers between 1 and a given positive integer `n` using the Sieve of Eratosthenes algorithm. The function should return a list of all prime numbers up to and including `n`.
The code should start with:
```python
from typing import List
def find_primes(n: int) -> List[int]:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_primes(n: int) -> List[int]:
"""
Compute all prime numbers between 1 and a given positive integer n using the Sieve of Eratosthenes algorithm.
Args:
n (int): The upper limit to find... |
evol_instruct_66k | 12,951 | Write a Python function to sort a list of operating systems in descending order based on their names. The function should consider the full name of each operating system and sort them based on the first letter of each name. The code should start with:
```python
from typing import List
def sort_operating_systems_descen... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_operating_systems_descending(operating_systems: List[str]) -> List[str]:
"""
Sorts a list of operating systems in descending order based on their names.
Args:
operating_systems (Lis... |
evol_instruct_66k | 12,954 | Write a Python function to count the total number of characters in a given string, including punctuation and spaces, and also count the frequency of each unique character. The function should return a dictionary containing the total character count and a nested dictionary with each unique character mapped to its freque... | Here is the Python code to solve the given problem in the markdown block:
```python
def character_count_and_frequency(submitted_string: str) -> dict:
"""
Counts the total number of characters in the provided string and the frequency of each unique character.
Args:
submitted_string (str): The string... |
evol_instruct_66k | 12,968 | Write a Python function to find the k-th largest number in a list of integers. The function should be efficient and handle cases where k is greater than the length of the list. The code should start with:
```python
from typing import List
def find_kth_largest(nums: List[int], k: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_kth_largest(nums: List[int], k: int) -> int:
"""
Find the k-th largest number in a list of integers.
Args:
nums (List[int]): The list of integers from which to find the k-th largest... |
evol_instruct_66k | 12,974 | Write a Python function to sort a list of tuples containing string and integer values. The sorting should be done in ascending order based on both the string and integer components of the tuples. If two tuples have the same string component, they should be sorted by their integer component in descending order.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_tuples(lst: List[Tuple[str, int]]) -> List[Tuple[str, int]]:
"""
Sorts a list of tuples containing string and integer values.
The tuples are sorted in ascending order based on the st... |
evol_instruct_66k | 12,979 | Write a Python function to change the text color in the console output. The function should accept a string and a color code, and return the string wrapped in ANSI escape codes to change its color. The color codes should be predefined as constants in the function. The function should also include a reset code to revert... | Here is the Python code to solve the given problem in the markdown block:
```python
def color_text(text: str, color: str) -> str:
"""
Changes the text color in the console output using ANSI escape codes.
Args:
text (str): The text to be colored.
color (str): The color code to apply to the t... |
evol_instruct_66k | 12,980 | Write a Python function to create a matrix of size `m x n`, where each cell `(i, j)` is filled with the product of the row index `i` and the column index `j`. Then, calculate and return the sum of the diagonal elements in the matrix.
The code should start with:
```python
from typing import List
def calculate_diagonal... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_diagonal_sum(m: int, n: int) -> int:
"""
Create a matrix of size m x n where each cell (i, j) is filled with the product of i and j.
Then, calculate and return the sum of the diagonal e... |
evol_instruct_66k | 12,987 | Write a Python function that implements a nested for-loop with integrated break and continue statements based on specific conditions. The function should handle exceptions using try and except blocks. The conditions for break and continue should involve complex logical operators. The function should also print the resu... | Here is the Python code to solve the given problem in the markdown block:
```python
def nested_loop_with_conditions():
"""
Implements a nested for-loop with integrated break and continue statements based on specific conditions.
Handles exceptions using try and except blocks.
The function performs the f... |
evol_instruct_66k | 12,991 | Write a Python function to shuffle an array of integers in place. The function should use the Fisher-Yates (Knuth) shuffle algorithm to ensure a uniform random permutation of the array. The code should start with:
```python
from typing import List
def shuffle_array(array: List[int]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import random
def shuffle_array(array: List[int]) -> None:
"""
Shuffles the given array of integers in place using the Fisher-Yates (Knuth) shuffle algorithm.
Args:
array (List[int]): The ... |
evol_instruct_66k | 13,003 | Write a Python function to sort a given list of non-negative integers using the Radix Sort algorithm. The function should return the sorted list. The Radix Sort algorithm sorts numbers by processing individual digits from the least significant digit (LSD) to the most significant digit (MSD).
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def radix_sort(lst: List[int]) -> List[int]:
"""
Sorts a list of non-negative integers using the Radix Sort algorithm.
Args:
lst (List[int]): The list of non-negative integers to be sorted.
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.