source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 29,549 | Write a Python function to count the number of distinct elements in a given list of integers. The function should efficiently handle the input and return the count of unique elements.
The code should start with:
```python
from typing import List
def count_distinct_elements(numbers_list: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_distinct_elements(numbers_list: List[int]) -> int:
"""
Counts the number of distinct elements in a given list of integers.
Args:
numbers_list (List[int]): The list of integers from... |
evol_instruct_66k | 29,552 | Write a Python function to verify the validity of a provided electronic mail address by checking for the standard structure of such addresses. The function should ensure that the email address follows the general format of `username@domain.extension`, where:
- `username` can contain letters, digits, underscores, period... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_email(email: str) -> bool:
"""
Verifies the validity of a provided electronic mail address by checking for the standard structure.
Args:
email (str): The email address to be validated.
R... |
evol_instruct_66k | 29,570 | Write a Python function to calculate the average age of the seven dwarfs from the given dictionary that encapsulates their names and ages. The function should return the average age as a floating-point number.
The code should start with:
```python
from typing import Dict
def calculate_average_age(dwarfs_ages: Dict[st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def calculate_average_age(dwarfs_ages: Dict[str, int]) -> float:
"""
Calculate the average age of the dwarfs from the given dictionary.
Args:
dwarfs_ages (Dict[str, int]): A dictionary where... |
evol_instruct_66k | 29,571 | Write a Python function to calculate the sum of the cubes of the first n positive integers. The function should be efficient and handle edge cases such as when n is 0 or a negative number.
The code should start with:
```python
def sum_of_cubes(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_cubes(n: int) -> int:
"""
Calculate the sum of the cubes of the first n positive integers.
Args:
n (int): The number of positive integers to consider.
Returns:
int: The sum of the cubes of th... |
evol_instruct_66k | 29,583 | Write a Python function to find the number with the minimum frequency of appearances in a given sequence of float values. If there are multiple numbers with the same minimum frequency, return the smallest number among them.
The code should start with:
```python
from typing import List
from collections import Counter
... | 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_min_frequency_number(sequence: List[float]) -> float:
"""
Find the number with the minimum frequency of appearances in a given sequence of float values.
If ... |
evol_instruct_66k | 29,588 | Write a Python function to generate a pseudorandom floating-point number within a specified range. The function should allow the user to specify both the lower and upper limits of the range. The default range should be from -5 to 5. The function should return the generated random number.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_random_float(lower_limit: float = -5, upper_limit: float = 5) -> float:
"""
Generates a pseudorandom floating-point number within a specified range.
Args:
lower_limit (float, optional): T... |
evol_instruct_66k | 29,592 | Write a Python function to generate a Bash script for installing a given application on Ubuntu. The function should take the application name as a string and return the Bash script as a string. The script should include updating the system packages and installing the specified application using `apt-get`.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_install_script(application_name: str) -> str:
"""
Generates a Bash script for installing a given application on Ubuntu.
Args:
application_name (str): The name of the application to be installed.
Re... |
evol_instruct_66k | 29,595 | Write a Python function to check if a certain element is present in a given sorted array using a binary search algorithm. The function should not use any built-in array methods except for basic operations like indexing and length calculation. The code should start with:
```python
def binary_search(arr, ele):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def binary_search(arr, ele):
"""
Checks if a certain element is present in a given sorted array using a binary search algorithm.
Args:
arr (list): The sorted array to search in.
ele: The element to search fo... |
evol_instruct_66k | 29,597 | Write a Python function to create a key-value pair mapping for a given numerical array. Each key in the mapping should be an element from the array, and the corresponding value should be the index of that element in the array. The function should handle arrays of any length and ensure that each element maps to its corr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_index_mapping(arr: List[int]) -> Dict[int, int]:
"""
Creates a key-value pair mapping for the given numerical array.
Each key in the mapping is an element from the array, and the cor... |
evol_instruct_66k | 29,598 | Write a Python function to construct a dictionary that maps each planet in our solar system to its estimated number of moons. The function should take two lists as input: one containing the names of the planets and the other containing their corresponding number of moons. The function should return the constructed dict... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_planet_moon_dict(planets: List[str], moons: List[int]) -> Dict[str, int]:
"""
Constructs a dictionary that maps each planet in our solar system to its estimated number of moons.
Arg... |
evol_instruct_66k | 29,610 | Write a Python function to manage a collection of animals. The function should allow the addition of animals of specific types and provide a way to retrieve animals by their type. The allowed animal types are "dog", "cat", "mouse", and "bird". The function should reject any animal type that is not one of the approved t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def add_animal(collection: Dict[str, List[str]], animal: str) -> None:
"""
Add an animal to the collection if it is one of the approved types.
Args:
collection (Dict[str, List[str]]): ... |
evol_instruct_66k | 29,619 | Write a Python function to convert all characters in a given sentence into their corresponding ASCII values. The function should handle both words and special characters. The code should start with:
```python
from typing import List
def convert_to_ascii(sentence: str) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_to_ascii(sentence: str) -> List[int]:
"""
Convert all characters in a given sentence into their corresponding ASCII values.
Args:
sentence (str): The input sentence containing wo... |
evol_instruct_66k | 29,621 | Write a Python function to determine if a given string can be accurately transformed into a float. The function should return `True` if the conversion is successful, and `False` otherwise. The code should start with:
```python
def can_convert_to_float(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def can_convert_to_float(s: str) -> bool:
"""
Determines if a given string can be accurately transformed into a float.
Args:
s (str): The string to be checked for float conversion.
Returns:
bool: True... |
evol_instruct_66k | 29,632 | Write a Python function to extract phone numbers from a list of text strings using a regular expression. The phone numbers can be in various formats such as `xxx-xxx-xxxx`, `(xxx)xxx-xxxx`, `xxx.xxx.xxxx`, etc. The function should return a list of all phone numbers found in the input 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
import re
def extract_phone_numbers(text_list: List[str]) -> List[str]:
"""
Extracts phone numbers from a list of text strings using a regular expression.
Args:
text_list (List[str]): A list... |
evol_instruct_66k | 29,647 | Write a Python function to calculate the lowest common multiple (LCM) of an unrestricted number of positive integers. The function should take a list of integers as input and return the LCM of those integers. The code should start with:
```python
from typing import List
def get_lowest_common_multiple(list_of_ints: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from functools import reduce
from math import gcd
def get_lowest_common_multiple(list_of_ints: List[int]) -> int:
"""
Calculate the lowest common multiple (LCM) of an unrestricted number of positive inte... |
evol_instruct_66k | 29,654 | Write a Python function to calculate the square root of a given numeric value and return the result. The function should handle both positive and zero values. For negative values, the function should return `None` to indicate that the square root of a negative number is not a real number.
The code should start with:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_square_root(value: float) -> float:
"""
Calculate the square root of a given numeric value.
Args:
value (float): The numeric value for which to calculate the square root.
Returns:
... |
evol_instruct_66k | 29,655 | Write a Python function to calculate the cubes of every numerical entity within a given list of figures. The function should handle both integers and floating-point numbers. The code should start with:
```python
from typing import List
def calculate_cubes(numbers: List[float]) -> List[float]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def calculate_cubes(numbers: List[float]) -> List[float]:
"""
Calculate the cubes of every numerical entity within a given list of figures.
Args:
numbers (List[float]): A list of numerical... |
evol_instruct_66k | 29,673 | Write a Python function to extract unique qualitative values from a given alphabetical list while preserving the order of their first appearance. The function should handle lists of strings and return a list of unique strings in the order they first appear.
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
from collections import OrderedDict
def extract_unique_values(letters: List[str]) -> List[str]:
"""
Extracts unique qualitative values from a given alphabetical list while preserving the order of their f... |
evol_instruct_66k | 29,674 | Write a Python function to generate a random string of a specified length consisting of digits (0-9). The function should accept an integer `length` as its parameter and return the generated string. Ensure that the function handles edge cases such as a non-positive length by returning an empty string.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_random_digit_string(length: int) -> str:
"""
Generates a random string of digits of the specified length.
Args:
length (int): The length of the string to be generated.
Returns:
... |
evol_instruct_66k | 29,689 | Write a Python function to determine if the elements of a given multidimensional array form a palindrome. The function should handle both single-dimensional and multidimensional arrays. A multidimensional array is considered a palindrome if, when flattened, its elements read the same forward and backward.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def is_palindrome_multidimensional(arr: Union[List[Union[int, float]], List[List[Union[int, float]]]]) -> bool:
"""
Determine if the elements of a given multidimensional array form a palindrome.
... |
evol_instruct_66k | 29,691 | Write a Python function to create an inverted duplicate of a given list while maintaining the original list in its original state. The function should return the inverted list without modifying the original list. The code should start with:
```python
from typing import List
def invert_list(input_list: List[int]) -> Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def invert_list(input_list: List[int]) -> List[int]:
"""
Creates an inverted duplicate of the given list without modifying the original list.
Args:
input_list (List[int]): The original list ... |
evol_instruct_66k | 29,695 | Write a Python function to remove all words from a given text string that contain a specified target letter. The function should return the modified text string with the words containing the target letter removed. The code should start with:
```python
from typing import List
def remove_words_with_letter(text: str, tar... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_words_with_letter(text: str, target_letter: str) -> str:
"""
Removes all words from the given text string that contain the specified target letter.
Args:
text (str): The input tex... |
evol_instruct_66k | 29,714 | 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 | 29,716 | Write a Python function to compute and return the cumulative sum of the elements in a given list of integers. The function should return a list where each element at index `i` is the cumulative sum of the elements from the original list up to index `i`.
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 cumulative_sum(numbers: List[int]) -> List[int]:
"""
Compute the cumulative sum of the elements in the given list.
Args:
numbers (List[int]): The list of integers for which to compute th... |
evol_instruct_66k | 29,724 | Write a Python function to find and return the smallest three elements from a given list of integers. The function should sort the list in ascending order and then return the first three elements. The code should start with:
```python
from typing import List
def get_smallest_three(B: 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_smallest_three(B: List[int]) -> List[int]:
"""
Returns the smallest three elements from the given list of integers.
Args:
B (List[int]): The list of integers from which to extract ... |
evol_instruct_66k | 29,725 | Write a Python function to sum the first five elements of a given list. If the list has fewer than five elements, sum all the elements in the list. The function should handle lists of any length and ensure that it does not attempt to access elements that do not exist.
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 sum_first_five(arr: List[int]) -> int:
"""
Sum the first five elements of a given list. If the list has fewer than five elements, sum all the elements in the list.
Args:
arr (List[int]):... |
evol_instruct_66k | 29,738 | Write a Python function to find the length of the longest increasing subsequence (LIS) of a given array. The function should use a dynamic programming approach to efficiently compute the result. The code should start with:
```python
from typing import List
def longest_increasing_subsequence(arr: List[int]) -> int:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_increasing_subsequence(arr: List[int]) -> int:
"""
Calculate the length of the longest increasing subsequence in the given array.
Args:
arr (List[int]): The input array of intege... |
evol_instruct_66k | 29,748 | Write a Python function to calculate the product of all odd integers in a given list. The function should handle lists with both positive and negative integers, and should return 1 if there are no odd integers in the list.
The code should start with:
```python
from typing import List
def product_of_odds(lst: List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def product_of_odds(lst: List[int]) -> int:
"""
Calculate the product of all odd integers in the given list.
Args:
lst (List[int]): The list of integers from which to calculate the product o... |
evol_instruct_66k | 29,752 | Write a Python function to calculate the areas of triangles from a given list of tuples, where each tuple represents the base and height of a triangle. The function should exclude any triangles with negative base or height values and return a list of the areas of the valid triangles.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def calculate_triangle_areas(triangle_list: List[Tuple[int, int]]) -> List[float]:
"""
Calculate the areas of triangles from a list of tuples, excluding triangles with negative base or height.
... |
evol_instruct_66k | 29,754 | Write a Python function to sort a given list of complex numbers in ascending order based on their magnitude. For complex numbers with the same magnitude, sort them first by their real part, and if the real parts are also equal, sort them by their imaginary part. The function should return the sorted list of complex num... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_complex_numbers(complex_numbers: List[complex]) -> List[complex]:
"""
Sorts a list of complex numbers in ascending order based on their magnitude.
For complex numbers with the same magnitude... |
evol_instruct_66k | 29,757 | Write a Python function to perform polynomial addition for two polynomials represented as dictionaries. Each dictionary maps the exponent to the coefficient for a single variable polynomial. The function should handle polynomials with negative exponents and return the resulting polynomial as a dictionary.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def add_polynomials(poly1: Dict[int, complex], poly2: Dict[int, complex]) -> Dict[int, complex]:
"""
Adds two polynomials represented as dictionaries.
Args:
poly1 (Dict[int, complex]): The f... |
evol_instruct_66k | 29,766 | Write a Python function to calculate the value of `y` in the equation `3y = n`, where `n` is a non-negative integer. The function should handle erroneous inputs appropriately and throw meaningful error messages in such cases. The function should be named `calculate_y` and should accept `n` as its argument. The function... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_y(n):
"""
Calculate the value of `y` in the equation `3y = n`, where `n` is a non-negative integer.
Args:
n (int or float): The non-negative number for which to calculate `y`.
Returns:
int... |
evol_instruct_66k | 29,772 | Write a Python function to determine if a given variable is a categorical variable. A categorical variable is defined as a variable that can take on one of a limited, and usually fixed, number of possible values. The function should return `True` if the variable is categorical and `False` otherwise. The function should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union, List, Dict
def is_categorical(variable: Union[List, str, Dict], threshold: int) -> bool:
"""
Determine if a given variable is a categorical variable based on a specified threshold.
Args:
v... |
evol_instruct_66k | 29,775 | Write a Python function that iterates over a list of words and returns a list of messages indicating whether each word matches a specific target word. If a word matches the target word, the message should be 'success'; otherwise, it should be 'failure'. The function 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 word_match_messages(list_of_words: List[str], target_word: str) -> List[str]:
"""
Generates a list of messages based on whether each word in the input list matches the target word.
Args:
... |
evol_instruct_66k | 29,792 | Write a Python function to find the index of a particular node in a doubly linked list without traversing from the head. The doubly linked list is represented as a list of integers. The function should return the index of the given node if it exists in the list, otherwise, it should return `None`.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_node_index(dlinked_list: List[int], current_node: int) -> Optional[int]:
"""
Find the index of a particular node in a doubly linked list represented as a list of integers.
Args:
... |
evol_instruct_66k | 29,814 | Write a Python function to move an element from one list to another, preserving the initial order of the remaining elements in the source list, and adding the moved element at a particular index in the destination list. The function should handle edge cases such as invalid indices and empty lists.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def move_element(src_list: List[int], dest_list: List[int], src_index: int, dest_index: int) -> None:
"""
Moves an element from the source list to the destination list, preserving the order of the remain... |
evol_instruct_66k | 29,823 | Write a Python function to process a list of integers by performing the following steps:
1. Square each element in the list.
2. Filter out the elements that are greater than 100.
3. Sort the remaining elements in ascending order.
4. Convert the sorted list into a tuple.
The code should start with:
```python
from typin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def process_list(lst: List[int]) -> Tuple[int]:
"""
Process a list of integers by squaring each element, filtering out elements greater than 100,
sorting the remaining elements, and converting... |
evol_instruct_66k | 29,830 | Write a Python function to extract a specified number of initial characters from a given string. The function should handle cases where the requested number of characters exceeds the length of the string by returning the entire string. The code should start with:
```python
def extract_initial_characters(input_string: s... | Here is the Python code to solve the given problem in the markdown block:
```python
def extract_initial_characters(input_string: str, num_characters: int) -> str:
"""
Extracts the specified number of initial characters from the given string.
Args:
input_string (str): The string from which to extrac... |
evol_instruct_66k | 29,838 | Write a Python function to calculate the sum of all elements in a given list of integers. The function should accept a list of integers as its input parameter and return the sum of all elements in the list. The code should start with:
```python
from typing import List
def list_sum(num_list: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def list_sum(num_list: List[int]) -> int:
"""
Calculate the sum of all elements in a given list of integers.
Args:
num_list (List[int]): A list of integers whose sum needs to be calculated... |
evol_instruct_66k | 29,849 | Write a Python function to determine if a given string sequence is a palindrome. A palindrome is a string that reads the same backward as forward. The function should handle both uppercase and lowercase letters, treating them as equivalent. The function should also ignore spaces and punctuation.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_palindrome(sequence: str) -> bool:
"""
Determine if the given string sequence is a palindrome.
A palindrome is a string that reads the same backward as forward, ignoring case, spaces, and punctuation.
Args:
... |
evol_instruct_66k | 29,866 | Write a Python function to compute the sum of the cubes of all individual numeric elements in a given list. The function should handle lists of integers and return the computed sum. The code should start with:
```python
from typing import List
def sum_of_cubes(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_cubes(numbers: List[int]) -> int:
"""
Computes the sum of the cubes of all individual numeric elements in the given list.
Args:
numbers (List[int]): A list of integers for which t... |
evol_instruct_66k | 29,867 | Write a Python function to calculate the standard deviation of a given list of numerical entries. The function should compute the standard deviation without using any external libraries like `numpy`. The code should start with:
```python
from typing import List
def calculate_standard_deviation(data: List[float]) -> fl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def calculate_standard_deviation(data: List[float]) -> float:
"""
Calculate the standard deviation of a given list of numerical entries.
Args:
data (List[float]): The list of num... |
evol_instruct_66k | 29,884 | Write a Python function to count the occurrences of each item in a given list and return a dictionary where the keys are the items from the list and the values are their respective counts. The function should handle lists with any type of elements, including integers, strings, and other data types. The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Any
def count_occurrences(lst: List[Any]) -> Dict[Any, int]:
"""
Counts the occurrences of each item in the given list and returns a dictionary with the counts.
Args:
lst (List[Any]):... |
evol_instruct_66k | 29,888 | Write a Python function to find the last index of a specific item in a given list. The function should not use Python's built-in `rindex` or `list.reverse` methods. The function should handle cases where the item is not present in the list by returning `-1`.
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
def find_last_index(my_list: List[int], item_to_find: int) -> int:
"""
Find the last index of a specific item in a given list.
Args:
my_list (List[int]): The list in which to search for the ... |
evol_instruct_66k | 29,892 | Write a Python function to search for a specific value within a given two-dimensional matrix. The function should return the coordinates (row and column indices) of the target value if it is found, or a message indicating that the value is not found if it is not present in the matrix.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Union
def search_matrix(matrix: List[List[int]], target: int) -> Union[Tuple[int, int], str]:
"""
Searches for a specific value within a given two-dimensional matrix.
Args:
matrix (L... |
evol_instruct_66k | 29,905 | Write a Python function to implement the Bubble Sort algorithm to sort a given numerical dataset in ascending order. The function should be able to handle real numbers and negative values. Additionally, identify and correct the errors in the provided erroneous code snippet. The function should start with:
```python
fro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(arr: List[float]) -> List[float]:
"""
Sorts a given numerical dataset in ascending order using the Bubble Sort algorithm.
Args:
arr (List[float]): The numerical dataset to be... |
evol_instruct_66k | 29,907 | Write a Python function that prints the cube of numbers from 1 to 10 using a while loop. The function should handle any potential exceptions that might occur during the execution of the loop. The code should start with:
```python
def print_cubes_of_numbers():
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def print_cubes_of_numbers():
"""
Prints the cube of numbers from 1 to 10 using a while loop.
Handles any potential exceptions that might occur during the execution of the loop.
Args:
None
Returns:
... |
evol_instruct_66k | 29,914 | Write a Python function to evaluate a mathematical expression given as a string, ensuring it correctly follows the order of operations (BODMAS/PEMDAS). The function should handle basic arithmetic operations: addition (+), subtraction (-), multiplication (*), and division (/). The code should start with:
```python
def e... | Here is the Python code to solve the given problem in the markdown block:
```python
def evaluate_expression(expression: str) -> float:
"""
Evaluates a mathematical expression given as a string, ensuring it follows the order of operations (BODMAS/PEMDAS).
Args:
expression (str): The mathematical exp... |
evol_instruct_66k | 29,919 | Write a Python function to transform a given textual string into an array of distinct words, sorted in lexicographical order. The function should handle multiple spaces and leading/trailing spaces gracefully.
The code should start with:
```python
from typing import List
def distinct_words_sorted(text: str) -> List[st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def distinct_words_sorted(text: str) -> List[str]:
"""
Transforms a given textual string into an array of distinct words sorted in lexicographical order.
Args:
text (str): The input textual ... |
evol_instruct_66k | 29,930 | Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of a given m x n grid, where you can only move right or down. The function should 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 | 29,931 | Write a Python function to create a dictionary from two lists: one containing keys and the other containing values. The function should ensure that each key-value pair is unique and handle specific exceptions for violations. The exceptions to be handled are:
1. If the lengths of the given lists are not equal.
2. If any... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_dict(keys: List[str], values: List[object]) -> Dict[str, object]:
"""
Create a dictionary from two lists of keys and values, ensuring data integrity.
Args:
keys (List[str]):... |
evol_instruct_66k | 29,939 | Write a Python function to convert a JSON representation of an HTML document into a string representation of the HTML document. The JSON structure is a tree-like representation where each node has a `tagName` and may have `children` or `textContent`. The function should recursively traverse the JSON structure and const... | Here is the Python code to solve the given problem in the markdown block:
```python
import json
from typing import Dict, Union
def json_to_html(json_data: Union[Dict, str]) -> str:
"""
Converts a JSON representation of an HTML document into an HTML string.
Args:
json_data (Union[Dict, str]): The J... |
evol_instruct_66k | 29,948 | Write a Python function to find the smallest element in an array of size N efficiently. The function should iterate through the array only once to minimize the number of steps.
The code should start with:
```python
from typing import List
def find_smallest_element(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_smallest_element(arr: List[int]) -> int:
"""
Finds the smallest element in an array of size N efficiently.
Args:
arr (List[int]): The array of integers from which to find the smalle... |
evol_instruct_66k | 29,952 | Write a Python function to detect arrays composed of single-character strings and replace each occurrence with a predetermined, non-empty value. The function should handle lists of strings and replace any string that is exactly one character long with a specified replacement string.
The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def replace_single_char_strings(arr: List[str], replacement: str) -> List[str]:
"""
Replaces all single-character strings in the given list with a specified replacement string.
Args:
arr (Li... |
evol_instruct_66k | 29,955 | Write a Python function to convert a dictionary into a list of tuples, where each tuple contains a key-value pair from the dictionary. Additionally, provide separate functions to convert the dictionary keys and values into lists.
The code should start with:
```python
from typing import Dict, List, Tuple
def dict_to_l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def dict_to_list_of_tuples(d: Dict[str, int]) -> List[Tuple[str, int]]:
"""
Convert a dictionary into a list of tuples, where each tuple contains a key-value pair from the dictionary.
A... |
evol_instruct_66k | 29,960 | Write a Python function to perform a binary search on a lexicographically sorted list of alphabetic words to find the index of a target word. If the target word is not found, return -1.
The code should start with:
```python
from typing import List
def find_word_index(words: List[str], target: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_word_index(words: List[str], target: str) -> int:
"""
Perform a binary search to find the index of a target word in a lexicographically sorted list of words.
Args:
words (List[str])... |
evol_instruct_66k | 29,962 | Write a Python function to count the frequency of all elements in a nested list, including duplicates and elements within nested lists. The function should return a dictionary where the keys are the elements and the values are their respective counts.
The code should start with:
```python
from typing import List, Dict... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_elements_frequency(nested_list: List) -> Dict[int, int]:
"""
Counts the frequency of all elements in a nested list, including duplicates and elements within nested lists.
Args:
... |
evol_instruct_66k | 29,979 | Write a Python function to convert an HTML string from uppercase to lowercase. The function should take an HTML string as input and return the same HTML string with all characters converted to lowercase. The code should start with:
```python
def convert_html_to_lowercase(html_code_in_uppercase: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def convert_html_to_lowercase(html_code_in_uppercase: str) -> str:
"""
Converts an HTML string from uppercase to lowercase.
Args:
html_code_in_uppercase (str): The HTML string in uppercase.
Returns:
str... |
evol_instruct_66k | 29,991 | Write a Python function to count the number of alphabetic characters in a given string, ignoring punctuation and spaces. The function should consider case sensitivity, meaning 'A' and 'a' should be counted separately.
The code should start with:
```python
def count_alphabetic_characters(s: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_alphabetic_characters(s: str) -> int:
"""
Counts the number of alphabetic characters in a given string, ignoring punctuation and spaces.
Args:
s (str): The input string to count alphabetic characters from.... |
evol_instruct_66k | 30,005 | Write a Python function to determine the letter grade and the grade point equivalent (GPA) of a student based on the inputted numerical grade. The function should use a ternary operator to determine the letter grade and calculate the GPA on a scale of 4.0, considering fractions for intermediate grades.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_grade_and_gpa(numerical_grade: float) -> tuple:
"""
Calculate the letter grade and GPA for a given numerical grade.
Args:
numerical_grade (float): The numerical grade of the student.
Returns:
... |
evol_instruct_66k | 30,024 | Write a Python function `add_key_value_pair` that adds a new key-value pair to a given dictionary if the key does not already exist. If the key already exists, update the value for that key with the provided value. The function should return the updated dictionary.
The code should start with:
```python
from typing imp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def add_key_value_pair(my_dict: Dict[Any, Any], key: Any, value: Any) -> Dict[Any, Any]:
"""
Adds a new key-value pair to the dictionary if the key does not already exist.
If the key already exi... |
evol_instruct_66k | 30,032 | Write a Python function to find the highest and lowest values within a list of integers without using the built-in `min()` and `max()` functions, while maintaining the original list's order. The function should return a tuple containing the highest and lowest values.
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, Tuple
def find_extremes(lst: List[int]) -> Tuple[int, int]:
"""
Find the highest and lowest values within a list of integers without using the built-in min() and max() functions.
Args:
lst ... |
evol_instruct_66k | 30,036 | Write a Python function to create a deep copy of a given list of lists and demonstrate the difference between a shallow copy and a deep copy. The function should return a tuple containing the original list, the shallow copy, and the deep copy. The code should start with:
```python
from typing import List, Tuple
import ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import copy
def copy_list_of_lists(orig_list: List[List[int]]) -> Tuple[List[List[int]], List[List[int]], List[List[int]]]:
"""
Creates a shallow copy and a deep copy of a given list of lists and ... |
evol_instruct_66k | 30,039 | Write a Python function to convert a given list of integers into a dictionary where each key is an integer from the list and the value is a list of the square roots of all non-negative integers less than that integer. Use dictionary comprehension for this task. The function should handle both positive and negative inte... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
import math
def convert_to_dict(my_list: List[int]) -> Dict[int, List[float]]:
"""
Converts a given list of integers into a dictionary where each key is an integer from the list
and the value i... |
evol_instruct_66k | 30,046 | Write a Python function to determine if an array of integers can be partitioned into subsets of `k` consecutive numbers. The function should return `True` if such a partition is possible, and `False` otherwise. The code should start with:
```python
from typing import List
def can_partition_into_consecutive_subsets(num... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import collections
import heapq
def can_partition_into_consecutive_subsets(nums: List[int], k: int) -> bool:
"""
Determine if the array can be partitioned into subsets of k consecutive numbers.
Args... |
evol_instruct_66k | 30,051 | Write a Python function to merge three given dictionaries and remove any duplicates, ensuring that the value from the last dictionary with a given key is retained. The function should start with:
```python
from typing import Dict
def merge_dicts(dictA: Dict[str, int], dictB: Dict[str, int], dictC: Dict[str, int]) -> D... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_dicts(dictA: Dict[str, int], dictB: Dict[str, int], dictC: Dict[str, int]) -> Dict[str, int]:
"""
Merges three dictionaries and removes any duplicates, retaining the value from the last diction... |
evol_instruct_66k | 30,052 | Write a Python function to calculate the nth Catalan number using memoization to improve computation efficiency. The function should handle invalid inputs and boundary conditions by raising appropriate exceptions. The code should start with:
```python
def catalan_number(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def catalan_number(n: int) -> int:
"""
Compute the nth Catalan number using memoization.
Args:
n (int): The ordinal integer to compute the Catalan number.
Returns:
int: The nth Catalan number.
Rais... |
evol_instruct_66k | 30,054 | Write a Python function to determine if a target value exists within a given two-dimensional matrix. The matrix is sorted in ascending order both row-wise and column-wise, meaning:
1. Each row is sorted in ascending order from left to right.
2. The first integer of every row is larger than the last integer of the prece... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def search_in_matrix(matrix: List[List[int]], target: int) -> bool:
"""
Searches for a target value in a sorted 2D matrix using binary search.
Args:
matrix (List[List[int]]): A 2D list of in... |
evol_instruct_66k | 30,058 | Write a Python function to move all zeros to the end of a given list while maintaining the relative order of the non-zero elements. The function should be efficient and should not use any additional data structures except for a constant amount of extra space.
The code should start with:
```python
from typing import Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def move_zeros_to_end(arr: List[int]) -> List[int]:
"""
Moves all zeros to the end of the given list while maintaining the relative order of the non-zero elements.
Args:
arr (List[int]): The... |
evol_instruct_66k | 30,074 | Write a Python function to detect whether a given sequence contains a floating point number and identify its index/position in the list. The function should return a tuple containing the index and the floating point number if found, otherwise return `None`. The function should handle various data types and structures w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Optional
def find_float_in_sequence(sequence: List) -> Optional[Tuple[int, float]]:
"""
Detects whether a given sequence contains a floating point number and identifies its index/position in the ... |
evol_instruct_66k | 30,075 | Write a Python function to convert a measurement from meters to kilometers. The function should take a single parameter representing the measurement in meters and return the equivalent measurement in kilometers. The function should handle both positive and zero values for the input.
The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
def meters_to_kilometers(meters: float) -> float:
"""
Converts a measurement from meters to kilometers.
Args:
meters (float): The measurement in meters to be converted.
Returns:
float: The equivalent me... |
evol_instruct_66k | 30,089 | Write a Python function to calculate the product of all numbers in a given list. The function should handle exceptions for empty lists and non-numeric values. If the list is empty, return a specific error message. If the list contains non-numeric values, return a different specific error message. The function should st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def product_of_list(lst: List[Union[int, float]]) -> Union[int, float, str]:
"""
Calculate the product of all numbers in a given list.
Args:
lst (List[Union[int, float]]): The list of... |
evol_instruct_66k | 30,090 | Write a Python function to convert a binary string into its corresponding decimal number. The function should iterate through the binary string from right to left, calculating the decimal value by multiplying each binary digit by 2 raised to the power of its position index (starting from 0 on the right). The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_decimal(binary_string: str) -> int:
"""
Converts a binary string to its corresponding decimal number.
Args:
binary_string (str): The binary string to convert. It should consist only of '0's and '1's.
... |
evol_instruct_66k | 30,095 | Write a Python function to convert a list of given times from EDT (Eastern Daylight Time) to JST (Japan Standard Time) given the list times in 24-hour format, and also handle cases for Daylight Saving Time adjustments. The function should take a list of strings representing times in EDT and return a list of strings rep... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from datetime import datetime, timedelta
def convert_edt_to_jst(edt_times: List[str]) -> List[str]:
"""
Convert a list of given times from EDT (Eastern Daylight Time) to JST (Japan Standard Time).
A... |
evol_instruct_66k | 30,096 | Write a Python function to verify that all elements in a given list have the same data type. The function should also return the data type of the list itself and the data type of each element in the list. The code should start with:
```python
from typing import List, Union
def verify_array_data_type_uniformity(my_arra... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def verify_array_data_type_uniformity(my_array: List[Union[int, float, str, bool]]) -> str:
"""
Verifies that all elements in the given list have the same data type and returns the data type of th... |
evol_instruct_66k | 30,098 | Write a Python function to count the number of closed islands in a given 2D grid. A closed island is defined as a group of `0`s (land) that are completely surrounded by `1`s (water) or `2`s (obstacles) on all four sides (left, top, right, bottom). Obstacles (`2`s) are impassable and cannot be part of an island.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_closed_islands(grid: List[List[int]]) -> int:
"""
Count the number of closed islands in a given 2D grid.
A closed island is a group of `0`s (land) that are completely surrounded by `1`s (w... |
evol_instruct_66k | 30,100 | Write a Python function to interpret and format a date string in the MM-DD-YYYY format into a more readable format "Month Day, Year". The function should handle date strings with numerical months and return the formatted date string.
The code should start with:
```python
from datetime import datetime
def format_date(... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def format_date(date_string: str) -> str:
"""
Formats a date string from MM-DD-YYYY to a more readable format "Month Day, Year".
Args:
date_string (str): The input date string in the f... |
evol_instruct_66k | 30,106 | Write a Python function to divide a given string into an array of individual lexical terms, ignoring any numbers or special characters. Additionally, convert alternating terms to uppercase and lowercase. The function should start with:
```python
from typing import List
def divide_and_convert_terms(input_str: str) -> L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def divide_and_convert_terms(input_str: str) -> List[str]:
"""
Divides a given string into an array of individual lexical terms, ignoring any numbers or special characters.
Converts alternating terms... |
evol_instruct_66k | 30,116 | Write a Python function to compute the nth Fibonacci number using matrix multiplication and dynamic programming principles. The function should have a lower time complexity than the original recursive version and should implement a memoization strategy to avoid redundant calculations. The function should handle large i... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def fibonacci(num: int) -> int:
"""
Compute the nth Fibonacci number using matrix multiplication and dynamic programming principles.
Args:
num (int): The position of the Fibonacci number to compu... |
evol_instruct_66k | 30,121 | Write a Python function to efficiently concatenate two lists. The function should take two lists as input and return a new list that is the concatenation of the two input lists. The function should handle lists of any length, including empty lists.
The code should start with:
```python
from typing import List
def con... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def concatenate_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Concatenates two lists and returns the result.
Args:
list1 (List[int]): The first list to concatenate.
lis... |
evol_instruct_66k | 30,126 | Write a Python function to calculate the mean of a given dataset. If the dataset is empty, the function should raise a `ValueError` with an appropriate message. The function should be corrected to ensure it calculates the mean correctly without any logical errors.
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 calculate_mean(dataset: List[int]) -> float:
"""
Calculate the mean of a given dataset. If the dataset is empty, raise a ValueError.
Args:
dataset (List[int]): The dataset for which to c... |
evol_instruct_66k | 30,146 | Write a Python function to filter a list of integers and return the sum of all integers that are divisible by a given divisor. The function should take two parameters: a list of integers and an integer divisor. The function should return the sum of all integers in the list that are divisible by the divisor.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_divisibles(numbers: List[int], divisor: int) -> int:
"""
Computes the sum of all integers in the given list that are divisible by the specified divisor.
Args:
numbers (List[int]):... |
evol_instruct_66k | 30,156 | Write a Python function to assign a value to a variable and validate it. The function should take in two parameters: the variable name (as a string) and the number (as an integer). The function should return a dictionary with the variable name as the key and the assigned value as the value. Additionally, the function s... | Here is the Python code to solve the given problem in the markdown block:
```python
def assign_and_validate(variable_name: str, number: int) -> dict:
"""
Assigns a value to a variable and validates the inputs.
Args:
variable_name (str): The name of the variable to which the value will be assigned.
... |
evol_instruct_66k | 30,158 | Write a Python function to format a given dictionary as a valid JSON string. The function should ensure that the JSON string is properly formatted with double quotes for keys and values, and that there are no trailing commas. The code should start with:
```python
from typing import Dict
def format_as_json(data: Dict) ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import json
def format_as_json(data: Dict) -> str:
"""
Formats the given dictionary as a valid JSON string.
Args:
data (Dict): The dictionary to be formatted as a JSON string.
Returns:
... |
evol_instruct_66k | 30,171 | Write a Python function to calculate the area of a non-uniform trapezium given the lengths of its parallel sides, the distance between them, and the angle opposite to the longer side. The function should handle input validation and precision issues in floating point computations. Additionally, generate 10,000 random te... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
import random
def trapezium_area(base1: float, base2: float, distance: float, angle_deg: float) -> float:
"""
Calculate the area of a non-uniform trapezium given the lengths of its parallel sides,
the distance b... |
evol_instruct_66k | 30,188 | Write a Python function to generate an orthogonal grid (a two-dimensional matrix) of dimensions `n` by `m`, populated with a specified value. The function should be able to handle any non-negative integer values for `n` and `m`, and the default value to populate the grid should be `None`. The function should return the... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def generate_grid(n: int, m: int, value: Any = None) -> List[List[Any]]:
"""
Generates an orthogonal grid (a two-dimensional matrix) of dimensions n by m,
populated with the specified value.
... |
evol_instruct_66k | 30,199 | Write a Python function to swap neighboring elements in a given list of integers. If the list has an odd number of elements, the last element should remain in its original position. The function should start with:
```python
from typing import List
def swap_neighbours(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 swap_neighbours(arr: List[int]) -> List[int]:
"""
Swaps neighboring elements in a given list of integers.
Args:
arr (List[int]): The list of integers in which to swap neighboring element... |
evol_instruct_66k | 30,227 | Write a Python function to create a DataFrame from a given dictionary and return the DataFrame. The dictionary contains two keys: 'State' and 'Zipcode', each with a list of corresponding values. The function should handle the conversion from dictionary to DataFrame using the pandas library.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
import pandas as pd
from typing import Dict, List
def create_dataframe(data: Dict[str, List[str]]) -> pd.DataFrame:
"""
Create a DataFrame from a given dictionary containing 'State' and 'Zipcode' keys.
Args:
data (... |
evol_instruct_66k | 30,248 | Write a Python function to find the intersection of two lists without using built-in functions like `set.intersection` or list comprehensions. The function should iterate through both lists and append common elements to a new list. The code should start with:
```python
from typing import List
def list_intersection(lst... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def list_intersection(lst1: List[int], lst2: List[int]) -> List[int]:
"""
Find the intersection of two lists without using built-in functions.
Args:
lst1 (List[int]): The first list of integ... |
evol_instruct_66k | 30,281 | Write a Python function to generate a spiral matrix of size n x n, where n is a positive integer. The spiral matrix should start from the top-left corner and proceed in a clockwise direction, filling the matrix with numbers from 1 to n^2.
The code should start with:
```python
from typing import List
def generate_spir... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_spiral_matrix(n: int) -> List[List[int]]:
"""
Generate a spiral matrix of size n x n.
Args:
n (int): The size of the matrix (n x n).
Returns:
List[List[int]]: A 2D ... |
evol_instruct_66k | 30,290 | Write a Python function to determine the appropriate index at which a specified element should be inserted into a sorted array to maintain the ascending order. The function should use a binary search approach to find the index efficiently.
The code should start with:
```python
from typing import List
def find_inserti... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_insertion_index(array: List[int], num: int) -> int:
"""
Determine the appropriate index at which a specified element should be inserted into a sorted array to maintain the ascending order.
... |
evol_instruct_66k | 30,294 | Write a Python function to reverse a given list without modifying the original list. The function should return a new list that is the reverse of the input list. The code should start with:
```python
from typing import List
def reverse_list(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 reverse_list(lst: List[int]) -> List[int]:
"""
Returns a new list that is the reverse of the input list without modifying the original list.
Args:
lst (List[int]): The input list to be... |
evol_instruct_66k | 30,299 | Write a Python function to process a given paragraph, separate each word, eliminate punctuation, and store them in a linked list. The function should return the linked list containing the processed words.
The code should start with:
```python
from typing import Deque
from collections import deque
import string
def pr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Deque
from collections import deque
import string
def process_paragraph(paragraph: str) -> Deque[str]:
"""
Processes a given paragraph by removing punctuation, separating each word, and storing them in a link... |
evol_instruct_66k | 30,302 | Write a Python function to find the prime factors of each number in a given list of numerical integers and return a list of lists where each sublist contains the prime factors of the corresponding number, sorted in ascending order. If a number is less than 2, its corresponding sublist should be empty.
The code should ... | 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 a list of prime factors of the given integer n.
Args:
n (int): The integer to factorize.
Returns:
List[int]: A list of prime ... |
evol_instruct_66k | 30,305 | Write a Python function to generate an array of ten unique integers within a specified range. The function should take two parameters: the lower bound (inclusive) and the upper bound (exclusive) of the range. The function should return a list of ten unique integers within this range.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_unique_numbers(lower_bound: int, upper_bound: int) -> List[int]:
"""
Generates an array of ten unique integers within the specified range.
Args:
lower_bound (int):... |
evol_instruct_66k | 30,306 | Write a Python function to remove repetitive elements from an array of integers while maintaining the original order of the first occurrence of each element. The function should handle large arrays efficiently and should not use built-in functions like `set()` or `dict.fromkeys()`. The array will contain integers rangi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_repetitive_elements(arr: List[int]) -> List[int]:
"""
Removes repetitive elements from the given array while maintaining the order of their first occurrence.
Args:
arr (List[int])... |
evol_instruct_66k | 30,308 | Write a Python function to generate and display a pattern of stars with a variable size. The pattern should consist of two parts:
1. A right-angled triangle of stars where each row has one more star than the previous row.
2. An isosceles triangle of stars where each row has an increasing number of stars centered with s... | Here is the Python code to solve the given problem in the markdown block:
```python
def display_star_pattern(size: int) -> None:
"""
Generates and displays a pattern of stars with a variable size.
The pattern consists of two parts:
1. A right-angled triangle of stars where each row has one more star th... |
evol_instruct_66k | 30,319 | Write a Python function to split a given string into an array of individual lexical terms (words). The function should handle various delimiters such as spaces, commas, periods, and semicolons. The function should also handle multiple consecutive delimiters by treating them as a single delimiter.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def split_into_words(text: str) -> List[str]:
"""
Splits a given string into an array of individual lexical terms (words) while handling various delimiters.
Args:
text (str): The i... |
evol_instruct_66k | 30,320 | Write a Python function to estimate the time complexity of the given algorithm and determine the resulting sum of `i + j` after every iteration. The final result should be a list `T` such that its `k-th` element is the sum of every `i + j` for the `k-th` iteration. The function 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 iter_sum(n: int) -> List[int]:
"""
Estimate the time complexity of the given algorithm and determine the resulting sum of i + j after every iteration.
The final result is a list T such that its k... |
evol_instruct_66k | 30,332 | Write a Python function to determine if a given string is a valid palindrome considering only alphanumeric characters and ignoring cases. The function should return `True` if the string is a valid palindrome, otherwise `False`.
The code should start with:
```python
def is_valid_palindrome(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_palindrome(s: str) -> bool:
"""
Determines if a given string is a valid palindrome considering only alphanumeric characters and ignoring cases.
Args:
s (str): The input string to be checked.
Return... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.