source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 25,254 | Write a Python function to remove all punctuation marks from a given input string and return the cleaned string. The function should handle various punctuation marks such as commas, periods, exclamation marks, question marks, colons, semicolons, apostrophes, and quotation marks.
The code should start with:
```python
i... | Here is the Python code to solve the given problem in the markdown block:
```python
import string
def remove_punctuation(input_string: str) -> str:
"""
Removes all punctuation marks from the given input string.
Args:
input_string (str): The input string from which punctuation marks are to be remov... |
evol_instruct_66k | 25,255 | Write a Python function to print a given phrase a specified number of times. The function should take two parameters: the phrase to be printed and the number of times to print it. The function should use a loop to achieve this.
The code should start with:
```python
def print_phrase_repeatedly(phrase: str, times: int) ... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_phrase_repeatedly(phrase: str, times: int) -> None:
"""
Prints the given phrase the specified number of times.
Args:
phrase (str): The phrase to be printed.
times (int): The number of times to prin... |
evol_instruct_66k | 25,268 | Write a Python function to reverse a given string using a loop structure. The function should iterate through each character of the string and build the reversed string by appending each character to the beginning of the result string. The code should start with:
```python
def reverse_string_with_loop(s: str) -> str:
`... | Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_string_with_loop(s: str) -> str:
"""
Reverses the given string using a loop structure.
Args:
s (str): The input string to be reversed.
Returns:
str: The reversed string.
"""
revers... |
evol_instruct_66k | 25,275 | Write a Python function to generate an SQL query that retrieves the individual names of clients alongside the total count of unique orders per client from a table named 'orders'. Additionally, the query should account for cases where multiple orders are placed on the same day by a single client, treating them as a sing... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_sql_query() -> str:
"""
Generates an SQL query to retrieve the individual names of clients alongside the total count of unique orders per client from the 'orders' table.
Additionally, the query accounts for mult... |
evol_instruct_66k | 25,280 | Write a Python function to compute the sum of all elements in a given list of integers. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def compute_sum(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def compute_sum(arr: List[int]) -> int:
"""
Computes the sum of all elements in the given list of integers.
Args:
arr (List[int]): The list of integers whose sum is to be computed.
Re... |
evol_instruct_66k | 25,298 | Write a Python function to swap the elements at two given indices in a list. The function should handle cases where the indices are out of bounds by returning the original list unchanged. The code should start with:
```python
from typing import List
def swap_elements(lst: List[int], index1: int, index2: int) -> List[i... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def swap_elements(lst: List[int], index1: int, index2: int) -> List[int]:
"""
Swaps the elements at the given indices in the list.
Args:
lst (List[int]): The list in which elements are to ... |
evol_instruct_66k | 25,306 | Write a Python function to merge two sorted arrays of integers, `arr1` and `arr2`, into a single sorted array without using any built-in sorting functions or additional space. The merged array should be stored within `arr1` or `arr2`. The function should maintain the sorted nature of the arrays and efficiently use spac... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Merge two sorted arrays of integers into a single sorted array without using any built-in sorting functions or additional space... |
evol_instruct_66k | 25,311 | Write a Python function to solve a quadratic equation of the form \( ax^2 + bx + c = 0 \). The function should return the real or complex solutions of the equation. The code should start with:
```python
import cmath
def solve_quadratic_equation(a: float, b: float, c: float) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import cmath
def solve_quadratic_equation(a: float, b: float, c: float) -> tuple:
"""
Solve a quadratic equation of the form ax^2 + bx + c = 0 and return the roots.
Args:
a (float): Coefficient of x^2.
b (f... |
evol_instruct_66k | 25,323 | Write a Python function to find the second smallest value among four given integers. The function should be efficient and avoid unnecessary computations. The code should start with:
```python
def find_second_smallest(x1: int, x2: int, x3: int, x4: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_second_smallest(x1: int, x2: int, x3: int, x4: int) -> int:
"""
Finds the second smallest value among four given integers.
Args:
x1 (int): The first integer.
x2 (int): The second integer.
x3... |
evol_instruct_66k | 25,324 | Write a Python function to merge two sorted arrays of integers into a single sorted array without using built-in sorting functions. The function should handle edge cases such as empty arrays and negative numbers. Additionally, the function should output the time complexity of the merging process.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Merges two sorted arrays of integers into a single sorted array.
Args:
arr1 (List[int]): The first sorted array.
... |
evol_instruct_66k | 25,326 | Write a Python function to determine if a given number `a` is the product of exactly three distinct prime numbers, and if so, return those three prime numbers. If `a` is not the product of three distinct prime numbers, return the string `'Not a product of 3 distinct prime numbers.'`. The function should handle numbers ... | Here is the Python code to solve the given problem in the markdown block:
```python
def intricate_prime_triplet_product(a: int) -> tuple[int, int, int] | str:
"""
Determine if the given number `a` is the product of exactly three distinct prime numbers.
If so, return those three prime numbers as a tuple. Oth... |
evol_instruct_66k | 25,328 | Write a Python function to calculate the cube of all whole numbers within a given numeric interval, inclusive of both endpoints. The function should return a dictionary where the keys are the numbers within the interval and the values are their respective cubes.
The code should start with:
```python
from typing import... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def calculate_cubes(start: int, end: int) -> Dict[int, int]:
"""
Calculate the cube of all whole numbers within a given numeric interval, inclusive of both endpoints.
Args:
start (int): The ... |
evol_instruct_66k | 25,330 | Write a Python function to create and fill a 2-dimensional list (matrix) with dimensions `n` by `m`, and another function to rotate this matrix 90 degrees clockwise. The matrix should be filled with values such that each element is uniquely identifiable by its position. 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 create_matrix(n: int, m: int) -> List[List[int]]:
"""
Create and fill a 2-dimensional list (matrix) with dimensions n by m.
Args:
n (int): The number of rows in the matrix.
m... |
evol_instruct_66k | 25,338 | Write a Python function to count the frequency of each distinct word in a given sentence. The function should return a dictionary where the keys are the words and the values are the counts of those words in the sentence. The sentence should be case-insensitive, meaning that 'Word' and 'word' should be considered the sa... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def word_frequency(sentence: str) -> Dict[str, int]:
"""
Counts the frequency of each distinct word in a given sentence.
Args:
sentence (str): The input sentence to analyze.
Returns:
... |
evol_instruct_66k | 25,347 | Write a Python function to process a sequence of consecutive numerical values. The function should identify prime numbers in the sequence and replace them with their respective cubed equivalents. The function should return the modified sequence.
The code should start with:
```python
from typing import List
def proces... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise.
... |
evol_instruct_66k | 25,360 | Write a Python function to determine if two given strings have the same alphabetic arrangement, ignoring case and spaces. The function should return `True` if the two strings have the same alphabetic arrangement, and `False` otherwise. The code should start with:
```python
def are_anagrams(str1: str, str2: str) -> bool... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(str1: str, str2: str) -> bool:
"""
Determine if two given strings are anagrams of each other, ignoring case and spaces.
Args:
str1 (str): The first string to compare.
str2 (str): The second ... |
evol_instruct_66k | 25,361 | Write a Python function to find the least common multiple (LCM) of two given integers. The function should efficiently compute the LCM using the relationship between the Greatest Common Divisor (GCD) and LCM.
The code should start with:
```python
def find_lcm(num1: int, num2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_lcm(num1: int, num2: int) -> int:
"""
Calculate the least common multiple (LCM) of two integers.
Args:
num1 (int): The first integer.
num2 (int): The second integer.
Returns:
int: The l... |
evol_instruct_66k | 25,364 | Write a Python function to find the last two elements from a given list of odd numbers. The function should handle cases where the list has fewer than two elements by returning an empty list.
The code should start with:
```python
from typing import List
def find_last_two_elements(odd_numbers_list: List[int]) -> List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_last_two_elements(odd_numbers_list: List[int]) -> List[int]:
"""
Find the last two elements from a given list of odd numbers.
Args:
odd_numbers_list (List[int]): A list of odd numbe... |
evol_instruct_66k | 25,370 | Write a Python function to extract and segregate the street number and street name from a given geospatial string using a regular expression pattern. The function should return a tuple containing the street number and street name. The geospatial string may contain various formats, but the street number and street name ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import Tuple
def extract_street_info(geospatial_string: str) -> Tuple[str, str]:
"""
Extracts the street number and street name from a given geospatial string.
Args:
geospatial_string (str): T... |
evol_instruct_66k | 25,374 | Write a Python function to generate the Fibonacci sequence up to the nth number. The function should return a list containing the Fibonacci sequence. The code should start with:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the Fibonacci sequence up to the nth number.
Args:
n (int): The number of Fibonacci numbers to generate.
Returns:
Lis... |
evol_instruct_66k | 25,381 | Write a Python function that prints the numbers from 0 to 9, following specific conditions:
- If the number is divisible by 3, print "Fizz".
- If the number is divisible by 5, print "Buzz".
- If the number is divisible by both 3 and 5, print "FizzBuzz".
- Otherwise, print the number itself.
The function should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
def fizz_buzz():
"""
Prints numbers from 0 to 9 with specific conditions:
- If the number is divisible by 3, prints "Fizz".
- If the number is divisible by 5, prints "Buzz".
- If the number is divisible by both 3 and... |
evol_instruct_66k | 25,383 | Write a Python function to concatenate a string and an integer into a single string, ensuring that the integer is first converted to a string. The function should handle any input types and ensure that the concatenation is performed correctly. The code should start with:
```python
from typing import Union
def concaten... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union
def concatenate_string_and_integer(s: Union[str, int], i: Union[str, int]) -> str:
"""
Concatenates a string and an integer into a single string.
Args:
s (Union[str, int]): The first input,... |
evol_instruct_66k | 25,396 | Write a Python function to generate an exclusive series of geometrically linked numbers and ensure the uniqueness of each generated value by filtering out duplicates. The function should start with:
```python
from typing import List
def generate_unique_geometric_series(start: float, ratio: float, length: int) -> List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_unique_geometric_series(start: float, ratio: float, length: int) -> List[float]:
"""
Generates a unique series of geometrically linked numbers and ensures each value is unique.
Args:
... |
evol_instruct_66k | 25,401 | Write a Python function to find the index of the first occurrence of a number within a specified range in a list of floating-point numbers. If no number within the range is found, return a specific message.
The code should start with:
```python
from typing import List, Tuple
def find_first_in_range(nums: List[float],... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_first_in_range(nums: List[float], range: Tuple[float, float]) -> int or str:
"""
Find the index of the first occurrence of a number within a specified range in a list of floating-point nu... |
evol_instruct_66k | 25,417 | Write a Python function to convert a given text string into its hexadecimal representation. Each character in the string should be converted to its corresponding hexadecimal value, and the results should be concatenated into a single string with each hexadecimal value separated by a space.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_hex(text: str) -> str:
"""
Converts a given text string into its hexadecimal representation.
Args:
text (str): The input text string to be converted.
Returns:
str: A string containing the... |
evol_instruct_66k | 25,425 | Write a Python function to generate a new sequence from a given sequence of non-repeating whole numbers, where each element in the new sequence is the result of multiplying the corresponding element in the original sequence by a constant factor of two. The function should yield each element of the new sequence one by o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Iterator, List
def amplify_sequence(numbers: List[int]) -> Iterator[int]:
"""
Generates a new sequence by multiplying each element of the given sequence by 2.
Args:
numbers (List[int]): A list of... |
evol_instruct_66k | 25,431 | Write a Python function to check if a given string contains any of the specified special characters: `;`, `:`, `!`, `@`, `#`, `$`, `%`, `^`, `&`, `*`, `(`, `)`, `-`, `_`, `+`, `=`, `[`, `]`, `{`, `}`, `|`, `\`, `,`, `.`, `?`, `/`, `<`, `>`, `'`, `"`, or `` ` ``. The function should return `True` if any of these charact... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_special_characters(string: str) -> bool:
"""
Check if the given string contains any of the specified special characters.
Args:
string (str): The string to be checked for special characters.
... |
evol_instruct_66k | 25,445 | Write a Python function to find the category and the name associated with the lowest occurrence frequency in a nested dictionary. If there are multiple names with the same lowest frequency, return any one of them. If two categories have the same name with the lowest frequency, then return the category which has fewer o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def find_lowest_frequency(dictionary: Dict[str, Dict[str, int]]) -> Tuple[str, str]:
"""
Finds the category and the name associated with the lowest occurrence frequency in a nested dictionary.
... |
evol_instruct_66k | 25,454 | Write a Python function to compute the dissimilarity between two non-identical arrays by identifying elements that are exclusive to each array and quantifying their occurrences. The function should return a dictionary where the keys are the exclusive elements and the values are their counts in the respective arrays. Th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
from collections import Counter
def calculate_dissimilarity(arr1: List[int], arr2: List[int]) -> Dict[int, int]:
"""
Computes the dissimilarity between two non-identical arrays by identifying eleme... |
evol_instruct_66k | 25,461 | Write a Python function to filter and transform a list of integers based on a given condition. The function should return a new list containing the squares of all even numbers from the input list. The code should start with:
```python
from typing import List
def filter_and_square_even_numbers(numbers: List[int]) -> Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_and_square_even_numbers(numbers: List[int]) -> List[int]:
"""
Filters and squares all even numbers from the given list of integers.
Args:
numbers (List[int]): A list of integers t... |
evol_instruct_66k | 25,473 | Write a Python function to find and return the index of the first occurrence of a specified target value in a given list of integers. If the target value is not found in the list, the function should return `-1`.
The code should start with:
```python
from typing import List
def find_first_occurrence(nums: List[int], ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_first_occurrence(nums: List[int], target: int) -> int:
"""
Find the index of the first occurrence of a specified target value in a list of integers.
Args:
nums (List[int]): The list... |
evol_instruct_66k | 25,474 | Write a Python function to invert a given sequence of numerical integers. The function should return a new list with the elements in reverse order. The code should start with:
```python
from typing import List
def invert_sequence(seq: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def invert_sequence(seq: List[int]) -> List[int]:
"""
Inverts the given sequence of numerical integers.
Args:
seq (List[int]): The sequence of numerical integers to be inverted.
Retur... |
evol_instruct_66k | 25,493 | Write a Python function to calculate the power of a number raised to the nth power without using the power (**) operator or any in-built Python function like `pow()`. Additionally, handle edge cases like the power being negative or zero. The function should also handle exceptions like non-numeric inputs and return a su... | Here is the Python code to solve the given problem in the markdown block:
```python
def power_of_number(base: float, exponent: int) -> float:
"""
Calculate the power of a number raised to the nth power without using the power (**) operator or any in-built Python function like pow().
Args:
base (flo... |
evol_instruct_66k | 25,495 | Write a Python function to sort a dictionary by its values, handling both numeric and string values separately. Numeric values should be sorted in ascending order, and string values should be sorted in alphabetical order. The function should return a new dictionary with the sorted key-value pairs.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def sort_dictionary_by_values(d: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Sorts a dictionary by its values, handling numeric and string values separately.
Numeric values are sorted in ascending or... |
evol_instruct_66k | 25,504 | Write a Python function to swap the key-value pairs in a dictionary. The keys should represent sports, and the values should be the names of famous athletes related to the sport. The function should return a new dictionary with the swapped key-value pairs.
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 swap_key_value_pairs(sports_dict: Dict[str, str]) -> Dict[str, str]:
"""
Swaps the key-value pairs in a given dictionary where keys represent sports and values represent famous athletes.
Args:
... |
evol_instruct_66k | 25,505 | Write a Python function to find and return the duplicate values in a given dictionary. The function should traverse through the dictionary and identify values that appear more than once. The code should start with:
```python
from typing import Dict, List
def find_duplicate_values(input_dict: Dict[str, int]) -> List[in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def find_duplicate_values(input_dict: Dict[str, int]) -> List[int]:
"""
Find and return the duplicate values in a given dictionary.
Args:
input_dict (Dict[str, int]): The dictionary to... |
evol_instruct_66k | 25,511 | Write a Python function to generate an array of `n` randomly selected real numbers within a specified range `[low, high)`, ensuring that the numbers are uniformly distributed. The function should return the generated array.
The code should start with:
```python
from typing import List
import numpy as np
def generate_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import numpy as np
def generate_random_numbers(n: int, low: float, high: float) -> List[float]:
"""
Generates an array of n random numbers uniformly distributed within the range [low, high).
Args:
... |
evol_instruct_66k | 25,512 | Write a Python function to calculate the factorial of a specified integer using an iterative approach. The function should handle both positive and zero inputs. The code should start with:
```python
def factorial(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int:
"""
Calculate the factorial of a specified integer using an iterative approach.
Args:
n (int): The integer for which to calculate the factorial. Must be non-negative.
Returns:
... |
evol_instruct_66k | 25,540 | Write a Python function to find the position of the maximum value in a given numerical array. If there are multiple occurrences of the maximum value, return the position of the first occurrence.
The code should start with:
```python
from typing import List
def find_max_position(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_max_position(arr: List[int]) -> int:
"""
Find the position of the maximum value in a given numerical array.
Args:
arr (List[int]): The numerical array in which to find the maximum v... |
evol_instruct_66k | 25,545 | Write a Python function to sequentially extract and return each character from a given input string. The function should return a list of characters. The code should start with:
```python
from typing import List
def extract_characters(input_string: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def extract_characters(input_string: str) -> List[str]:
"""
Extracts and returns each character from the given input string as a list.
Args:
input_string (str): The input string from which c... |
evol_instruct_66k | 25,547 | Write a Python function to calculate the median value of a given list of integers. The function should handle lists of any length, including empty lists. The median is the middle value in a sorted list of numbers. If the list has an odd number of elements, the median is the middle element. If the list has an even numbe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def calculate_median(numbers: List[int]) -> Optional[float]:
"""
Calculate the median value of a given list of integers.
Args:
numbers (List[int]): The list of integers from which ... |
evol_instruct_66k | 25,564 | Write a Python function to generate a stochastic floating-point number within a specified range defined by a lower and upper bound. The function should handle both positive and negative bounds and ensure that the generated number is within the specified range. The code should start with:
```python
import random
def ge... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_random_number(lower_bound: float, upper_bound: float) -> float:
"""
Generates a stochastic floating-point number within the specified range.
Args:
lower_bound (float): The lower bound of ... |
evol_instruct_66k | 25,570 | Write a Python function to convert a given non-negative integer to its binary representation. The function should return the binary representation as a string. Additionally, identify and correct the issue in the given erroneous code.
The code should start with:
```python
def convert_to_binary(number: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_binary(number: int) -> str:
"""
Converts a given non-negative integer to its binary representation.
Args:
number (int): The non-negative integer to be converted to binary.
Returns:
str: T... |
evol_instruct_66k | 25,573 | Write a Python function to create a dictionary from two given lists, where the first list contains the keys and the second list contains the corresponding values. Ensure that the function handles cases where the lists are of different lengths by ignoring the extra elements in the longer 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, Dict
def create_dict_from_lists(keys: List[str], values: List[int]) -> Dict[str, int]:
"""
Creates a dictionary from two lists, where the first list contains the keys and the second list contains the co... |
evol_instruct_66k | 25,582 | Write a Python function to determine if one string (`str_1`) is a substring of another string (`str_2`). The function should return `True` if `str_1` is a contiguous sequence of characters within `str_2`, and `False` otherwise. The function should handle edge cases such as empty strings and strings where `str_1` is lon... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_substring(str_1: str, str_2: str) -> bool:
"""
Determines if `str_1` is a substring of `str_2`.
Args:
str_1 (str): The string to check if it is a substring.
str_2 (str): The string in which to check f... |
evol_instruct_66k | 25,592 | Write a Python function to find the largest number in a given array without using the built-in `max` function. The function should iterate through the array and keep track of the largest number encountered.
The code should start with:
```python
from typing import List
def find_largest_number(array: List[int]) -> int:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_largest_number(array: List[int]) -> int:
"""
Find the largest number in a given array without using the built-in max function.
Args:
array (List[int]): The array of integers from wh... |
evol_instruct_66k | 25,610 | Write a Python function to calculate the total weight of groceries in a shopping basket. Each grocery item is represented as a dictionary with keys "item" and "weight". The function should sum up the weights of all items in the list and return the total weight.
The code should start with:
```python
from typing import ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def calculate_total_weight(groceries: List[Dict[str, float]]) -> float:
"""
Calculate the total weight of groceries in a shopping basket.
Args:
groceries (List[Dict[str, float]]): A li... |
evol_instruct_66k | 25,624 | Write a Python function to calculate the occurrence rate of each alphabet letter within a given string, considering case sensitivity. The function should exclude digits and special characters from the count. The result should be accumulated in a dictionary where the keys are the letters and the values are their respect... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def letter_occurrence_rate(text: str) -> Dict[str, int]:
"""
Calculate the occurrence rate of each alphabet letter in the given text, considering case sensitivity.
Args:
text (str): The inpu... |
evol_instruct_66k | 25,634 | Write a Python function to reverse a given string, ensuring that each character, including punctuation and spaces, is placed in a backward sequence compared to their original positions. The function should handle strings of any length, including empty strings.
The code should start with:
```python
def reverse_string(s... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(s: str) -> str:
"""
Reverses the given string, ensuring each character, including punctuation and spaces,
is placed in a backward sequence compared to their original positions.
Args:
s (str): ... |
evol_instruct_66k | 25,640 | Write a Python function to generate a chessboard pattern of a given size using 'X' and 'O'. The chessboard should be represented as a string where each cell is either 'X' or 'O', and the pattern alternates between rows and columns. The function should start with:
```python
def generate_chessboard(size: int) -> str:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_chessboard(size: int) -> str:
"""
Generates a chessboard pattern of the given size using 'X' and 'O'.
Args:
size (int): The size of the chessboard (size x size).
Returns:
str: A string repr... |
evol_instruct_66k | 25,643 | Write a Python function to alternate the positions of consecutive elements in a given list. The function should swap each pair of consecutive elements in place and return the modified list. If the list has an odd number of elements, the last element should remain in its original position.
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 alternate_positions(lst: List[int]) -> List[int]:
"""
Alternate the positions of consecutive elements in the given list.
This function iterates through the list in steps of 2, swapping each pair... |
evol_instruct_66k | 25,644 | Write a Python function to implement the merge sort algorithm to sort a given list of integers in ascending order. The function should be efficient and handle edge cases such as empty lists or lists with a single element. The code should start with:
```python
from typing import List
def merge_sort(array: List[int]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(array: List[int]) -> List[int]:
"""
Sorts a given list of integers in ascending order using the merge sort algorithm.
Args:
array (List[int]): The list of integers to be sorte... |
evol_instruct_66k | 25,652 | Write a Python function to extract the last n characters from a given input string. The function should handle cases where n is greater than the length of the string by returning the entire string. The function should also handle cases where n is less than or equal to zero by returning an empty string.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
def extract_last_n_chars(input_string: str, n: int) -> str:
"""
Extracts the last n characters from the given input string.
Args:
input_string (str): The input string from which to extract characters.
n (int... |
evol_instruct_66k | 25,659 | Write a Python function to count the repeated occurrence of sub-arrays within a multi-dimensional array and return these repeated sub-arrays along with their counts. The function should handle sub-arrays of any depth and type, ensuring that the comparison is done correctly without converting sub-arrays to strings.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Any
from collections import defaultdict
def hash_subarray(subarray: List[Any]) -> str:
"""
Generates a unique hash for a sub-array.
Args:
subarray (List[Any]): The sub-array to hash.... |
evol_instruct_66k | 25,666 | Write a Python function to generate a successor set from a given input set of non-repeated integer values. Each element in the successor set should be the result of multiplying the corresponding element in the input set by an arithmetic relativity of precisely two. The function should be efficient and use list comprehe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_successor_set(input_set: List[int]) -> List[int]:
"""
Generates a successor set from a given input set of non-repeated integer values.
Each element in the successor set is the result of ... |
evol_instruct_66k | 25,670 | Write a Python function to classify a list of words into their respective parts of speech: Nouns, Verbs, Adverbs, and Adjectives. The function should use a predefined dictionary to map words to their parts of speech. If a word is not found in the dictionary, it should be classified as "Unknown".
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Union
def classify_words(words: List[str], pos_dict: Dict[str, str]) -> List[str]:
"""
Classify a list of words into their respective parts of speech using a predefined dictionary.
Args:
... |
evol_instruct_66k | 25,680 | Write a Python function to sort an array of strings in alphabetical order. The function should take a list of strings as input and return a new list that is sorted in alphabetical order. The original list should remain unchanged.
The code should start with:
```python
from typing import List
def sort_strings_alphabeti... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_strings_alphabetically(arr: List[str]) -> List[str]:
"""
Sorts an array of strings in alphabetical order and returns the sorted array.
The original array remains unchanged.
Args:
... |
evol_instruct_66k | 25,682 | Write a Python function to determine if a given word is composed entirely of vowels. The function should be case-insensitive, meaning it should treat 'A' and 'a' as the same vowel. The function should return `True` if the word is composed entirely of vowels and `False` otherwise.
The code should start with:
```python
... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_all_vowels(word: str) -> bool:
"""
Determines if a given word is composed entirely of vowels.
Args:
word (str): The word to be checked.
Returns:
bool: True if the word is composed entirely of vow... |
evol_instruct_66k | 25,690 | Write a Python function to simulate a simple shell script that starts by printing "Hello World" and then executes a list of predefined tasks. The function should be flexible enough to allow for future enhancements by accepting a list of additional tasks to be executed after the initial "Hello World" task. Each task in ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable
def shell_script(additional_tasks: List[Callable[[], None]]) -> None:
"""
Simulates a simple shell script that starts by printing "Hello World" and then executes a list of additional tasks.
... |
evol_instruct_66k | 25,722 | Write a Python function to perform element-wise exponentiation on two tuples of identical size. The function should handle various error scenarios, such as:
- If the inputs are not tuples.
- If the tuples are of different sizes.
- If the tuple elements are not real numbers.
- If the second tuple contains any negative v... | Here is the Python code to solve the given problem in the markdown block:
```python
def element_wise_exponentiation(t1, t2):
"""
Perform element-wise exponentiation on two tuples of identical size.
Args:
t1 (tuple): The base tuple.
t2 (tuple): The exponent tuple.
Returns:
tuple... |
evol_instruct_66k | 25,732 | Write a Python function to validate and modify a nested dictionary representing a person's details. The dictionary has the following structure: `{"Name": "John", "Age": 35, "details": {"Salary": 50000, "Position": "Developer"}}`. The function should:
1. Validate the given values to ensure they meet the specified criter... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Union
def validate_and_update_details(person_details: Dict[str, Union[str, int, Dict]], new_name: str, new_age: int, new_salary: float, new_position: str) -> str:
"""
Validates and updates the person's ... |
evol_instruct_66k | 25,756 | Write a Python function to calculate the sum of the first `n` even integers. The function should use an efficient mathematical approach rather than a loop to compute the sum. The code should start with:
```python
def sum_of_first_n_even_integers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_first_n_even_integers(n: int) -> int:
"""
Calculate the sum of the first n even integers.
Args:
n (int): The number of even integers to sum.
Returns:
int: The sum of the first n even integers... |
evol_instruct_66k | 25,762 | Write a Python function to translate a hierarchical tree structure represented as a nested dictionary into a list of tuples, where each tuple represents a node and its parent. The root node has no parent, so its parent should be `None`. The function should start with:
```python
from typing import Dict, List, Tuple, Opt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple, Optional
def tree_to_tuples(tree: Dict) -> List[Tuple[str, Optional[str]]]:
"""
Translates a hierarchical tree structure represented as a nested dictionary into a list of tuples.
Each t... |
evol_instruct_66k | 25,763 | Write a Python function to generate a dictionary that maps each number in a given list to its cubed representation. The function should take a list of integers as input and return a dictionary where the keys are the original numbers and the values are their respective cubes.
The code should start with:
```python
from ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def generate_cubed_mapping(numbers: List[int]) -> Dict[int, int]:
"""
Generates a dictionary that maps each number in the input list to its cubed representation.
Args:
numbers (List[in... |
evol_instruct_66k | 25,777 | Write a Python function to merge two sorted arrays into one sorted array. The function should efficiently combine the elements from both arrays while maintaining the sorted order. The code should start with:
```python
from typing import List
def merge_sorted_arrays(array1: List[int], array2: List[int]) -> List[int]:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(array1: List[int], array2: List[int]) -> List[int]:
"""
Merges two sorted arrays into one sorted array.
Args:
array1 (List[int]): The first sorted array.
arra... |
evol_instruct_66k | 25,779 | Write a Python function that accepts four inputs and returns a tuple containing these inputs. The function should validate that the inputs are of the correct data types: the first input must be a string, the second an integer, the third a float, and the fourth a boolean. If any input does not match the required data ty... | Here is the Python code to solve the given problem in the markdown block:
```python
def create_tuple(a: str, b: int, c: float, d: bool) -> tuple:
"""
Create a tuple with the given inputs after validating their types.
Args:
a (str): The first element of the tuple, must be a string.
b (int): ... |
evol_instruct_66k | 25,785 | Write a Python function to remove all duplicates from a given list while retaining the order of elements. Additionally, determine the original index positions of the remaining elements in the modified list. The function should return a tuple containing the modified list and a list of the original index positions.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def remove_duplicates_with_indices(arr: List[int]) -> Tuple[List[int], List[int]]:
"""
Removes duplicates from the given list while retaining the order of elements.
Additionally, returns the o... |
evol_instruct_66k | 25,795 | Write a Python function to generate a string of a given length `n` composed solely of asterisk characters (`*`). The function should handle potential errors gracefully by raising appropriate exceptions. The code should start with:
```python
def generate_asterisk_string(n: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def generate_asterisk_string(n: int) -> str:
"""
Generates a string of length `n` composed solely of asterisk characters (`*`).
Args:
n (int): The length of the string to be generated. Must be a non-negative integer... |
evol_instruct_66k | 25,799 | Write a Python function to combine the contents of two dictionaries by merging their common keys and aggregating the associated numeric values. If a key exists in only one dictionary, it should be included in the result with its value from that dictionary. The function should start with:
```python
from typing import Di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_and_aggregate_dicts(d1: Dict[str, int], d2: Dict[str, int]) -> Dict[str, int]:
"""
Combines the contents of two dictionaries by merging their common keys and aggregating the associated numeric ... |
evol_instruct_66k | 25,808 | Write a Python function to generate a 5x5 NumPy array populated with arbitrarily chosen floating-point numbers within the range of -3.0 and 7.0. The function should initialize an empty array of the specified dimensions and then populate each cell with a distinct floating-point number chosen randomly from the specified ... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
import random
def generate_random_float(start=-3.0, end=7.0) -> float:
"""
Generates a random floating-point number within the specified range.
Args:
start (float): The lower bound of the range (... |
evol_instruct_66k | 25,811 | Write a Python function to find the smallest numerical value in a given list, ensuring proper error handling for non-iterable or non-numeric inputs. The function should ignore non-numeric elements and raise appropriate exceptions if no valid numeric values are found.
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 find_smallest_number(lst: List[Union[int, float, str]]) -> Union[int, float]:
"""
Finds the smallest numerical value in a given list, ignoring non-numeric elements.
Args:
lst (Lis... |
evol_instruct_66k | 25,812 | Write a Python function to count the number of vowel letters in a given string. The function should be case-insensitive and should consider both uppercase and lowercase vowels.
The code should start with:
```python
def count_vowels(text: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_vowels(text: str) -> int:
"""
Count the number of vowel letters in a given string.
Args:
text (str): The input string to count vowels from.
Returns:
int: The number of vowel letters in the inp... |
evol_instruct_66k | 25,818 | Write a Python function to determine if two given strings are anagrams of each other, ignoring case sensitivity. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
The code should start with:
```python
def are_anagrams(... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(string1: str, string2: str) -> bool:
"""
Determine if two given strings are anagrams of each other, ignoring case sensitivity.
Args:
string1 (str): The first string to compare.
string2 (str)... |
evol_instruct_66k | 25,821 | Write a Python function to convert an ASCII string to its binary representation. Each character in the ASCII string should be converted to an 8-bit binary string. The function should concatenate these 8-bit binary strings to form the final binary representation of the entire ASCII string.
The code should start with:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
def ascii_to_binary(ascii_string: str) -> str:
"""
Converts an ASCII string to its binary representation.
Each character in the ASCII string is converted to an 8-bit binary string,
and these binary strings are concatena... |
evol_instruct_66k | 25,825 | Write a Python function to create a bijective mapping of a 3-dimensional matrix composed of decimal numbers. The function should take a 3D list of decimal numbers as input and return a dictionary where each key is a tuple representing the indices of the element in the 3D list, and the value is the corresponding element... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_bijective_mapping(matrix: List[List[List[float]]]) -> Dict[tuple, float]:
"""
Creates a bijective mapping of a 3-dimensional matrix composed of decimal numbers.
Args:
matrix... |
evol_instruct_66k | 25,826 | Write a Python function to generate a GraphQL query string that retrieves a list of all posts from a blog, including the author details, and filters the posts by a specified publication date range. The function should accept two parameters: `start_date` and `end_date`, both of which are strings in the format "YYYY-MM-D... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_graphql_query(start_date: str, end_date: str) -> str:
"""
Generates a GraphQL query string to fetch a list of posts from a blog, including author details,
and filters the posts by a specified publication date ra... |
evol_instruct_66k | 25,831 | Write a Python function to calculate the Least Common Multiple (LCM) of two integers `x` and `y` using an improved algorithm. The function should handle the constraints where `1 <= x, y <= 10^9`. The code should start with:
```python
def lcm(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def gcd(x: int, y: int) -> int:
"""
Compute the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm.
Args:
x (int): The first integer.
y (int): The second integer.
Returns:
... |
evol_instruct_66k | 25,853 | Write a Python function to display the elements of a given list in a specific format. The function should take a list of strings as input and print each element on a new line, prefixed with a hyphen and a space. The code should start with:
```python
from typing import List
def display_elements(elements: List[str]) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def display_elements(elements: List[str]) -> None:
"""
Displays each element of the given list of strings on a new line, prefixed with a hyphen and a space.
Args:
elements (List[str]): A lis... |
evol_instruct_66k | 25,857 | Write a Python function to find the smallest positive number in a given array of integers. The function must ensure that it runs in O(n log n) time complexity. The array may contain both negative and positive numbers. If no positive number is found, the function should return `None`.
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, Optional
def find_smallest_positive(nums: List[int]) -> Optional[int]:
"""
Find the smallest positive number in a given array of integers.
Args:
nums (List[int]): The array of integers to s... |
evol_instruct_66k | 25,866 | Write a Python function to filter and remove special characters from a given input text, leaving only letters, digits, spaces, and newline characters. The function should use regular expressions to achieve this. The code should start with:
```python
import re
def filter_text(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
import re
def filter_text(text: str) -> str:
"""
Filters and removes special characters from the given input text, leaving only letters, digits, spaces, and newline characters.
Args:
text (str): The input text fr... |
evol_instruct_66k | 25,872 | Write a Python function to detect duplicates in a tuple and calculate their weights based on their types. The function should only consider integer and string entries as valid. The weight of each entry is determined by its type: integers have a weight of 3 times their count, and strings have a weight of 5 times their c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict
def detect_duplicates(t: Tuple) -> Dict:
"""
Detects duplicates in a tuple and calculates their weights based on their types.
Args:
t (Tuple): The tuple to analyze. Only integer and s... |
evol_instruct_66k | 25,891 | Write a Python function to determine the illumination status of cells in a grid after a series of queries. The grid is of size `N x N`, and each cell initially contains a lamp that is off. Given an array of lamp positions `lamps`, where each lamp is turned on, and an array of queries `queries`, for each query, determin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import defaultdict
def grid_illumination(N: int, lamps: List[List[int]], queries: List[List[int]]) -> List[int]:
"""
Determine the illumination status of cells in a grid after a series o... |
evol_instruct_66k | 25,903 | Write a Python function to manipulate a nested dictionary representing a person's profile. The dictionary should include fields for "Name", "Age", "Occupation", and "Skills". The "Occupation" field should be another dictionary with fields for "Title" and "Years of Experience". The "Skills" field should be a list of str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Union
def create_profile() -> Dict[str, Union[str, int, Dict[str, Union[str, int]], List[str]]]:
"""
Creates and returns a dictionary representing a person's profile.
Returns:
dict: A... |
evol_instruct_66k | 25,906 | Write a Python function to extract all values between quotation marks from a given string. The function should handle nested quotations and return the values in the order they appear. It should also be able to handle different types of quotation marks (single quotes `'`, double quotes `"`, and backticks `` ` ``). The c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def extract_quoted_strings(text: str) -> List[str]:
"""
Extracts all values between quotation marks from a given string.
Handles nested quotations and different types of quotation marks (si... |
evol_instruct_66k | 25,910 | Write a Python function to calculate the sum of the first `n` natural numbers using an optimized approach. The function should use a mathematical formula to compute the sum instead of a loop, reducing the line count and optimizing the computation.
The code should start with:
```python
def sum_of_first_n_natural_number... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_first_n_natural_numbers(n: int) -> int:
"""
Calculate the sum of the first n natural numbers using an optimized mathematical formula.
Args:
n (int): The number of natural numbers to sum.
Returns:
... |
evol_instruct_66k | 25,919 | Write a Python function to analyze two lists of numerical entities, `list1` and `list2`, each with `n` elements. The function should produce an array of ternary replies of length `n`: a '0' implies equality, a '-1' suggests that the corresponding element in `list1` is less than the one in `list2`, and a '1' confirms th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def analyze_lists(list1: List[int], list2: List[int]) -> Union[List[int], str]:
"""
Analyze two lists of numerical entities and produce an array of ternary replies.
Args:
list1 (List[... |
evol_instruct_66k | 25,934 | Write a Python function to find the index of the single unpaired element in a given list of integers. The list contains pairs of integers except for one unpaired element. The function should return the index of this unpaired element.
The code should start with:
```python
from typing import List
def find_unpaired_elem... | 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_unpaired_element_index(arr: List[int]) -> int:
"""
Find the index of the single unpaired element in a given list of integers.
Args:
arr (List[int]): ... |
evol_instruct_66k | 25,935 | Write a Python function to calculate the nth Fibonacci number using memoization to optimize the computation. The function should take an integer `n` as input and return the nth Fibonacci number. The code should start with:
```python
def fibonacci_memoized(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci_memoized(n: int) -> int:
"""
Calculate the nth Fibonacci number using memoization to optimize the computation.
Args:
n (int): The position in the Fibonacci sequence to calculate.
Returns:
... |
evol_instruct_66k | 25,939 | Write a Python function to evaluate a postfix expression. The postfix expression is given as a list of tokens, where each token is either an integer or an operator (`+`, `-`, `*`, `/`). The function should return the result of the postfix expression as an integer.
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 evaluate_postfix_expression(tokens: List[str]) -> int:
"""
Evaluate a postfix expression given as a list of tokens.
Args:
tokens (List[str]): A list of tokens representing the postfix ex... |
evol_instruct_66k | 25,947 | Write a Python function to add two binary digits and return the result as a binary string. The function should accept two binary strings as input and return the sum of these binary numbers as a binary string. The code should start with:
```python
def add_binary_digits(a: str, b: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def add_binary_digits(a: str, b: str) -> str:
"""
Adds two binary digits and returns the result as a binary string.
Args:
a (str): The first binary digit as a string.
b (str): The second binary digit as a st... |
evol_instruct_66k | 25,968 | Write a Python function to identify and extract the smallest numerical element within a given array. The function should handle arrays of integers and floating-point numbers. The code should start with:
```python
from typing import List, Union
def find_smallest_element(array: List[Union[int, float]]) -> Union[int, flo... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Union
def find_smallest_element(array: List[Union[int, float]]) -> Union[int, float]:
"""
Identify and extract the smallest numerical element within the provided array.
Args:
array (List[... |
evol_instruct_66k | 25,974 | Write a Python function to calculate the maximum sum of a contiguous sub-array within a given array of integers. The function should handle both positive and negative integers. The code should start with:
```python
from typing import List
def max_sum_subarray(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def max_sum_subarray(arr: List[int]) -> int:
"""
Calculate the maximum sum of a contiguous sub-array within the given array.
Args:
arr (List[int]): The array of integers.
Returns:
... |
evol_instruct_66k | 25,983 | Write a Python function to validate a JSON object against a predefined JSON schema. The JSON object represents biographical details of a person, and the schema ensures that the data is correctly structured and contains the necessary fields. The function should return `True` if the JSON object is valid according to the ... | Here is the Python code to solve the given problem in the markdown block:
```python
import json
from jsonschema import validate, ValidationError
def validate_biographical_details(json_data: dict) -> bool:
"""
Validates a JSON object against a predefined JSON schema for biographical details.
Args:
... |
evol_instruct_66k | 25,986 | Write a Python function to determine if two given expressions comprise of equivalent permutations of distinct phrases, ignoring case and punctuation. The function should return `True` if the phrases are equivalent permutations, and `False` otherwise.
The code should start with:
```python
import re
def compare_word_pe... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def compare_word_permutations(phrase1: str, phrase2: str) -> bool:
"""
Compare two phrases to determine if they comprise of equivalent permutations of distinct words, ignoring case and punctuation.
Args:
... |
evol_instruct_66k | 25,995 | Write a Python function to merge two dictionaries while maintaining their unique entries. If duplicate keys exist in both dictionaries, the value from the first dictionary should be retained. The function should avoid using pre-built methods such as `dict.update()`. Additionally, calculate the time complexity of your s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_dicts(dict1: Dict, dict2: Dict) -> Dict:
"""
Merges two dictionaries while maintaining their unique entries. If duplicate keys exist,
the value from the first dictionary is retained.
A... |
evol_instruct_66k | 25,998 | Write a Python function to sort a given list of non-negative numerical values in descending order. The function should return the sorted list. 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 non-negative numerical values in descending order.
Args:
lst (List[int]): The list of non-negative integers to b... |
evol_instruct_66k | 26,006 | Write a Python function to merge two ascending-sequenced numeric arrays into a single sorted array without using the built-in `sorted` function. The function should efficiently merge the two arrays by comparing elements from both arrays and placing them in the correct order in the resulting array.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(A: List[int], B: List[int]) -> List[int]:
"""
Merges two ascending-sequenced numeric arrays into a single sorted array.
Args:
A (List[int]): The first ascending-seque... |
evol_instruct_66k | 26,011 | Write a Python function to find the fruit(s) with the longest name(s) from a given list of fruit names. If there are multiple fruits with the same longest length, the function should return all of them. The function should be efficient and handle edge cases such as an empty list or a list with all fruit names of the sa... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_fruit_names(fruits: List[str]) -> List[str]:
"""
Returns the fruit(s) with the longest name(s) from the given list of fruit names.
Args:
fruits (List[str]): A list of fruit names... |
evol_instruct_66k | 26,012 | Write a Python function to convert a list of tuples into a dictionary where each tuple's second element is used as the key and the first element is used as the value. The function should handle lists of tuples where each tuple contains exactly two elements.
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, Tuple, Dict
def convert_tuple_list_to_dict(tuple_list: List[Tuple[str, str]]) -> Dict[str, str]:
"""
Converts a list of tuples into a dictionary where each tuple's second element is used as the key and ... |
evol_instruct_66k | 26,017 | Write a Python function to generate the first `n` element dyads from a given numerical sequence. A dyad is a tuple consisting of two consecutive elements from the sequence. The function should return a list of these dyads.
The code should start with:
```python
from typing import List, Tuple
def generate_dyads(sequenc... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def generate_dyads(sequence: List[int], n: int) -> List[Tuple[int, int]]:
"""
Generates the first n element dyads from a given numerical sequence.
Args:
sequence (List[int]): The nume... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.