source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 39,824 | Write a Python function to encrypt a given text using the ROT13 cipher. The ROT13 cipher is a simple substitution cipher that replaces a letter with the 13th letter after it in the alphabet. The function should handle both uppercase and lowercase letters, leaving any non-alphabetic characters unchanged.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
def rot13_encrypt(text: str) -> str:
"""
Encrypts the given text using the ROT13 cipher.
The ROT13 cipher is a simple substitution cipher that replaces each letter
with the letter 13 positions after it in the alphabet. ... |
evol_instruct_66k | 39,832 | Write a Python function to modify each element in a given 2D array (matrix) such that every element in a row is replaced with the maximum value in that row. The function should return the modified matrix.
The code should start with:
```python
from typing import List
def replace_with_row_max(matrix: List[List[int]]) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def replace_with_row_max(matrix: List[List[int]]) -> List[List[int]]:
"""
Modifies each element in a given 2D array such that every element in a row is replaced with the maximum value in that row.
A... |
evol_instruct_66k | 39,845 | Write a Python function to generate a list of numbers in a geometric progression starting from 1, with a given fixed ratio, until the last number in the sequence reaches or exceeds a provided integer `m`. The function should return the list of numbers in the geometric progression.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def geometric_progression(ratio: int, m: int) -> List[int]:
"""
Generate a list of numbers in a geometric progression starting from 1,
with a given fixed ratio, until the last number in the sequence ... |
evol_instruct_66k | 39,860 | Write a Python function to enumerate and count the frequency of recurring lexical items (words and punctuation marks) in a given text. The function should return a dictionary where the keys are the lexical items and the values are their respective frequencies. The function should handle both words and punctuation marks... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import re
from collections import Counter
def count_lexical_items(text: str) -> Dict[str, int]:
"""
Counts the frequency of each lexical item (words and punctuation marks) in the given text.
Args:
... |
evol_instruct_66k | 39,865 | Write a Python function to find the maximum element in a list containing both numeric and alphanumeric strings. The function should also sort the alphanumeric strings in increasing order. The function should handle edge cases, such as lists with duplicate values and empty lists. The code should start with:
```python
fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_max_and_sort_alphanumeric(arr: List[Union[int, str]]) -> List[Union[int, str]]:
"""
Finds the maximum numeric element and sorts the alphanumeric strings in a list.
Args:
arr ... |
evol_instruct_66k | 39,878 | Write a Python function to iterate over a list and print each element using a while loop. Ensure that the function handles the iteration correctly and avoids common pitfalls such as using incorrect length functions or increment operators.
The code should start with:
```python
from typing import List
def print_list_el... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_list_elements(array: List[int]) -> None:
"""
Iterates over a list and prints each element using a while loop.
Args:
array (List[int]): The list of integers to be printed.
Retu... |
evol_instruct_66k | 39,879 | Write a Python function to safely handle exceptions when connecting to an external API and processing sensitive data. The function should ensure that no sensitive information is leaked in case of an error. The function should log the error message without exposing any sensitive details and return a generic error messag... | Here is the Python code to solve the given problem in the markdown block:
```python
import logging
def safe_api_call(api_url: str, sensitive_data: dict) -> str:
"""
Safely handle exceptions when connecting to an external API and processing sensitive data.
Args:
api_url (str): The URL of the extern... |
evol_instruct_66k | 39,885 | Write a Python function to extract all email addresses from a given text string using regular expressions. The function should return a list of all email addresses found in the text.
The code should start with:
```python
from typing import List
import re
def extract_emails(text: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def extract_emails(text: str) -> List[str]:
"""
Extracts all email addresses from the given text string using regular expressions.
Args:
text (str): The input text string from whic... |
evol_instruct_66k | 39,890 | Write a Python function to rotate a given matrix by 90 degrees clockwise without using any external libraries like NumPy. The matrix is represented as a list of lists, where each inner list represents a row of the matrix. The function should return the rotated matrix.
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 rotate_matrix_90_clockwise(matrix: List[List[int]]) -> List[List[int]]:
"""
Rotates a given matrix by 90 degrees clockwise.
Args:
matrix (List[List[int]]): The input matrix represented a... |
evol_instruct_66k | 39,895 | Write a Python function to validate if a given string is a valid hexadecimal color code. A valid hexadecimal color code starts with a `#` followed by either 3 or 6 hexadecimal digits (0-9, A-F, a-f). The function should return `True` if the input string is a valid hexadecimal color code, and `False` otherwise.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_hex_color(code: str) -> bool:
"""
Validate if a given string is a valid hexadecimal color code.
A valid hexadecimal color code starts with a `#` followed by either 3 or 6 hexadecimal digits (0-9, A-F... |
evol_instruct_66k | 39,896 | Write a Python function to extract and validate user details from a given HTML form data. The function should ensure that the email, residential address, and educational background are correctly formatted and adhere to data privacy guidelines. The function should return a dictionary containing the validated details.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Optional
import re
def validate_user_details(form_data: Dict[str, str]) -> Optional[Dict[str, str]]:
"""
Validates and extracts user details from an HTML form data.
Args:
form_data (Dict[st... |
evol_instruct_66k | 39,903 | Write a Python function to generate a string that concatenates all elements of a given list, separated by a specified delimiter. The function should handle lists of integers and strings. The code should start with:
```python
from typing import List, Union
def concatenate_elements(elements: List[Union[int, str]], delim... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def concatenate_elements(elements: List[Union[int, str]], delimiter: str = ' ') -> str:
"""
Concatenates all elements of a given list, separated by a specified delimiter.
Args:
elemen... |
evol_instruct_66k | 39,904 | Write a Python function to implement the Quick Sort algorithm. The function should sort a given list of integers in ascending order. The function should be recursive and should use a pivot element to partition the list into two sublists: one containing elements less than or equal to the pivot, and the other containing ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def quick_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the Quick Sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
List... |
evol_instruct_66k | 39,917 | Write a Python function to evaluate a mathematical expression given specific values for variables `p` and `q`. The expression to evaluate is `g(p, q) = pq^2 + 3p^3`. The function should take two integer inputs `p` and `q`, and return the result of the expression as an integer.
The code should start with:
```python
def... | Here is the Python code to solve the given problem in the markdown block:
```python
def evaluate_expression(p: int, q: int) -> int:
"""
Evaluate the mathematical expression g(p, q) = pq^2 + 3p^3 for given values of p and q.
Args:
p (int): The first variable in the expression.
q (int): The s... |
evol_instruct_66k | 39,939 | Write a Python function to generate a list of numbers from a given start value up to a specified end value (inclusive). The function should handle both positive and negative ranges, and should return an empty list if the start value is greater than the end value.
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 generate_numbers(start: int, end: int) -> List[int]:
"""
Generate a list of numbers from the start value to the end value (inclusive).
Args:
start (int): The starting value of the range.... |
evol_instruct_66k | 39,942 | Write a Python function to generate a JSON representation of employee data based on the provided details. The function should accept three parameters: the employee's name, age, and department. The function should return a JSON string that includes these details in a structured format.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
import json
def generate_employee_json(name: str, age: int, department: str) -> str:
"""
Generates a JSON representation of employee data.
Args:
name (str): The name of the employee.
age (int): The age of t... |
evol_instruct_66k | 39,951 | Write a Python function to correct the error in the given code snippet and check if the resulting output of the division is an integer. The function should take two integers as input, perform the correct division, and return a boolean indicating whether the result is an integer.
The code should start with:
```python
d... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_division_result_integer(a: int, b: int) -> bool:
"""
Check if the result of the division of two integers is an integer.
Args:
a (int): The numerator.
b (int): The denominator.
Returns:
bo... |
evol_instruct_66k | 39,963 | Write a Python function to perform an interpolative search in a sorted list. The function should return the index of the target element if it exists in the list, otherwise, it should return -1. The code should start with:
```python
from typing import List
def interpolative_search(array: List[int], x: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def interpolative_search(array: List[int], x: int) -> int:
"""
Perform an interpolative search in a sorted list to find the index of the target element.
Args:
array (List[int]): A sorted lis... |
evol_instruct_66k | 39,970 | Write a Python function to segregate elements of a given list into nested lists, each containing elements of a specific, predetermined length. The function should handle cases where the length of the input list is not a multiple of the predetermined length by including the remaining elements in the last nested list.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def segregate_elements(arr: List[int], sz: int) -> List[List[int]]:
"""
Segregates elements of a given list into nested lists, each containing elements of a specific, predetermined length.
Args:
... |
evol_instruct_66k | 39,973 | Write a Python function to generate a 1-dimensional matrix (an array) of length 10, where each element is a random integer between 1 and 10 (inclusive). The function should return the generated matrix.
The code should start with:
```python
from typing import List
import random
def generate_random_matrix() -> List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_random_matrix() -> List[int]:
"""
Generates a 1-dimensional matrix (an array) of length 10, where each element is a random integer between 1 and 10 (inclusive).
Returns:
... |
evol_instruct_66k | 39,977 | Write a Python function to compute the total expenditure involved in acquiring a specified number of products at a given unit price. The function should be flexible enough to handle any number of products and any unit price. The code should start with:
```python
def compute_total_expenditure(num_products: int, price_pe... | Here is the Python code to solve the given problem in the markdown block:
```python
def compute_total_expenditure(num_products: int, price_per_product: float) -> float:
"""
Compute the total expenditure for acquiring a specified number of products at a given unit price.
Args:
num_products (int): Th... |
evol_instruct_66k | 39,978 | Write a Python function to categorize four distinct items based on their attributes (shape, color, and size) using a decision tree algorithm. The constraint is that items with similar colors must not reside on the same branch. The items are:
1. Item 1: spherical, crimson, 5cm in diameter
2. Item 2: quadrilateral, emera... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def categorize_items(items: List[Tuple[str, str, float]]) -> Dict[str, List[Tuple[str, str, float]]]:
"""
Categorizes items into branches based on their color, ensuring items with similar co... |
evol_instruct_66k | 39,994 | Write a Python function that applies a given function to only the elements of a list that satisfy a specified condition. The function should return a new list containing the results of the function applied to the filtered elements. The code should start with:
```python
from typing import Callable, List
def apply_funct... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Callable, List
def apply_function_to_filtered_elements(func: Callable, lst: List, condition: Callable) -> List:
"""
Applies a given function to only the elements of a list that satisfy a specified condition.
... |
evol_instruct_66k | 39,996 | Write a Python function to create a dictionary that maps each letter of the English alphabet to its corresponding position (1-26) and vice versa. The function should take no arguments and return the dictionary.
The code should start with:
```python
def create_alphabet_map() -> dict:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def create_alphabet_map() -> dict:
"""
Creates a dictionary that maps each letter of the English alphabet to its corresponding position (1-26) and vice versa.
Returns:
dict: A dictionary where keys are letters and v... |
evol_instruct_66k | 40,003 | Write a Python function to compute the value of Euler's number (e) using the infinite series expansion up to a specified number of terms. The infinite series for Euler's number is given by:
\[ e = \sum_{n=0}^{\infty} \frac{1}{n!} \]
The function should start with:
```python
import math
def compute_euler_number(num_t... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def compute_euler_number(num_terms: int) -> float:
"""
Compute the value of Euler's number (e) using the infinite series expansion up to a specified number of terms.
The series is defined as:
e = sum(1 / n!... |
evol_instruct_66k | 40,009 | Write a Python function to iterate over a list in reverse order and return a new list containing the elements in the reversed order. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def reverse_list(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 reverse_list(numbers: List[int]) -> List[int]:
"""
Reverses the order of elements in the input list and returns the reversed list.
Args:
numbers (List[int]): The list of integers to be r... |
evol_instruct_66k | 40,019 | Write a Python function to verify if a list or any nested lists within it are empty, including lists nested within other lists to any depth. The function should return `True` only if the main list and all nested lists are empty. Additionally, the function should handle circular references without entering an infinite l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def is_all_empty(lst: List[Any], seen: set = None) -> bool:
"""
Verifies if a list or any nested lists within it are empty, including lists nested within other lists to any depth.
The function r... |
evol_instruct_66k | 40,033 | Write a Python function to replace multiple consecutive occurrences of a specific character in a string with a single replacement character. The function should handle any string and any characters for the target and replacement.
The code should start with:
```python
def replace_multiple_consecutive(string: str, targe... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_multiple_consecutive(string: str, target: str, replacement: str) -> str:
"""
Replaces multiple consecutive occurrences of a specific character in a string with a single replacement character.
Args:
strin... |
evol_instruct_66k | 40,034 | Write a Python function to determine the composition of a given set of values, which may embody a heterogeneous mix of data types including integers and alphabetic characters. The function should return a dictionary where the keys are the data types and the values are the counts of elements of that data type in the inp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Any
def count_data_types(values: List[Any]) -> Dict[type, int]:
"""
Counts the occurrences of each data type in the given list of values.
Args:
values (List[Any]): A list containing a... |
evol_instruct_66k | 40,097 | Write a Python function that iterates over a given range and stops the iteration when a specified condition is met. The function should return the last value of the iterator before the loop breaks. If the loop completes without breaking, the function should return the last value in the range.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
:
```python
def find_last_value_before_break(start: int, end: int, break_condition: int) -> int:
"""
Iterates over a range from start to end and returns the last value before the loop breaks.
The loop breaks when the current value mat... |
evol_instruct_66k | 40,098 | Write a Python function to determine if an even-length integer array `arr` can be rearranged such that for every `0 <= i < len(arr) / 2`, the condition `arr[2 * i + 1] = 2 * arr[2 * i]` holds true. The function should return `True` if such a rearrangement is possible, and `False` otherwise.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import Counter
from queue import PriorityQueue
def can_reorder_doubled(arr: List[int]) -> bool:
"""
Determines if the given even-length integer array can be rearranged such that
for ... |
evol_instruct_66k | 40,102 | Write a Python function to remove consecutive repeating digits from a given string of numeric characters. The function should return a new string where all consecutive, repeating digits are eliminated, resulting in a unique, modified string.
The code should start with:
```python
def remove_consecutive_repeats(s: str) ... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_consecutive_repeats(s: str) -> str:
"""
Removes consecutive repeating digits from a given string of numeric characters.
Args:
s (str): The input string containing numeric characters.
Returns:
... |
evol_instruct_66k | 40,129 | Write a Python function to count the occurrences of each element in a given list, where the elements can be of different data types such as integers, strings, and tuples. The function should return a dictionary where the keys are the unique elements from the list and the values are their respective counts.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Any
from collections import Counter
def count_occurrences(elements: List[Any]) -> Dict[Any, int]:
"""
Counts the occurrences of each element in a given list.
Args:
elements (List[Any]... |
evol_instruct_66k | 40,133 | Write a Python function to convert a given numerical value from one numbering scheme to another. Specifically, the function should convert a binary number to its decimal equivalent. The function should be able to handle binary strings of any length and return the corresponding decimal integer.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_decimal(binary_num: str) -> int:
"""
Converts a binary number represented as a string to its decimal equivalent.
Args:
binary_num (str): The binary number to be converted, represented as a string of '0... |
evol_instruct_66k | 40,135 | Write a Python function to calculate the disparity between two provided Unix timestamps, taking into account their chronological distinction. The function should return the difference in seconds and minutes.
The code should start with:
```python
def calculate_timestamp_disparity(timestamp1: int, timestamp2: int) -> tu... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_timestamp_disparity(timestamp1: int, timestamp2: int) -> tuple:
"""
Calculate the disparity between two Unix timestamps in seconds and minutes.
Args:
timestamp1 (int): The first Unix timestamp.
... |
evol_instruct_66k | 40,143 | Write a Python function to sort a dictionary by its values in ascending order. The function should return a new dictionary with the same keys and values, but ordered by the values.
The code should start with:
```python
from typing import Dict
def sort_dict_by_value(d: Dict[str, int]) -> Dict[str, int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_value(d: Dict[str, int]) -> Dict[str, int]:
"""
Sorts a dictionary by its values in ascending order.
Args:
d (Dict[str, int]): The dictionary to be sorted.
Returns:
... |
evol_instruct_66k | 40,155 | Write a Python function to calculate the value of Euler's number (e) using the infinite series definition. The series is defined as:
\[ e = \sum_{n=0}^{\infty} \frac{1}{n!} \]
The function should take an integer `num_terms` as input, which specifies the number of terms to include in the series summation. The function... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_eulers_number(num_terms: int) -> float:
"""
Calculate the value of Euler's number (e) using the infinite series definition.
The series is defined as:
\[ e = \sum_{n=0}^{\infty} \frac{1}{n!} \]... |
evol_instruct_66k | 40,166 | Write a Python function to find the most profitable sequence of trades given a list of stock prices. The function should return the maximum profit that can be achieved by buying and selling the stock once. The code should start with:
```python
from typing import List
def max_profit(prices: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def max_profit(prices: List[int]) -> int:
"""
Calculate the maximum profit that can be achieved by buying and selling the stock once.
Args:
prices (List[int]): A list of stock prices where... |
evol_instruct_66k | 40,170 | Write a Python function to convert a nested JSON object to a Python dictionary, while handling potential type mismatches and null values. The function should recursively traverse the JSON object and convert all keys and values to their appropriate Python types. If a value is `null`, it should be converted to `None`. Th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, Dict, List, Union
def convert_json_to_dict(json_obj: Union[Dict, List, Any]) -> Union[Dict, List, Any]:
"""
Converts a nested JSON object to a Python dictionary, handling potential type mismatches and nu... |
evol_instruct_66k | 40,172 | Write a Python function to maximize the number of content progeny by assigning cookies to them. Each progeny has a greed factor, and each cookie has a size. A progeny will be content if the size of the cookie is greater than or equal to their greed factor. The function should return the maximum number of content progen... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_content_progeny(g: List[int], s: List[int]) -> int:
"""
Maximizes the number of content progeny by assigning cookies to them.
Args:
g (List[int]): A list of integers representing th... |
evol_instruct_66k | 40,174 | Write a Python function to create a three-dimensional array of dimensions 4x4x4, where each entry is populated with a randomly selected float within the inclusive range of -1 to 1. The function should utilize the Numpy library to achieve this. The code should start with:
```python
import numpy as np
def create_random_... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def create_random_3d_array() -> np.ndarray:
"""
Create a three-dimensional array of dimensions 4x4x4 with each entry populated by a randomly selected float within the inclusive range of -1 to 1.
Returns:... |
evol_instruct_66k | 40,179 | Write a Python function to find the intersection of two arrays, each containing 20 distinct randomly generated numerical integers, without using built-in functions like `set.intersection`. Additionally, ensure that any duplicates in the intersection are removed. The function 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 List
import random
def find_intersection(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Finds the intersection of two arrays, each containing 20 distinct randomly generated numerical integers,
withou... |
evol_instruct_66k | 40,184 | Write a Python function to create a dictionary composed of 15 unique pairings, where the keys are color codes in hexadecimal format and the values are randomly generated decimal figures within the range of 0.1 and 1.0. The function should ensure that each color code is unique and that the decimal figures are rounded to... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import random
def generate_color_code_dict() -> Dict[str, float]:
"""
Generates a dictionary composed of 15 unique pairings, where the keys are color codes in hexadecimal format
and the values are ra... |
evol_instruct_66k | 40,186 | Write a Python function to generate the first `n` Fibonacci numbers. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the previous two. The function should return a list of the first `n` Fibonacci numbers.
The code should start with:
```python
from typing import List
def generate_f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the first n Fibonacci numbers.
The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the previous two.
A... |
evol_instruct_66k | 40,188 | Write a Python function to segregate and sort a given list into two distinct sections based on a specified threshold value. The function should return two lists: one containing elements less than or equal to the threshold, and the other containing elements greater than the threshold. Both lists should be sorted in asce... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def segregate_and_sort(lst: List[int], threshold: int) -> Tuple[List[int], List[int]]:
"""
Segregates and sorts a list into two distinct sections based on a specified threshold value.
Args:
... |
evol_instruct_66k | 40,199 | Write a Python function to reverse the order of keys in a given dictionary that contains mixed types as keys (i.e., containing both numeric and string data types). The dictionary must include at least one string key, one integer key, one float key, and one tuple key. Empty strings or tuples are not valid inputs.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def reverse_keys_order(dictionary: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Reverses the order of keys in a given dictionary that contains mixed types as keys.
Args:
dictionary (Dict[Any,... |
evol_instruct_66k | 40,202 | Write a Python function to identify and replace all special characters present in the given string with their respective ASCII values while maintaining the order of occurrence of these characters. The function should only replace non-alphanumeric characters (i.e., characters that are neither letters nor digits). The co... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_special_characters(s: str) -> str:
"""
Replaces all special characters in the given string with their respective ASCII values.
Args:
s (str): The input string containing alphanumeric and special characte... |
evol_instruct_66k | 40,209 | Write a Python function to generate a random alphanumeric sequence of a specified length that strictly alternates between uppercase English alphabets (A-Z) and numerical integers (0-9). The sequence should start with either an alphabet or a number, and the function should validate that the sequence meets the alternatin... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
import string
def generate_and_validate_sequence(length: int) -> str:
"""
Generates a random alphanumeric sequence of the specified length that alternates
strictly between uppercase English alphabets (A-Z) an... |
evol_instruct_66k | 40,222 | Write a Python function to categorize a list of strings based on the first two characters of each string. The function should return a dictionary where the keys are the first two characters of the strings and the values are lists of strings that start with those characters.
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, Dict
def categorize_strings(input_list: List[str]) -> Dict[str, List[str]]:
"""
Categorizes a list of strings based on the first two characters of each string.
Args:
input_list (List[str]):... |
evol_instruct_66k | 40,225 | Write a Python function to find all prime numbers up to a given number `n` using the Sieve of Eratosthenes algorithm. The function should return a list of all prime numbers in the range from 2 to `n` (inclusive).
The code should start with:
```python
from typing import List
def sieve_of_eratosthenes(n: int) -> List[i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sieve_of_eratosthenes(n: int) -> List[int]:
"""
Calculate all prime numbers up to a given number n using the Sieve of Eratosthenes algorithm.
Args:
n (int): The upper limit of the range ... |
evol_instruct_66k | 40,233 | Write a Python function to extract and return every second element from a given NumPy array. The function should start with:
```python
from typing import List
import numpy as np
def get_secondary_elements(arr: np.ndarray) -> List[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 get_secondary_elements(arr: np.ndarray) -> List[int]:
"""
Extracts and returns every second element from a given NumPy array.
Args:
arr (np.ndarray): The input NumPy a... |
evol_instruct_66k | 40,246 | Write a Python function to remove duplicate elements from a given list while maintaining the order of the first occurrence of each element. The function should use the `set` module to achieve this efficiently.
The code should start with:
```python
from typing import List
def remove_duplicates_keep_order(lst: List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_keep_order(lst: List[int]) -> List[int]:
"""
Removes duplicate elements from the given list while maintaining the order of the first occurrence of each element.
Args:
l... |
evol_instruct_66k | 40,248 | Write a Python function to extract and return the keys from a given dictionary. The function should handle any dictionary, regardless of its size or the types of its keys and values. The code should start with:
```python
from typing import Dict, List
def extract_keys(dictionary: Dict) -> List:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def extract_keys(dictionary: Dict) -> List:
"""
Extracts and returns the keys from a given dictionary.
Args:
dictionary (Dict): The dictionary from which to extract the keys.
Retu... |
evol_instruct_66k | 40,257 | Write a Python function to remove duplicate elements from a given list while preserving the order of the first occurrence of each element. The function should be efficient and should handle lists of various sizes.
The code should start with:
```python
from typing import List
def remove_duplicates(lst: List[int]) -> L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates(lst: List[int]) -> List[int]:
"""
Removes duplicate elements from the given list while preserving the order of the first occurrence of each element.
Args:
lst (List[int... |
evol_instruct_66k | 40,267 | Write a Python function to determine if a given number is a perfect cube. The function should return `True` if the number is a perfect cube and `False` otherwise. Additionally, generate the first 20 perfect cubes and validate each one using the function. 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 is_perfect_cube(n: int) -> bool:
"""
Determines if a given number is a perfect cube.
Args:
n (int): The number to check.
Returns:
bool: True if the number is a perfect cube,... |
evol_instruct_66k | 40,271 | Write a Python function to merge multiple dictionaries into a single dictionary. The function should take a variable number of dictionaries as input and return a new dictionary that contains all the key-value pairs from the input dictionaries. If there are duplicate keys, the value from the last dictionary in the input... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def merge_dictionaries(*dicts: Dict[str, Any]) -> Dict[str, Any]:
"""
Merge multiple dictionaries into a single dictionary.
Args:
*dicts: A variable number of dictionaries to be merged.... |
evol_instruct_66k | 40,274 | Write a Python function to determine the maximum subarray sum within a given array. The function should efficiently compute the maximum sum of contiguous subarrays, considering various subarray combinations. The code should start with:
```python
from typing import List
def max_subarray_sum(nums: List[int]) -> int:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_subarray_sum(nums: List[int]) -> int:
"""
Calculate the maximum sum of a contiguous subarray within the given array.
Args:
nums (List[int]): The input list of integers.
Returns:... |
evol_instruct_66k | 40,275 | Write a Python function to compute the square root of each non-negative integer in a given list, rounded to two decimal places. Only include integers that have rational square root values (i.e., their square roots are integers).
The code should start with:
```python
from typing import List
import math
def rational_sq... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def rational_square_roots(numbers: List[int]) -> List[float]:
"""
Computes the square root of each non-negative integer in the given list, rounded to two decimal places.
Only includes int... |
evol_instruct_66k | 40,294 | Write a Python function to convert a given number into its word representation. The function should handle numbers up to 999,999. The code should start with:
```python
def number_to_words(num: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def number_to_words(num: int) -> str:
"""
Convert a given number into its word representation.
Args:
num (int): The number to be converted. Must be between 0 and 999,999.
Returns:
str: The word represen... |
evol_instruct_66k | 40,296 | Write a Python function to sort a dictionary by its values in ascending order. The function should return a new dictionary with the keys rearranged according to their corresponding values in ascending order. The original dictionary should remain unchanged.
The code should start with:
```python
from typing import Dict
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_value(my_dict: Dict[str, int]) -> Dict[str, int]:
"""
Sorts a dictionary by its values in ascending order and returns a new dictionary.
Args:
my_dict (Dict[str, int]): The d... |
evol_instruct_66k | 40,297 | Write a Python function to combine two lists of strings without any duplicate items. The function should return a new list containing all unique items from both lists, maintaining the order of first occurrence.
The code should start with:
```python
from typing import List
def combine_lists_without_duplicates(list1: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def combine_lists_without_duplicates(list1: List[str], list2: List[str]) -> List[str]:
"""
Combines two lists of strings without any duplicate items, maintaining the order of first occurrence.
Args:... |
evol_instruct_66k | 40,306 | Write a Python function to sort a list of numeric integers using the bubble sort technique. The function should also perform rigorous error checking to handle potential erroneous inputs. The function should raise a `ValueError` if the input is not a list or if the list contains elements that are not integers.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(num_list: List[int]) -> List[int]:
"""
Sorts a list of numeric integers using the bubble sort technique.
Args:
num_list (List[int]): The list of integers to be sorted.
R... |
evol_instruct_66k | 40,317 | Write a Python function to replace every third occurrence of a specified element `x` in a given list with another specified element `y`. The function should return the modified list.
The code should start with:
```python
from typing import List, Any
def replace_third_occurrence(input_list: List[Any], x: Any, y: Any) ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def replace_third_occurrence(input_list: List[Any], x: Any, y: Any) -> List[Any]:
"""
Replace every third occurrence of the element `x` in the given list with the element `y`.
Args:
inp... |
evol_instruct_66k | 40,339 | Write a Python function to determine if a given integer is a perfect square. A perfect square is an integer that is the square of an integer. The function should handle both positive and negative integers, returning `False` for negative integers since they cannot be perfect squares. The function should be efficient and... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def is_perfect_square(n: int) -> bool:
"""
Determines if a given integer is a perfect square.
Args:
n (int): The integer to check.
Returns:
bool: True if n is a perfect square, False otherw... |
evol_instruct_66k | 40,348 | Write a Python function to extract the value of the element located at a specified position in a given numerical series. The function should handle cases where the specified position is out of bounds by returning `None`.
The code should start with:
```python
from typing import List, Optional
def extract_element_at_po... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def extract_element_at_position(series: List[int], position: int) -> Optional[int]:
"""
Extracts the value of the element located at the specified position in the given numerical series.
A... |
evol_instruct_66k | 40,359 | Write a Python function to generate the Fibonacci sequence up to the nth term. The function should handle invalid inputs by raising appropriate exceptions. The code should start with:
```python
from typing import List
def generate_fibonacci_sequence(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci_sequence(n: int) -> List[int]:
"""
Generate the Fibonacci sequence up to the nth term.
Args:
n (int): The number of terms in the Fibonacci sequence to generate.
R... |
evol_instruct_66k | 40,362 | Write a Python function to merge two lists of dictionaries into a single consolidated list. Each dictionary in the lists contains key-value pairs representing attributes of an entity, such as 'name' and 'age'. The function should handle the merging process in a multistage manner, ensuring that the resulting list contai... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def merge_dictionaries(list1: List[Dict[str, any]], list2: List[Dict[str, any]]) -> List[Dict[str, any]]:
"""
Merges two lists of dictionaries into a single consolidated list.
Args:
li... |
evol_instruct_66k | 40,383 | Write a Python function to filter and return a list of even numbers from a given list of integers. The function should efficiently handle the input list and return only the even numbers.
The code should start with:
```python
from typing import List
def filter_even_numbers(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 filter_even_numbers(numbers: List[int]) -> List[int]:
"""
Filters and returns a list of even numbers from the given list of integers.
Args:
numbers (List[int]): The list of integers from... |
evol_instruct_66k | 40,386 | Write a Python function to determine if a given string is an isogram and if it is a perfect isogram. An isogram is a word or phrase without a repeating letter, and a perfect isogram is a word or phrase in which every letter of the alphabet is used exactly once. The function should be case-insensitive and should disrega... | Here is the Python code to solve the given problem in the markdown block:
```python
import string
def check_isogram(phrase: str) -> tuple:
"""
Determine if a given string is an isogram and if it is a perfect isogram.
Args:
phrase (str): The input string to be checked.
Returns:
tuple: ... |
evol_instruct_66k | 40,390 | Write a Python function to compute the item-by-item scalar product of two single-dimensional numerical vectors. The function should ensure that both vectors have the same length before performing the computation. If the vectors are of different lengths, the function should return an error message. The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def scalar_product(vector1: List[int], vector2: List[int]) -> Union[List[int], str]:
"""
Computes the item-by-item scalar product of two single-dimensional numerical vectors.
Args:
ve... |
evol_instruct_66k | 40,391 | Write a Python function to find the maximum sum of a contiguous subarray (also known as the maximum subarray sum) from a given list of integers. The function should efficiently compute the maximum sum using an optimal algorithm.
The code should start with:
```python
from typing import List
def max_subarray_sum(arr: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_subarray_sum(arr: List[int]) -> int:
"""
Calculate the maximum sum of a contiguous subarray from the given list of integers.
Args:
arr (List[int]): The list of integers from which to... |
evol_instruct_66k | 40,397 | Write a Python function to perform a bitwise operation on three given integers and return the result. The function should also update two additional variables with the result of the operation. The bitwise operation to be performed is specified by a string input ('AND', 'OR', 'XOR'). The function should handle invalid o... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_operation(e: int, f: int, g: int, h: int, i: int, operation: str) -> int:
"""
Perform a bitwise operation on three integers and update two additional variables with the result.
Args:
e (int): The first i... |
evol_instruct_66k | 40,399 | Write a Python function to calculate the sum of the squares of all elements in a given list of integers. The function should be efficient and handle any size of input list. The code should start with:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
"""
Calculate the sum of the squares of all elements in the given list of integers.
Args:
numbers (List[int]): A list of integers for which the... |
evol_instruct_66k | 40,427 | Write a Python function to sort a given list of 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 integers using the insertion sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
... |
evol_instruct_66k | 40,429 | Write a Python function to perform a subtraction operation between two numeric parameters. The function should handle both integral and floating-point numbers. The code should start with:
```python
def subtract_numbers(x: float, y: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def subtract_numbers(x: float, y: float) -> float:
"""
Perform a subtraction operation where the second parameter is subtracted from the first.
Args:
x (float): The first numeric parameter.
y (float): The ... |
evol_instruct_66k | 40,442 | Write a Python function to increment each element in a list of integers by a given integer value. The function should take two parameters: a list of integers (`marks`) and an integer (`mark`). The function should return a new list where each element in the original list is incremented by the given integer value.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def increment_marks(marks: List[int], mark: int) -> List[int]:
"""
Increment each element in the given list of integers by the specified integer value.
Args:
marks (List[int]): A list of int... |
evol_instruct_66k | 40,443 | Write a Python function to implement an optimal algorithm for data compression to reduce the storage space required for a multidimensional matrix composed of integer values. The function should handle edge cases, such as empty matrices or ones with a large number of zeros. The code should start with:
```python
from typ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def compress_matrix(matrix: List[List[int]]) -> List[List[List[int]]]:
"""
Compresses a multidimensional matrix by reducing consecutive identical elements into tuples of (element, count).
Args:
... |
evol_instruct_66k | 40,463 | Write a Python function to convert a given sequence of lowercase English alphabets into their equivalent respective symbols in uppercase typographical representation. The function should handle any string input and return the uppercase version of the input string.
The code should start with:
```python
def convert_to_u... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_uppercase(text: str) -> str:
"""
Converts a given sequence of lowercase English alphabets into their equivalent uppercase typographical representation.
Args:
text (str): The input string containing lo... |
evol_instruct_66k | 40,474 | Write a Python function to return a random non-vowel character from a given list of strings. The function should ensure that the character returned is not a vowel (i.e., 'a', 'e', 'i', 'o', 'u' and their uppercase counterparts). The code should start with:
```python
from typing import List
import random
def get_random... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def get_random_non_vowel(strings: List[str]) -> str:
"""
Returns a random non-vowel character from a given list of strings.
Args:
strings (List[str]): A list of strings from wh... |
evol_instruct_66k | 40,492 | Write a Python function to perform matrix subtraction between two given two-dimensional arrays (matrices). The function should handle matrices of the same dimensions and return the resulting matrix after subtraction. The code should start with:
```python
from typing import List
def subtract_matrices(matrix1: List[List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def subtract_matrices(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[List[int]]:
"""
Subtracts matrix2 from matrix1 and returns the resulting matrix.
Args:
matrix1 (List[List[in... |
evol_instruct_66k | 40,500 | Write a Python function that generates an infinite sequence of prime numbers using the Sieve of Eratosthenes algorithm. The function should yield each prime number as it is found, rather than returning a list of all primes up to a given limit. The function should start from the first prime number (2) and continue indef... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_primes():
"""
Generates an infinite sequence of prime numbers using the Sieve of Eratosthenes algorithm.
Yields:
int: The next prime number in the sequence.
"""
primes = [] # List to store the ... |
evol_instruct_66k | 40,501 | Write a Python function to calculate the Euclidean distance between two points in a 3-dimensional Cartesian coordinate system. The function should handle input validation to ensure that the coordinates are valid numbers. The code should start with:
```python
from typing import Tuple
def euclidean_distance_3d(point1: T... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import Tuple
import math
def euclidean_distance_3d(point1: Tuple[float, float, float], point2: Tuple[float, float, float]) -> float:
"""
Calculate the Euclidean distance between two points in a 3-dimensional Carte... |
evol_instruct_66k | 40,503 | Write a Python function to determine the common elements among three distinct collections (groupA, groupB, and groupC) and report the count of each common element found in each group. The function should handle collections of any length and account for potential duplicates within the collections. The result should be a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
from collections import Counter
def find_common_elements(groupA: List[int], groupB: List[int], groupC: List[int]) -> Dict[int, Tuple[int, int, int]]:
"""
Finds the common elements among thre... |
evol_instruct_66k | 40,504 | Write a Python function to sort a given numeric array in descending order. The function should return the sorted array. The code should start with:
```python
from typing import List
def sort_descending(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_descending(arr: List[int]) -> List[int]:
"""
Sorts the given numeric array in descending order.
Args:
arr (List[int]): The numeric array to be sorted.
Returns:
List[i... |
evol_instruct_66k | 40,510 | Write a Python function to determine if a given integer is a perfect square. The function should efficiently determine whether the integer is a perfect square without using floating-point arithmetic. The function should also handle edge cases such as negative numbers and zero.
The code should start with:
```python
def... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_perfect_square(n: int) -> bool:
"""
Determine if a given integer is a perfect square.
Args:
n (int): The integer to check.
Returns:
bool: True if the integer is a perfect square, False otherwise.... |
evol_instruct_66k | 40,521 | Write a Python function to simulate the insertion of an order document into a MongoDB collection. The function should take a dictionary representing the order details and return a string indicating the success or failure of the insertion. The order details dictionary should include the following fields: `order_id`, `cu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def insert_order(order_details: Dict[str, str]) -> str:
"""
Simulate the insertion of an order document into a MongoDB collection.
Args:
order_details (Dict[str, str]): A dictionary containi... |
evol_instruct_66k | 40,549 | Write a Python function to generate a 4-dimensional matrix filled with random floating-point numbers and then reshape it into a 2-dimensional matrix. The function should return the reshaped 2-dimensional matrix.
The code should start with:
```python
import numpy as np
from typing import List
def generate_and_reshape_... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List
def generate_and_reshape_matrix(dim1: int, dim2: int, dim3: int, dim4: int) -> List[List[float]]:
"""
Generates a 4-dimensional matrix filled with random floating-point numbers and res... |
evol_instruct_66k | 40,560 | Write a Python function to sort a list of integral numerical values in decreasing order. The function should take a list of integers as input and return a new list with the same integers sorted in descending order. The original list should not be modified.
The code should start with:
```python
from typing import List
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_descending(numbers: List[int]) -> List[int]:
"""
Sorts a list of integral numerical values in decreasing order.
Args:
numbers (List[int]): The list of integers to be sorted.
Re... |
evol_instruct_66k | 40,568 | Write a Python function to reverse the elements of a given array and return the reversed array. The function should handle arrays of any length, including empty arrays. The code should start with:
```python
from typing import List
def reverse_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 reverse_array(arr: List[int]) -> List[int]:
"""
Reverses the elements of a given array and returns the reversed array.
Args:
arr (List[int]): The input array to be reversed.
Retur... |
evol_instruct_66k | 40,575 | Write a Python function to calculate the summation of all elements in a list using a recursive approach. The function should have two parameters: the list and an optional index (default 0) to keep track of the current position in the list. Implement the recursion without using loops or built-in sum functions.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_elements_recursive(lst: List[int], index: int = 0) -> int:
"""
Calculate the sum of all elements in a list using a recursive approach.
Args:
lst (List[int]): The list of integers to ... |
evol_instruct_66k | 40,580 | Write a Python function to determine the smallest non-negative value from a given list of floating-point numbers. The function should handle lists with both positive and negative floating-point numbers, and return `None` if there are no non-negative numbers in the list.
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, Optional
def find_smallest_non_negative(numbers: List[float]) -> Optional[float]:
"""
Determine the smallest non-negative value from a given list of floating-point numbers.
Args:
numbers (L... |
evol_instruct_66k | 40,584 | Write a Python function to iterate over a list of integers, print each element, and calculate and print the cumulative sum of the elements as you iterate. The function should handle the initial errors in the given code snippet and ensure that the cumulative sum is correctly calculated and printed.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_elements_and_cumulative_sum(my_list: List[int]) -> None:
"""
Iterates over a list of integers, prints each element, and calculates and prints the cumulative sum of the elements.
Args:
... |
evol_instruct_66k | 40,597 | Write a Python function to simulate the behavior of a Unix Shell script that echoes the argument passed to it in the form of a positional parameter. The function should accept a list of strings as arguments and return a string that concatenates these arguments with spaces, similar to how the Unix `echo` command would d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def unix_echo(args: List[str]) -> str:
"""
Simulates the behavior of a Unix Shell script that echoes the arguments passed to it.
Args:
args (List[str]): A list of strings representing the ar... |
evol_instruct_66k | 40,599 | Write a Python function to find the most frequent character 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 handle any non-empty string input.
The code should start with:
```python
def most_frequent_char(string: s... | Here is the Python code to solve the given problem in the markdown block:
```python
def most_frequent_char(string: str) -> str:
"""
Finds the most frequent character in a given string. If there are multiple characters
with the same highest frequency, returns the one that appears first in the string.
Ar... |
evol_instruct_66k | 40,600 | Write a Python function to retrieve and print the second level sub-dictionary for a specific key from a given dictionary. The function should handle cases where the key does not exist in the dictionary by returning `None`. The code should start with:
```python
from typing import Dict, Any
def get_subdict(data: Dict[st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def get_subdict(data: Dict[str, Dict[str, Any]], key: str) -> Dict[str, Any]:
"""
Retrieves the second level sub-dictionary for a specific key from the given dictionary.
Args:
data (Dic... |
evol_instruct_66k | 40,602 | Write a Python function to calculate the sums of each row and the sum of the diagonal elements of a given square matrix. The function should return a list containing the row sums followed by the diagonal sum. The input matrix will always be a square matrix (i.e., have equal number of rows and columns).
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_rows_and_diagonal(matrix: List[List[int]]) -> List[int]:
"""
Calculate the sums of each row and the sum of the diagonal elements of a given square matrix.
Args:
matrix (List[List[int... |
evol_instruct_66k | 40,622 | Write a Python function to search for a specified character sequence within an array of character strings. The function should return the index of the first occurrence of the specified character sequence if it exists in the array, otherwise it should return -1. The code should start with:
```python
from typing import L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def search_sequence(arr: List[str], given_str: str) -> int:
"""
Searches for a specified character sequence within an array of character strings.
Args:
arr (List[str]): The array of characte... |
evol_instruct_66k | 40,624 | Write a Python function to transform a given string such that all subsequent alphabetic characters rendered in lower-case typography are converted into their equivalent representation in upper-case typography. The function should handle strings with mixed case characters and non-alphabetic characters, leaving the non-a... | Here is the Python code to solve the given problem in the markdown block:
```python
def to_upper(text: str) -> str:
"""
Transforms all lowercase alphabetic characters in the input string to their uppercase equivalents.
Args:
text (str): The input string to be transformed.
Returns:
str:... |
evol_instruct_66k | 40,626 | Write a Python function to find the longest common subsequence (LCS) of two given strings. The function should return the LCS as a string. The code should start with:
```python
from typing import List
def longest_common_subsequence(X: str, Y: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_common_subsequence(X: str, Y: str) -> str:
"""
Finds the longest common subsequence (LCS) of two given strings.
Args:
X (str): The first string.
Y (str): The second strin... |
evol_instruct_66k | 40,640 | Write a Python function to calculate the factorial of a given number using memoization to improve efficiency and computation time. The function should be based on a recursive routine and should store previously computed factorial values in a dictionary to avoid redundant calculations.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
def factorial_memo(n: int, memo: dict = None) -> int:
"""
Calculate the factorial of a given number using memoization to improve efficiency.
Args:
n (int): The number for which to calculate the factorial.
me... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.