source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 23,344 | Write a Python function to remove all non-letter characters from a given string. The function should return a new string that contains only the alphabetic characters from the original string, preserving their order.
The code should start with:
```python
import re
def remove_non_letters(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def remove_non_letters(input_string: str) -> str:
"""
Removes all non-letter characters from the given string and returns a new string
containing only the alphabetic characters from the original string.
Args:... |
evol_instruct_66k | 23,350 | Write a Python function to rotate an array a definite number of places to the right. The function should handle both positive and negative rotation values, where a positive value indicates a right rotation and a negative value indicates a left rotation. The function should also handle cases where the number of rotation... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def rotate_array(arr: List[int], num_rotations: int) -> List[int]:
"""
Rotates the given array by the specified number of places to the right.
Args:
arr (List[int]): The array to be rotated.... |
evol_instruct_66k | 23,358 | Write a Python function to find all perfect numbers within a given range. A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding itself). The function should take an integer `n` as input and return a list of all perfect numbers up to `n`.
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 find_perfect_numbers(n: int) -> List[int]:
"""
Find all perfect numbers within the range up to `n`.
A perfect number is a positive integer that is equal to the sum of its proper divisors (exclud... |
evol_instruct_66k | 23,360 | Write a Python function to calculate the Kronecker product of two given matrices using the NumPy package. The function should take two matrices as input and return the resulting Kronecker product matrix. The code should start with:
```python
from typing import List
import numpy as np
def kronecker_product(matrix1: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import numpy as np
def kronecker_product(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[List[int]]:
"""
Calculate the Kronecker product of two given matrices.
Args:
matrix1 (Lis... |
evol_instruct_66k | 23,372 | Write a Python function to generate a random string of a specified length containing only lowercase letters. The function should ensure that the string is composed of random characters from the English alphabet (a-z). The code should start with:
```python
from typing import List
import random
import string
def generat... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import random
import string
def generate_random_string(length: int) -> str:
"""
Generates a random string of the specified length containing only lowercase letters.
Args:
length (int): The... |
evol_instruct_66k | 23,377 | Write a Python function to evaluate a series of numbers and return the maximum and the minimum number from the given list of numbers. The function should handle an empty list by returning `None` for both the maximum and minimum values.
The code should start with:
```python
from typing import List, Tuple
def find_max_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Optional
def find_max_min(numbers: List[float]) -> Tuple[Optional[float], Optional[float]]:
"""
Find the maximum and minimum numbers from a given list of numbers.
Args:
numbers (List... |
evol_instruct_66k | 23,384 | Write a Python function to find and return the smallest numerical value from a given list of integers. The function should handle lists of any size, including empty lists. If the list is empty, the function should return `None`.
The code should start with:
```python
from typing import List, Optional
def find_smallest... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_smallest_value(numbers: List[int]) -> Optional[int]:
"""
Find and return the smallest numerical value from a given list of integers.
Args:
numbers (List[int]): A list of i... |
evol_instruct_66k | 23,399 | Write a Python function to isolate all unique components from a given data assembly, ensuring no repetitious items survive in the final output. The data assembly is a list of tuples, where each tuple contains a string and an integer. The function should consider the string part of the tuple as the identifier for unique... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def isolate_unique_components(data_collection: List[Tuple[str, int]]) -> List[Tuple[str, int]]:
"""
Isolates all unique components from a given data assembly, ensuring no repetitious items survive... |
evol_instruct_66k | 23,405 | Create a Python function that validates user input for a form with fields for name, email, and age. The function should return a dictionary containing the validated input values if all fields are valid, or an error message if any field is invalid. The form fields are:
- **Name**: Must be a non-empty string.
- **Email**... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Union
import re
def validate_form(name: str, email: str, age: int) -> Union[Dict[str, Union[str, int]], str]:
"""
Validates the input fields for a form and returns the validated input values or an error... |
evol_instruct_66k | 23,406 | Write a Python function to calculate the Highest Common Factor (HCF) and Lowest Common Multiple (LCM) of three given integers. The function should return both the HCF and LCM as a tuple. The code should start with:
```python
import math
def find_hcf_and_lcm(num1: int, num2: int, num3: int) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def find_hcf_and_lcm(num1: int, num2: int, num3: int) -> tuple:
"""
Calculate the Highest Common Factor (HCF) and Lowest Common Multiple (LCM) of three given integers.
Args:
num1 (int): The first intege... |
evol_instruct_66k | 23,412 | Write a Python function to transform a given text input into uppercase, ensuring that the function handles various edge cases such as empty strings, strings with special characters, and strings with numbers. The function should return the transformed text in uppercase.
The code should start with:
```python
def transfo... | Here is the Python code to solve the given problem in the markdown block:
```python
def transform_to_uppercase(text: str) -> str:
"""
Transforms the given text input into uppercase.
Args:
text (str): The input text to be transformed.
Returns:
str: The transformed text in uppercase.
... |
evol_instruct_66k | 23,418 | Write a Python function to reverse the digits of a given numerical value and convert them into an array of individual digits in the reversed order. The function should handle both positive and negative numbers. The code should start with:
```python
from typing import List
def reverse_digits_to_array(n: int) -> List[in... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def reverse_digits_to_array(n: int) -> List[int]:
"""
Reverses the digits of a given numerical value and converts them into an array of individual digits in the reversed order.
Args:
n (in... |
evol_instruct_66k | 23,424 | Write a Python function to flatten a nested list and return a single list containing all elements from the nested list in the same order they appear. The function should handle lists of any depth and should not modify the original nested list.
The code should start with:
```python
from typing import List, Any
def fla... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def flatten_list(nested_list: List[Any]) -> List[Any]:
"""
Flattens a nested list into a single list containing all elements in the same order.
Args:
nested_list (List[Any]): The nested... |
evol_instruct_66k | 23,428 | Write a Python function that takes a tuple of integers as input and returns a list of strings where each string is the English word representation of the corresponding integer in the tuple. The function should handle integers from 0 to 10. If an integer outside this range is encountered, the function should return the ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, List
def int_to_word(numbers: Tuple[int]) -> List[str]:
"""
Converts a tuple of integers to a list of their corresponding English word representations.
Args:
numbers (Tuple[int]): A tuple ... |
evol_instruct_66k | 23,434 | Write a Python function to calculate the factorial of a large number using bitwise operations and string manipulation. The function should be able to handle large numbers up to \(10^8\). The traditional arithmetic methods should not be used. The code should start with:
```python
def large_factorial_bitwise(n: int) -> s... | Here is the Python code to solve the given problem in the markdown block:
```python
def large_factorial_bitwise(n: int) -> str:
"""
Calculate the factorial of a large number using bitwise operations and string manipulation.
Args:
n (int): The number to calculate the factorial of.
Returns:
... |
evol_instruct_66k | 23,437 | Write a Python function to sort a given dictionary by its values in ascending order. The function should return a new dictionary with the same keys but sorted by their corresponding values.
The code should start with:
```python
from typing import Dict
def sort_dictionary_by_values(dictionary: Dict[str, float]) -> Dic... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dictionary_by_values(dictionary: Dict[str, float]) -> Dict[str, float]:
"""
Sorts a given dictionary by its values in ascending order.
Args:
dictionary (Dict[str, float]): The dicti... |
evol_instruct_66k | 23,443 | Write a Python function to filter out odd numbers from a given list of integers using a lambda expression and the `filter()` function. The list should contain more than 10 numbers. The function should return a list of even numbers.
The code should start with:
```python
from typing import List
def filter_even_numbers(... | 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 out odd numbers from a given list of integers and returns a list of even numbers.
Args:
numbers (List[int]): A list of i... |
evol_instruct_66k | 23,456 | Write a Python function to count the occurrences of each byte in a given byte array. The function should return a dictionary where the keys are the bytes and the values are the counts of those bytes in the byte array.
The code should start with:
```python
from typing import Dict, ByteString
def count_byte_occurrences... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, ByteString
def count_byte_occurrences(byte_array: ByteString) -> Dict[int, int]:
"""
Counts the occurrences of each byte in a given byte array.
Args:
byte_array (ByteString): The byte array... |
evol_instruct_66k | 23,465 | Write a Python function to validate email addresses using a regular expression. The function should check if the email address is in a proper format, including the presence of an "@" symbol, a domain name, and a top-level domain (TLD). The function should return `True` if the email is valid and `False` otherwise.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_email(email: str) -> bool:
"""
Validates an email address using a regular expression.
Args:
email (str): The email address to validate.
Returns:
bool: True if the email is valid,... |
evol_instruct_66k | 23,478 | Write a Python function to merge two dictionaries based on their keys. If there is a key collision (i.e., both dictionaries have the same key), the function should append the values from both dictionaries into a list. The function should handle cases where the values are already lists by extending them.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def merge_dicts(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Merge two dictionaries based on their keys. If there is a key collision, append the values from both dictionaries... |
evol_instruct_66k | 23,482 | Write a Python function to calculate the sum of all integer elements in a given list. 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(elements: 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(elements: List[int]) -> int:
"""
Calculate the sum of all integer elements in a given list.
Args:
elements (List[int]): A list of integers whose sum needs to be calcula... |
evol_instruct_66k | 23,496 | Write a Python function to print all the integer elements of a given list, and handle errors if an element is not an integer. The function should iterate through the list, check if each element is an integer, and print it if it is. If an element is not an integer, it should print an error message indicating that the el... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_integer_elements(my_list: List[int]) -> None:
"""
Prints all the integer elements of a given list and handles errors for non-integer elements.
Args:
my_list (List[int]): The list o... |
evol_instruct_66k | 23,500 | Write a Python function to determine and return a list of all prime numbers within a given range `[start, end]`. The function should efficiently check for prime numbers using loops and conditional statements. The code should start with:
```python
from typing import List
def find_primes_in_range(start: int, end: int) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def find_primes_in_range(start: int, end: int) -> List[int]:
"""
Returns a list of all prime numbers within the given range [start, end].
Args:
start (int): The starting number o... |
evol_instruct_66k | 23,505 | Write a Python function to sort a given list of integers using the Merge Sort algorithm. The function should recursively divide the list into halves until each sublist contains a single element, and then merge the sublists back together in sorted order. The code should start with:
```python
from typing import List
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the Merge Sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
List... |
evol_instruct_66k | 23,508 | Write a Python function to implement the quicksort algorithm. The function should take a list of integers as input and return a sorted list of integers. The quicksort algorithm should be implemented using a recursive approach, where the list is partitioned into three sublists: elements less than the pivot, elements equ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def quicksort(array: List[int]) -> List[int]:
"""
Sorts a list of integers using the quicksort algorithm.
Args:
array (List[int]): The list of integers to be sorted.
Returns:
Li... |
evol_instruct_66k | 23,515 | Write a Python function to homogenize a given sequence of characters by performing the following transformations:
1. Remove all spaces.
2. Convert all characters to lowercase.
3. Replace all non-alphanumeric characters with underscores (`_`).
The function should start with:
```python
def homogenize_text(text: str) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
def homogenize_text(text: str) -> str:
"""
Homogenizes a given sequence of characters by removing spaces, converting all characters to lowercase,
and replacing all non-alphanumeric characters with underscores.
Args:
... |
evol_instruct_66k | 23,535 | Write a Python function to generate a sequence of numbers where each element is twice its position index (starting from 1). The function should return the sequence up to the nth element. Additionally, write a function to find the nth element in this sequence.
The code should start with:
```python
from typing import Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_sequence(n: int) -> List[int]:
"""
Generate a sequence where each element is twice its position index (starting from 1).
Args:
n (int): The number of elements in the sequence to... |
evol_instruct_66k | 23,537 | Write a Python function to create a deep copy of a 2D array. The function should handle nested arrays and ensure that changes to the copied array do not affect the original array. The function should also handle edge cases such as empty arrays or arrays with non-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
import copy
def deep_copy_2d_array(arr: List[List[int]]) -> List[List[int]]:
"""
Creates a deep copy of a 2D array.
Args:
arr (List[List[int]]): The original 2D array to be copied.
Retu... |
evol_instruct_66k | 23,568 | Write a Python function to estimate the probability of an event based on the number of times the event occurs and the total number of trials. The function should return the probability as a floating-point number. The code should start with:
```python
def estimate_probability(event_occurrences: int, total_trials: int) -... | Here is the Python code to solve the given problem in the markdown block:
```python
def estimate_probability(event_occurrences: int, total_trials: int) -> float:
"""
Estimate the probability of an event based on the number of times the event occurs and the total number of trials.
Args:
event_occurr... |
evol_instruct_66k | 23,579 | Write a Python function to convert a given hexadecimal numeral into its equivalent representation in the base-10 number system without using built-in conversion functions. The function should handle both uppercase and lowercase hexadecimal digits and should strip the "0x" prefix if present.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_decimal(hex_value: str) -> int:
"""
Converts a given hexadecimal numeral into its equivalent representation in the base-10 number system.
Args:
hex_value (str): The hexadecimal numeral to be converted. It... |
evol_instruct_66k | 23,592 | Write a Python function to simulate a multi-threading process where each thread performs a unique operation and synchronizes with other threads using a mutex. The function should take a list of operations (each represented as a callable) and the number of threads as input. Each thread should execute its corresponding o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable
from threading import Thread, Lock
def multi_threaded_operations(operations: List[Callable], num_threads: int) -> None:
"""
Simulate a multi-threading process where each thread performs a uniqu... |
evol_instruct_66k | 23,598 | Write a Python function to convert a given octal string to its reverse palindrome form. The function should take an octal string as input and return a new string that is the concatenation of the original octal string and its reverse. The function should handle octal strings of any length, including empty strings.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_palindrome_octal(octal_str: str) -> str:
"""
Converts an octal string to its reverse palindrome form.
Args:
octal_str (str): The input octal string.
Returns:
str: The reverse palindrome form... |
evol_instruct_66k | 23,601 | Write a Python function to enumerate and return a list of formatted strings representing the entries in a given dictionary. Each string should be formatted as "Entry <index>: <key> = <value>", where `<index>` is the 1-based index of the entry, `<key>` is the dictionary key, and `<value>` is the corresponding value.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def enumerate_dictionary_entries(dictionary: Dict) -> List[str]:
"""
Enumerates the entries in a given dictionary and returns a list of formatted strings.
Args:
dictionary (Dict): The ... |
evol_instruct_66k | 23,643 | Write a Python function to compute an array where each element at index `i` is the product of all elements in the input array except the one at index `i`. The function should be efficient and avoid using division. The code should start with:
```python
from typing import List
def product_except_self(nums: List[int]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def product_except_self(nums: List[int]) -> List[int]:
"""
Compute an array where each element at index i is the product of all elements in the input array except the one at index i.
Args:
n... |
evol_instruct_66k | 23,644 | Write a Python function to filter students based on their height, weight, and age, and then sort them in descending order by age. The function should take a dictionary where each key is a student's name and each value is a tuple containing the student's height (in cm), weight (in kg), and age (in years). Additionally, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def filter_and_sort_students(students_dict: Dict[str, Tuple[float, float, int]], min_height: float, min_weight: float, min_age: int) -> List[Tuple[str, Tuple[float, float, int]]]:
"""
Filter... |
evol_instruct_66k | 23,648 | Write a Python function to segregate the even integers from a given list, square each of these even integers, and then compute their sum. The function should start with:
```python
from typing import List
def sum_of_even_squares(data: 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_even_squares(data: List[int]) -> int:
"""
Segregates the even integers from the given list, squares each of these even integers,
and then computes their sum.
Args:
data (List[... |
evol_instruct_66k | 23,649 | Write a Python function to remove all punctuation marks from a given sentence. The function should handle various punctuation marks and return the sentence without them. The code should start with:
```python
from typing import List
def remove_punctuation(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import string
def remove_punctuation(input_string: str) -> str:
"""
Removes all punctuation marks from the given input string.
Args:
input_string (str): The input string from which punctuati... |
evol_instruct_66k | 23,650 | Write a Python function to sort a list of integers in ascending order while handling and correcting erroneous inputs (non-integer values). The function should be able to handle at least one thousand inputs efficiently. The code should start with:
```python
from typing import List
def robust_sort(collection: List[int])... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def robust_sort(collection: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order while handling and correcting erroneous inputs (non-integer values).
Args:
collection (... |
evol_instruct_66k | 23,661 | Write a Python function to determine if a given integer exists in a sorted array using a binary search algorithm. The function should return `True` if the integer is found, and `False` otherwise. The array is guaranteed to be sorted in ascending order.
The code should start with:
```python
from typing import List
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(arr: List[int], x: int) -> bool:
"""
Determines if a given integer exists in a sorted array using binary search.
Args:
arr (List[int]): A sorted list of integers.
x... |
evol_instruct_66k | 23,668 | Write a Python function to find the maximum number in a given 2D array with dimensions up to 1000x1000. The function should efficiently handle large arrays and return the maximum value. The code should start with:
```python
from typing import List
def find_max_in_2d_array(arr: List[List[int]]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_max_in_2d_array(arr: List[List[int]]) -> int:
"""
Find the maximum number in a given 2D array with dimensions up to 1000x1000.
Args:
arr (List[List[int]]): A 2D array (list of lists... |
evol_instruct_66k | 23,679 | Write a Python function to determine and count the tokens present in a provided text document. The function should break down the document into individual tokens and count their occurrences. The code should start with:
```python
from typing import Dict
def count_tokens(document: str) -> Dict[str, int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import Dict
def count_tokens(document: str) -> Dict[str, int]:
"""
Counts the occurrences of each token in the provided text document.
Args:
document (str): The text document from which to count token... |
evol_instruct_66k | 23,700 | Write a Python function to perform a linear search on an unordered array to find a target value. The function should return the index of the target value if found, otherwise return -1. The code should start with:
```python
from typing import List
def linear_search(arr: List[int], target_value: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def linear_search(arr: List[int], target_value: int) -> int:
"""
Perform a linear search on the given unordered array to find the target value.
Args:
arr (List[int]): The unordered array of ... |
evol_instruct_66k | 23,704 | Write a Python function to verify the presence of a decimal number within a given iterable object. The function should return `True` if at least one decimal number (float) is found in the iterable, otherwise it should return `False`. The iterable can contain any type of elements, including integers, strings, and other ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Iterable
def has_decimal(iterable: Iterable) -> bool:
"""
Verifies the presence of a decimal number (float) within a given iterable object.
Args:
iterable (Iterable): The iterable object to check... |
evol_instruct_66k | 23,710 | Write a Python function to compare two integer values and return a string indicating the relationship between the two numbers. The function should handle three cases: when the numbers are equal, when the first number is greater than the second, and when the second number is greater than the first. The function should a... | Here is the Python code to solve the given problem in the markdown block:
```python
def compare_numbers(num1: int, num2: int) -> str:
"""
Compare two integer values and return a string indicating their relationship.
Args:
num1 (int): The first integer to compare.
num2 (int): The second inte... |
evol_instruct_66k | 23,717 | Write a Python function to find the length of the longest consecutive sequence of 1s in a given integer array. The array contains only 0s and 1s. The function should return the maximum length of consecutive 1s found in the array.
The code should start with:
```python
from typing import List
def longest_consecutive_on... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_consecutive_ones(array: List[int]) -> int:
"""
Find the length of the longest consecutive sequence of 1s in a given integer array.
Args:
array (List[int]): The array containing o... |
evol_instruct_66k | 23,719 | Write a Python function to generate the first `n` Lucas numbers. The Lucas numbers are a sequence similar to the Fibonacci sequence, where each number is the sum of the two preceding ones, but starting with 2 and 1. The function should return a list containing the first `n` Lucas numbers.
The code should start with:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_lucas_numbers(n: int) -> List[int]:
"""
Generate the first n Lucas numbers.
The Lucas numbers are a sequence similar to the Fibonacci sequence, where each number is the sum of the two p... |
evol_instruct_66k | 23,722 | Write a Python function to replace all occurrences of a specified number in a given list with a new number. The function should return the updated list. The code should start with:
```python
from typing import List
def replace_number(input_array: List[int], origin_number: int, new_number: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def replace_number(input_array: List[int], origin_number: int, new_number: int) -> List[int]:
"""
Replaces all occurrences of a specified number in a given list with a new number.
Args:
inpu... |
evol_instruct_66k | 23,736 | Write a Python function to sort a given list of complex numbers based on their magnitudes in descending order. The complex numbers are represented as tuples, with the first element of the tuple being the real part and the second being the imaginary part. The function should return the sorted list of tuples.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_complex_numbers_by_magnitude(nums: List[Tuple[float, float]]) -> List[Tuple[float, float]]:
"""
Sorts a list of complex numbers represented as tuples based on their magnitudes in descendi... |
evol_instruct_66k | 23,754 | Write a Python function to determine the number of unique pairings that can be formed from a given set of distinct elements. Each pairing should consist of exactly two distinct elements from the set, and no element should be repeated in any pairing. The function should return the total number of such unique pairings.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
import itertools
def count_unique_pairings(elements: Set[int]) -> int:
"""
Calculate the number of unique pairings that can be formed from a given set of distinct elements.
Args:
elements (Se... |
evol_instruct_66k | 23,758 | Write a Python function to remove duplicate elements from a list and shift the remaining elements to the end of the list, maintaining their original order. The function should not use additional data structures and should modify the list in place.
The code should start with:
```python
from typing import List
def remo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_and_shift_duplicates(arr: List[int]) -> List[int]:
"""
Removes duplicate elements from the list and shifts the remaining elements to the end of the list,
maintaining their original order. ... |
evol_instruct_66k | 23,761 | Write a Python function to check if two provided arrays have the same elements in reverse order. The arrays can contain multiple types of data types, including integers, strings, and nested arrays. Additionally, the arrays can be of different lengths. The function should handle this case and implement an algorithm that... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def are_arrays_reverse_equal(arr1: List[Any], arr2: List[Any]) -> bool:
"""
Check if two arrays have the same elements in reverse order.
Args:
arr1 (List[Any]): The first array to compa... |
evol_instruct_66k | 23,767 | Write a Python function to print the elements of a list along with their indices using the `enumerate` function. The function should take a list as input and print each element along with its index in a formatted string. The code should start with:
```python
from typing import List
def print_elements_with_indices(arr:... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def print_elements_with_indices(arr: List[int]) -> None:
"""
Prints each element of the list along with its index.
Args:
arr (List[int]): The list of integers whose elements and indices ar... |
evol_instruct_66k | 23,784 | Write a Python function to generate the Fibonacci sequence up to the nth term, where n is a given integer. Each term in the sequence should be formatted such that odd-indexed terms are displayed in uppercase and even-indexed terms are displayed in lowercase. The sequence should be returned as a single string with terms... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_fibonacci_sequence(n: int) -> str:
"""
Generates the Fibonacci sequence up to the nth term, formatting odd-indexed terms in uppercase and even-indexed terms in lowercase.
Args:
n (int): The number of te... |
evol_instruct_66k | 23,785 | Write a Python function to reverse a given string. The function should raise a `TypeError` if the input is not a string. The code should start with:
```python
def reverse_string(input_str: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(input_str: str) -> str:
"""
Reverses the given string.
Args:
input_str (str): The string to be reversed.
Returns:
str: The reversed string.
Raises:
TypeError: If the inpu... |
evol_instruct_66k | 23,787 | 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 return `True` if the integer is a perfect square and `False` otherwise. The code should start with:
```python
def is_perfect_square(n: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
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, Fal... |
evol_instruct_66k | 23,805 | Write a Python function to determine if two multi-dimensional lists are identical, regardless of the order of their sublists and the order of elements within each sublist. The function should return `True` if the lists are identical and `False` otherwise.
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 are_multi_lists_identical(list1: List[List[int]], list2: List[List[int]]) -> bool:
"""
Determines if two multi-dimensional lists are identical, regardless of the order of their sublists and the order... |
evol_instruct_66k | 23,825 | Write a Python function to convert a given two-dimensional matrix into a linear, one-dimensional array. The function should take a list of lists (matrix) as input and return a single list containing all the elements of the matrix in row-major order.
The code should start with:
```python
from typing import List
def fl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def flatten_matrix(matrix: List[List[int]]) -> List[int]:
"""
Converts a given two-dimensional matrix into a linear, one-dimensional array.
Args:
matrix (List[List[int]]): A list of lists re... |
evol_instruct_66k | 23,826 | Write a Python function to find the minimum value in a tuple of 15 elements without using the built-in `min()` function or sorting the tuple. The function should iterate through the tuple and keep track of the smallest value found.
The code should start with:
```python
def find_minimum_value(tpl: tuple) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_minimum_value(tpl: tuple) -> int:
"""
Find the minimum value in a tuple of 15 elements without using the built-in min() function or sorting the tuple.
Args:
tpl (tuple): A tuple containing exactly 15 elemen... |
evol_instruct_66k | 23,835 | Write a Python function to calculate the sum of the squares of all the even numbers in a given list. The function should take a list of integers as input and return the sum of the squares of the even numbers in the list. The code should start with:
```python
from typing import List
def sum_of_squares_of_evens(nums: Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_squares_of_evens(nums: List[int]) -> int:
"""
Calculate the sum of the squares of all even numbers in the given list.
Args:
nums (List[int]): A list of integers.
Returns:
... |
evol_instruct_66k | 23,838 | Write a Python function to calculate the sum of two numbers. The function should take two integers as input and return their sum. The code should start with:
```python
def add_two_numbers(num1: int, num2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def add_two_numbers(num1: int, num2: int) -> int:
"""
Calculate the sum of two given integers.
Args:
num1 (int): The first integer to be added.
num2 (int): The second integer to be added.
Returns:
... |
evol_instruct_66k | 23,846 | Write a Python function to determine if a given sequence contains at least one floating-point number. The sequence can contain various data types, including integers, strings, and other objects. The function should return `True` if there is at least one floating-point number in the sequence, and `False` otherwise.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def contains_float(sequence: List[Union[int, str, float]]) -> bool:
"""
Determines if the given sequence contains at least one floating-point number.
Args:
sequence (List[Union[int, s... |
evol_instruct_66k | 23,861 | Write a Python function to find the smallest repeating substring within a given string. The function should return the smallest substring that, when repeated, reconstructs the original string. If no such substring exists, the function should return the original string itself.
The code should start with:
```python
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_min_repeating_substring(input_string: str) -> str:
"""
Finds the smallest repeating substring within the given string.
Args:
input_string (str): The string to analyze for the smallest repeating substring.
... |
evol_instruct_66k | 23,862 | Write a Python function to find and return the first non-repeating character in a given string. If there are no non-repeating characters, the function should return `None`. The function should be efficient and should handle strings of varying lengths.
The code should start with:
```python
def first_non_repeating_char(... | Here is the Python code to solve the given problem in the markdown block:
```python
def first_non_repeating_char(s: str) -> str:
"""
Finds and returns the first non-repeating character in the given string.
Args:
s (str): The input string to search for the first non-repeating character.
Returns... |
evol_instruct_66k | 23,866 | Write a Python function to sort a given matrix of integers in ascending order. The matrix is represented as a list of lists, where each sublist represents a row in the matrix. The function should return a new matrix with the same dimensions, where all elements are sorted in ascending order.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_matrix(matrix: List[List[int]]) -> List[List[int]]:
"""
Sorts a given matrix of integers in ascending order.
Args:
matrix (List[List[int]]): A 2D list of integers representing the m... |
evol_instruct_66k | 23,870 | Write a Python function to filter out numbers from a given list that are divisible by a specified factor. The function should return a new list containing only the numbers that are divisible by the given factor. The code should start with:
```python
from typing import List
def filter_divisible_numbers(data: List[int],... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_divisible_numbers(data: List[int], factor: int) -> List[int]:
"""
Filters out numbers from the given list that are divisible by the specified factor.
Args:
data (List[int]): The l... |
evol_instruct_66k | 23,883 | Write a Python function to classify musical notes based on their frequency using a decision tree algorithm. The function should take a list of frequencies and return a list of corresponding musical notes. The musical notes to be classified are:
- Middle C (261.63 Hz)
- A4 (440 Hz)
- E4 (329.63 Hz)
- B4 (493.88 Hz)
- G3... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def classify_musical_notes(frequencies: List[float]) -> List[str]:
"""
Classify musical notes based on their frequencies using a decision tree algorithm.
Args:
frequencies (List[float]): A l... |
evol_instruct_66k | 23,887 | Write a Python function to filter out objects from a list of dictionaries where the 'cost' value is greater than or equal to a given threshold. The function should return a new list containing only the objects that do not meet this condition.
The code should start with:
```python
from typing import List, Dict
def fil... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def filter_inventory(inventory: List[Dict[str, any]], threshold: int) -> List[Dict[str, any]]:
"""
Filters out objects from the inventory list where the 'cost' value is greater than or equal to the... |
evol_instruct_66k | 23,888 | Write a Python function to compute the value of a mathematical expression given two variables `x` and `y`. The expression to be evaluated is `(x^2 + y^2) / (x + y)`. The function should return the result of this expression.
The code should start with:
```python
def compute_expression(x: int, y: int) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def compute_expression(x: int, y: int) -> float:
"""
Compute the value of the mathematical expression (x^2 + y^2) / (x + y).
Args:
x (int): The first integer variable.
y (int): The second integer variable.
... |
evol_instruct_66k | 23,914 | Write a Python function to determine the occupation of the second character in a given list of dictionaries. Each dictionary contains information about a character, including their name and occupation. The function should return the occupation of the second character in the list.
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, Dict
def find_second_character_occupation(characters: List[Dict[str, str]]) -> str:
"""
Determine the occupation of the second character in a list of dictionaries.
Args:
characters (List[Di... |
evol_instruct_66k | 23,936 | Write a Python function to find the most common elements in a list of strings without using any built-in functions like `count` or `max`. If multiple elements share the highest frequency, return all of them. The function should start with:
```python
from typing import List
def find_most_common_elements(mylist: List[st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_most_common_elements(mylist: List[str]) -> List[str]:
"""
Find the most common elements in a list of strings without using built-in functions like count or max.
Args:
mylist (List[s... |
evol_instruct_66k | 23,941 | Write a Python function to remove extra spaces from a given string. The function should handle leading, trailing, and multiple spaces between words. The code should start with:
```python
def remove_extra_spaces(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_extra_spaces(input_string: str) -> str:
"""
Removes extra spaces from a given string, including leading, trailing, and multiple spaces between words.
Args:
input_string (str): The input string from which ... |
evol_instruct_66k | 23,947 | Write a Python function to find the smallest and largest missing positive numbers in a given array, along with their indices. The function should return a tuple containing the smallest missing positive number, its index, the largest missing positive number, and its index. The index should be 1-based, meaning the first ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_missing_numbers_with_indices(arr: List[int]) -> Tuple[int, int, int, int]:
"""
Find the smallest and largest missing positive numbers in the given array, along with their indices.
Ar... |
evol_instruct_66k | 23,948 | Write a Python function to convert a JSON object into a Python dictionary. The JSON object is represented as a string and contains key-value pairs. The function should parse the JSON string and return a corresponding Python dictionary.
The code should start with:
```python
import json
def json_to_dict(json_str: str) ... | Here is the Python code to solve the given problem in the markdown block:
```python
import json
def json_to_dict(json_str: str) -> dict:
"""
Converts a JSON string into a Python dictionary.
Args:
json_str (str): The JSON string to be converted.
Returns:
dict: A Python dictionary repre... |
evol_instruct_66k | 23,956 | Write a Python function to determine if the keys of a given dictionary are a subset of a specified list. The function should return a boolean value indicating whether all keys in the dictionary are present in the list.
The code should start with:
```python
from typing import List, Dict
def is_dict_keys_subset(main_li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def is_dict_keys_subset(main_list: List[str], dict_keys: Dict[str, int]) -> bool:
"""
Determines if the keys of a given dictionary are a subset of a specified list.
Args:
main_list (Li... |
evol_instruct_66k | 23,990 | Write a Python function to calculate the power of one number raised to another. The function should take two integers as input and return the result of raising the first integer to the power of the second integer. The code should start with:
```python
def power_of_number(base: int, exponent: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def power_of_number(base: int, exponent: int) -> int:
"""
Calculate the power of one number raised to another.
Args:
base (int): The base number.
exponent (int): The exponent to which the base is raised.
... |
evol_instruct_66k | 24,007 | Write a Python function to generate a list of the first `n` positive integers. The function should take an integer `n` as input and return a list containing the first `n` positive integers. If `n` is less than or equal to 0, the function should return an empty list.
The code should start with:
```python
from typing im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_first_n_integers(n: int) -> List[int]:
"""
Generate a list of the first n positive integers.
Args:
n (int): The number of positive integers to generate.
Returns:
Li... |
evol_instruct_66k | 24,016 | Write a Python function to create a nested dictionary from two lists of tuples, where each tuple in the first list represents a key path (e.g., `("key1", "subkey1")`), and each tuple in the second list represents a value path (e.g., `("value1", "subvalue1")`). The function should handle cases where the lengths of the k... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict, Union
def create_nested_dict(keys: List[Tuple[str, str]], values: List[Tuple[str, str]]) -> Union[Dict[str, Dict[str, str]], str]:
"""
Create a nested dictionary from two lists of tuples re... |
evol_instruct_66k | 24,024 | Create a Python function that categorizes professional attributes into a dictionary. The function should take three parameters: `profession`, `tenure`, and `geographical_working_area`. The function should return a dictionary with keys "Profession", "Tenure", and "Geographical Working Area" and their corresponding value... | Here is the Python code to solve the given problem in the markdown block:
```python
def categorize_professional_attributes(profession: str, tenure: str, geographical_working_area: str) -> dict:
"""
Categorizes professional attributes into a dictionary.
Args:
profession (str): The profession of the ... |
evol_instruct_66k | 24,037 | Write a Python function to reorder a given dictionary object based on the numerical values contained within, handling both negative and decimal values. The function should return a new dictionary with the keys sorted by their corresponding values in ascending order.
The code should start with:
```python
from collectio... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import OrderedDict
def sort_dict_by_value(d: dict) -> OrderedDict:
"""
Reorders the given dictionary based on the numerical values of its items.
Args:
d (dict): The dictionary to be reordered.
... |
evol_instruct_66k | 24,053 | Write a Python function to reverse a given string. The function should take a string as input and return the reversed string. The code should start with:
```python
def reverse_string(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(input_string: str) -> str:
"""
Reverses the given input string.
Args:
input_string (str): The string to be reversed.
Returns:
str: The reversed string.
"""
# Use slicing to re... |
evol_instruct_66k | 24,067 | Write a Python function to sort a list of integers in descending order using the selection 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 sort_descending_order(input_list: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def sort_descending_order(input_list: List[int]) -> List[int]:
"""
Sorts a list of integers in descending order using the selection sort algorithm.
Args:
input_list (List[int]): The list o... |
evol_instruct_66k | 24,069 | Write a Python function to calculate the sum of all elements in a multi-dimensional array. The multi-dimensional array can have any number of dimensions, and the function should handle arrays of varying depths. The function should start with:
```python
from typing import List
def sum_multi_dimensional_array(arr: List)... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_multi_dimensional_array(arr: List) -> int:
"""
Calculate the sum of all elements in a multi-dimensional array.
Args:
arr (List): A multi-dimensional array of integers.
Returns:
... |
evol_instruct_66k | 24,073 | Write a Python function to sort a given list of integers in ascending order using the built-in `sorted` function. The function should return the sorted list. The code should start with:
```python
from typing import List
def sort_array(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_array(arr: List[int]) -> List[int]:
"""
Sorts a given list of integers in ascending order.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
List[int]:... |
evol_instruct_66k | 24,085 | Write a Python function to extract all email addresses from a given string using regular expressions. The function should return a list of all email addresses found in the input string. The code should start with:
```python
from typing import List
import re
def extract_emails(input_string: 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(input_string: str) -> List[str]:
"""
Extracts all email addresses from the given input string using regular expressions.
Args:
input_string (str): The string f... |
evol_instruct_66k | 24,087 | Write a Python function to separate and alphabetize a predetermined list of book titles and author names represented as strings. The list alternates between book titles and author names. The function should return two lists: one containing the sorted book titles and the other containing the sorted author names.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def separate_and_sort_books_and_authors(list_of_strings: List[str]) -> Tuple[List[str], List[str]]:
"""
Separates and alphabetizes a predetermined list of book titles and author names.
Args:
... |
evol_instruct_66k | 24,092 | Write a Python function to sort an unordered list of integers in ascending order using the Merge Sort algorithm. The function should take a list of integers as input and return the sorted list. The Merge Sort algorithm should be implemented from scratch without using Python's built-in sorting functions.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
"""
Sorts an unordered list of integers in ascending order using the Merge Sort algorithm.
Args:
arr (List[int]): The list of integers to be sort... |
evol_instruct_66k | 24,095 | Write a Python function to filter a list of dictionaries representing persons, each containing the fields "name", "age", and "job". The function should return a new list containing only the persons whose 'job' field is 'developer'. The returned list should only consist of dictionaries with the 'name' and 'age' fields. ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def get_developers(person_list: List[Dict[str, any]]) -> List[Dict[str, any]]:
"""
Filters a list of dictionaries representing persons and returns a new list containing only the persons
whose '... |
evol_instruct_66k | 24,097 | Write a Python function to generate an array of `n` distinct random numbers within a specified range `[lower_bound, upper_bound]`. The function should validate the input to ensure that it is not generating more unique numbers than possible within the given range. The generated numbers should not follow any repeating se... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_distinct_random_numbers(n: int, lower_bound: int, upper_bound: int) -> List[int]:
"""
Generates an array of n distinct random numbers within the specified range [lower_bound, u... |
evol_instruct_66k | 24,109 | Write a Python function to sort a list of numbers in ascending order using the built-in `sorted` function. The function should take a list of integers as input and return a new list containing the sorted elements. 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_numbers(numbers: List[int]) -> List[int]:
"""
Sorts a list of numbers in ascending order.
Args:
numbers (List[int]): The list of numbers to be sorted.
Returns:
List[int... |
evol_instruct_66k | 24,121 | Write a Python function to combine two lists into a single list of tuples. If the lists have different lengths, the function should only combine elements up to the length of the shorter list. The code should start with:
```python
from typing import List, Tuple
def combine_lists(list1: List[any], list2: List[any]) -> L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def combine_lists(list1: List[any], list2: List[any]) -> List[Tuple[any, any]]:
"""
Combines two lists into a single list of tuples.
Args:
list1 (List[any]): The first list to combine... |
evol_instruct_66k | 24,154 | Write a Python function to convert a list of tuples into a dictionary, where each tuple contains an individual's name, occupation, birthday, and hobby. The function should handle cases where some tuples may be missing one or more elements and should set default values for those missing elements. The function should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict, Any
def convert_to_dict(people_list: List[Tuple[str, str, str, str]], default_value: Any = None) -> Dict[str, Dict[str, Any]]:
"""
Converts a list of tuples into a dictionary, where each tu... |
evol_instruct_66k | 24,171 | Write a Python function to analyze the attendance of events by different people. The function should output the number of events each person attended, the unique events they attended that no one else did, and the count of how many unique events each person attended. The input is a dictionary where keys are names of peo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
from collections import Counter
def analyze_event_attendance(events: Dict[str, List[str]]) -> None:
"""
Analyze the attendance of events by different people and output the number of events each per... |
evol_instruct_66k | 24,174 | Write a Python function to count the number of positive elements in a given integer array. The function should return the count of elements that are greater than zero. The code should start with:
```python
from typing import List
def count_positive_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 count_positive_elements(arr: List[int]) -> int:
"""
Counts the number of positive elements in a given integer array.
Args:
arr (List[int]): The array of integers to be processed.
... |
evol_instruct_66k | 24,201 | Write a Python function to remove leading and trailing whitespace characters from a given string. The function should handle various types of whitespace characters, including spaces, tabs, and newlines. The code should start with:
```python
def remove_whitespace(phrase: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_whitespace(phrase: str) -> str:
"""
Removes leading and trailing whitespace characters from the given string.
Args:
phrase (str): The input string from which to remove whitespace characters.
Returns:... |
evol_instruct_66k | 24,206 | Write a Python function to find the largest even number from a given list of integers efficiently. The function should return `None` if there are no even numbers in the list. The code should start with:
```python
from typing import List, Optional
def largest_even_number(numbers: List[int]) -> Optional[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def largest_even_number(numbers: List[int]) -> Optional[int]:
"""
Find the largest even number from a given list of integers.
Args:
numbers (List[int]): A list of integers from whi... |
evol_instruct_66k | 24,207 | Write a Python function to find the pair of numbers in a list of floating-point numbers that have the largest proportional discrepancy. The function should return the pair in ascending order (i.e., the smaller number first, the larger number second). The function should handle lists with at least two elements and ensur... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_furthest_elements(numbers: List[float]) -> Tuple[float, float]:
"""
Find the pair of numbers in a list of floating-point numbers that have the largest proportional discrepancy.
Args:... |
evol_instruct_66k | 24,212 | Write a Python function to replace all special symbols or non-alphanumeric characters in a given text with underscores, while preserving the original structure and length of the text. The function should handle any string input and return the modified string.
The code should start with:
```python
import re
def replac... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def replace_special_characters(text: str) -> str:
"""
Replace all special symbols or non-alphanumeric characters in the given text with underscores.
Args:
text (str): The input text string to be processed... |
evol_instruct_66k | 24,223 | Write a Python function to convert punctuation marks (., ,, ?, !) in a given text into corresponding text phrases while ensuring that contractions and possessive forms are not mistakenly converted. The function should also handle situations where the same punctuation mark has different meanings based on the context in ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def convert_punctuations(text: str) -> str:
"""
Converts punctuation marks (., ,, ?, !) in the given text into corresponding text phrases
while ensuring that contractions and possessive forms are not mistakenly co... |
evol_instruct_66k | 24,238 | Write a Python function to sort a list of numerical values in ascending order using the merge sort algorithm. The merge sort algorithm is a divide-and-conquer algorithm that recursively divides the list into halves until each sublist contains a single element, then merges these sublists back together in sorted order.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(input_list: List[int]) -> List[int]:
"""
Sorts a list of numerical values in ascending order using the merge sort algorithm.
Args:
input_list (List[int]): The list of numerica... |
evol_instruct_66k | 24,256 | Write a Python function to find the index of an element in a 2D list, considering that the list could be jagged (not every row has the same length) and the element may not exist within the list. The function should return a tuple `(row_index, col_index)` if the element is found, or `None` if the element is not present ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional, Tuple
def find_element_index(matrix: List[List[int]], target: int) -> Optional[Tuple[int, int]]:
"""
Find the index of a target element in a 2D list.
Args:
matrix (List[List[int]]... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.