source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 102,185 | Create a Python function to generate a list of 15 distinct documents representing historical monuments, each with a unique identifier and specific fields. The function should return a list of dictionaries, where each dictionary represents a monument with fields such as `_id`, `name`, `location`, `year_built`, `architec... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def generate_monument_documents() -> List[Dict[str, str]]:
"""
Generates a list of 15 distinct documents representing historical monuments.
Each document contains the following fields:
- _... |
magic_evol_110k | 102,204 | Write a Python function to calculate the difference between two numbers. The function should handle both positive and negative numbers, as well as floating-point numbers. The code should start with:
```python
def subtract_two_numbers(x: float, y: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def subtract_two_numbers(x: float, y: float) -> float:
"""
Calculate the difference between two numbers.
Args:
x (float): The first number.
y (float): The second number.
Returns:
float: The diff... |
magic_evol_110k | 102,205 | Write a Python function that implements the **Merge Sort** algorithm. The function should sort a list of integers in ascending order. Include a multi-line comment that breaks down in detail how the Merge Sort algorithm works in a generalized case. Also, highlight how and why your function would be appropriate in certai... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
"""
This function implements the Merge Sort algorithm.
The algorithm works as follows:
1. Divide the unsorted list into n sublists, each containing o... |
magic_evol_110k | 102,208 | Write a Python function to concatenate a given string with a predefined prefix and return the result. The function should accept a single string parameter and return a new string that is the concatenation of the predefined prefix "Salutations, " and the given string.
The code should start with:
```python
def concatena... | Here is the Python code to solve the given problem in the markdown block:
```python
def concatenate_with_prefix(greeting_text: str) -> str:
"""
Concatenates a given string with a predefined prefix and returns the result.
Args:
greeting_text (str): The string to be concatenated with the prefix.
... |
magic_evol_110k | 102,210 | Write a Python function to bin every 3 rows of a specific column in a DataFrame and sum the values of another column while keeping the values of the remaining columns unchanged. The function should take a DataFrame and the name of the column to be summed as input and return a new DataFrame with the desired transformati... | Here is the Python code to solve the given problem in the markdown block:
```python
import pandas as pd
from typing import List
def bin_and_sum_specific_column(df: pd.DataFrame, sum_column: str, keep_columns: List[str]) -> pd.DataFrame:
"""
Bin every 3 rows of a specific column in a DataFrame and sum the value... |
magic_evol_110k | 102,220 | 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
def calculate_cube... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_cubes(start: int, end: int) -> dict:
"""
Calculate the cube of all whole numbers within a given interval, inclusive of both endpoints.
Args:
start (int): The starting number of the interval.
en... |
magic_evol_110k | 102,225 | Write a Python function that accepts a variable number of arguments and returns the product of all the provided arguments. The function should handle both positional and keyword arguments. If no arguments are provided, the function should return 1. The code should start with:
```python
def product_of_arguments(*args, *... | Here is the Python code to solve the given problem in the markdown block:
```python
def product_of_arguments(*args, **kwargs) -> int:
"""
Calculate the product of all provided positional and keyword arguments.
Args:
*args: Variable length positional arguments.
**kwargs: Variable length keyw... |
magic_evol_110k | 102,228 | Write a Python function to reorder an array of logs according to the specified rules. Each log is a space-delimited string of words, where the first word is the identifier. The logs are categorized into letter-logs and digit-logs. The letter-logs should come before all digit-logs. The letter-logs should be sorted lexic... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reorder_log_files(logs: List[str]) -> List[str]:
"""
Reorders the logs according to the specified rules.
Args:
logs (List[str]): A list of log strings. Each log is a space-delimited stri... |
magic_evol_110k | 102,238 | Write a Python function to compute the difference between the highest and lowest values in a given list of integers. The function should handle scenarios where the list may contain duplicate values, negative numbers, or be empty. Additionally, the function should efficiently handle large lists without exceeding time an... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def compute_difference(arr: List[int]) -> int:
"""
Computes the difference between the highest and lowest values in a given list of integers.
Args:
arr (List[int]): The list of integers from... |
magic_evol_110k | 102,252 | Write a Python function to initialize a dictionary from two lists: one containing keys and the other containing corresponding values. The function should ensure that the dictionary is correctly assigned with the provided keys and values. The code should start with:
```python
from typing import List, Dict
def create_di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_dictionary(keys: List[str], values: List[any]) -> Dict[str, any]:
"""
Creates a dictionary from two lists: one containing keys and the other containing corresponding values.
Args:
... |
magic_evol_110k | 102,279 | Write a Python function to increment the values of each key in a given dictionary by a specified increment value. The function should return the modified dictionary. The code should start with:
```python
from typing import Dict
def increment_dictionary_values(d: Dict[str, int], increment: int) -> Dict[str, int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def increment_dictionary_values(d: Dict[str, int], increment: int) -> Dict[str, int]:
"""
Increment the values of each key in the given dictionary by the specified increment value.
Args:
d (... |
magic_evol_110k | 102,284 | Write a Python function to calculate the derivative of an exponential series represented by a list of coefficients. The series is defined as:
\[ \text{series}(x) = \sum_{i=0}^{n-1} \text{xs}[i] \cdot e^{x / (i+1)} \]
The derivative of this series is:
\[ \text{derivative}(x) = \sum_{i=0}^{n-1} \frac{\text{xs}[i]}{i+1} \... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def derivative(xs: List[float]) -> List[float]:
"""
Calculate the derivative of an exponential series represented by a list of coefficients.
The series is defined as:
series(x) = sum(xs[i] * e^(... |
magic_evol_110k | 102,285 | Write a Python function named `find_mode` that accepts a list of integers as an argument. The function should determine the mode, which is the integer that occurs most frequently within the list. In the event of a tie, the function should return the mode that has the greatest numerical value. The function should also h... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_mode(numbers: List[int]) -> Optional[int]:
"""
Determine the mode of a list of integers. The mode is the integer that occurs most frequently.
In case of a tie, the mode with the gr... |
magic_evol_110k | 102,313 | Write a Python function to decode a numerical string using a given decryption key. The decryption key is a dictionary where each key is a single digit string and the corresponding value is a letter. The function should convert each digit in the input string to its corresponding letter using the decryption key and retur... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def decode_string(integer_string: str, decryption_key: Dict[str, str]) -> str:
"""
Decodes a numerical string using a given decryption key.
Args:
integer_string (str): The numerical st... |
magic_evol_110k | 102,326 | Write a Python function to check if a given string input is a palindromic prime number. A palindromic number is a number that remains the same when its digits are reversed. A prime number is a number greater than 1 that has no positive divisors other than 1 and itself. The function should return `True` if the input str... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_palindromic_prime(s: str) -> bool:
"""
Checks if a given string input is a palindromic prime number.
Args:
s (str): The input string to be checked.
Returns:
bool: True if the input string represe... |
magic_evol_110k | 102,343 | Write a Python function to calculate the volume of a pyramid given its base area and height. The function should include an intermediary step where the product of the base area and height is calculated before determining the final volume. The function should return the volume as a float.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_pyramid_volume(base_area: float, height: float) -> float:
"""
Calculate the volume of a pyramid given its base area and height.
Args:
base_area (float): The area of the base of the pyramid.
hei... |
magic_evol_110k | 102,369 | Write a Python function to simulate the behavior of the `posix_fadvise` system call, which is used to provide hints to the operating system about how to manage file data in the cache. The function should take a file descriptor, offset, size, and advice type as parameters, and simulate the effect of the advice on a list... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def simulate_posix_fadvise(cache: List[int], offset: int, size: int, advice: str) -> List[int]:
"""
Simulate the behavior of the posix_fadvise system call on a list representing the file cache.
... |
magic_evol_110k | 102,379 | Write a Python function to recursively amplify each element in a multidimensional list by twice its magnitude. The function should handle lists of arbitrary depth and structure. The code should start with:
```python
from typing import List, Any
def amplify_elements(original_list: List[Any]) -> List[Any]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def amplify_elements(original_list: List[Any]) -> List[Any]:
"""
Recursively amplify each element in a multidimensional list by twice its magnitude.
Args:
original_list (List[Any]): The... |
magic_evol_110k | 102,403 | Write a Python script that counts from 0 to 100 and includes a function to check if the current count is a prime number. The function should be refactored to correct any errors and ensure it works correctly. The script should print each number along with whether it is a prime number.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(n: int) -> bool:
"""
Check if a given number is a prime number.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
if n < 2:
... |
magic_evol_110k | 102,411 | Write a Python function to generate a string of length `n` filled solely with asterisk characters (`*`). The function should be efficient and capable of handling any length `n`, including very large values. The function should also include input validation to ensure `n` is a non-negative integer.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_asterisk_string(n: int) -> str:
"""
Generates a string of length n filled with asterisk characters ('*').
Args:
n (int): The length of the string to be created. Must be a non-negative integer.
Retu... |
magic_evol_110k | 102,425 | Write a Python function to determine if the sum of squares of all elements in a given list of integers lies within a specified inclusive range. The function should return `True` if the sum of squares is within the range, and `False` otherwise.
The code should start with:
```python
from typing import List
def sum_of_s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_squares_in_range(l: List[int], min_val: int, max_val: int) -> bool:
"""
Determine if the sum of squares of all elements in the list l lies within the inclusive range of min_val and max_val.
... |
magic_evol_110k | 102,453 | Write a Python function to find the largest numerical value and its index in a list of integers without using any built-in Python functions or libraries for searching or sorting. The function should return a tuple containing the largest number and its index.
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, Tuple
def find_max_and_index(lst: List[int]) -> Tuple[int, int]:
"""
Finds the largest numerical value and its index in a list of integers.
Args:
lst (List[int]): A list of integers from wh... |
magic_evol_110k | 102,457 | Write a Python function to find the most common elements in a list of strings without using any built-in functions like `count` or `max`. If multiple elements share the highest frequency, return all of them. The function should start with:
```python
from typing import List
def find_most_common_elements(mylist: List[st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_most_common_elements(mylist: List[str]) -> List[str]:
"""
Find the most common elements in a list of strings without using built-in functions like count or max.
Args:
mylist (List[s... |
magic_evol_110k | 102,460 | Write a Python function that accepts a list of mixed data types, where some elements may be nested lists. The function should flatten all nested lists, convert the flattened list to a tuple, and then return a new tuple with all duplicates removed. The function should handle any level of nested lists and ensure that the... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any, Tuple
def flatten_and_unique(input_list: List[Any]) -> Tuple[Any, ...]:
"""
Flattens a list with potential nested lists, removes duplicates, and returns a tuple of unique elements.
Args:
... |
magic_evol_110k | 102,475 | Write a Python function to create a dictionary that counts the frequency of each unique element in a given list. The keys of the dictionary should be the unique elements, and the values should be the counts of their occurrences.
The code should start with:
```python
from typing import List, Dict
def count_frequencies... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_frequencies(lst: List[str]) -> Dict[str, int]:
"""
Counts the frequency of each unique element in the given list.
Args:
lst (List[str]): The list of elements to count frequen... |
magic_evol_110k | 102,489 | Write a Python function to process an unordered list of numbers from 0 to 10 which may contain duplicates and errors. The function should return a sorted list of unique values from 0 to 10, excluding any erroneous data. The function should handle non-numeric values gracefully.
The function should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_unique_nums(lst: List[int]) -> List[int]:
"""
Processes an unordered list of numbers from 0 to 10, which may contain duplicates and errors.
Returns a sorted list of unique values from 0 to 1... |
magic_evol_110k | 102,513 | Write a Python function to find the second largest even number in a given list of integers. The function should ignore negative numbers and return `None` if there is no second largest even number. The code should start with:
```python
from typing import List, Optional
def second_largest_even(l: List[int]) -> Optional[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def second_largest_even(l: List[int]) -> Optional[int]:
"""
Find the second largest even number in a given list of integers.
Args:
l (List[int]): The list of integers to search thr... |
magic_evol_110k | 102,518 | Write a Python function to filter out all the vowels from a given string. The function should handle both uppercase and lowercase vowels. The code should start with:
```python
def filter_vowels(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def filter_vowels(text: str) -> str:
"""
Filters out all the vowels from the given string.
Args:
text (str): The input string from which vowels are to be removed.
Returns:
str: The input string with a... |
magic_evol_110k | 102,521 | Write a Python function that takes a dictionary as input and performs two operations: first, it extracts the unique keys from the dictionary, and then it sorts these keys in descending alphabetical order. The function should return a list of these sorted unique keys.
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 Dict, List
def unique_keys_sorted(d: Dict[str, int]) -> List[str]:
"""
Extracts the unique keys from a dictionary and returns them sorted in descending alphabetical order.
Args:
d (Dict[str, int]... |
magic_evol_110k | 102,531 | Write a Python function to calculate the sum of the squares of all even numbers in a given list of integers. The function should iterate through the list, identify even numbers, square them, and then sum these squared values. The code should start with:
```python
from typing import List
def sum_of_squares_of_evens(num... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def sum_of_squares_of_evens(nums: List[int]) -> int:
"""
Calculate the sum of the squares of all even numbers in the given list.
Args:
nums (List[int]): A list of integers.
Returns:
... |
magic_evol_110k | 102,543 | Write a Python function to reverse the order of individual alphabetic characters in a given string. The function should return a new string with the characters in reverse order. The code should start with:
```python
def reverse_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(s: str) -> str:
"""
Reverses the order of individual alphabetic characters in the given string.
Args:
s (str): The input string to be reversed.
Returns:
str: A new string with the cha... |
magic_evol_110k | 102,547 | Write a Python function to perform division of two integers without using the division operator '/', without using any loops, and without using the math library. The function should handle scenarios where the divisor is zero by returning `None`. The function should also handle negative numbers correctly by considering ... | Here is the Python code to solve the given problem in the markdown block:
```python
def divide(dividend: int, divisor: int) -> int:
"""
Perform division of two integers without using the division operator '/',
without using any loops, and without using the math library. If the
divisor is zero, then ret... |
magic_evol_110k | 102,557 | Write a Python function to sort a given list of integers in descending order. The function should return the sorted list. The code should start with:
```python
from typing import List
def sort_descending(sequence: 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(sequence: List[int]) -> List[int]:
"""
Sorts a given list of integers in descending order.
Args:
sequence (List[int]): The list of integers to be sorted.
Returns:
... |
magic_evol_110k | 102,566 | Write a Python function to merge two nested dictionaries without losing any data. If there are conflicting keys at the same level, the value from the second dictionary should overwrite the value from the first dictionary. The function should handle nested dictionaries recursively.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_nested_dicts(dict1: Dict, dict2: Dict) -> Dict:
"""
Merge two nested dictionaries without losing any data. If there are conflicting keys at the same level,
the value from the second diction... |
magic_evol_110k | 102,570 | Write a Python function to detect if a given string is a palindrome. A palindrome is a string that reads the same forwards and backwards. The function should ignore case and non-alphanumeric characters when checking for palindrome.
The code should start with:
```python
def is_palindrome_ignore_case_and_non_alnum(s: st... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_palindrome_ignore_case_and_non_alnum(s: str) -> bool:
"""
Determines if a given string is a palindrome, ignoring case and non-alphanumeric characters.
Args:
s (str): The input string to check for palindrome.
... |
magic_evol_110k | 102,576 | Write a Python function to capitalize the first letter of each word in a given input string while keeping the rest of the characters unchanged. The function should handle various edge cases, such as empty strings, strings with multiple spaces, and strings with punctuation.
The code should start with:
```python
def cap... | Here is the Python code to solve the given problem in the markdown block:
```python
def capitalize_words(sentence: str) -> str:
"""
Capitalizes the first letter of each word in the given sentence while keeping the rest of the characters unchanged.
Args:
sentence (str): The input string to be proces... |
magic_evol_110k | 102,577 | Write a Python function to calculate the degree measurement of an angle given the fraction of a full circular rotation. The function should take a fraction as input and return the corresponding degree measurement. The code should start with:
```python
def calculate_angle(fraction_of_rotation: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_angle(fraction_of_rotation: float) -> float:
"""
Calculate the degree measurement of an angle given the fraction of a full circular rotation.
Args:
fraction_of_rotation (float): The fraction of a full ... |
magic_evol_110k | 102,587 | Write a Python function to determine the maximum length of a continuous subarray consisting solely of 1s in a given binary array `A`, after changing at most `K` values from 0 to 1. The function should start with:
```python
from typing import List
def max_consecutive_ones_iii(A: List[int], K: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_consecutive_ones_iii(A: List[int], K: int) -> int:
"""
Determine the maximum length of a continuous subarray consisting solely of 1s
after changing at most K values from 0 to 1 in the given b... |
magic_evol_110k | 102,595 | Write a Python function to multiply each item in a given tuple by a specified factor and return the result as a list. The function should use list comprehension for this operation. The code should start with:
```python
from typing import Tuple, List
def multiply_tuple_items(input_tuple: Tuple[int], factor: int) -> Lis... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import Tuple, List
def multiply_tuple_items(input_tuple: Tuple[int], factor: int) -> List[int]:
"""
Multiplies each item in the given tuple by the specified factor and returns the result as a list.
Args:
... |
magic_evol_110k | 102,604 | Write a Python function to convert a binary string to its corresponding octal string representation. The function should accept a binary numeral string as input and return a string representing its octal form. The code should start with:
```python
def binary_to_octal(binary_str: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_octal(binary_str: str) -> str:
"""
Converts a binary string to its corresponding octal string representation.
Args:
binary_str (str): The binary numeral string to be converted.
Returns:
st... |
magic_evol_110k | 102,617 | Write a Python function to simulate the behavior of a Unix Shell script that echoes the argument passed to it in the form of a positional parameter. The function should accept a list of strings as arguments and return a string that concatenates all the arguments with a space separator, similar to how the Unix `echo` co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def unix_echo(args: List[str]) -> str:
"""
Simulates the behavior of a Unix Shell script that echoes the argument passed to it in the form of a positional parameter.
Args:
args (List[str]): ... |
magic_evol_110k | 102,618 | Write a Python function to implement the bottom-up cut rod algorithm. This algorithm is used to determine the maximum revenue that can be obtained by cutting up a rod and selling the pieces. Given an array `p` of length `n+1`, where `p[i]` specifies the price of a rod of length `i` for `i=0,1,..,n`. The function should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def cut_rod(p: List[int], n: int) -> Tuple[int, List[int]]:
"""
Calculate the maximum revenue obtainable by cutting a rod of length n
and selling the pieces, along with the lengths of the piec... |
magic_evol_110k | 102,630 | Write a Python function to sort a list in ascending order without using any built-in `sort()` method or sorting function from a library. The function should handle lists containing both numeric values (integers and floats) and string values. If the input list contains both numbers and strings, the function should retur... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union, Tuple
def custom_sort_list_mixed_types(my_list: List[Union[int, float, str]]) -> Tuple[List[Union[int, float]], List[str]]:
"""
Sorts a list containing both numeric values (integers and floats) a... |
magic_evol_110k | 102,644 | Write a Python function to perform basic arithmetic operations and advanced mathematical operations on two numbers. The function should handle errors gracefully, such as division by zero or invalid operations like finding the square root or logarithm of a negative number. Additionally, the function should maintain a hi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import math
def calculator(operation: str, *args) -> Tuple[float, List[Tuple[str, float, float, float]]]:
"""
Perform basic arithmetic and advanced mathematical operations on two numbers.
Hand... |
magic_evol_110k | 102,645 | Write a Python function to calculate the disparity between the maximum and minimum numerical values present in a provided list of lists. The function should handle the following scenarios:
1. Ignore empty sublists.
2. Ignore non-numerical values (e.g., strings).
3. Return a specific message if no numerical values are f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def calculate_disparity(lst: List[List[Union[int, float, str]]]) -> Union[float, str]:
"""
Calculate the disparity between the maximum and minimum numerical values in a list of lists.
Args:
... |
magic_evol_110k | 102,658 | Write a Python function to efficiently segregate elements of a given list into nested lists, each containing elements of a specific, predetermined length. The function should handle cases where the length of the input list is not perfectly divisible by the predetermined length, ensuring that the last nested list may co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def segregate_elements(arr: List[int], sz: int) -> List[List[int]]:
"""
Segregates elements of a given list into nested lists, each containing elements of a specific, predetermined length.
Args:
... |
magic_evol_110k | 102,686 | Write a Python function to calculate the absolute difference between two numbers `c` and `d`. The function should be optimized, free of superfluous white spaces and redundant semi-colons, and should return the absolute difference between the two numbers. The function should start with:
```python
def calculate_absolute_... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_absolute_difference(c: int, d: int) -> int:
"""
Calculate the absolute difference between two numbers c and d.
Args:
c (int): The first number.
d (int): The second number.
Returns:
... |
magic_evol_110k | 102,708 | Write a Python function to traverse through each individual component of a given tuple and return a list of these components. The function should handle tuples of any length, including empty tuples. The code should start with:
```python
from typing import List, Tuple
def traverse_tuple(tup: Tuple[int]) -> List[int]:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def traverse_tuple(tup: Tuple[int]) -> List[int]:
"""
Traverse through each individual component of a given tuple and return a list of these components.
Args:
tup (Tuple[int]): The tu... |
magic_evol_110k | 102,713 | Write a Python function to convert a given phrase into a format following the snake_case convention. The function should replace spaces with underscores and convert all characters to lower case. The code should start with:
```python
def convert_to_snake_case(phrase: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_snake_case(phrase: str) -> str:
"""
Converts a given phrase into a format following the snake_case convention.
Args:
phrase (str): The input phrase to be converted.
Returns:
str: The phra... |
magic_evol_110k | 102,714 | Write a Python function to find the largest prime factor of a given number. The function should efficiently determine the largest prime factor by iteratively dividing the number by its smallest prime factor until only the largest prime factor remains.
The code should start with:
```python
def largest_prime_factor(n: i... | Here is the Python code to solve the given problem in the markdown block:
```python
def largest_prime_factor(n: int) -> int:
"""
Find the largest prime factor of a given number.
Args:
n (int): The number for which to find the largest prime factor.
Returns:
int: The largest prime factor... |
magic_evol_110k | 102,729 | 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... |
magic_evol_110k | 102,735 | Write a Python function to find both the smallest and the largest numbers in a given list of integers. The function should return a tuple containing the smallest number and the largest number in the list. If the list is empty, the function should return `None`.
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, Optional, Tuple
def find_min_max(lst: List[int]) -> Optional[Tuple[int, int]]:
"""
Find the smallest and largest numbers in a given list of integers.
Args:
lst (List[int]): The list of inte... |
magic_evol_110k | 102,736 | Write a Python function that processes a tuple of numeric values and returns the sum and average of these values. The function should handle any unexpected errors gracefully and return `None` for both the sum and average in case of an error. The function should also print each value in the tuple as it processes them. T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Union
def process_tuple(input_tuple: Tuple[Union[int, float], ...]) -> Tuple[Union[int, float, None], Union[float, None]]:
"""
Processes a tuple of numeric values, calculates the sum and average, and h... |
magic_evol_110k | 102,752 | Write a Python function to calculate the exponential value of two integers, `x` and `y`, and return the result. The function should correctly handle the calculation without any logical errors. The code should start with:
```python
def exponential_function(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def exponential_function(x: int, y: int) -> int:
"""
Calculate the exponential value of x raised to the power of y.
Args:
x (int): The base integer.
y (int): The exponent integer.
Returns:
int: ... |
magic_evol_110k | 102,754 | Write a Python function to find and return all prime numbers that are also odd within a given range `[start, end]` inclusively. Additionally, write a helper function to verify if a number is both prime and odd. The code should start with:
```python
from typing import List
def find_prime_and_odd_numbers(start: int, end... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime_and_odd(n: int) -> bool:
"""
Check if a number is both prime and odd.
Args:
n (int): The number to check.
Returns:
bool: True if the number is both prime and odd, F... |
magic_evol_110k | 102,755 | Write a Python function to traverse a multi-layered dictionary and return the aggregate sum of all numerical values within. The dictionary can have an arbitrary number of nested dictionaries. The function should handle both integers and floating-point numbers.
The code should start with:
```python
from typing import U... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union, Dict
def sum_numerical_values(dictionary: Dict[str, Union[int, float, Dict]]) -> Union[int, float]:
"""
Traverse a multi-layered dictionary and return the sum of all numerical values within.
Args:... |
magic_evol_110k | 102,756 | Write a Python function to count the occurrences of each sublist in a given list of lists. The sublists can contain either integers or dictionaries. The function should return a dictionary where the keys are the unique sublists (converted to tuples for lists and frozensets for dictionaries) and the values are the count... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Union
from collections import Counter
def count_sublists(list1: List[Union[List[int], Dict[str, int]]]) -> Dict[Union[tuple, frozenset], int]:
"""
Count the occurrences of each sublist in a given ... |
magic_evol_110k | 102,761 | Write a Python function to implement the bubble sort algorithm with an optimization that allows the function to terminate early if the array is already sorted. The function should return the sorted array.
The code should start with:
```python
from typing import List
def optimized_bubble_sort(arr: List[int]) -> List[i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def optimized_bubble_sort(arr: List[int]) -> List[int]:
"""
Sorts the given list using the bubble sort algorithm with an optimization
that allows the function to terminate early if the array is alrea... |
magic_evol_110k | 102,764 | Write a Python function to evaluate whether a list of numbers are prime or not, and return the count of prime and non-prime numbers, the largest prime number, and the numbers sorted in ascending order. The function should handle errors and edge cases such as negative numbers, zero, and non-numeric inputs.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def is_prime(n: int) -> bool:
"""
Helper function to check if a number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False oth... |
magic_evol_110k | 102,771 | 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 binary search to efficiently find the insertion index.
The code should start with:
```python
from typing import List
def find_insertio... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import bisect
def find_insertion_index(array: List[int], num: int) -> int:
"""
Determines the appropriate index at which the specified element should be inserted into a sorted array to maintain the ascen... |
magic_evol_110k | 102,794 | Write a Python function to extrapolate and return a list of specific data values from a given cosmo-geographical dictionary. The dictionary contains key celestial facts such as the planet's name, distance from the sun, and orbital period. The function should handle cases where the dictionary might not contain all the e... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Optional
def extrapolate_cosmo_data(cosmo_dict: Dict[str, float], keys: List[str]) -> List[Optional[float]]:
"""
Extrapolates specific data values from a given cosmo-geographical dictionary.
... |
magic_evol_110k | 102,798 | Write a Python function called `multiply_elements` that takes in two lists of numbers as inputs and returns a list of their products. The function should adhere to the following constraints:
1. If the input is not a list or if it contains elements which are not numbers, the function should raise a `TypeError`.
2. If th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_elements(list1: List[float], list2: List[float]) -> List[float]:
"""
Multiplies corresponding elements of two lists and returns a list of their products as floating point numbers.
Args:... |
magic_evol_110k | 102,800 | Write a Python function that calculates and yields the minimum and maximum integers from a given list of numbers. The function should handle lists of any length, including empty lists, and should yield the results one at a time. If the list is empty, the function should yield `None` for both the minimum and maximum val... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Iterator
def find_min_max(numbers: List[int]) -> Iterator[int]:
"""
Yields the minimum and maximum integers from a given list of numbers.
Args:
numbers (List[int]): The list of integers fro... |
magic_evol_110k | 102,804 | Write a Python function to reverse a given string using a procedural approach. The function should take a string as input and return the reversed string. The code should start with:
```python
def reverse_string(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(input_string: str) -> str:
"""
Reverses the given input string using a procedural approach.
Args:
input_string (str): The string to be reversed.
Returns:
str: The reversed string.
... |
magic_evol_110k | 102,811 | Write a Python function to count the occurrences of a given element in a list efficiently. The function should handle large datasets optimally and should be designed to avoid common pitfalls in the provided code snippet. The code should start with:
```python
from typing import List
def count_occurrences(lst: List[int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_occurrences(lst: List[int], ele: int) -> int:
"""
Counts the occurrences of a given element in a list efficiently.
Args:
lst (List[int]): The list of integers in which to count occ... |
magic_evol_110k | 102,813 | Write a Python function to generate all possible subsets of a given set. The set is represented as a list of unique elements. The function should return a list of lists, where each inner list represents a subset. The order of subsets or elements within a subset does not matter.
The code should start with:
```python
fr... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
from itertools import chain, combinations
def generate_subsets(input_set: List[int]) -> List[List[int]]:
"""
Generate all possible subsets of a given set.
Args:
input_set (List[int]): The ... |
magic_evol_110k | 102,816 | Write a Python function to shuffle a given list in place and return the shuffled list. The function should use the Fisher-Yates (Knuth) shuffle algorithm to ensure a uniform random permutation of the list. The code should start with:
```python
from typing import List
def shuffle_list(input_list: List[int]) -> List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def shuffle_list(input_list: List[int]) -> List[int]:
"""
Shuffles the given list in place using the Fisher-Yates (Knuth) shuffle algorithm.
Args:
input_list (List[int]): The l... |
magic_evol_110k | 102,820 | Write a Python function to identify prime numbers from a given list of integers and return a new list containing only the unique prime numbers, sorted in ascending order. The function should start with:
```python
from typing import List
def unique_prime_numbers(numbers: List[int]) -> List[int]:
```
| 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.
... |
magic_evol_110k | 102,867 | Write a Python function to count the number of odd numbers within a given range from 1 to n (inclusive). The function should handle edge cases such as when n is 0 or negative. The code should start with:
```python
def count_odd_numbers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_odd_numbers(n: int) -> int:
"""
Counts the number of odd numbers within the range from 1 to n (inclusive).
Args:
n (int): The upper limit of the range (inclusive).
Returns:
int: The number of ... |
magic_evol_110k | 102,868 | Write a Python function to create a nested dictionary from two lists of tuples, where each tuple in the first list represents a key pair (main key and subkey), and each tuple in the second list represents a value pair (main value and subvalue). The function should map each key pair to the corresponding value pair in th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def create_nested_dict(keys: List[Tuple[str, str]], values: List[Tuple[str, str]]) -> Dict[str, Dict[str, Tuple[str, str]]]:
"""
Creates a nested dictionary from two lists of tuples.
Ar... |
magic_evol_110k | 102,890 | Write a Python function to perform element-wise multiplication of two 1D arrays. If the arrays are not of the same length, the function should handle this scenario by either truncating the longer array to the length of the shorter one or by padding the shorter array with zeros to match the length of the longer one. The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def element_wise_multiplication(arr1: List[int], arr2: List[int], mode: str = 'truncate') -> Union[List[int], str]:
"""
Perform element-wise multiplication of two 1D arrays.
Args:
arr... |
magic_evol_110k | 102,893 | Write a Python function to clone a list along with its nested elements. The list can contain multiple data types including integers, strings, floats, and nested lists. The function should handle this complexity and perfectly duplicate the given list. Additionally, provide a piece of erroneous code for the problem and e... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
import copy
def clone_list(original_list: List[Any]) -> List[Any]:
"""
Clones a list along with its nested elements.
Args:
original_list (List[Any]): The original list to be cloned.
... |
magic_evol_110k | 102,911 | Write a Python function to extract all valid email addresses from a given text using regular expressions. The function should be able to handle various formats of email addresses and return a list of all found email addresses.
The code should start with:
```python
import re
from typing import List
def extract_emails(... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def extract_emails(text: str) -> List[str]:
"""
Extracts all valid email addresses from the given text using regular expressions.
Args:
text (str): The text from which to extract e... |
magic_evol_110k | 102,919 | Write a Python function to convert a given decimal number to its hexadecimal representation and return the hexadecimal value as a string. The function should handle both positive and negative decimal numbers. The code should start with:
```python
def decimal_to_hex(decimal_number: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def decimal_to_hex(decimal_number: int) -> str:
"""
Convert a given decimal number to its hexadecimal representation.
Args:
decimal_number (int): The decimal number to be converted.
Returns:
str: The he... |
magic_evol_110k | 102,922 | Write a Python function to calculate the product of two integers `x` and `y` using a recursive approach. The function should handle both positive and negative integers. The code should start with:
```python
def recursive_multiply(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def recursive_multiply(x: int, y: int) -> int:
"""
Calculate the product of two integers x and y using a recursive approach.
Args:
x (int): The first integer.
y (int): The second integer.
Returns:
... |
magic_evol_110k | 102,925 | Write a Python function that verifies if a list of numerical values follows a strictly descending sequence, meaning no two consecutive numbers are the same. The function should handle exceptions for non-numeric inputs, empty lists, and lists with a single element. The function should return `False` for empty lists and ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def check_strictly_descending_order(lst: List[float]) -> bool:
"""
Verifies if a list of numerical values follows a strictly descending sequence.
Args:
lst (List[float]): The list of numeric... |
magic_evol_110k | 102,943 | Write a Python function to find the longest common subsequence (LCS) among three given strings. The function should return the LCS as a string. The code should start with:
```python
def longest_common_subsequence_of_three(s1: str, s2: str, s3: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def longest_common_subsequence_of_three(s1: str, s2: str, s3: str) -> str:
"""
Find the longest common subsequence among three given strings.
Args:
s1 (str): The first string.
s2 (str): The second string.
... |
magic_evol_110k | 102,950 | Write a Python function to perform simple arithmetic operations on two given numbers. The function should support addition, subtraction, multiplication, and division. The operation to be performed should be specified as a string ('add', 'subtract', 'multiply', 'divide'). The function should handle division by zero by r... | Here is the Python code to solve the given problem in the markdown block:
```python
def arithmetic_operations(num1: float, num2: float, operation: str) -> float or str:
"""
Perform simple arithmetic operations on two given numbers.
Args:
num1 (float): The first number.
num2 (float): The sec... |
magic_evol_110k | 102,951 | Write a Python function to systematically replace all vowel characters (both uppercase and lowercase) within a provided string of text with the underscore symbol (`_`). The function should handle any string input and return the modified string.
The code should start with:
```python
def replace_vowels_with_underscore(s... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_vowels_with_underscore(string: str) -> str:
"""
Replace all vowel characters (both uppercase and lowercase) in the given string with underscores.
Args:
string (str): The input string in which vowels need... |
magic_evol_110k | 102,954 | Write a Python function to generate the first `n` even integers starting from 2. The function should return a list of these integers. The code should start with:
```python
from typing import List
def first_n_even_numbers(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def first_n_even_numbers(n: int) -> List[int]:
"""
Generate the first n even integers starting from 2.
Args:
n (int): The number of even integers to generate.
Returns:
List[int]... |
magic_evol_110k | 102,962 | Write a Python function to generate and print an asterisk-based pyramid structure with a specified number of rows. The pyramid should be centered, with each row containing an odd number of asterisks, and the number of asterisks in each row should increase by two as you move down the pyramid.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_pyramid(rows: int):
"""
Prints an asterisk-based pyramid structure with the specified number of rows.
Args:
rows (int): The number of rows in the pyramid.
Returns:
None: This function only pri... |
magic_evol_110k | 102,994 | Write a Python function to calculate the percentage difference in the speed-to-cost ratio between a contemporary computing system and an older computing system, given that the older system functioned at half the speed of the contemporary system and amounted to twice the current cost.
The function should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_speed_cost_ratio_difference(contemporary_speed: float, contemporary_price: float) -> float:
"""
Calculate the percentage difference in the speed-to-cost ratio between a contemporary computing system
and an olde... |
magic_evol_110k | 102,995 | Write a Python function to subtract two given two-dimensional matrices. The matrices are represented as lists of lists, where each inner list represents a row of the matrix. The function should ensure that the matrices are of the same dimensions before performing the subtraction. If the matrices are not of the same dim... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def subtract_matrices(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[List[int]]:
"""
Subtracts two given two-dimensional matrices.
Args:
matrix1 (List[List[int]]): The first mat... |
magic_evol_110k | 102,996 | Write a Python function to convert a list of strings representing numbers into a list of integers. The function should handle both positive and negative numbers, as well as numbers with decimal points. If a string cannot be converted to an integer (e.g., it contains non-numeric characters or is a floating-point number)... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def convert_strings_to_integers(strings: List[str]) -> List[Union[int, None]]:
"""
Converts a list of strings representing numbers into a list of integers.
If a string cannot be converted to a... |
magic_evol_110k | 103,008 | Write a Python function to generate a 5x5 NumPy 2D array filled with random decimal numbers within a specified closed interval. The function should allow the user to specify the lower and upper bounds of the interval. The code should start with:
```python
import numpy as np
def generate_random_array(lower_bound: float... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def generate_random_array(lower_bound: float, upper_bound: float) -> np.ndarray:
"""
Generates a 5x5 NumPy 2D array filled with random decimal numbers within a specified closed interval.
Args:
lo... |
magic_evol_110k | 103,018 | Write a Python function to find the smallest prime number in a given list of integers. If no prime numbers are found, the function should return `None`. The function should be efficient and handle edge cases such as an empty list or a list with no prime numbers.
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, Optional
import math
def find_smallest_prime(lst: List[int]) -> Optional[int]:
"""
Finds the smallest prime number in a given list of integers.
Args:
lst (List[int]): The list of integers t... |
magic_evol_110k | 103,020 | Write a Python function to determine the maximum number of fruits that can be harvested from a linear orchard, given the constraint that each basket can only contain one type of fruit. The function should start with:
```python
from typing import List
def max_fruits_harvested(tree: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import defaultdict
def max_fruits_harvested(tree: List[int]) -> int:
"""
Calculate the maximum number of fruits that can be harvested from a linear orchard
with the constraint that e... |
magic_evol_110k | 103,026 | Write a Python function to convert a list of integers into a list of floats. The function should take a list of integers as input and return a new list where each integer has been converted to a float. The function should handle an empty list by returning an empty list. 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 convert_integers_to_floats(integers: List[int]) -> List[float]:
"""
Converts a list of integers into a list of floats.
Args:
integers (List[int]): A list of integers to be converted.
... |
magic_evol_110k | 103,035 | Write a Python function to compute an array where each element at index `i` is the product of all the elements of the input array except the element at index `i`. The function should handle arrays of integers and should be efficient in terms of both time and space complexity. 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
def product_except_self(nums: List[int]) -> List[int]:
"""
Compute an array where each element at index i is the product of all elements
of the input array except the element at index i.
Args:
... |
magic_evol_110k | 103,042 | Write a Python function to find the shortest contiguous sequence in a given series of numbers that contains every unique numeric digit. If multiple such sequences exist, prioritize the sequence that contains an equal number of odd and even digits. The sequence should always start from the smallest digit to the largest ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import collections
def find_shortest_balanced_subsequence(input_numbers: str) -> str:
"""
Finds the shortest contiguous sequence in a given series of numbers that contains every unique numeric dig... |
magic_evol_110k | 103,050 | Write a Python function to find the index of a target word in a list of words and return the index along with the word. If the target word is not found, return `None`. The function should be efficient and handle cases where the list is empty or the target word is not present.
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, Tuple, Optional
def find_word_index(words: List[str], target: str) -> Optional[Tuple[int, str]]:
"""
Find the index of a target word in a list of words and return the index along with the word.
If t... |
magic_evol_110k | 103,052 | Write a Python function to reorder the items in a dictionary based on a given permutation of indices. The function should take a dictionary and a list of indices that represent the new order of the dictionary items. The function should return a new dictionary with the items reordered according to the given permutation.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def reorder_dictionary(original_dict: Dict[str, int], permutation: List[int]) -> Dict[str, int]:
"""
Reorders the items in the original dictionary based on the given permutation of indices.
Ar... |
magic_evol_110k | 103,066 | Write a Python function to determine if two given strings are anagrams of each other. 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 function should ignore spaces and be case-insensitive.
The code should start w... | 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 strings are anagrams of each other.
Args:
str1 (str): The first string to compare.
str2 (str): The second string to compare.
Returns:... |
magic_evol_110k | 103,067 | Write a Python function to construct an SQL query that retrieves specific columns from a given table in a relational database. The function should allow the user to specify the table name and a list of columns to be selected. The function should return the constructed SQL query as a string.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def construct_sql_query(table_name: str, columns: List[str]) -> str:
"""
Constructs an SQL query to select specific columns from a given table.
Args:
table_name (str): The name of the table ... |
magic_evol_110k | 103,070 | Write a Python function to filter out non-integer values from a given list and return a list of unique integer values sorted in ascending order. The function should handle and ignore non-integer values without terminating the program. The code should start with:
```python
from typing import List
def filter_and_sort_un... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_and_sort_unique_integers(input_list: List[int]) -> List[int]:
"""
Filters out non-integer values from the input list and returns a list of unique integer values sorted in ascending order.
... |
magic_evol_110k | 103,075 | Write a Python function to compute the element-wise product of two lists. The function should take two lists of integers as input and return a new list where each element is the product of the corresponding elements from the input lists. If the input lists are of different lengths, the function should raise a `ValueErr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def element_wise_product(lst1: List[int], lst2: List[int]) -> List[int]:
"""
Computes the element-wise product of two lists.
Args:
lst1 (List[int]): The first list of integers.
lst2 ... |
magic_evol_110k | 103,085 | Write a Python function to shuffle a given list of numbers in place without using the built-in `random.shuffle` function. The function should return the shuffled list. The code should start with:
```python
from typing import List
import random
def shuffle_list(numbers: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import random
def shuffle_list(numbers: List[int]) -> List[int]:
"""
Shuffles the given list of numbers in place using the Fisher-Yates shuffle algorithm.
Args:
numbers (List[int]): The li... |
magic_evol_110k | 103,089 | Write a Python function to check if a string consists of only alphabetic characters and if these characters exist in a predefined list. For each character in the predefined list, count the number of occurrences in the string. The function should handle potential errors and exceptions that might occur during the executi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def check_and_count_alphabets(s: str, alphabets: List[str]) -> Dict[str, int]:
"""
Check if a string consists of only alphabetic characters and count the occurrences of each character in a predefin... |
magic_evol_110k | 103,104 | Write a Python function to add two integers using bitwise operations. The function should take two integer arguments and return their sum. The function should handle both positive and negative integers. The code should start with:
```python
def add_numbers(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def add_numbers(x: int, y: int) -> int:
"""
Adds two integers using bitwise operations.
Args:
x (int): The first integer.
y (int): The second integer.
Returns:
int: The sum of the two integers.
... |
magic_evol_110k | 103,122 | Write a Python function to manipulate a given string by replacing all exclamation marks (`!`) with periods (`.`). The function should handle potential exceptions and ensure that the modified string is printed correctly. The code should start with:
```python
def replace_exclamation_with_period(input_str: str) -> str:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_exclamation_with_period(input_str: str) -> str:
"""
Replaces all exclamation marks in the input string with periods.
Args:
input_str (str): The input string to be modified.
Returns:
str: The... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.