source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 76,989 | Write a Python function to determine if two given alpha-numeric sequences are lexical anagrams. The sequences may contain uppercase and lowercase letters, numbers, and special characters. The function should be case sensitive and should also be able to handle string inputs that have punctuation marks and white spaces. ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
import re
from collections import Counter
def are_lexical_anagrams(seq1: str, seq2: str) -> bool:
"""
Determines if two given alpha-numeric sequences are lexical anagrams.
The function is case sens... |
magic_evol_110k | 76,993 | Write a Python function to create a dictionary that maps each continent to its aggregate landmass in square kilometers. The function should take a list of continents and a list of corresponding landmasses as input and return a dictionary. The code should start with:
```python
from typing import List, Dict
def create_l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_landmass_dict(continents: List[str], landmasses: List[int]) -> Dict[str, int]:
"""
Creates a dictionary that maps each continent to its aggregate landmass in square kilometers.
Args... |
magic_evol_110k | 77,006 | Write a Python function to create a two-dimensional array from a given list of numerical values, ensuring that the values are distributed evenly across the specified number of rows and columns. The function should handle cases where the number of elements in the list does not perfectly fit into the specified dimensions... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def create_2d_array(numbers: List[Any], rows: int, cols: int, default_value: Any = None) -> List[List[Any]]:
"""
Create a two-dimensional array from a given list of numerical values.
Args:
... |
magic_evol_110k | 77,019 | Write a Python function to calculate the sum of the first `n` elements in a given array while excluding any repeating elements. If `n` is greater than the length of the array, the function should consider the entire array. The function should start with:
```python
from typing import List
def sum_first_n_unique_element... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_first_n_unique_elements(arr: List[int], n: int) -> int:
"""
Calculate the sum of the first n unique elements in the given array.
Args:
arr (List[int]): The array of integers from whi... |
magic_evol_110k | 77,037 | Write a Python function to determine the maximum value between two given integers `x` and `y` using a more efficient algorithmic methodology. The function should return the larger of the two integers. The code should start with:
```python
def get_max_value(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_max_value(x: int, y: int) -> int:
"""
Returns the maximum value between two given integers.
Args:
x (int): The first integer to compare.
y (int): The second integer to compare.
Returns:
... |
magic_evol_110k | 77,040 | Write a Python function to check if a list of numerical values adheres to a strictly descending order, meaning no two successive numbers are identical. The function should handle exceptions for non-numeric inputs, empty lists, and lists with a single element. The function should return `True` if the list is strictly de... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def check_strictly_descending_order(lst: List[float]) -> bool:
"""
Check if a list of numerical values adheres to a strictly descending order.
Args:
lst (List[float]): The list of numerical ... |
magic_evol_110k | 77,041 | Write a Python function to remove all duplicate strings from a given list while maintaining the original order of occurrence. Additionally, the function should determine and output the strings that were removed, their counts, and the new list after removing the duplicates. The function should start with:
```python
from... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
def remove_duplicates_and_report(input_list: List[str]) -> Tuple[List[str], Dict[str, int]]:
"""
Removes duplicate strings from the input list while maintaining the original order of occurre... |
magic_evol_110k | 77,042 | Write a Python function to replace all occurrences of a specified character in a given string with another specified character. The function should return the modified string.
The code should start with:
```python
def replace_character(text: str, old_char: str, new_char: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def replace_character(text: str, old_char: str, new_char: str) -> str:
"""
Replace all occurrences of a specified character in a given string with another specified character.
Args:
text (str): The input string in w... |
magic_evol_110k | 77,045 | Write a Python function to calculate the sum of elements in a given list efficiently. The function should handle lists of any size and ensure optimal performance. The code should start with:
```python
from typing import List
def calculate_sum(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def calculate_sum(arr: List[int]) -> int:
"""
Calculate the sum of elements in a given list efficiently.
Args:
arr (List[int]): The list of integers whose sum needs to be calculated.
... |
magic_evol_110k | 77,048 | Write a Python function to display the values from a given dictionary in a specific format. The dictionary contains key-value pairs where the keys are strings and the values can be of any type. The function should return a formatted string where each key-value pair is displayed in the format "key: value". The final str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def display_values_from_map(map_data: Dict) -> str:
"""
Returns a formatted string displaying all key-value pairs from the given dictionary.
Args:
map_data (Dict): A dictionary containing ke... |
magic_evol_110k | 77,049 | Write a Python function to sort words in a dictionary based on the number of meanings each word has. The dictionary is provided in the format where keys are words and values are lists of meanings. The function should return a list of words sorted by the number of meanings in ascending order by default, but it should al... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Union
def sort_words_by_meanings(dictionary: Dict[str, List[str]], reverse: bool = False) -> List[str]:
"""
Sorts the words in the given dictionary based on the number of meanings each word has.
... |
magic_evol_110k | 77,056 | Write a Python function to calculate the Hamming distance between two binary sequences. The Hamming distance is defined as the number of positions at which the corresponding bits are different. The function should take two binary strings as input and return an integer representing the Hamming distance.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
def hamming_distance(bin_seq1: str, bin_seq2: str) -> int:
"""
Calculate the Hamming distance between two binary sequences.
The Hamming distance is the number of positions at which the corresponding bits are different.
... |
magic_evol_110k | 77,068 | Write a Python function to transform an array of numerical entities into a string delineated by commas, while ensuring the numbers are sorted in ascending order and any duplicate numbers are removed. The function should have a time complexity less than O(n^2).
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 transform_and_sort_array(arr: List[int]) -> str:
"""
Transforms an array of numerical entities into a string delineated by commas,
with the numbers sorted in ascending order and any duplicate num... |
magic_evol_110k | 77,071 | Write a Python function to convert a given integer to its binary representation without using the built-in `bin()` function. The function should handle both positive and negative integers. The binary representation should be in the form of a string, prefixed with '0b' for positive numbers and '-0b' for negative numbers... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_binary(n: int) -> str:
"""
Converts a given integer to its binary representation without using the built-in `bin()` function.
Args:
n (int): The integer to be converted to binary.
Returns:
... |
magic_evol_110k | 77,102 | Write a Python function to filter out and return a list of odd numbers from a given list of integers. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def filter_odd_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_odd_numbers(numbers: List[int]) -> List[int]:
"""
Filters out and returns a list of odd numbers from the given list of integers.
Args:
numbers (List[int]): The list of integers fr... |
magic_evol_110k | 77,105 | Write a Python function to find the maximum numeric value within a given array without using any built-in functions that directly solve the problem (e.g., `max()`, `sorted()`, etc.). The function should not alter the original array's structure. The function should start with:
```python
from typing import List
def find... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_max_value(array: List[int]) -> int:
"""
Finds the maximum numeric value in the given array without using any built-in functions.
Args:
array (List[int]): The array of integers from ... |
magic_evol_110k | 77,147 | Write a Python function that iteratively prints "Goodbye Universe" for a specified number of iterations, while maintaining a live count of the iterations. Additionally, the function should print a "Still Working" message every 10 iterations. The function should handle any exceptions that might occur during execution an... | Here is the Python code to solve the given problem in the markdown block:
```python
def goodbye_universe(iterations: int):
"""
Iteratively prints "Goodbye Universe" for a specified number of iterations,
while maintaining a live count of the iterations. Additionally, prints a
"Still Working" message ever... |
magic_evol_110k | 77,150 | Write a Python function to find the frequency of a given word in a given text. The function should be case-insensitive and should handle punctuation by stripping it from the words before counting. The function should start with:
```python
from typing import List
def word_frequency(text: str, word: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import string
def word_frequency(text: str, word: str) -> int:
"""
Calculate the frequency of a given word in a given text.
The function is case-insensitive and handles punctuation by stripping it... |
magic_evol_110k | 77,162 | Write a Python function to calculate the highest common factor (HCF) of two given integers using the Euclidean algorithm. The function should be efficient and handle both positive and negative integers. The code should start with:
```python
def highest_common_factor(num1: int, num2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def highest_common_factor(num1: int, num2: int) -> int:
"""
Calculate the highest common factor (HCF) of two integers using the Euclidean algorithm.
Args:
num1 (int): The first integer.
num2 (int): The secon... |
magic_evol_110k | 77,172 | Write a Python function to generate a list of tuples where each tuple contains successive elements from a given list. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List, Tuple
def successive_pairs(lst: List[int]) -> List[Tuple[int, int]]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def successive_pairs(lst: List[int]) -> List[Tuple[int, int]]:
"""
Generate a list of tuples where each tuple contains successive elements from the given list.
Args:
lst (List[int]): ... |
magic_evol_110k | 77,179 | Write a Python function to construct a Uniform Resource Locator (URL) using the given components: transfer protocol, secondary level domain, main domain name, and resource locator. The function should correctly concatenate these components to form a valid URL. The code should start with:
```python
def create_URL(transf... | Here is the Python code to solve the given problem in the markdown block:
```python
def create_URL(transfer_protocol: str, secondary_level_domain: str, main_domain_name: str, resource_locator: str) -> str:
"""
Constructs a Uniform Resource Locator (URL) from the given components.
Args:
transfer_pro... |
magic_evol_110k | 77,182 | Write a Python function to search for specific subsets of characters within a provided text fragment. The function should implement a customized searching algorithm without using Python's built-in substring search functions like `in`, `find()`, or `index()`. The function should return the exact indices at which each su... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def search_substrings(text: str, subsets: List[str]) -> Dict[str, List[int]]:
"""
Searches for specific subsets of characters within a provided text fragment.
Returns the exact indices at which... |
magic_evol_110k | 77,193 | Write a Python function to determine if a given list of integers contains any perfect numbers. A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding itself). The function should return a list of boolean values corresponding to whether each input number is a perfect number.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def is_perfect(n: int) -> bool:
"""
Determine if a given integer is a perfect number.
Args:
n (int): The integer to check.
Returns:
bool: True if the integer is a pe... |
magic_evol_110k | 77,196 | Write a Python function to parse a given string based on specific delimiters and return either a list of words divided by a comma or a colon, or the count of lowercase alphabetic characters with odd ASCII values if neither delimiter is present.
The code should start with:
```python
from typing import List, Union
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def parse_details(s: str) -> Union[List[str], int]:
"""
Parse a given string based on specific delimiters and return either a list of words
divided by a comma or a colon, or the count of lower... |
magic_evol_110k | 77,206 | Write a Python function to calculate the sum of all integer elements in a given list that may contain different types of elements, including integers, strings, and even other lists. The function should recursively traverse through any nested lists to sum up all integer values.
The code should start with:
```python
fro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def recursive_sum(lst: List[Union[int, str, List]]) -> int:
"""
Calculate the sum of all integer elements in a given list that may contain different types of elements,
including integers, stri... |
magic_evol_110k | 77,215 | Write a Python function to extract and return the values from a given dictionary. The function should handle dictionaries with various types of values, including nested dictionaries and lists. The function should return a list containing all the values from the dictionary, maintaining the order of insertion.
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Any
def extract_values(dictionary: Dict[str, Any]) -> List[Any]:
"""
Extracts and returns all values from a given dictionary, including values from nested dictionaries and lists.
Args:
... |
magic_evol_110k | 77,227 | Write a Python function to group and sort a list of books by multiple keys using the `itertools.groupby` function. The function should take a list of dictionaries, where each dictionary represents a book with keys `"author"`, `"title"`, and `"year_published"`. The function should return a list of tuples, where each tup... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
from itertools import groupby
from operator import itemgetter
def group_books_by_author_and_year(books: List[Dict[str, str]]) -> List[Tuple[Tuple[str, int], List[Dict[str, str]]]]:
"""
Group... |
magic_evol_110k | 77,262 | Write a Python function to detect duplicate elements in a tuple and return a dictionary where the keys are the duplicate elements and the values are the counts of their occurrences. The function should not use any built-in Python libraries for this task.
The code should start with:
```python
def detect_duplicates(t: t... | Here is the Python code to solve the given problem in the markdown block:
```python
def detect_duplicates(t: tuple) -> dict:
"""
Detects duplicate elements in a tuple and returns a dictionary where the keys are the duplicate elements
and the values are the counts of their occurrences.
Args:
t (... |
magic_evol_110k | 77,265 | Write a Python function to sort an array of strings based on their length and the number of vowels in the string, with priority given to the length. If two strings have the same length and number of vowels, maintain their original order in the array. The function 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 sort_array(arr: List[str]) -> List[str]:
"""
Sorts an array of strings based on their length and the number of vowels in the string,
with priority given to the length. If two strings have the sam... |
magic_evol_110k | 77,270 | Write a Python function to segregate a given array of numbers into even and odd entries. The function should return two arrays: one with all the even numbers and another with all the odd numbers. The order of numbers in the arrays does not matter. The function should be optimized to reduce the number of iterations thro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def segregate_array(arr: List[int]) -> Tuple[List[int], List[int]]:
"""
Segregates a given array of numbers into even and odd entries.
Args:
arr (List[int]): The array of numbers to b... |
magic_evol_110k | 77,281 | Write a Python function to find all duplicate characters in a given string using a more efficient approach than the provided code snippet. Instead of using Python's built-in `count` function, which has a time complexity of O(n^2), use a dictionary to count character occurrences. The function should return a set of char... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_duplicate_characters(string: str) -> set:
"""
Finds all duplicate characters in a given string using a dictionary to count occurrences.
Args:
string (str): The input string to analyze for duplicate characte... |
magic_evol_110k | 77,282 | Write a Python function to evaluate a given arithmetic expression represented as a string. The function should handle basic arithmetic operations: addition (`+`), subtraction (`-`), multiplication (`*`), and division (`/`). The expression will not contain parentheses or nested operations. The function should return the... | Here is the Python code to solve the given problem in the markdown block:
```python
def evaluate_arithmetic_expression(expression: str) -> float:
"""
Evaluates a basic arithmetic expression represented as a string.
Args:
expression (str): The arithmetic expression to evaluate.
Returns:
... |
magic_evol_110k | 77,288 | Write a Python function to sanitize a nested list of integers by removing any "arcane" numerals. An arcane numeral is defined as any integer that is less than 0 or greater than 9. The function should recursively traverse the nested list and remove any arcane numerals. The function should start with:
```python
from typi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def sanitize_nested_list(data: List[Union[int, List]]) -> List[Union[int, List]]:
"""
Sanitize a nested list of integers by removing any arcane numerals.
An arcane numeral is defined as any i... |
magic_evol_110k | 77,290 | Write a Python function to classify a given data point using the k-Nearest Neighbors (k-NN) algorithm with k = 3. The function should take a list of training data points (each represented as a tuple of features and a label) and a test data point (represented as a tuple of features) as input, and return the predicted la... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import heapq
def classify_knn(training_data: List[Tuple[List[float], str]], test_point: List[float]) -> str:
"""
Classify a given test point using the k-Nearest Neighbors algorithm with k = 3.
... |
magic_evol_110k | 77,299 | Write a Python function to generate a list of progressively highest values at each point in a given sequence of integers. The function should start with:
```python
from typing import List
def rolling_max(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 rolling_max(numbers: List[int]) -> List[int]:
"""
Generate a list of progressively highest values at each point in the given sequence of integers.
Args:
numbers (List[int]): The sequence... |
magic_evol_110k | 77,301 | Write a Python function to validate the nesting and balance of brackets within a mathematical expression. The function should ensure that all types of brackets (parentheses '()', square brackets '[]', and curly braces '{}') are correctly nested and balanced. The function should return 'Correct' if the expression is val... | Here is the Python code to solve the given problem in the markdown block:
```python
def validate_brackets(expr: str) -> str:
"""
Validates the nesting and balance of brackets within a mathematical expression.
Args:
expr (str): The mathematical expression to validate.
Returns:
str: 'Cor... |
magic_evol_110k | 77,313 | Write a Python function to calculate and return the count of synonymous words for each key word in a given thesaurus. The thesaurus is represented as a dictionary where each key is a word and the corresponding value is a list of its synonyms. The function should return a dictionary where each key is a word from the the... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def count_synonyms(thesaurus: Dict[str, List[str]]) -> Dict[str, int]:
"""
Calculate the count of synonymous words for each key word in the given thesaurus.
Args:
thesaurus (Dict[str, ... |
magic_evol_110k | 77,321 | Write a Python function to replace all instances of dual spaces with single spaces in a given string. The function should handle multiple occurrences of dual spaces and ensure that the resulting string has no consecutive spaces. The code should start with:
```python
def replace_dual_spaces(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def replace_dual_spaces(text: str) -> str:
"""
Replace all instances of dual spaces with single spaces in the given string.
Args:
text (str): The input string in which dual spaces need to be replaced.
Returns:
... |
magic_evol_110k | 77,328 | Write a Python function to remove all occurrences of a specified item from a given list. If the item is not found in the list, print an error message. The function should start with:
```python
from typing import List
def remove_all_occurrences(given_list: List[int], item_to_remove: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_all_occurrences(given_list: List[int], item_to_remove: int) -> List[int]:
"""
Removes all occurrences of a specified item from a given list.
Args:
given_list (List[int]): The list... |
magic_evol_110k | 77,333 | Write a Python function to verify if a specified textual content is comprised of alphanumeric characters using a multi-step reasoning process. The function should check each character individually and ensure that it is either a letter (both uppercase and lowercase) or a digit. The function should return `True` if all c... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_alphanumeric_multi_step(text: str) -> bool:
"""
Verifies if the specified textual content is comprised of alphanumeric characters using a multi-step reasoning process.
Args:
text (str): The input text to be v... |
magic_evol_110k | 77,361 | Write a Python function to convert a given decimal number to its binary representation without using the built-in `bin()` function. The function should handle both positive and negative integers. The code should start with:
```python
def decimal_to_binary(num: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def decimal_to_binary(num: int) -> str:
"""
Converts a given decimal number to its binary representation without using the built-in `bin()` function.
Args:
num (int): The decimal number to be converted.
Returns... |
magic_evol_110k | 77,363 | Write a Python function to evaluate mathematical expressions embedded within strings. The function should handle single-depth nested parentheses and the basic mathematical operations: addition, subtraction, multiplication, and division. The function should be recursive and should start with:
```python
def evaluate_expr... | Here is the Python code to solve the given problem in the markdown block:
```python
def evaluate_expression(expression: str) -> float:
"""
Evaluate a mathematical expression embedded within a string.
The function handles single-depth nested parentheses and the basic mathematical operations:
addition, s... |
magic_evol_110k | 77,374 | Write a Python function to find and return the duplicate items in a given list of integers. The function should return a list of unique duplicate items in the order they first appear in the input list.
The code should start with:
```python
from typing import List
def find_duplicates(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 find_duplicates(arr: List[int]) -> List[int]:
"""
Find and return the duplicate items in a given list of integers.
Args:
arr (List[int]): The list of integers to check for duplicates.
... |
magic_evol_110k | 77,385 | Write a Python function to identify and classify valid IPv4 and IPv6 addresses within a given string. The function should return a dictionary with keys "IPv4" and "IPv6", each containing a list of valid addresses found in the string. If no valid addresses are found, the corresponding list should be empty.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
import re
def find_ip_addresses(text: str) -> Dict[str, List[str]]:
"""
Identify and classify valid IPv4 and IPv6 addresses within a given string.
Args:
text (str): The input string to... |
magic_evol_110k | 77,387 | Write a Python function to generate an orthogonal grid (a two-dimensional matrix) of dimensions `n` by `m`, populated with a specified value. The function should allow the user to specify the dimensions of the grid and the value to fill the grid with. The code should start with:
```python
from typing import List, Any
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def generate_grid(n: int, m: int, fill_value: Any = 0) -> List[List[Any]]:
"""
Generates an orthogonal grid (a two-dimensional matrix) of dimensions n by m,
populated with the specified fill_val... |
magic_evol_110k | 77,398 | Write a Python function to validate an email address using a regular expression. The function should ensure that the email address follows the standard format, including the presence of a local part, an "@" symbol, a domain name, and a top-level domain (TLD). The function should return `True` if the email is valid and ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_email(email: str) -> bool:
"""
Validate an email address using a regular expression.
Args:
email (str): The email address to validate.
Returns:
bool: True if the email is valid, ... |
magic_evol_110k | 77,405 | Write a Python function to reverse the sequence of a given list of whole numbers without using any built-in utility functions such as `reverse()`. The function should handle lists with up to \(10^6\) elements and complete execution in less than 2 seconds. The code should start with:
```python
from typing import List
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_sequence(seq: List[int]) -> List[int]:
"""
Reverses the sequence of a given list of whole numbers without using built-in utility functions.
Args:
seq (List[int]): The list of who... |
magic_evol_110k | 77,408 | Write a Python function to determine if it is possible to complete all the courses given a certain number of courses and their prerequisites. Each course is labeled from `0` to `numCourses - 1`. The prerequisites are provided in an array where each element `prerequisites[i] = [ai, bi]` signifies that course `bi` must b... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def can_finish_courses(numCourses: int, prerequisites: List[List[int]]) -> bool:
"""
Determine if it is possible to complete all the courses given their prerequisites.
Args:
numCourses (int)... |
magic_evol_110k | 77,410 | Write a Python function to calculate the sum of all elements in a given list of integers. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def sum_of_elements(arr: 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_elements(arr: List[int]) -> int:
"""
Calculate the sum of all elements in a given list of integers.
Args:
arr (List[int]): The list of integers whose sum needs to be calculated.
... |
magic_evol_110k | 77,412 | Write a Python function to calculate the sum of all elements in a given list efficiently. The function should be optimized for speed execution. The code should start with:
```python
from typing import List
def sum_all_elements(my_list: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_all_elements(my_list: List[int]) -> int:
"""
Calculate the sum of all elements in a given list efficiently.
Args:
my_list (List[int]): The list of integers to sum.
Returns:
... |
magic_evol_110k | 77,420 | Write a Python function to replace empty tuples in a list of tuples with either a specific value or a randomly generated string of a specified length. The function should take the list of tuples, an optional specific value to replace the empty tuples, and an optional length for the randomly generated string. The functi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional, Tuple
import random
import string
def replace_empty_tuple(list_of_tuples: List[Tuple], value: Optional[str] = None, length_of_string: int = 5) -> List[Tuple]:
"""
Replaces empty tuples in a li... |
magic_evol_110k | 77,423 | Write a Python function to replace all non-alphanumeric characters in a given string with a specified substitute character. The function should handle any string input and return the modified string.
The code should start with:
```python
def replace_non_alphanumeric(text: str, substitute: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def replace_non_alphanumeric(text: str, substitute: str) -> str:
"""
Replaces all non-alphanumeric characters in the given text with the specified substitute character.
Args:
text (str): The input string to be proce... |
magic_evol_110k | 77,448 | Write a Python function to compute the factorial of a given non-negative integer `n`. The factorial of a number `n` (denoted as `n!`) is the product of all positive integers less than or equal to `n`. The function should handle edge cases such as `n = 0` and `n = 1` correctly.
The code should start with:
```python
def... | Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int:
"""
Compute the factorial of a given non-negative integer n.
The factorial of n (denoted as n!) is the product of all positive integers
less than or equal to n. For example, 5! = 5 * 4 * 3 ... |
magic_evol_110k | 77,463 | Write a Python function to generate a string with a specified pattern and convert it to uppercase. The function should take an integer `n` as input and generate a string consisting of the word "hello" repeated `n` times, separated by spaces. The function should then convert the entire string to uppercase and return it.... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_and_capitalize(n: int) -> str:
"""
Generates a string consisting of the word "hello" repeated `n` times, separated by spaces,
and converts the entire string to uppercase.
Args:
n (int): The number o... |
magic_evol_110k | 77,468 | Write a Python function to remove all duplicate elements from a given list while preserving the initial sequence of the remaining elements. The function should return a new list with unique elements in the order they first appeared in the original list.
The code should start with:
```python
from typing import List
de... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates(elements_list: List[int]) -> List[int]:
"""
Removes duplicate elements from the given list while preserving the initial sequence of the remaining elements.
Args:
elemen... |
magic_evol_110k | 77,473 | Write a Python function to create an identity matrix of size n x n using NumPy. The function should return the identity matrix as a NumPy array. The code should start with:
```python
import numpy as np
def create_identity_matrix(n: int) -> np.ndarray:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def create_identity_matrix(n: int) -> np.ndarray:
"""
Create an identity matrix of size n x n using NumPy.
Args:
n (int): The size of the identity matrix.
Returns:
np.ndarray: A NumP... |
magic_evol_110k | 77,478 | Write a Python function to find the greatest and smallest values in a given array of numbers. The function should return a list containing these two values in the order: smallest, greatest. The function should handle edge cases such as an empty array and an array with a single element.
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 find_extremes(numbers: List[int]) -> List[int]:
"""
Find the smallest and greatest values in a given array of numbers.
Args:
numbers (List[int]): The array of numbers from which to find ... |
magic_evol_110k | 77,487 | Write a Python function to transform a given list of integer values into a singular concatenated textual representation, where individual numerical values are disjointed by a hyphen. The function should handle lists of varying lengths and ensure that the output is always a single string with elements separated by hyphe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def concatenate_with_hyphens(numbers: List[int]) -> str:
"""
Transforms a list of integer values into a singular concatenated textual representation,
where individual numerical values are disjointed ... |
magic_evol_110k | 77,515 | Write a Python function to validate a date string in the format "MM-DD-YYYY" and return a boolean indicating whether the date is valid. The function should handle leap years and ensure that the month and day are within the correct ranges.
The code should start with:
```python
def is_valid_date(date_str: str) -> bool:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_date(date_str: str) -> bool:
"""
Validates whether a given date string in the format "MM-DD-YYYY" is a valid date.
Args:
date_str (str): The date string to validate, in the format "MM-DD-YYYY".
Ret... |
magic_evol_110k | 77,522 | Write a Python function to generate a list of all numerical values that are lesser than or exactly equal to a given integer `n`. The function should start with:
```python
from typing import List
def generate_numbers_up_to(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_numbers_up_to(n: int) -> List[int]:
"""
Generates a list of all numerical values that are lesser than or exactly equal to the given integer `n`.
Args:
n (int): The upper limit f... |
magic_evol_110k | 77,531 | Write a Python function that transforms a given list of integers by adding 5 to each element. However, if an element in the input list is an odd number, increase its value by 10 instead. Ensure that a copy of the input list is modified, rather than the input list itself, to prevent side effects. The function should ret... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def transform_list(input_list: List[int]) -> List[int]:
"""
Transform the list by adding 5 to each element, but if the element is odd, increase its value by 10.
Args:
input_list (List[int]):... |
magic_evol_110k | 77,532 | 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 strings with varying lengths and characters, including special characters and numbers. The code should start with:
```python
import rando... | 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... |
magic_evol_110k | 77,543 | Write a Python function to manage a list of employees' data, including their employee ID, name, salary, and department. The function should allow adjusting an employee's salary, finding the average salary in a given department, and returning the details of the highest-earning employee. The function should start with:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple, Union
def manage_employees(employees: List[Dict[str, str]], operation: str, *args) -> Union[float, Dict[str, str], None]:
"""
Manages a list of employees' data, including operations to adju... |
magic_evol_110k | 77,554 | Write a Python function to find the last index of a specified item in a given list. If the item is not found in the list, the function should return -1. The function should be efficient and handle edge cases such as an empty list or an item that does not exist in the list.
The code should start with:
```python
from ty... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_last_index(my_list: List[int], item_to_find: int) -> int:
"""
Find the last index of a specified item in a given list.
Args:
my_list (List[int]): The list in which to search for the... |
magic_evol_110k | 77,567 | Write a Python function to reverse a binary string. The input string consists only of '0's and '1's. The function should return the reversed binary string.
The code should start with:
```python
def reverse_binary(a: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_binary(a: str) -> str:
"""
Reverses a binary string consisting only of '0's and '1's.
Args:
a (str): The input binary string.
Returns:
str: The reversed binary string.
Raises:
V... |
magic_evol_110k | 77,572 | Write a Python function to validate if a given list of IP addresses are valid private IP addresses using a regular expression. The function should return a list of boolean values indicating whether each IP address in the input list is a valid private IP address or not.
The code should start with:
```python
from typing... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def validate_private_ips(ip_list: List[str]) -> List[bool]:
"""
Validates if each IP address in the given list is a valid private IP address.
Args:
ip_list (List[str]): A list of I... |
magic_evol_110k | 77,580 | Write a Python function to generate a list of 10 random non-repeating numbers from a given range from 0 to `x` (where `x > 10`). The function should also include a mechanism to validate that the numbers generated are unique and within the specified range. The code should start with:
```python
from typing import List
im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_unique_random_numbers(x: int) -> List[int]:
"""
Generates a list of 10 random non-repeating numbers from the range [0, x] (where x > 10).
Also validates that the numbers ge... |
magic_evol_110k | 77,593 | Write a Python function to generate the first `n` numbers in the Fibonacci sequence. The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. The function should return a list containing the first `n` Fibonacci numbers.
The code should start w... | 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 numbers in the Fibonacci sequence.
The Fibonacci sequence is a series of numbers where each number is the sum of the two precedi... |
magic_evol_110k | 77,607 | Write a Python function `split_string` that takes a string `s`, a delimiter `delimiter`, and an optional integer argument `max_splits`. The function should return a list containing the string `s` split by the `delimiter`, with a total number of splits not exceeding `max_splits`. If `max_splits` is not provided, the fun... | Here is the Python code to solve the given problem in the markdown block:
```python
def split_string(s: str, delimiter: str, max_splits: int = None) -> list:
"""
Splits the string `s` by the `delimiter` with a maximum number of splits not exceeding `max_splits`.
Args:
s (str): The string to be spli... |
magic_evol_110k | 77,625 | Write a Python function to generate an alert message for a trading indicator. The function should take a float value representing the closing price and a string representing the timeframe period (e.g., "D" for daily, "W" for weekly). The function should then construct a message that includes the closing price and the c... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def generate_alert_message(close_price: float, timeframe_period: str) -> str:
"""
Generates an alert message for a trading indicator.
Args:
close_price (float): The closing price of th... |
magic_evol_110k | 77,628 | Write a Python function to calculate the area of a triangle given its side length and the corresponding altitude. The function should be able to handle both integer and floating-point inputs and return the area as a floating-point number. The code should start with:
```python
def triangle_area(side_length: float, altit... | Here is the Python code to solve the given problem in the markdown block:
```python
def triangle_area(side_length: float, altitude: float) -> float:
"""
Calculate the area of a triangle given its side length and the corresponding altitude.
Args:
side_length (float): The length of the base side of t... |
magic_evol_110k | 77,654 | Write a Python function to extract all valid email addresses from a given text using a regular expression. The function should handle various email address formats and domain variations. The code should start with:
```python
import re
from typing import List
def extract_emails(text: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def extract_emails(text: str) -> List[str]:
"""
Extracts all valid email addresses from the given text using a regular expression.
Args:
text (str): The text from which to extract ... |
magic_evol_110k | 77,657 | Write a Python function to remove all occurrences of specific values contained in an array from another array. The function should handle edge cases where the input arrays are empty or undefined/null. Additionally, the function should be optimized for large arrays. 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 List, Union, Dict
def remove_values(arr1: Union[List[int], None], arr2: Union[List[int], Dict[str, List[int]], None]) -> List[int]:
"""
Removes all occurrences of specific values contained in an array from an... |
magic_evol_110k | 77,666 | Write a Python function to iterate through a given dictionary and remove key-value pairs where the value is less than 10. Replace these removed items with a new key-value pair "underTen" where the value is the total sum of the removed values.
The code should start with:
```python
from typing import Dict
def process_d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def process_dictionary(B: Dict[str, int]) -> Dict[str, int]:
"""
Process the given dictionary by removing key-value pairs where the value is less than 10,
and replace these removed items with a new k... |
magic_evol_110k | 77,673 | Write a Python function to count the frequency of each character in a given string and return the result as a dictionary. The dictionary should map each unique character to the number of times it appears in the string. The function should be case-sensitive, meaning 'A' and 'a' should be considered different characters.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def character_frequency(text: str) -> Dict[str, int]:
"""
Counts the frequency of each character in the given string and returns the result as a dictionary.
Args:
text (str): The input strin... |
magic_evol_110k | 77,682 | Write two Python functions to analyze a given string:
1. **Function 1**: Find the longest consecutive character string and its length.
2. **Function 2**: Count how many times each character appears consecutively in the string and return the results in a dictionary. The keys in the dictionary should be the consecutive c... | Here is the Python code to solve the given problem in the markdown block:
```python
def longest_consecutive_character(input_str: str) -> tuple:
"""
Find the longest consecutive character string and its length in the given string.
Args:
input_str (str): The input string to analyze.
Returns:
... |
magic_evol_110k | 77,703 | Write a Python function to separate and return a list of balanced, non-enclosed, and unique groups of nested round brackets from a given string. Each group should be a balanced set of parentheses, meaning every opening bracket has a corresponding closing bracket, and no group should be enclosed within another group. Ig... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def separate_paren_groups(paren_string: str) -> List[str]:
"""
Separates and returns a list of balanced, non-enclosed, and unique groups of nested round brackets from a given string.
Args:
p... |
magic_evol_110k | 77,706 | Write a Python function to convert a binary string into its corresponding hexadecimal string. The function should handle binary strings of any length and ensure that the hexadecimal output is properly padded with leading zeros if necessary to maintain a length that is a multiple of two.
The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_hexadecimal(binary: str) -> str:
"""
Converts a binary string to its corresponding hexadecimal string.
Args:
binary (str): The binary string to be converted.
Returns:
str: The hexadecimal ... |
magic_evol_110k | 77,714 | Write a Python function to generate an array of `n` random numbers between `a` and `b` (inclusive). The function should return the generated array. The code should start with:
```python
import numpy as np
def generate_random_numbers(n: int, a: float, b: float) -> np.ndarray:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def generate_random_numbers(n: int, a: float, b: float) -> np.ndarray:
"""
Generates an array of `n` random numbers between `a` and `b` (inclusive).
Args:
n (int): The number of random numbers to... |
magic_evol_110k | 77,742 | Write a Python function to generate the Fibonacci sequence up to the nth number. The function should return a list containing the Fibonacci sequence. The code should start with:
```python
from typing import List
def generate_fibonacci(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(n: int) -> List[int]:
"""
Generate the Fibonacci sequence up to the nth number.
Args:
n (int): The number of Fibonacci numbers to generate.
Returns:
List[... |
magic_evol_110k | 77,744 | Write a Python function to convert all occurrences of double spaces in a given string to single spaces. The function should handle multiple consecutive double spaces and ensure that the final string contains only single spaces between words. The code should start with:
```python
def convert_double_spaces_to_single(text... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_double_spaces_to_single(text: str) -> str:
"""
Converts all occurrences of double spaces in the given string to single spaces.
Args:
text (str): The input string containing potential double spaces.
... |
magic_evol_110k | 77,754 | Write a Python function to exclude specific keys from a given dictionary. The function should take a dictionary and a list of keys to exclude as input and return a new dictionary that contains only the keys that are not in the exclusion list. The code should start with:
```python
from typing import Dict, List, Any
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Any
def exclude_keys(dictionary: Dict[Any, Any], exclude_list: List[Any]) -> Dict[Any, Any]:
"""
Exclude specific keys from a given dictionary.
Args:
dictionary (Dict[Any, Any]): The ... |
magic_evol_110k | 77,757 | Write a Python function to determine if a given mathematical expression has balanced parentheses. The function should check if every opening parenthesis `(`, `{`, or `[` has a corresponding closing parenthesis `)`, `}`, or `]` in the correct order. The function should return `True` if the expression is balanced and `Fa... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_balanced(expression: str) -> bool:
"""
Determines if the given mathematical expression has balanced parentheses.
Args:
expression (str): The mathematical expression to check.
Returns:
bool: True ... |
magic_evol_110k | 77,768 | Write a Python function to check 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 disregard a... | Here is the Python code to solve the given problem in the markdown block:
```python
import string
def check_isogram_and_perfect_isogram(phrase: str) -> tuple:
"""
Check if a given string is an isogram and if it is a perfect isogram.
Args:
phrase (str): The input string to be checked.
Returns:... |
magic_evol_110k | 77,769 | Write a Python function to efficiently combine two hash sets while maintaining the integrity of their non-repetitive elements. The function should return a new set that contains all unique elements from both sets. The code should start with:
```python
from typing import Set
def combine_hash_sets(hash_set1: Set[int], h... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def combine_hash_sets(hash_set1: Set[int], hash_set2: Set[int]) -> Set[int]:
"""
Combines two hash sets into a single set containing all unique elements from both sets.
Args:
hash_set1 (Set[i... |
magic_evol_110k | 77,771 | Write a Python function to count the frequency of each vowel (a, e, i, o, u) in a given string. The function should return a dictionary where the keys are the vowels and the values are their respective counts. The function should be case-insensitive, meaning 'A' and 'a' should be treated as the same vowel.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_vowel_frequencies(text: str) -> Dict[str, int]:
"""
Counts the frequency of each vowel (a, e, i, o, u) in the given text.
Args:
text (str): The input string to analyze.
Return... |
magic_evol_110k | 77,780 | Write a Python function to concatenate two strings with an optional separator. The function should allow the user to specify a separator string that will be inserted between the two input strings during concatenation. If no separator is provided, the function should concatenate the strings without any separator.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
def concatenate_strings(str1: str, str2: str, separator: str = '') -> str:
"""
Concatenates two strings with an optional separator.
Args:
str1 (str): The first string to concatenate.
str2 (str): The second s... |
magic_evol_110k | 77,788 | Write a Python function to invert an integer without converting it to a string, preserving its numerical properties. The function should handle both positive and negative integers. The code should start with:
```python
def invert_integer(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def invert_integer(n: int) -> int:
"""
Inverts an integer without converting it to a string, preserving its numerical properties.
Args:
n (int): The integer to be inverted.
Returns:
int: The inverted in... |
magic_evol_110k | 77,806 | Write a Python function to divide a given string into equal segments of length `n`, where `n` is a user-defined integer. If the length of the string is not perfectly divisible by `n`, the function should handle the remainder by including it as the last segment. The function should return a list of these segments.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def divide_string_into_segments(s: str, n: int) -> List[str]:
"""
Divides a given string into segments of length `n`. If the string length is not perfectly divisible by `n`,
the last segment will con... |
magic_evol_110k | 77,827 | Write a Python function to validate if a given name already exists in a list of contacts. If the name exists, raise a custom exception with a specific error message. If the name does not exist, return the name.
The code should start with:
```python
from typing import List
class NameAlreadyExistsError(Exception):
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
class NameAlreadyExistsError(Exception):
"""Custom exception for when a name already exists in the contacts list."""
pass
def validate_name(contacts: List[str], name: str) -> str:
"""
Validate i... |
magic_evol_110k | 77,842 | Write a Python function to invert the order of keys in a given dictionary. The function should return a new dictionary with the keys in the reverse order of the original dictionary. The original dictionary should remain unchanged.
The code should start with:
```python
from typing import Dict, Any
def invert_dict_orde... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def invert_dict_order(d: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Inverts the order of keys in the given dictionary.
Args:
d (Dict[Any, Any]): The input dictionary whose keys' order is to... |
magic_evol_110k | 77,844 | Write a Python function to invert the case of every character in a given string. The function should return a new string where each uppercase letter is converted to lowercase and each lowercase letter is converted to uppercase. Non-alphabetic characters should remain unchanged.
The code should start with:
```python
de... | Here is the Python code to solve the given problem in the markdown block:
```python
def invert_case(s: str) -> str:
"""
Inverts the case of every character in the given string.
Args:
s (str): The input string whose characters' cases are to be inverted.
Returns:
str: A new string with t... |
magic_evol_110k | 77,848 | Write a Python function to find the smallest positive integer that is absent from a given array. The array is arranged in a sequence that is either non-increasing or non-decreasing. The solution must comply with the computational complexity not exceeding O(n) and the space complexity restricted to O(1). Additionally, t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def smallest_absent_positive_integer(nums: List[int]) -> int:
"""
Find the smallest positive integer that is absent from the given array.
Args:
nums (List[int]): The array of integers, which... |
magic_evol_110k | 77,855 | Write a Python function to generate the Collatz sequence for a given integer `n`. The Collatz sequence is defined as follows:
- Start with an integer `n`.
- If `n` is even, the next number is `n / 2`.
- If `n` is odd, the next number is `3 * n + 1`.
- Repeat the process until `n` becomes 1.
The function should return ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def collatz_sequence(n: int) -> List[int]:
"""
Generate the Collatz sequence for a given integer `n`.
The Collatz sequence is defined as follows:
- Start with an integer `n`.
- If `n` is eve... |
magic_evol_110k | 77,857 | Write a Python function that accepts a list of numbers and returns both the sum and the product of all elements within the list. The function should be able to handle situations where the list contains negative numbers and zero. The code should start with:
```python
from typing import List, Tuple
def sum_and_product(n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sum_and_product(numbers: List[int]) -> Tuple[int, int]:
"""
Calculate the sum and product of all elements in the given list of numbers.
Args:
numbers (List[int]): A list of intege... |
magic_evol_110k | 77,865 | Write a Python function to randomly select a letter from a given text expression. The function should handle any non-empty string input and return a single randomly chosen character from the string.
The code should start with:
```python
import random
def random_letter_from_text(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import random
def random_letter_from_text(text: str) -> str:
"""
Randomly selects a letter from the given text expression.
Args:
text (str): The text expression from which to select a random letter.
Returns:
... |
magic_evol_110k | 77,873 | Write a Python function to verify whether each number in a given sequence of numerical values is even. The function should return a list of boolean values, where each boolean value indicates whether the corresponding number in the input sequence is even (`True`) or not (`False`).
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 check_evenness(numbers: List[int]) -> List[bool]:
"""
Verifies whether each number in a given sequence of numerical values is even.
Args:
numbers (List[int]): A list of integers to check... |
magic_evol_110k | 77,874 | Write a Python function to count the number of unique paths from the top-left corner to the bottom-right corner of a given m x n grid, where you can only move right or down. The function should handle edge cases such as a 0x0 grid or a grid with only one row or column.
The code should start with:
```python
from typing... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
"""
Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid.
Args:
m (int): The number of rows ... |
magic_evol_110k | 77,878 | Write a Python function to find the k-th smallest element in a given list of integers efficiently. The function should handle lists of any length and return the k-th smallest element without modifying the original list. The code should start with:
```python
from typing import List
def find_kth_smallest(numbers: List[i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_kth_smallest(numbers: List[int], k: int) -> int:
"""
Finds the k-th smallest element in the given list of integers.
Args:
numbers (List[int]): The list of integers from which to fin... |
magic_evol_110k | 77,904 | Write a Python function to select all rows from a given list of dictionaries representing a "customers" table that have the same age and email domain as a given customer. Calculate and display their average account balance. Exclude the given customer from the results. The function should start with:
```python
from typi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
def find_similar_customers_and_average_balance(customers: List[Dict[str, any]], given_customer: Tuple[str, int, str]) -> float:
"""
Finds all customers with the same age and email domain as ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.