source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 651 | Write a Python function to filter a list of dictionaries based on a search query. Each dictionary represents a person with keys "Id", "Name", "Age", and "Occupation". The function should return a list of dictionaries where the "Name" value partially matches the search query, case-insensitively.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def filter_people(people: List[Dict[str, any]], query: str) -> List[Dict[str, any]]:
"""
Filters a list of dictionaries based on a search query.
Args:
people (List[Dict[str, any]]): A ... |
evol_instruct_66k | 652 | Write a Python function to multiply each element of a given list by a specified integer and return the resulting list. The function should use a `for` loop to iterate through the elements of the list and perform the multiplication operation. The code should start with:
```python
from typing import List
def multiply_li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_list_elements(original_list: List[int], multiplier: int) -> List[int]:
"""
Multiplies each element of the given list by the specified multiplier and returns the resulting list.
Args:
... |
evol_instruct_66k | 657 | Write a Python function to find the smallest and largest integers in a given list of integers. The function should return a tuple containing the smallest and largest integers. The code should start with:
```python
from typing import List, Tuple
def find_min_max(lst: 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
def find_min_max(lst: List[int]) -> Tuple[int, int]:
"""
Find the smallest and largest integers in a given list of integers.
Args:
lst (List[int]): The list of integers from which to ... |
evol_instruct_66k | 660 | Write a Python function to calculate the sum of all individual digits in a given integer. The function should handle both positive and negative integers. The code should start with:
```python
def sum_of_digits(num: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def sum_of_digits(num: int) -> int:
"""
Calculate the sum of all individual digits in a given integer.
Args:
num (int): The integer whose digits are to be summed.
Returns:
int: The sum of all individu... |
evol_instruct_66k | 665 | Write a Python function to rearrange a person's full name such that the middle name comes first, followed by the first initial of the first name (with a period), and then the last name. The function should accept three distinct arguments: the first name, the middle name, and the last name. The output should be a single... | Here is the Python code to solve the given problem in the markdown block:
```python
def rearrange_name(first_name: str, middle_name: str, last_name: str) -> str:
"""
Rearranges the full name such that the middle name comes first, followed by the first initial of the first name (with a period), and then the last... |
evol_instruct_66k | 673 | Write a Python function to compute the cumulative sum of all integer values in a given list. The function should take a list of integers as input and return the cumulative sum as an integer. The code should start with:
```python
from typing import List
def cumulative_sum(data: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_sum(data: List[int]) -> int:
"""
Computes the cumulative sum of all integer values in the given list.
Args:
data (List[int]): A list of integers for which the cumulative sum i... |
evol_instruct_66k | 676 | Write a Python function to reverse the orientation of a given textual input. The function should take a string as input and return the reversed string. The code should start with:
```python
def reverse_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_string(s: str) -> str:
"""
Reverses the orientation of a given textual input.
Args:
s (str): The input string to be reversed.
Returns:
str: The reversed string.
"""
# Use slicing t... |
evol_instruct_66k | 681 | Write a Python function to count the number of unique words in a given paragraph, identify their frequency of occurrence, and store them in a dictionary where keys are the unique words and values are their respective frequencies. Additionally, implement a secondary function to identify the top 3 most frequently occurri... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def word_counter(paragraph: str) -> Dict[str, int]:
"""
Counts the number of unique words in a given paragraph and stores their frequencies in a dictionary.
Args:
paragraph (str... |
evol_instruct_66k | 683 | Write a Python function to calculate the combined total of all integers present within a given list of integers. The function should handle lists of varying lengths, including empty lists. The code should start with:
```python
from typing import List
def sum_integers(integer_list: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def sum_integers(integer_list: List[int]) -> int:
"""
Calculate the combined total of all integers present within the given list.
Args:
integer_list (List[int]): A list of integers.
R... |
evol_instruct_66k | 694 | Write a Python function to analyze a given text and determine if it contains any flamboyant or excessively illustrative expressions. The function should return "Present" if such language is detected and "Absent" otherwise. The code should start with:
```python
def detect_flamboyant_language(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def detect_flamboyant_language(text: str) -> str:
"""
Analyzes the given text to determine if it contains any flamboyant or excessively illustrative expressions.
Args:
text (str): The text to be analyzed.
Retur... |
evol_instruct_66k | 700 | Write a Python function to create a new array where each element is the cube of the corresponding element in a given initial array. The function should take a list of integers as input and return a new list of integers. The code should start with:
```python
from typing import List
def cube_array(initial_array: List[in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cube_array(initial_array: List[int]) -> List[int]:
"""
Creates a new array where each element is the cube of the corresponding element in the given initial array.
Args:
initial_array (Li... |
evol_instruct_66k | 718 | Write a Python function to find all the positions (indices) of a specified element within a given list. The function should return a list of indices where the specified element occurs. The code should start with:
```python
from typing import List
def find_element_positions(lst: List[int], val: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_element_positions(lst: List[int], val: int) -> List[int]:
"""
Find all positions (indices) of a specified element within a given list.
Args:
lst (List[int]): The list in which to se... |
evol_instruct_66k | 724 | Write a Python function to return a list of unique elements from a given list, maintaining the order of their first appearance. The function should start with:
```python
from typing import List
def unique_elements_in_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 unique_elements_in_order(input_list: List[int]) -> List[int]:
"""
Returns a list of unique elements from the given list, maintaining the order of their first appearance.
Args:
input_li... |
evol_instruct_66k | 729 | Write a Python function to compute the area of a triangle given its three side lengths using Heron's formula. The function should validate that the given side lengths can form a valid triangle before computing the area. If the side lengths do not form a valid triangle, the function should return `None`.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
from typing import Optional
def triangle_area(a: float, b: float, c: float) -> Optional[float]:
"""
Compute the area of a triangle given its side lengths using Heron's formula.
Args:
a (float): The leng... |
evol_instruct_66k | 743 | Write a Python function to convert all string elements in a nested list to uppercase while maintaining the original structure of the nested list. The nested list can contain strings, integers, or other lists at any level of nesting. The function should only convert strings to uppercase and leave other types of elements... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def nested_to_uppercase(nested_list: List[Union[str, int, List]]) -> List[Union[str, int, List]]:
"""
Converts all string elements in a nested list to uppercase while maintaining the original stru... |
evol_instruct_66k | 751 | Write a Python function to extract and return the last n elements from a given list of integers. The function should handle cases where n is greater than the length of the list, and where n is less than or equal to zero. The code should start with:
```python
from typing import List
def get_last_n_elements(lst: List[in... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def get_last_n_elements(lst: List[int], n: int) -> List[int]:
"""
Extracts and returns the last n elements from the given list.
Args:
lst (List[int]): The list from which to extract the la... |
evol_instruct_66k | 769 | Write a Python function to find and return a list of all integers that appear more than once in a given list of integers. The function should handle any list of integers, including an empty list. The code should start with:
```python
from typing import List
def find_duplicates(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 find_duplicates(lst: List[int]) -> List[int]:
"""
Find and return a list of all integers that appear more than once in the given list.
Args:
lst (List[int]): The list of integers to chec... |
evol_instruct_66k | 776 | Write a Python function to decrypt a message encrypted using the Caesar cipher. The function should take two parameters: the encrypted message and the key used for encryption. The function should return the decrypted message. The code should start with:
```python
def caesar_decrypt(encrypted_message: str, key: int) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
def caesar_decrypt(encrypted_message: str, key: int) -> str:
"""
Decrypts a message encrypted using the Caesar cipher.
Args:
encrypted_message (str): The message to be decrypted.
key (int): The key used for ... |
evol_instruct_66k | 785 | Write a Python function to calculate the combined total of three numerical arrays, each representing 'a', 'b', and 'c' values respectively. Each array has `n` elements. The function should sum the corresponding elements from each array in the order of `a`, `b`, `c`, and then increase the result by an additional five un... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_combined_total(a: List[int], b: List[int], c: List[int]) -> List[int]:
"""
Calculate the combined total of three numerical arrays, each representing 'a', 'b', and 'c' values respectively.
... |
evol_instruct_66k | 786 | Write a Python function to return the first five elements of a given array in mirrored sequence. If the array has fewer than five elements, the function should return the entire array in mirrored sequence. The function should start with:
```python
from typing import List
def first_five_mirrored(arr: List[int]) -> List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def first_five_mirrored(arr: List[int]) -> List[int]:
"""
Returns the first five elements of the given array in mirrored sequence.
If the array has fewer than five elements, the entire array is retur... |
evol_instruct_66k | 790 | Write a Python function to calculate the Greatest Common Divisor (GCD) of two non-negative integers using the Euclidean algorithm. The function should handle the case where one or both of the inputs are zero.
The code should start with:
```python
def gcd(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def gcd(a: int, b: int) -> int:
"""
Calculate the Greatest Common Divisor (GCD) of two non-negative integers using the Euclidean algorithm.
Args:
a (int): The first non-negative integer.
b (int): The second ... |
evol_instruct_66k | 792 | Write a Python function to find the exact position of a distinct element within a set of sequence-aligned textual items. If the target element is not found, the function should return -1. The function should be efficient and handle edge cases such as an empty list or a target not present in the list.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_element_position(words: List[str], target: str) -> int:
"""
Find the exact position of a distinct element within a set of sequence-aligned textual items.
Args:
words (List[str]): A ... |
evol_instruct_66k | 797 | Write a Python function to find the prime factors of multiple numbers and count the frequency of each distinct prime factor for each number. The function should return a dictionary where the keys are the numbers and the values are dictionaries containing the prime factors and their respective counts.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def prime_factors(n: int) -> Dict[int, int]:
"""
Calculate the prime factors of a given number and their frequencies.
Args:
n (int): The number to factorize.
Returns:
Dict... |
evol_instruct_66k | 806 | Write a Python function to calculate the cumulative sum of elements in a given list. The function should modify the input list in place and return the modified list. The code should start with:
```python
from typing import List
def cumulative_sum(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 cumulative_sum(arr: List[int]) -> List[int]:
"""
Calculate the cumulative sum of elements in the given list and return the modified list.
Args:
arr (List[int]): The list of integers fo... |
evol_instruct_66k | 811 | Write a Python function to calculate the surface area and volume of a torus given the radius `r` of the tube and the distance `d` from the center of the tube to the center of the torus. The functions should handle edge cases such as when the radius or distance is zero or negative by returning `None`.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def surface_area_torus(r: float, d: float) -> float:
"""
Calculate the surface area of a torus.
Args:
r (float): The radius of the tube.
d (float): The distance from the center of the tube to th... |
evol_instruct_66k | 827 | Write a Python function to concatenate two given strings with a space in between them. The function should handle cases where the input strings might be empty or contain only whitespace. The code should start with:
```python
def concatenate_strings(str1: str, str2: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def concatenate_strings(str1: str, str2: str) -> str:
"""
Concatenates two given strings with a space in between.
Args:
str1 (str): The first string to concatenate.
str2 (str): The second string to concatena... |
evol_instruct_66k | 833 | Write a Python function to convert a given string representation of an age to an integer and return it. If the input string cannot be converted to an integer, return `None`. The function should handle various edge cases, such as empty strings, non-numeric strings, and strings with leading/trailing whitespace.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_age_to_int(age_str: str) -> int:
"""
Converts a given string representation of an age to an integer.
Args:
age_str (str): The string representation of the age to be converted.
Returns:
int: ... |
evol_instruct_66k | 844 | Write a Python function to convert a given length in inches to centimeters using the standard conversion rate of 1 inch = 2.54 centimeters. The function should handle both positive and negative values for inches, but should return 0 for any non-numeric input.
The code should start with:
```python
def inches_to_cm(inch... | Here is the Python code to solve the given problem in the markdown block:
```python
def inches_to_cm(inches: float) -> float:
"""
Convert a given length in inches to centimeters using the standard conversion rate.
Args:
inches (float): The length in inches to be converted.
Returns:
flo... |
evol_instruct_66k | 848 | Write a Python function to find the longest common subsequence (LCS) between two given strings. The function should return the length of the LCS.
The code should start with:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
"""
Calculate the length of the longest common subsequence (LCS) between two strings.
Args:
str1 (str): The first string.
str2 (str): The second... |
evol_instruct_66k | 857 | Write a Python function to convert a floating-point number to a fixed-point number with a specified precision. The function should return the fixed-point number as a string. The code should start with:
```python
from typing import Union
def convert_to_fixed_point(num: float, precision: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union
def convert_to_fixed_point(num: float, precision: int) -> str:
"""
Converts a floating-point number to a fixed-point number with a specified precision and returns it as a string.
Args:
num ... |
evol_instruct_66k | 885 | Write a Python function to sort a list of non-negative integers in O(n) time complexity using the counting sort algorithm. The function should take a list of integers as input and return a sorted list. The code should start with:
```python
from typing import List
def counting_sort(unsorted_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 counting_sort(unsorted_list: List[int]) -> List[int]:
"""
Sorts a list of non-negative integers in O(n) time complexity using the counting sort algorithm.
Args:
unsorted_list (List[int... |
evol_instruct_66k | 904 | Write a Python function to compute the number of derangements of a numerical sequence of length `n`, where `n` is an integer ranging from 1 to 10^6. A derangement is a permutation of the elements of a set such that no element appears in its original position. The result should be returned modulo 10^9 + 7 due to the pot... | Here is the Python code to solve the given problem in the markdown block:
```python
def derangement_count(n: int) -> int:
"""
Compute the number of derangements of a sequence of length `n` modulo 10^9 + 7.
A derangement is a permutation of the elements of a set such that no element appears in its original ... |
evol_instruct_66k | 908 | Write a Python function to count the occurrences of a specified item in a given list. The function should be able to handle lists of any data type, including integers, strings, and other objects. The function should start with:
```python
from typing import List, Any
def count_occurrences(array: List[Any], item: Any) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def count_occurrences(array: List[Any], item: Any) -> int:
"""
Counts the number of occurrences of a specified item in a given list.
Args:
array (List[Any]): The list in which to count ... |
evol_instruct_66k | 926 | Write a Python function to find the n smallest elements from a given list of integers efficiently. The function should handle cases where n is greater than the length of the list, and it should return an empty list if n is less than or equal to 0. The function should start with:
```python
from typing import List
def f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import heapq
def find_n_smallest_elements(arr: List[int], n: int) -> List[int]:
"""
Finds the n smallest elements from the given list of integers.
Args:
arr (List[int]): The list of integers... |
evol_instruct_66k | 935 | Write a Python function to convert a given string from snake_case to kebab-case. The function should replace all underscores `_` in the input string with hyphens `-`. The code should start with:
```python
def snake_to_kebab(snake_case_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def snake_to_kebab(snake_case_string: str) -> str:
"""
Converts a given string from snake_case to kebab-case.
Args:
snake_case_string (str): The input string in snake_case format.
Returns:
str: The conv... |
evol_instruct_66k | 939 | Write a Python function to return a list containing every third element from a given array. The function should start with:
```python
from typing import List
def get_every_third_element(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 get_every_third_element(arr: List[int]) -> List[int]:
"""
Returns a list containing every third element from the given array.
Args:
arr (List[int]): The input array from which to extra... |
evol_instruct_66k | 942 | Write a Python function to balance and sort a binary search tree (BST) while maintaining the BST properties throughout these operations. The function should take a list of integers representing the nodes of the BST and return a list of integers representing the in-order traversal of the balanced BST.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def balance_and_sort_bst(nodes: List[int]) -> List[int]:
"""
Balances and sorts a binary search tree (BST) while maintaining its properties.
Args:
nodes (List[int]): A list of integers repre... |
evol_instruct_66k | 943 | Write a Python function to reverse a given list in place and efficiently. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def reverse_list(A: 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(A: List[int]) -> List[int]:
"""
Reverses the given list in place and returns the reversed list.
Args:
A (List[int]): The list to be reversed.
Returns:
List[int]... |
evol_instruct_66k | 951 | Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should start with:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
"""
Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid.
Args:
m (int): The number of row... |
evol_instruct_66k | 954 | Write a Python function to remove all occurrences of a specified numerical value from a given list and return the modified list. The function should handle lists of integers and the value to be removed should also be an integer. The code should start with:
```python
from typing import List
def remove_all_occurrences(i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_all_occurrences(input_list: List[int], value_to_remove: int) -> List[int]:
"""
Removes all occurrences of a specified numerical value from a given list and returns the modified list.
Args... |
evol_instruct_66k | 963 | Write a Python function to find all palindromic tuples within a given one-dimensional array. A palindromic tuple is defined as a pair of the same integer that appears at least twice in the array. The function should return a list of tuples where each tuple represents a palindromic pair.
The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_palindromic_pairs(nums: List[int]) -> List[Tuple[int, int]]:
"""
Finds all palindromic tuples within a given one-dimensional array.
A palindromic tuple is defined as a pair of the sa... |
evol_instruct_66k | 971 | Write a Python function to find and return a list of prime numbers within a given range `[min_value, max_value]`. The function should handle invalid ranges by raising a `ValueError`. The code should start with:
```python
def find_prime_numbers(min_value: int, max_value: int) -> list:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_prime_numbers(min_value: int, max_value: int) -> list:
"""
Find and return a list of prime numbers within the given range [min_value, max_value].
Args:
min_value (int): The starting value of the range (incl... |
evol_instruct_66k | 974 | Write a Python function that accepts three parameters: a text string, a collection in the form of a list, and a separator punctuation. The function should return a single string where each element of the list is prefixed by the given text string and separated by the provided punctuation.
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 format_list_with_prefix(text_prefix: str, elements: List[str], separator: str) -> str:
"""
Formats a list of elements by prefixing each element with a given text string and joining them with a specif... |
evol_instruct_66k | 976 | Write a Python function to merge two given dictionaries into one. If there are any key clashes, the function should prefer the highest value. The solution should be efficient for larger dictionaries.
The code should start with:
```python
from typing import Dict
def merge_dicts(dict1: Dict[str, int], dict2: Dict[str, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_dicts(dict1: Dict[str, int], dict2: Dict[str, int]) -> Dict[str, int]:
"""
Merges two dictionaries into one. If there are any key clashes, the highest value is preferred.
Args:
dic... |
evol_instruct_66k | 977 | Write a Python function to unpack elements from a list of tuples and assign them to individual variables. The function should handle tuples of varying lengths and gracefully handle unexpected data types. The function should return a list of dictionaries, where each dictionary contains the unpacked elements with keys 'n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Any, Dict
def unpack_tuples(lst: List[Tuple[Any, ...]]) -> List[Dict[str, Any]]:
"""
Unpacks elements from a list of tuples and assigns them to individual variables.
Handles tuples of varying... |
evol_instruct_66k | 981 | Write a Python function to extract and magnify words from a given list of strings that contain dual vowel clusters. A dual vowel cluster is defined as two consecutive vowels (a, e, i, o, u) in a word. The function should return a list of these magnified words in uppercase.
The code should start with:
```python
from ty... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def magnify_dual_vowel_words(words: List[str]) -> List[str]:
"""
Extracts and magnifies words from a given list of strings that contain dual vowel clusters.
Args:
words (List[str])... |
evol_instruct_66k | 988 | Write a Python function to validate the structure and content of a dictionary representing a "Scholar" object. The dictionary must contain specific keys (`id`, `name`, `grade`) with valid values. The `id` must be an integer, the `name` must be a non-empty string, and the `grade` must be an integer between 0 and 100 (in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def validate_scholar(scholar: Dict[str, any]) -> bool:
"""
Validates the structure and content of a dictionary representing a "Scholar" object.
Args:
scholar (Dict[str, any]): A dictionary r... |
evol_instruct_66k | 999 | Write a Python function to translate a given ASCII string into a hexadecimal string and then encode this hexadecimal string into a binary string without using any built-in binary conversion functions. The function should start with:
```python
def ascii_to_binary(ascii_str: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def ascii_to_binary(ascii_str: str) -> str:
"""
Translates a given ASCII string into a hexadecimal string and then encodes this hexadecimal string into a binary string.
Args:
ascii_str (str): The input ASCII string ... |
evol_instruct_66k | 1,000 | Write a Python function to calculate the conditional probability that a randomly selected student from a class is the other twin girl, given that one twin is already known to be a girl. The class has a total number of students, a specified number of boys, and one twin girl. The function should start with:
```python
def... | Here is the Python code to solve the given problem in the markdown block:
```python
def conditional_probability_other_twin_girl(total_students: int, boys: int, one_twin_is_girl: int) -> float:
"""
Calculate the conditional probability that a randomly selected student is the other twin girl,
given that one t... |
evol_instruct_66k | 1,002 | Write a Python function to sort each row of a given 2D array in ascending order. The function should ensure that the sorting algorithm has a time complexity of O(n log n), where n is the number of elements in each row. The code should start with:
```python
from typing import List
def sort_2D_array(arr: List[List[int]]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_2D_array(arr: List[List[int]]) -> List[List[int]]:
"""
Sorts each row of a given 2D array in ascending order.
Args:
arr (List[List[int]]): The 2D array to be sorted.
Returns:
... |
evol_instruct_66k | 1,012 | Write a Python function to perform the addition of two matrices with matching dimensions. The function should take two matrices as input and return the resulting matrix after addition. The matrices are represented as lists of lists, where each inner list represents a row of the matrix.
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 add_matrices(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[List[int]]:
"""
Adds two matrices with matching dimensions.
Args:
matrix1 (List[List[int]]): The first matrix rep... |
evol_instruct_66k | 1,018 | Write a Python function to calculate the factorial of a non-negative integer `n` efficiently using memoization. The function should handle invalid inputs (e.g., negative numbers, non-integer values) by returning a meaningful error message. The code should start with:
```python
def factorial_with_memoization(n: int) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
def factorial_with_memoization(n: int) -> int:
"""
Calculate the factorial of a non-negative integer `n` using memoization.
Args:
n (int): The non-negative integer for which to calculate the factorial.
Returns:... |
evol_instruct_66k | 1,027 | Write a Python function to retrieve the second element from a given list of integers. If the list has fewer than two elements, return `None`. The function should handle lists of varying lengths and ensure that it only returns the second element if it exists.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def get_second_element(arr: List[int]) -> Optional[int]:
"""
Retrieves the second element from a given list of integers.
Args:
arr (List[int]): The list of integers from which to r... |
evol_instruct_66k | 1,035 | Write a Python function to manipulate a multidimensional array based on the following guidelines:
1. Flatten the multidimensional array into a single list.
2. Remove any duplicate elements from the flattened list while preserving the order of their first appearance.
3. Return the manipulated list.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def manipulate_array(array_info: List[List[int]]) -> List[int]:
"""
Manipulates a multidimensional array by flattening it and removing duplicates while preserving the order of their first appearance.
... |
evol_instruct_66k | 1,045 | Write a Python function to find the position of a given value in a sorted array using a binary search algorithm. If the value is not found, return -1. The array is guaranteed to be sorted in ascending order.
The code should start with:
```python
from typing import List
def binary_search(array: List[int], givenValue: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(array: List[int], givenValue: int) -> int:
"""
Find the position of a given value in a sorted array using binary search.
Args:
array (List[int]): A sorted list of integers ... |
evol_instruct_66k | 1,047 | Write a Python function to calculate the product of the individual digits of a given integer. The function should handle both positive and negative integers. If the integer is zero, the function should return zero.
The code should start with:
```python
def digit_product(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def digit_product(n: int) -> int:
"""
Calculate the product of the individual digits of a given integer.
Args:
n (int): The integer whose digit product is to be calculated.
Returns:
int: The product of ... |
evol_instruct_66k | 1,051 | Write a Python function to convert a given dictionary into a list of tuples, where each tuple contains a key-value pair from the dictionary. The function should handle dictionaries with any type of keys and values. The code should start with:
```python
from typing import Dict, List, Tuple, Any
def dict_to_list_of_tupl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple, Any
def dict_to_list_of_tuples(dictionary: Dict[Any, Any]) -> List[Tuple[Any, Any]]:
"""
Converts a given dictionary into a list of tuples, where each tuple contains a key-value pair from t... |
evol_instruct_66k | 1,059 | Write a Python function to convert two given lists into a dictionary where the elements of the first list serve as keys and the elements of the second list serve as corresponding values. Ensure that the function handles cases where the lists are of different lengths by ignoring the extra elements in the longer list.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def lists_to_dict(list1: List[str], list2: List[int]) -> Dict[str, int]:
"""
Converts two lists into a dictionary where elements from the first list serve as keys
and elements from the second l... |
evol_instruct_66k | 1,079 | Write a Python function to compute the average of the numbers in a given list. The function should handle lists of integers and floating-point numbers. The code should start with:
```python
from typing import List
def compute_average(numbers: List[float]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def compute_average(numbers: List[float]) -> float:
"""
Computes the average of the numbers in the given list.
Args:
numbers (List[float]): A list of numbers (integers or floating-point numb... |
evol_instruct_66k | 1,086 | Write a Python function to perform a binary search on a sorted array to find the index of a given element. If the element is not found, return -1. The function should be efficient and handle edge cases such as an empty array or an element not present in the array.
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 binary_search(arr: List[int], x: int) -> int:
"""
Perform a binary search on a sorted array to find the index of a given element.
Args:
arr (List[int]): A sorted list of integers.
... |
evol_instruct_66k | 1,090 | Write a Python function to restructure a given dictionary into a list of dictionaries, where each dictionary represents an individual's data, including their name, age, occupation, and location. Ensure that any missing values for location are filled with 'Unknown'. Handle any other potential missing data or inconsisten... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Optional, Union
def restructure_data(data: Dict[str, List[Union[str, int, Optional[str]]]]) -> List[Dict[str, Union[str, int]]]:
"""
Restructures the given dictionary into a list of dictionaries, ... |
evol_instruct_66k | 1,095 | Write a Python function that converts a given for loop into an equivalent while loop. The function should take a list of integers as input and print each element of the list using a while loop. The function should start with:
```python
from typing import List
def print_elements_with_while_loop(data_list: List[int]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_elements_with_while_loop(data_list: List[int]) -> None:
"""
Prints each element of the given list using a while loop.
Args:
data_list (List[int]): The list of integers to be printe... |
evol_instruct_66k | 1,099 | Write a Python function to compute the algebraic addition of elements present within a provided numerical array. The function should handle both positive and negative integers, and should be efficient in terms of both time and space complexity. The function should also be able to handle an empty array by returning 0.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_array_elements(arr: List[int]) -> int:
"""
Computes the algebraic sum of elements in a provided numerical array.
Args:
arr (List[int]): A list of integers for which the sum needs to ... |
evol_instruct_66k | 1,101 | Write a Python function to sort a given list of integers in descending order and return the sorted list. The function should be efficient and handle lists of varying sizes. The code should start with:
```python
from typing import List
def sort_descending(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 sort_descending(lst: List[int]) -> List[int]:
"""
Sorts a given list of integers in descending order and returns the sorted list.
Args:
lst (List[int]): The list of integers to be sort... |
evol_instruct_66k | 1,102 | Write a Python function to create a 5x5 NumPy array containing randomly generated floating point numbers within the interval of -3.0 and 7.0. Then, find and replace all the negative values in the array with their absolute values using NumPy's masking capabilities. The function should return the modified array.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def replace_negatives_with_abs(arr: np.ndarray) -> np.ndarray:
"""
Replace all negative values in a 5x5 NumPy array with their absolute values.
Args:
arr (np.ndarray): A 5x5 NumPy array containin... |
evol_instruct_66k | 1,140 | Write a Python function to convert a list of strings into a list of dictionaries where each dictionary has a single key-value pair. The keys for the dictionaries are predefined and correspond to the elements in the input list. The values in the dictionaries should be empty strings.
The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def convert_to_dict_list(keys: List[str]) -> List[Dict[str, str]]:
"""
Converts a list of strings into a list of dictionaries where each dictionary has a single key-value pair.
The keys are pre... |
evol_instruct_66k | 1,146 | Write a Python function to calculate the cumulative sum of elements in a given list of integers. The function should return a list where each element at index `i` is the sum of all elements from the original list up to index `i`.
The code should start with:
```python
from typing import List
def cumulative_sum(arr: Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_sum(arr: List[int]) -> List[int]:
"""
Calculate the cumulative sum of elements in a given list of integers.
Args:
arr (List[int]): The list of integers for which to calculate ... |
evol_instruct_66k | 1,151 | Write a Python function that processes a list of integers and returns the sum of all positive integers in the list. The function should use the `continue` statement to skip the processing of negative integers within the loop.
The code should start with:
```python
from typing import List
def sum_of_positives(numbers: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_positives(numbers: List[int]) -> int:
"""
Calculate the sum of all positive integers in the given list.
Args:
numbers (List[int]): A list of integers to process.
Returns:
... |
evol_instruct_66k | 1,153 | Write a Python function to generate the first `n` numbers in the Lucas sequence. The Lucas sequence is similar to the Fibonacci sequence but starts with 2 and 1 instead of 0 and 1. The `n`th Lucas number is defined as the sum of the two preceding numbers in the sequence. The function should return a list of the first `... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_lucas_sequence(n: int) -> List[int]:
"""
Generate the first n numbers in the Lucas sequence.
The Lucas sequence is similar to the Fibonacci sequence but starts with 2 and 1.
Each su... |
evol_instruct_66k | 1,154 | Write a Python function to calculate the maximum profit that can be achieved by buying and selling a stock multiple times over a given period, given the stock prices for each day. Each transaction consists of buying one share of the stock and selling it on a subsequent day. The function should return the maximum profit... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def max_profit(prices: List[int]) -> int:
"""
Calculate the maximum profit that can be achieved by buying and selling a stock multiple times.
Args:
prices (List[int]): A list of stock pric... |
evol_instruct_66k | 1,155 | Write a Python function that implements a nested while loop structure. The outer loop should run from 0 to a specified maximum count, and the inner loop should count down from 5 to 1. The function should raise a `ValueError` if any of the counters becomes negative. The function should print the values of both counters ... | Here is the Python code to solve the given problem in the markdown block:
```python
def nested_while_loops(max_count: int) -> None:
"""
Implements a nested while loop structure. The outer loop runs from 0 to max_count,
and the inner loop counts down from 5 to 1. Raises a ValueError if any counter
become... |
evol_instruct_66k | 1,157 | Write a Python function to convert a string-based time input formatted as `hh:mm:ss` into its equivalent time represented in seconds. The function should handle the input validation and ensure that the input string is correctly formatted. If the input string is not in the correct format, the function should return `Non... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def convert_time_to_seconds(time_str: str) -> int:
"""
Convert a string-based time input formatted as 'hh:mm:ss' into its equivalent time represented in seconds.
Args:
time_str (str): The time input strin... |
evol_instruct_66k | 1,160 | Write a Python function to generate the first `n` prime numbers. The function should efficiently determine whether a number is prime and collect the first `n` prime numbers in a list. The code should start with:
```python
from typing import List
def generate_n_primes(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def generate_n_primes(n: int) -> List[int]:
"""
Generate the first n prime numbers.
Args:
n (int): The number of prime numbers to generate.
Returns:
List[int]: A lis... |
evol_instruct_66k | 1,174 | Write a Python function to find the common elements among three given sorted arrays without using any built-in methods. The function should be optimized to run in O(n) time complexity, where n is the total number of elements in all arrays. The function should start with:
```python
from typing import List
def find_comm... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_common_elements(list1: List[int], list2: List[int], list3: List[int]) -> List[int]:
"""
Finds common elements among three sorted arrays in O(n) time complexity, where n is the total number of el... |
evol_instruct_66k | 1,179 | Write a Python function to calculate the product of all distinct numerical equivalents of the values in a given dictionary. The dictionary maps string keys to string values, where each value is a lowercase letter. The numerical equivalent of a letter is its position in the alphabet (e.g., 'a' is 1, 'b' is 2, etc.). The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def get_product_of_distinct_values(d: Dict[str, str]) -> int:
"""
Calculate the product of all distinct numerical equivalents of the values in a given dictionary.
Args:
d (Dict[str, str]): A... |
evol_instruct_66k | 1,186 | Write a Python function to find the smallest non-negative number from a given list of floating-point numbers. The function should handle cases where the list might contain negative numbers, zero, or only negative numbers. If the list contains no non-negative numbers, the function should return `None`.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_smallest_nonnegative_number(numbers: List[float]) -> Optional[float]:
"""
Find the smallest non-negative number from a given list of floating-point numbers.
Args:
numbers ... |
evol_instruct_66k | 1,195 | Write a Python function to implement an Insertion Sort algorithm that sorts a list of floating-point numbers. The function should handle exceptions for invalid input types and empty lists. The function should not modify the original list but return a new sorted list.
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, Union
def insertion_sort_float_list(float_list: List[float]) -> Union[List[float], None]:
"""
Sorts a list of floating-point numbers using the Insertion Sort algorithm.
Args:
float_list (Li... |
evol_instruct_66k | 1,202 | Write a Python function to consolidate a given multi-dimensional list of discrete alphabetic entities into a consolidated, uninterrupted textual representation, preserving the sequencing of its sublists. The function should ignore non-alphabetic characters and spaces. 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 consolidate_list(characters: List[List[str]]) -> str:
"""
Consolidates a given multi-dimensional list of discrete alphabetic entities into a consolidated, uninterrupted textual representation, preser... |
evol_instruct_66k | 1,212 | Write a Python function to calculate the result of raising a given number to the power of another number. The function should take two parameters: the base number and the exponent. The function should return the result of the base number raised to the power of the exponent.
The code should start with:
```python
def po... | Here is the Python code to solve the given problem in the markdown block:
```python
def power_of(base: float, exponent: float) -> float:
"""
Calculate the result of raising a base number to the power of an exponent.
Args:
base (float): The base number.
exponent (float): The exponent to whic... |
evol_instruct_66k | 1,216 | Write a Python function to identify the smallest repeating unit of a given string and return the number of times this unit is repeated. If no repeating unit is found, return 'None'. Additionally, include error handling for non-string inputs. The function should start with:
```python
def find_smallest_rep_unit(s: str) -... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_smallest_rep_unit(s: str) -> str:
"""
Identify the smallest repeating unit of a given string and return the number of times this unit is repeated.
If no repeating unit is found, return 'None'. Additionally, handle n... |
evol_instruct_66k | 1,219 | Write a Python function to flatten a nested list, specifically a 2D matrix, into a single linear list. The function should handle any depth of nested lists and ensure that all elements are included in the resulting linear list. The code should start with:
```python
from typing import List, Any
def flatten_nested_list(... | 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[List[Any]]) -> List[Any]:
"""
Flattens a nested list, specifically a 2D matrix, into a single linear list.
Args:
nested_list (List[List[Any]]):... |
evol_instruct_66k | 1,221 | Write a Python function to sort a list of tuples by their second element (score) in descending order. Each tuple in the list contains a name and a score. The function should return the sorted list.
The code should start with:
```python
from typing import List, Tuple
def sort_by_score_descending(data: List[Tuple[str, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_by_score_descending(data: List[Tuple[str, int]]) -> List[Tuple[str, int]]:
"""
Sorts a list of tuples by their second element (score) in descending order.
Args:
data (List[Tu... |
evol_instruct_66k | 1,233 | Write a Python function to compute the factorial of a non-negative integer `n`, with the capability to handle an optional parameter `power`. If `power` is provided, the function should return the factorial of `n` raised to the power of `power`. Additionally, the function should handle a third optional parameter `modulo... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def factorial(n: int, power: int = 1, modulo: int = None) -> int:
"""
Compute the factorial of a non-negative integer `n`, optionally raised to the power of `power` and modulo `modulo`.
Args:
n (int): T... |
evol_instruct_66k | 1,265 | Write a Python function to convert an integer into its corresponding Roman numeral representation. The function should handle integers in the range from 1 to 3999. The Roman numeral system uses seven symbols (`I`, `V`, `X`, `L`, `C`, `D`, `M`) with specific values. Additionally, there are six instances where subtractio... | Here is the Python code to solve the given problem in the markdown block:
```python
def int_to_roman(num: int) -> str:
"""
Convert an integer to its corresponding Roman numeral representation.
Args:
num (int): The integer to be converted, ranging from 1 to 3999.
Returns:
str: The Roman... |
evol_instruct_66k | 1,271 | Write a Python function to count the occurrences of each punctuation symbol in a given English statement and return a dictionary where the keys are the punctuation symbols and the values are their respective counts. The function should handle any string input, including those with no punctuation symbols.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import string
def count_punctuation_symbols(statement: str) -> Dict[str, int]:
"""
Counts the occurrences of each punctuation symbol in a given English statement.
Args:
statement (str): The ... |
evol_instruct_66k | 1,275 | Write a Python function to determine if a given string is an isogram, which is a word or phrase without any repeating letters. The function should be case-insensitive and should ignore non-alphabetic characters.
The code should start with:
```python
def is_isogram(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_isogram(string: str) -> bool:
"""
Determine if a given string is an isogram (a word or phrase without repeating letters).
Args:
string (str): The input string to check.
Returns:
bool: True if the... |
evol_instruct_66k | 1,295 | Write a Python function to create an n x m matrix with all elements initialized to a specified value. The function should take three parameters: the number of rows `n`, the number of columns `m`, and the initial value `value`. The function should return the created matrix.
The code should start with:
```python
from ty... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_matrix(n: int, m: int, value: int) -> List[List[int]]:
"""
Create an n x m matrix with all elements initialized to a specified value.
Args:
n (int): The number of rows in the matr... |
evol_instruct_66k | 1,296 | Write a Python function to sort a list of complex numbers in descending order based on their real parts. If the real parts are equal, the numbers should be ordered by their imaginary parts in descending order. The function should handle lists of complex numbers and return the sorted list.
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_complex_numbers(numbers: List[complex]) -> List[complex]:
"""
Sorts a list of complex numbers in descending order based on their real parts.
If the real parts are equal, the numbers are orde... |
evol_instruct_66k | 1,331 | Write a Python function to find the common elements between two lists of integers. The function should return a list of these common elements in ascending order. The code should start with:
```python
from typing import List
def get_common_elements(list1: List[int], list2: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_common_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Find the common elements between two lists of integers and return them in ascending order.
Args:
list1 (List[int... |
evol_instruct_66k | 1,353 | Write a Python function to selectively remove objects from a list named `library` that have a 'pages' attribute with a value less than or equal to 100. The function should return the filtered list.
The code should start with:
```python
from typing import List, Dict
def remove_small_books(library: List[Dict[str, int]]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def remove_small_books(library: List[Dict[str, int]]) -> List[Dict[str, int]]:
"""
Removes books from the library list that have a 'pages' attribute less than or equal to 100.
Args:
li... |
evol_instruct_66k | 1,357 | Write a Python function to generate an Elasticsearch query that searches for all entries in a database where the "location" attribute has a value exactly matching "Los Angeles". The function should return a dictionary representing the Elasticsearch query.
The code should start with:
```python
from typing import Dict
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def generate_elasticsearch_query() -> Dict:
"""
Generates an Elasticsearch query to search for all entries where the "location" attribute
exactly matches "Los Angeles".
Returns:
Dict: A ... |
evol_instruct_66k | 1,360 | Write a Python function to find and return the two nearest numerical values from a given list of at least two elements. The returned pair should be in ascending order. The function should have a computational complexity better than O(n log n), where 'n' is the size of the list. Ensure that the function handles outliers... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_closest_numbers(lst: List[int]) -> Tuple[int, int]:
"""
Finds and returns the two nearest numerical values from a given list of at least two elements.
The returned pair is in ascendin... |
evol_instruct_66k | 1,374 | Write a Python function to parse and format a given address tuple into a structured string representation. The address tuple contains two elements: the street name and the dwelling number. The function should return a formatted string that combines these two elements in a specific format.
The code should start with:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def format_address(address: Tuple[str, str]) -> str:
"""
Formats a given address tuple into a structured string representation.
Args:
address (Tuple[str, str]): A tuple containing the stree... |
evol_instruct_66k | 1,375 | Write a Python function to compute the factorial of each digit in a given integer and return the results as a list. The function should handle both positive and negative integers. If the input is a negative integer, the function should ignore the negative sign and process the digits as if the number were positive.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
from typing import List
def factorial_of_digits(number: int) -> List[int]:
"""
Compute the factorial of each digit in the given integer and return the results as a list.
Args:
number (int): The integer ... |
evol_instruct_66k | 1,382 | Write a Python function to evaluate the mathematical sum between two inputted numerical values. The function should accept two command-line arguments, convert them to integers, and print the sum. The code should start with:
```python
import sys
def sum_of_two_numbers():
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import sys
def sum_of_two_numbers():
"""
Evaluates the mathematical sum between two inputted numerical values provided as command-line arguments.
This function reads two command-line arguments, converts them to integers, c... |
evol_instruct_66k | 1,395 | Write a Python function to create an array of length `n` that contains the numbers from `0` to `n-1` in random order. The function should ensure that the array is shuffled in a way that each possible permutation is equally likely.
The code should start with:
```python
from typing import List
import random
def create_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def create_random_array(n: int) -> List[int]:
"""
Creates an array of length n containing numbers from 0 to n-1 in random order.
Args:
n (int): The length of the array to be cr... |
evol_instruct_66k | 1,406 | Write a Python function to separate an input alphanumeric string into two sequences: one containing only alphabetic characters and the other containing only numeric characters. The function should return these two sequences as a tuple.
The code should start with:
```python
from typing import Tuple
def separate_alphan... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def separate_alphanumeric_sequences(s: str) -> Tuple[str, str]:
"""
Separates an input alphanumeric string into two sequences: one containing only alphabetic characters and the other containing only num... |
evol_instruct_66k | 1,413 | Write a Python function to remove all occurrences of a specified element from a given list. The function should handle edge cases such as an empty list or a non-existing target element. The function should return the modified list.
The code should start with:
```python
from typing import List
def remove_all_occurrenc... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_all_occurrences(lst: List[str], element: str) -> List[str]:
"""
Removes all occurrences of a specified element from a given list.
Args:
lst (List[str]): The list from which to rem... |
evol_instruct_66k | 1,420 | Write a Python function to count the occurrences of a given word in a given string. The function should return the number of times the word appears in the string, considering overlapping occurrences.
The code should start with:
```python
def count_word_occurrences(string: str, word: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_word_occurrences(string: str, word: str) -> int:
"""
Counts the occurrences of a given word in a given string, considering overlapping occurrences.
Args:
string (str): The string in which to search for the... |
evol_instruct_66k | 1,422 | Write a Python function that generates an SQL query to retrieve the first 5 distinct rows from a given table where the product price is above a certain threshold and the available stock quantity is below a certain limit. The function should take the table name, price threshold, and stock limit as parameters and return ... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_sql_query(table_name: str, price_threshold: float, stock_limit: int) -> str:
"""
Generates an SQL query to retrieve the first 5 distinct rows from a given table
where the product price is above a certain thresho... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.