source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 38,114 | Write a Python function to generate the first `n` numbers in the Fibonacci sequence. The function should return a list of the first `n` Fibonacci numbers. Additionally, provide a detailed explanation of the mathematical principle that underlies the Fibonacci sequence.
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 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... |
evol_instruct_66k | 38,121 | Write a Python function to reverse the order of characters in a given string. The function should handle strings of varying lengths, including empty strings. The code should start with:
```python
def reverse_string(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_string(text: str) -> str:
"""
Reverses the order of characters in the given string.
Args:
text (str): The input string to be reversed.
Returns:
str: The reversed string.
"""
# Ensu... |
evol_instruct_66k | 38,123 | Write a Python function to count the occurrences of each character in a given string, excluding spaces. The function should return a dictionary where the keys are the characters and the values are their respective counts. The code should start with:
```python
from typing import Dict
def count_char_occurrences(txt: str... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import Dict
def count_char_occurrences(txt: str) -> Dict[str, int]:
"""
Counts the occurrences of each character in the given string, excluding spaces.
Args:
txt (str): The input string to count chara... |
evol_instruct_66k | 38,135 | Write a Python function to generate an array of `n` random floating point numbers, each within the bounds of a specified range `[min_value, max_value]`. The function should ensure that the generated numbers are uniformly distributed within the specified range. 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
import numpy as np
def generate_random_floats(n: int, min_value: float, max_value: float) -> List[float]:
"""
Generates an array of `n` random floating point numbers within the specified range `[min_valu... |
evol_instruct_66k | 38,142 | Write a Python function to calculate the sum of the Triangle Series up to a given number `n`, as well as the sum of the square of each number in the Triangle Series up to `n`. The function should handle large values of `n` efficiently and include error handling for invalid inputs. The function should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
def triangle_square_sum(n: int) -> tuple:
"""
Calculate the sum of the Triangle Series up to n and the sum of the square of each number in the Triangle Series up to n.
Args:
n (int): The upper limit of the Triangle ... |
evol_instruct_66k | 38,154 | Write a Python function to calculate the Levenshtein Distance between two strings. The Levenshtein Distance is defined as the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other. The function should be efficient and use dynamic programming to a... | Here is the Python code to solve the given problem in the markdown block:
```python
def levenshtein_distance(str1: str, str2: str) -> int:
"""
Calculate the Levenshtein Distance between two strings.
The Levenshtein Distance is the minimum number of single-character edits
(insertions, deletions, or subs... |
evol_instruct_66k | 38,161 | Write a Python function to convert a given string to uppercase and remove all non-alphabetic characters. The function should return the transformed string. The code should start with:
```python
def transform_to_uppercase_and_remove_non_alpha(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def transform_to_uppercase_and_remove_non_alpha(input_string: str) -> str:
"""
Converts the input string to uppercase and removes all non-alphabetic characters.
Args:
input_string (str): The string to be transform... |
evol_instruct_66k | 38,188 | Write a Python function to safely access an element in a list by providing a default value if the index is out of range. The function should take a list, an index, and a default value as parameters. If the index is within the bounds of the list, the function should return the element at that index. Otherwise, it should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, List
def safe_list_access(lst: List[Any], index: int, default: Any) -> Any:
"""
Safely access an element in a list by providing a default value if the index is out of range.
Args:
lst (List[... |
evol_instruct_66k | 38,189 | Write a Python function to interchange two elements in a given list at specified positions. The function should handle invalid positions gracefully by returning the original list without any changes. The code should start with:
```python
from typing import List
def interchange_elements(arr: List[int], pos1: int, pos2:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def interchange_elements(arr: List[int], pos1: int, pos2: int) -> List[int]:
"""
Interchanges the elements at the specified positions in the given list.
Args:
arr (List[int]): The list of in... |
evol_instruct_66k | 38,199 | Write a Python function to extract the first `n` elements from a given list. If `n` is greater than the length of the list, return the entire list. The function should handle cases where `n` is negative or zero by returning an empty list.
The code should start with:
```python
from typing import List
def get_first_n_e... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_first_n_elements(lst: List[int], n: int) -> List[int]:
"""
Extracts the first `n` elements from the given list.
Args:
lst (List[int]): The list from which to extract the elements.
... |
evol_instruct_66k | 38,212 | Write a Python function to generate an HTML formatted list from a given JSON object. The JSON object contains a list of items and a title for the list. The function should return a string containing the HTML code for the list.
The code should start with:
```python
from typing import Dict
def generate_html_list(info: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def generate_html_list(info: Dict[str, str]) -> str:
"""
Generates an HTML formatted list from a given JSON object.
Args:
info (Dict[str, str]): A dictionary containing the list items and th... |
evol_instruct_66k | 38,214 | Write a Python function to calculate the total number of friend requests that will be sent among a group of individuals based on their ages. The function should take a list of ages as input and return the total number of friend requests. The conditions for sending a friend request are as follows:
- Person A will not se... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def total_friend_requests(ages: List[int]) -> int:
"""
Calculate the total number of friend requests that will be sent among a group of individuals based on their ages.
Args:
ages (List[int]... |
evol_instruct_66k | 38,231 | Write a Python function to calculate and return the prime factors of a given positive integer. The function should handle any positive integer input and return a list of its prime factors in ascending order.
The code should start with:
```python
from typing import List
def prime_factors(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def prime_factors(n: int) -> List[int]:
"""
Calculate and return the prime factors of a given positive integer.
Args:
n (int): The positive integer for which to find the prime factors.
... |
evol_instruct_66k | 38,250 | Write a Python function to encrypt a given valid URL by replacing every forward slash `'/'` with `'[slash]'` and every period `'.'` with `'[dot]'`. The function should handle URLs with multiple forward slashes and periods.
The code should start with:
```python
def encrypt_url(address: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def encrypt_url(address: str) -> str:
"""
Encrypts a given valid URL by replacing every forward slash '/' with '[slash]' and every period '.' with '[dot]'.
Args:
address (str): The valid URL address to be encrypte... |
evol_instruct_66k | 38,263 | Write a Python function to generate a new array that contains the first letter of each word in a given array. The input array consists of strings, and the output array should contain the first letter of each string in the same order.
The code should start with:
```python
from typing import List
def first_letters(arr:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def first_letters(arr: List[str]) -> List[str]:
"""
Generate a new array that contains the first letter of each word in a given array.
Args:
arr (List[str]): A list of strings from which to ... |
evol_instruct_66k | 38,264 | Write a Python function to manage contact information using a dictionary. The function should allow adding, updating, and retrieving contact information for multiple people. Each contact should store the person's name, email ID, and a list of phone numbers. The function should start with:
```python
from typing import D... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Optional
def manage_contact_info(
contact_info: Dict[str, Dict[str, Optional[str]]],
operation: str,
name: str,
email: Optional[str] = None,
phone_numbers: Optional[List[str]] = None
)... |
evol_instruct_66k | 38,268 | Write a Python function to reverse each string in a given list and concatenate the reversed strings with a specified delimiter. The function should include input validation to ensure that the input list contains only strings and that the delimiter is a string. The function should raise appropriate exceptions if the inp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def concatenate_reversed_strings(array: List[str], delimiter: str) -> str:
"""
Reverses each string in the given list and concatenates them with the specified delimiter.
Args:
array (List[st... |
evol_instruct_66k | 38,272 | Write a Python function to implement the merge sort algorithm that sorts a list of integers in ascending order. The function should be recursive and should handle the merging of subarrays efficiently.
The code should start with:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order using the merge sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Re... |
evol_instruct_66k | 38,293 | Write a Python function to determine if a given single-character string represents a vowel. The function should return `True` if the character is a vowel (either uppercase or lowercase), and `False` otherwise. Consider the vowels to be 'a', 'e', 'i', 'o', 'u' in both uppercase and lowercase forms.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_vowel(char: str) -> bool:
"""
Determines if a given single-character string represents a vowel.
Args:
char (str): A single-character string to be checked.
Returns:
bool: True if the character is ... |
evol_instruct_66k | 38,295 | Write a Python function to iterate over a given list and return a new list containing the elements of the original list in reverse order. The function should handle lists of any length and type of elements. The code should start with:
```python
from typing import List, Any
def reverse_list(mylist: List[Any]) -> List[A... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def reverse_list(mylist: List[Any]) -> List[Any]:
"""
Returns a new list containing the elements of the input list in reverse order.
Args:
mylist (List[Any]): The list to be reversed.
... |
evol_instruct_66k | 38,297 | Write a Python function to find and list all hidden files in a specified directory. The function should return a list of paths to these hidden files. The code should start with:
```python
from typing import List
import os
def find_hidden_files(directory: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import os
def find_hidden_files(directory: str) -> List[str]:
"""
Find and list all hidden files in the specified directory.
Args:
directory (str): The path to the directory to search for ... |
evol_instruct_66k | 38,307 | Write a Python function to identify the third largest number in a given array. If the array has fewer than three elements, the function should return a specific message indicating that the array does not have enough elements. The function should be efficient and avoid sorting the entire array if possible.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_third_largest(arr: List[int]) -> Union[int, str]:
"""
Finds the third largest number in a given array.
Args:
arr (List[int]): The array of integers from which to find the thi... |
evol_instruct_66k | 38,319 | 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... |
evol_instruct_66k | 38,322 | Write a Python function to merge `k` sorted lists into a single sorted list efficiently. The function should be optimized for scenarios where `k` can be a large number and the lists may contain large data sets. The function should also analyze its time and space complexity.
The code should start with:
```python
from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import heapq
def merge_k_sorted_lists(lists: List[List[int]]) -> List[int]:
"""
Merge k sorted lists into a single sorted list.
Args:
lists (List[List[int]]): A list of k sorted lists.
... |
evol_instruct_66k | 38,324 | Write a Python function to perform exponentiation on a given numerical value using a provided power. The function should handle both positive and negative powers, and should be efficient for large values of the power. The code should start with:
```python
def exponentiate(num: float, power: int) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def exponentiate(num: float, power: int) -> float:
"""
Compute the exponentiation of a given number raised to a specified power.
Args:
num (float): The base number to be exponentiated.
power (int): The exp... |
evol_instruct_66k | 38,327 | Write a Python function to generate a JavaScript code snippet that creates a button with specified styles and text. The function should accept the button text and a dictionary of CSS properties and their values. The generated JavaScript code should apply these styles to the button and set its text.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def generate_button_js(button_text: str, styles: Dict[str, Any]) -> str:
"""
Generates a JavaScript code snippet to create a button with specified styles and text.
Args:
button_text (st... |
evol_instruct_66k | 38,338 | Write a Python function to find all occurrences of a pattern in a given text, considering case insensitivity and the use of lookaheads and lookbehinds to match specific patterns. The function should also handle nested patterns and quantifiers.
The code should start with:
```python
import re
from typing import List
de... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def find_pattern_occurrences(text: str, pattern: str) -> List[str]:
"""
Find all occurrences of a pattern in a given text, considering case insensitivity and using lookaheads and lookbehinds.
... |
evol_instruct_66k | 38,353 | Write a Python function to create a deep copy of a given list of integers. A deep copy means that the new list will have the same elements as the original list, but it will be a completely separate object in memory. The function should use a for loop to achieve this.
The code should start with:
```python
from typing i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def deep_copy_list(arr: List[int]) -> List[int]:
"""
Creates a deep copy of a given list of integers.
Args:
arr (List[int]): The original list of integers to be copied.
Returns:
... |
evol_instruct_66k | 38,355 | Write a Python function to shuffle a list of real numbers using the Fisher-Yates algorithm. The function should return a new list that is a randomly shuffled version of the input list. The input list is composed of real numbers, such as fractions and numbers that require a decimal point. The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def shuffle_real_numbers(lst: List[float]) -> List[float]:
"""
Shuffles a list of real numbers using the Fisher-Yates algorithm.
Args:
lst (List[float]): The list of real numbe... |
evol_instruct_66k | 38,356 | Write a Python function that processes each element in a given list until a specified 'stop' value is encountered. The function should ensure that all elements up to and including the 'stop' value are processed correctly. The function should emulate the behavior of a do-while loop, which is not natively supported in Py... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def process_until_stop(data: List[str], stop: str) -> None:
"""
Processes each element in the given list until a specified 'stop' value is encountered.
Ensures that all elements up to and including t... |
evol_instruct_66k | 38,358 | Write a Python function to compute the result of the operation achieved by integrating a 3x3 identity matrix with another 3x3 matrix by means of addition. The function should take two 3x3 matrices as input and return the resulting matrix after addition.
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 add_matrices(identity_matrix: List[List[int]], another_matrix: List[List[int]]) -> List[List[int]]:
"""
Compute the result of the operation achieved by integrating a 3x3 identity matrix with another ... |
evol_instruct_66k | 38,367 | Write a Python function to generate the power set of a given set of numbers. The power set is the set of all possible subsets, including the empty set and the set itself. The function should return a list of lists, where each inner list represents a subset.
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 generate_power_set(nums: List[int]) -> List[List[int]]:
"""
Generate the power set of a given set of numbers.
Args:
nums (List[int]): The input set of numbers.
Returns:
Li... |
evol_instruct_66k | 38,380 | Write a Python function to swap the positions of two elements in an array using a conditional iterative process. The function should ensure that the indices are valid before performing the swap. If the indices are not valid, the function should return the original array without any modifications.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def swap_elements(arr: List[int], i: int, j: int) -> List[int]:
"""
Swaps the positions of two elements in an array using a conditional iterative process.
Args:
arr (List[int]): The array in... |
evol_instruct_66k | 38,383 | Write a Python function to reorder elements in a list by swapping the initial element with the final element. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def swap_first_last(lst: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def swap_first_last(lst: List[int]) -> List[int]:
"""
Reorders the elements in a list by swapping the initial element with the final element.
Args:
lst (List[int]): The list of integers to b... |
evol_instruct_66k | 38,384 | Write a Python function to construct an SQL query that retrieves specific columns from a given table in a relational database. The function should allow the user to specify the table name and a list of columns to be selected. The function should return the constructed SQL query as a string.
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 construct_sql_query(table_name: str, columns: List[str]) -> str:
"""
Constructs an SQL query to select specific columns from a given table.
Args:
table_name (str): The name of the table ... |
evol_instruct_66k | 38,390 | Write a Python function to generate a 2D NumPy array of a specified size containing random numbers from a normal distribution with given mean and standard deviation. The function should allow the user to specify the number of rows and columns in the array.
The code should start with:
```python
import numpy as np
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def generate_normal_distribution_array(rows: int, cols: int, mean: float, std_dev: float) -> np.ndarray:
"""
Generate a 2D NumPy array of specified size containing random numbers from a normal distribution.
... |
evol_instruct_66k | 38,394 | Write a Python function to compare two numerical entities and return a trinary output based on their relation. The function should return `0` if the two entities are identical, `-1` if the second entity is greater than the first, and `1` if the first entity is greater than the second. The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
def compare_numbers(object1: int, object2: int) -> int:
"""
Compare two numerical entities and return a trinary output based on their relation.
Args:
object1 (int): The first numerical entity to compare.
obj... |
evol_instruct_66k | 38,399 | Write a Python function to sort a given list of integers using the Bubble Sort algorithm. The sorting should be done in-place, meaning no additional data structures should be used for auxiliary space. The function should not use any built-in sorting functions.
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 bubble_sort(numbers: List[int]) -> None:
"""
Sorts a list of integers in-place using the Bubble Sort algorithm.
Args:
numbers (List[int]): The list of integers to be sorted.
Returns... |
evol_instruct_66k | 38,400 | Write a Python function to manage a collection of personal contact details. The function should allow adding a new contact, retrieving a contact's details by name, and listing all contacts. The contact details should include the individual's full name, email address, and mobile telephone number. The function should han... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Optional, List
def manage_contacts() -> Dict[str, Dict[str, str]]:
"""
Manages a collection of personal contact details.
Returns:
Dict[str, Dict[str, str]]: A dictionary containing all cont... |
evol_instruct_66k | 38,404 | Write a Python function to group objects in a list based on a given criteria. The function should take a list of dictionaries and a string representing the key (criteria) by which to group the dictionaries. The function should return a dictionary where the keys are the unique values of the given criteria and the values... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
from collections import defaultdict
def group_objects_by_criteria(objects_list: List[Dict[str, any]], criteria: str) -> Dict[any, List[Dict[str, any]]]:
"""
Groups objects in a list of dictionaries... |
evol_instruct_66k | 38,418 | Write a Python function that converts a given list of integers into a list of their corresponding English words. The function should use a `while` loop to iterate over the list and convert each integer to its English word representation. The function should handle integers from 0 to 9.
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 convert_to_english_words(numbers: List[int]) -> List[str]:
"""
Converts a list of integers (0-9) into their corresponding English words.
Args:
numbers (List[int]): A list of integers to ... |
evol_instruct_66k | 38,420 | Write a Python function to sort an array in ascending order using the Bubble Sort algorithm without using any built-in sorting functions. The function should take a list of integers as input and return the sorted list. The code should start with:
```python
from typing import List
def bubble_sort(array: List[int]) -> L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(array: List[int]) -> List[int]:
"""
Sorts an array in ascending order using the Bubble Sort algorithm.
Args:
array (List[int]): The list of integers to be sorted.
Return... |
evol_instruct_66k | 38,426 | Write a Python function to simulate rolling a specified number of dice and return the results as a list of integers. The function should be optimized for performance by avoiding the use of a for loop to append values to the list. The code should start with:
```python
import random
from typing import List
def roll_dice... | Here is the Python code to solve the given problem in the markdown block:
:
```python
import random
from typing import List
def roll_dice(num: int) -> List[int]:
"""
Simulate rolling a specified number of dice and return the results as a list of integers.
Args:
num (int): The number of dice to rol... |
evol_instruct_66k | 38,434 | Write a Python function to determine if a given array of numbers, which can include both integers and floating-point numbers, forms a geometric progression. Handle edge cases such as arrays containing zeros and negative numbers.
The code should start with:
```python
from typing import List
def is_geometric_progressio... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_geometric_progression(arr: List[float]) -> bool:
"""
Determine if the given array of numbers forms a geometric progression.
Args:
arr (List[float]): The array of numbers to check.
... |
evol_instruct_66k | 38,471 | Write a Python function to validate an email address based on specific criteria:
1. The email address must match a predefined regular expression pattern.
2. The domain part of the email must be in a list of allowed domains.
3. The username part of the email must conform to specific guidelines:
- Length between 5 and... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def validate_email(email: str, allowed_domains: List[str]) -> bool:
"""
Validates an email address based on specific criteria:
1. The email must match a predefined regular expression patter... |
evol_instruct_66k | 38,476 | Write a Python function to reverse the order of elements in a given list. The function should return the reversed list without modifying the original list. The code should start with:
```python
from typing import List
def reverse_list(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def reverse_list(arr: List[int]) -> List[int]:
"""
Reverses the order of elements in a given list without modifying the original list.
Args:
arr (List[int]): The list of integers to be rev... |
evol_instruct_66k | 38,486 | Write a Python function to reverse an integer array in place without using any temporary variables. The function should take a list of integers as input and modify the list directly to reverse its elements. The code should start with:
```python
from typing import List
def reverse_array(arr: List[int]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_array(arr: List[int]) -> None:
"""
Reverses the given integer array in place without using any temporary variables.
Args:
arr (List[int]): The list of integers to be reversed.
... |
evol_instruct_66k | 38,489 | Write a Python function to create a new array where each element is the product of each element in the given array and a given number. The function should handle any length of the input array and any integer number. The code should start with:
```python
from typing import List
def create_new_array(arr: List[int], num:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_new_array(arr: List[int], num: int) -> List[int]:
"""
Creates a new array where each element is the product of each element in the given array and a given number.
Args:
arr (List[... |
evol_instruct_66k | 38,491 | Write a Python function to swap the values of two variables without using a temporary variable. The function should take two parameters and return the swapped values. The code should start with:
```python
def swap_values_without_temp(a: int, b: int) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def swap_values_without_temp(a: int, b: int) -> tuple:
"""
Swaps the values of two variables without using a temporary variable.
Args:
a (int): The first variable.
b (int): The second variable.
Returns:... |
evol_instruct_66k | 38,499 | Write a Python function to generate a list of exactly four strings, where each string is a randomly generated alphanumeric string of length 5. The function should return this list. The code should start with:
```python
from typing import List
import random
import string
def generate_random_string_list() -> List[str]:
... | 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_list() -> List[str]:
"""
Generates a list of exactly four strings, where each string is a randomly generated alphanumeric string of length 5.
... |
evol_instruct_66k | 38,504 | Write a Python function to identify and list out all types of coding languages primarily used in the construction and development of internet-based pages. The function should return a list of dictionaries, where each dictionary contains the language name, a brief description, and an example usage of the language. The f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def list_web_development_languages() -> List[Dict[str, str]]:
"""
Returns a list of dictionaries containing information about web development languages.
Each dictionary in the list contain... |
evol_instruct_66k | 38,510 | Write a Python function to calculate the surface area of a right-angled triangular prism given the base, height of the triangle, and the length of the prism. The function should start with:
```python
def calculate_surface_area(base: float, height: float, length: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_surface_area(base: float, height: float, length: float) -> float:
"""
Calculate the surface area of a right-angled triangular prism.
Args:
base (float): The base of the right-angled triangle.
h... |
evol_instruct_66k | 38,513 | Write a Python function to sort a list of integers using the heapsort algorithm. The heapsort algorithm should be implemented using the `heapq` module from the Python standard library. The function should take a list of integers as input and return a new list containing the sorted integers.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import heapq
def heapsort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the heapsort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
... |
evol_instruct_66k | 38,518 | Write a Python function to find and return the prime factors of a given integer `n`. The function should return a list of prime factors in ascending order. The code should start with:
```python
from typing import List
def prime_factors(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def prime_factors(n: int) -> List[int]:
"""
Returns the prime factors of a given integer `n` in ascending order.
Args:
n (int): The integer for which to find the prime factors.
Returns:... |
evol_instruct_66k | 38,529 | Write a Python function to perform basic arithmetic operations (addition, subtraction, multiplication, and division) on two numbers. The function should take two numbers and an operator as input and return the result of the operation. The operator should be one of the following strings: '+', '-', '*', or '/'. If the op... | Here is the Python code to solve the given problem in the markdown block:
```python
def basic_calculator(num1: float, num2: float, operator: str) -> float:
"""
Perform basic arithmetic operations on two numbers.
Args:
num1 (float): The first number.
num2 (float): The second number.
... |
evol_instruct_66k | 38,538 | Write a Python function to identify and return the unique elements from a given set. The function should iterate over the set and collect elements that have not been seen before. The code should start with:
```python
def get_unique_elements(elements_set: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_unique_elements(elements_set: set) -> set:
"""
Returns a set of unique elements from the given set.
Args:
elements_set (set): The set from which to extract unique elements.
Returns:
set: A set c... |
evol_instruct_66k | 38,559 | Write a Python function to compute the nth term in the Fibonacci sequence efficiently using dynamic programming. The function should handle large values of n and avoid redundant calculations to ensure optimal performance.
The code should start with:
```python
def fibonacci_nth_term(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci_nth_term(n: int) -> int:
"""
Compute the nth term in the Fibonacci sequence using dynamic programming.
Args:
n (int): The position in the Fibonacci sequence to compute.
Returns:
int: The n... |
evol_instruct_66k | 38,580 | Write a Python function to extract and return the first three words from a given text string. If the text contains fewer than three words, return the entire text. The function should handle cases where the input text is empty or contains only one or two words.
The code should start with:
```python
def get_first_three_... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_first_three_words(text: str) -> str:
"""
Extracts and returns the first three words from the given text string.
If the text contains fewer than three words, returns the entire text.
Args:
text (str): The... |
evol_instruct_66k | 38,588 | Write a Python function to extract elements found in even positions from a provided list, considering zero-based indexing. The function should return a new list containing only the elements at even indices.
The code should start with:
```python
from typing import List
def extract_even_position_elements(lst: List[int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def extract_even_position_elements(lst: List[int]) -> List[int]:
"""
Extracts elements found in even positions from a provided list, considering zero-based indexing.
Args:
lst (List[int]): T... |
evol_instruct_66k | 38,602 | Write a Python function to compute and return a list that contains every possible combination of two given lists, without using any built-in itertools functions. Additionally, do not repeat any combinations in the resulting list. The function should start with:
```python
from typing import List
def get_combinations(li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_combinations(list1: List[int], list2: List[int]) -> List[List[int]]:
"""
Compute and return a list that contains every possible combination of two given lists,
without using any built-in iter... |
evol_instruct_66k | 38,646 | Write a Python function to combine two sets without any repetition of elements. The function should take two sets as input and return a new set that contains all unique elements from both sets. The code should start with:
```python
def combine_sets(set1: set, set2: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def combine_sets(set1: set, set2: set) -> set:
"""
Combines two sets without any repetition of elements.
Args:
set1 (set): The first set to combine.
set2 (set): The second set to combine.
Returns:
... |
evol_instruct_66k | 38,652 | Write a Python function to verify if a specific set of items is a subset of a larger set of items, ensuring there are no duplications. The function should take two lists as input and return a boolean indicating whether the first list is a subset of the second list. 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
def is_subset_without_duplicates(set1: List[str], set2: List[str]) -> bool:
"""
Verifies if the first set of items is a subset of the second set of items, ensuring there are no duplications.
Args:
... |
evol_instruct_66k | 38,659 | Write a Python function to clean up a given string by performing the following operations:
1. Remove all punctuation characters.
2. Remove all non-alphanumeric characters.
3. Convert the string to lowercase.
The function should start with:
```python
from typing import List
def clean_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
import string
def clean_string(s: str) -> str:
"""
Cleans up a given string by removing punctuation, non-alphanumeric characters, and converting it to lowercase.
Args:
s (str): The... |
evol_instruct_66k | 38,663 | Write a Python function to detect the unique elements in two unsorted arrays of integers and output their count. Unique elements are those that appear in only one of the two arrays, not in both. The function should start with:
```python
from typing import List
def count_unique_elements(arr1: List[int], arr2: List[int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_unique_elements(arr1: List[int], arr2: List[int]) -> int:
"""
Counts the number of unique elements that appear in only one of the two given arrays.
Args:
arr1 (List[int]): The firs... |
evol_instruct_66k | 38,674 | Write a Python function to determine the maximum value between two given integers `a` and `b`. The function should return the larger of the two values. The code should start with:
```python
def get_maximum(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_maximum(a: int, b: int) -> int:
"""
Returns the maximum value between two given integers.
Args:
a (int): The first integer to compare.
b (int): The second integer to compare.
Returns:
in... |
evol_instruct_66k | 38,680 | Write a Python function to determine if a string ends with a specified substring, including scenarios where the same substring repeats at the end. The function should return `True` if the string ends with the specified substring, and `False` otherwise. The code should start with:
```python
def has_suffix(s: str, suffix... | Here is the Python code to solve the given problem in the markdown block:
```python
def has_suffix(s: str, suffix: str) -> bool:
"""
Determine if a string ends with a specified substring, including scenarios where the same substring repeats at the end.
Args:
s (str): The string to check.
su... |
evol_instruct_66k | 38,686 | Write a Python function to create a dictionary representing a person's professional profile. The dictionary should include the following keys: "Occupation", "Experience(Years)", "Location", "Specialization", and "Certification". The function should allow for optional parameters for "Specialization" and "Certification".... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Optional
def create_professional_profile(occupation: str, experience: int, location: str, specialization: Optional[str] = None, certification: Optional[str] = None) -> dict:
"""
Creates a dictionary represent... |
evol_instruct_66k | 38,693 | Write a Python function to remove all instances of a specified number from a given list. The function should return a new list that contains all elements from the original list except for the specified number. The code should start with:
```python
from typing import List
def remove_number(lst: List[int], num: int) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_number(lst: List[int], num: int) -> List[int]:
"""
Removes all instances of the specified number from the given list.
Args:
lst (List[int]): The list from which to remove the spec... |
evol_instruct_66k | 38,697 | Write a Python function to merge two dictionaries with unique key-value pairs. If there are overlapping keys, the value from the second dictionary should overwrite the value from the first dictionary. The function should be able to handle any number of dictionaries by accepting a variable number of arguments.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def merge_multiple_dicts(*dicts: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Merges multiple dictionaries into a single dictionary. If there are overlapping keys,
the value from the last dictionary w... |
evol_instruct_66k | 38,704 | Write a Python function to evaluate a logical condition and perform an arithmetic operation based on the result. The function should take three integers `a`, `b`, and `c` as input and return the product of `a`, `b`, and `c` if either `a` is greater than `b` or `b` is less than `c`. Otherwise, return `None`.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
def evaluate_condition_and_multiply(a: int, b: int, c: int) -> int:
"""
Evaluates a logical condition and performs an arithmetic operation based on the result.
Args:
a (int): The first integer.
b (int): The ... |
evol_instruct_66k | 38,729 | Write a Python function to calculate the Manhattan distance between two points in an n-dimensional space. The function should be able to handle points with any number of dimensions. The code should start with:
```python
from typing import List
def manhattan_distance(p1: List[float], p2: List[float]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def manhattan_distance(p1: List[float], p2: List[float]) -> float:
"""
Calculate the Manhattan distance between two points in an n-dimensional space.
Args:
p1 (List[float]): The first point ... |
evol_instruct_66k | 38,735 | Write a Python function to combine two dictionaries of similar structure together, such that the entries in the two dictionaries are merged into a single dictionary. If both dictionaries have the same key, the value from the second dictionary should overwrite the value from the first dictionary.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def combine_dictionaries(dict1: Dict[str, int], dict2: Dict[str, int]) -> Dict[str, int]:
"""
Combines two dictionaries into a single dictionary. If both dictionaries have the same key,
the value fro... |
evol_instruct_66k | 38,757 | Write a Python function to compute the volume of unique lexemes within a given statement. A lexeme is defined as a sequence of characters in a string that does not contain any whitespace. The function should return the number of unique lexemes found in the statement.
The code should start with:
```python
def compute_u... | Here is the Python code to solve the given problem in the markdown block:
```python
def compute_unique_lexeme_volume(statement: str) -> int:
"""
Computes the volume of unique lexemes within a given statement.
Args:
statement (str): The input statement from which to compute the unique lexemes.
... |
evol_instruct_66k | 38,773 | Write a Python function to find the smallest number among three given integers. The function should take three integers as input and return the smallest one. The code should start with:
```python
def find_smallest_number(a: int, b: int, c: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def find_smallest_number(a: int, b: int, c: int) -> int:
"""
Find the smallest number among three given integers.
Args:
a (int): The first integer.
b (int): The second integer.
c (int): The third i... |
evol_instruct_66k | 38,774 | Write a Python function to determine if a given list of numbers (set1) is a subset of another list of numbers (set2) without any duplication. The function should return `True` if all elements of set1 are present in set2, and `False` otherwise. The code should start with:
```python
from typing import List
def is_subset... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_subset_without_duplicates(set1: List[int], set2: List[int]) -> bool:
"""
Determines if all elements of set1 are present in set2 without any duplication.
Args:
set1 (List[int]): The fi... |
evol_instruct_66k | 38,788 | Write a Python function to perform a quadrille swap of four integers. The quadrille swap involves swapping the values of four variables in a cyclic manner. Specifically, given four integers `a`, `b`, `c`, and `d`, the function should swap their values such that:
- `a` takes the value of `c`
- `b` takes the value of `d`... | Here is the Python code to solve the given problem in the markdown block:
```python
def quadrille_swap(a: int, b: int, c: int, d: int) -> tuple:
"""
Perform a quadrille swap of four integers.
Args:
a (int): The first integer.
b (int): The second integer.
c (int): The third integer.
... |
evol_instruct_66k | 38,790 | Write a Python function to process a list of strings in a specific order, ensuring that each string is processed exactly once and in the given order. The function should return a new list where each string from the original list is transformed by appending its index and length. The function should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def process_strings(data: List[str]) -> List[str]:
"""
Processes a list of strings by appending each string's index and length to the string itself.
Args:
data (List[str]): A list of strings... |
evol_instruct_66k | 38,791 | Write a Python function to convert a given string into its binary representation, where each character is represented by an 8-bit binary string. The function should handle any string input and return a single concatenated binary string.
The code should start with:
```python
def string_to_binary(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def string_to_binary(s: str) -> str:
"""
Converts a given string into its binary representation where each character is represented by an 8-bit binary string.
Args:
s (str): The input string to be converted into bin... |
evol_instruct_66k | 38,798 | Write a Python function to sort a given array of integers and return the smallest and largest numbers in the array. The function should handle arrays of any length, including empty arrays. The code should start with:
```python
from typing import List, Tuple
def find_extremes(arr: List[int]) -> Tuple[int, int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Optional
def find_extremes(arr: List[int]) -> Tuple[Optional[int], Optional[int]]:
"""
Sorts the given array of integers and returns the smallest and largest numbers.
Args:
arr (List... |
evol_instruct_66k | 38,800 | Write a Python function to count the number of alphabetic characters in a given phrase, ignoring spaces and punctuation. The function should handle any string input and return the count of letters only.
The code should start with:
```python
def count_alphabetic_characters(phrase: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_alphabetic_characters(phrase: str) -> int:
"""
Counts the number of alphabetic characters in a given phrase, ignoring spaces and punctuation.
Args:
phrase (str): The input phrase to count alphabetic charac... |
evol_instruct_66k | 38,822 | Write a Python function to find the indices of any symmetric pairs within the rows of a given matrix. A symmetric pair is defined as two rows where one row is the reverse of the other. The function should return the indices of the symmetric pair if found, otherwise return `None`.
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, Tuple, Optional
def find_symmetric_pairs(matrix: List[List[int]]) -> Optional[Tuple[int, int]]:
"""
Find the indices of any symmetric pairs within the rows of a given matrix.
A symmetric pair is de... |
evol_instruct_66k | 38,831 | Write a Python function to validate if a given string is a chain composed strictly of uppercase alphabetic characters and numerical figures. The string should not contain any lowercase letters, special characters, or spaces. The function should return `True` if the string meets the criteria, and `False` otherwise.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_uppercase_numeric_chain(s: str) -> bool:
"""
Validates if the given string is a chain composed strictly of uppercase alphabetic characters and numerical figures.
Args:
s (str): The string to be val... |
evol_instruct_66k | 38,865 | Write a Python function to perform cross-multiplication on two given numerical inputs and return the result. The function should handle both positive and negative integers, as well as zero. The code should start with:
```python
def cross_multiply(num_1: int, num_2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def cross_multiply(num_1: int, num_2: int) -> int:
"""
Perform cross-multiplication on two given numerical inputs and return the result.
Args:
num_1 (int): The first numerical input.
num_2 (int): The second ... |
evol_instruct_66k | 38,873 | Write a Python function to extract the second, third, and fourth elements from a given list. If the list has fewer than four elements, return an empty list. The function should start with:
```python
from typing import List
def extract_elements(lst: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def extract_elements(lst: List[int]) -> List[int]:
"""
Extracts the second, third, and fourth elements from a given list.
Args:
lst (List[int]): The list from which to extract the elem... |
evol_instruct_66k | 38,876 | Write a Python function to group anagrams from a given list of strings. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, using all the original letters exactly once. The function should return a list of lists, where each sublist contains all the anagrams of a particular gr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import defaultdict
def group_anagrams(strs: List[str]) -> List[List[str]]:
"""
Groups anagrams from a given list of strings.
Args:
strs (List[str]): A list of strings to be ... |
evol_instruct_66k | 38,886 | Write a Python function to create a dictionary where the keys are integers from 1 to `n` (inclusive) and the values are their square roots. The function should use dictionary comprehension for efficiency.
The code should start with:
```python
import math
def create_square_root_dict(n: int) -> dict:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def create_square_root_dict(n: int) -> dict:
"""
Creates a dictionary where the keys are integers from 1 to n (inclusive) and the values are their square roots.
Args:
n (int): The upper limit for the ra... |
evol_instruct_66k | 38,890 | 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) using the given components.
Args:
transfer_pr... |
evol_instruct_66k | 38,906 | Write a Python function to generate the first 'n' Fibonacci numbers and calculate the corresponding Golden Ratio approximations for each pair of consecutive Fibonacci numbers. The function should be optimized for speed and capable of handling large values of 'n' efficiently. The code should start with:
```python
from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def fibonacci_golden_ratio(n: int) -> Tuple[List[int], List[float]]:
"""
Generate the first 'n' Fibonacci numbers and calculate the corresponding Golden Ratio approximations.
Args:
n ... |
evol_instruct_66k | 38,908 | Write a Python function that takes an arbitrary character string as input and returns the length of the string along with a dictionary containing the count of each character in the string. The function should handle any string, including those with special characters, spaces, and numbers. The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def analyze_string(s: str) -> Tuple[int, Dict[str, int]]:
"""
Analyzes the given string and returns its length along with a dictionary containing the count of each character.
Args:
s ... |
evol_instruct_66k | 38,913 | Write a Python function to simplify a given two-dimensional matrix by flattening it into a one-dimensional list. The matrix contains entities represented by integers. The function should handle matrices of varying sizes, including empty matrices.
The code should start with:
```python
from typing import List
def simpl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def simplify_matrix(matrix: List[List[int]]) -> List[int]:
"""
Simplifies a given two-dimensional matrix by flattening it into a one-dimensional list.
Args:
matrix (List[List[int]]): A two-d... |
evol_instruct_66k | 38,917 | Write a Python function to find and return the last element from a given list of floating-point numbers. The function should handle lists of any length, 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 get_last_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def get_last_element(float_arr: List[float]) -> Optional[float]:
"""
Returns the last element from a given list of floating-point numbers.
If the list is empty, returns None.
Args:
... |
evol_instruct_66k | 38,923 | Write a Python function to calculate the minimum daily expense required to employ an individual for a specific duration, given an array of daily income requirements. The function should assume that an individual must be employed for at least one day before their employment can be terminated. 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 min_daily_expense(salary_demands: List[int]) -> int:
"""
Calculate the minimum daily expense required to employ an individual for a specific duration,
given an array of daily income requirements.... |
evol_instruct_66k | 38,928 | Write a Python function to determine whether a given number is a perfect square without using any built-in square root or power functions. The function should return `True` if the number 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
def is_perfect_square(n: int) -> bool:
"""
Determines whether a given number is a perfect square without using any built-in square root or power functions.
Args:
n (int): The number to check.
Returns:
... |
evol_instruct_66k | 38,932 | Write a Python function to generate a new array where each element is the result of multiplying the corresponding element in the input array by a given factor. The input array consists of distinct integers, and the factor is a positive integer.
The code should start with:
```python
from typing import List
def multipl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_array_by_factor(arr: List[int], factor: int) -> List[int]:
"""
Generates a new array where each element is the result of multiplying the corresponding element in the input array by a given f... |
evol_instruct_66k | 38,935 | Write a Python function that generates a string of a specified length, `n`, filled with asterisk characters (`*`). The function should handle invalid input types and ensure it can handle values of `n` up to 1 million. If the input is invalid, the function should return an appropriate error message.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_asterisk_string(n: int) -> str:
"""
Generates a string of length `n` filled with asterisk characters ('*').
Args:
n (int): The length of the string to be generated. Must be between 0 and 1,000,000 inclu... |
evol_instruct_66k | 38,937 | Write a Python function to flatten a nested list of arbitrary depth into a single flat list. The function should maintain the sequence of elements as they appear in the original nested list. The code should start with:
```python
from typing import List, Any
def flatten_nested_list(nested_list: List[Any]) -> List[Any]:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def flatten_nested_list(nested_list: List[Any]) -> List[Any]:
"""
Flattens a nested list of arbitrary depth into a single flat list.
Args:
nested_list (List[Any]): The nested list to be... |
evol_instruct_66k | 38,946 | Write a Python function to determine the mode(s) for each series in a given matrix of n by m elements (n rows and m columns). Each cell of the matrix contains a series of integers. If there are multiple modes in a series, return all of them. The function should be optimized for time complexity.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import Counter
def find_matrix_modes(matrix: List[List[List[int]]]) -> List[List[List[int]]]:
"""
Determine the mode(s) for each series in a given matrix of n by m elements.
Args:
... |
evol_instruct_66k | 38,977 | Write a Python function to compute the nth Fibonacci number using a recursive method with memoization. The function should efficiently handle larger inputs by storing previously computed Fibonacci numbers to avoid redundant calculations. The code should start with:
```python
def fibonacci_memoized(n: int, memo: dict = ... | Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci_memoized(n: int, memo: dict = {}) -> int:
"""
Compute the nth Fibonacci number using a recursive method with memoization.
Args:
n (int): The position in the Fibonacci sequence to compute.
memo ... |
evol_instruct_66k | 38,979 | Write a Python function to compute the sum of the squares of two integers. The function should take two integer inputs and return the sum of their squares. The code should start with:
```python
def sum_of_squares(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_squares(a: int, b: int) -> int:
"""
Compute the sum of the squares of two integers.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
int: The sum of the squares... |
evol_instruct_66k | 38,987 | Write a Python function to reverse an alphanumeric sequence while preserving the positions of non-alphanumeric characters. The function should accept a string as input and return a string where all alphanumeric characters are reversed, but non-alphanumeric characters remain in their original positions.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_alphanumeric_sequence(sequence: str) -> str:
"""
Reverses the alphanumeric characters in the given sequence while preserving the positions of non-alphanumeric characters.
Args:
sequence (str): The input ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.