source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 97,036 | Write a Python function to output the distinct elements of a given list of strings, along with their respective indices. The function should use recursion instead of a simple loop to iterate through the list. The function should also handle potential exceptions efficiently and effectively.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def distinct_elements_with_indices(strings: List[str]) -> List[Tuple[str, int]]:
"""
Returns a list of distinct elements from the given list of strings along with their respective indices.
Ar... |
magic_evol_110k | 97,039 | Write a Python function to compute the Manhattan distance between two points in a multi-dimensional space. The function should accept two tuples representing the coordinates of the points and return the Manhattan distance between them. The Manhattan distance is defined as the sum of the absolute differences of their Ca... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def manhattan_distance(pointA: Tuple[int, ...], pointB: Tuple[int, ...]) -> int:
"""
Compute the Manhattan distance between two points in a multi-dimensional space.
Args:
pointA (Tuple[int,... |
magic_evol_110k | 97,059 | Write a Python function to merge two four-dimensional arrays of integers in alternating order. The elements from both arrays should be separated by a comma and a space. The function should handle cases where the arrays have different shapes by appending the remaining elements from the larger array at the end. The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_4d_arrays(array1: List[List[List[List[int]]]], array2: List[List[List[List[int]]]]) -> str:
"""
Merges two four-dimensional arrays of integers in alternating order.
Args:
array1 (L... |
magic_evol_110k | 97,079 | Write a Python function to find and return a list of all non-even integers within a given inclusive range `[start, end]`, along with their squares. The function should handle cases where `start` and `end` are not necessarily 1 and 10, respectively. The function should start with:
```python
from typing import List, Tupl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_non_even_with_squares(start: int, end: int) -> List[Tuple[int, int]]:
"""
Find all non-even integers within the inclusive range [start, end] and return a list of tuples containing each no... |
magic_evol_110k | 97,081 | Write a Python function to swap the positions of two elements in an array, ensuring that the function can handle an array of any length and data type. The function should also be able to handle cases where the array contains duplicate values. The function should raise an `IndexError` if either of the positions is out o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def swap_positions(arr: List[Any], position1: int, position2: int) -> List[Any]:
"""
Swap the positions of two elements in an array.
Args:
arr (List[Any]): The array in which to swap el... |
magic_evol_110k | 97,083 | Write a Python function to count the number of digits in a given string and return the frequency of each digit in the string. The function should handle any string input, including those with non-digit characters. The code should start with:
```python
from typing import Dict, Tuple
def count_digits_and_frequency(s: st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def count_digits_and_frequency(s: str) -> Tuple[int, Dict[str, int]]:
"""
Counts the number of digits in a given string and returns the frequency of each digit.
Args:
s (str): The inp... |
magic_evol_110k | 97,095 | Write a Python function to validate email addresses based on domain-specific requirements using regular expressions. The function should check if the email address is valid and meets the specific conditions for certain domains. If the domain is 'mail.com', the local part of the email must have at least 3 characters. If... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_email(email: str) -> str:
"""
Validates an email address based on domain-specific requirements.
Args:
email (str): The email address to validate.
Returns:
str: A string indicatin... |
magic_evol_110k | 97,098 | Write a Python function to convert a list of key-value pairs into a dictionary. The input list can be in one of the following forms:
1. A flat list where keys and values alternate, e.g., `['apple', 1, 'banana', 2]`.
2. A list of lists where each sublist contains exactly two elements, representing a key-value pair, e.g.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def convert_to_dict(lst: List[Union[str, int]]) -> dict:
"""
Converts a list of key-value pairs into a dictionary.
The input list can be in one of the following forms:
1. A flat list wher... |
magic_evol_110k | 97,118 | Write a Python function to convert an integer into its binary representation without using the inbuilt conversion functions. The function should also handle negative integers by converting them into their 2's complement binary form. The function should start with:
```python
def int_to_binary(num: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def int_to_binary(num: int) -> str:
"""
Converts an integer into its binary representation without using inbuilt conversion functions.
For negative integers, it returns the 2's complement binary form.
Args:
num ... |
magic_evol_110k | 97,120 | Write a Python function to remove duplicates from a list of strings while maintaining the original order of appearance of the unique elements. The function should not use any built-in Python functions or libraries specifically designed for handling duplicates, such as `set()`, `dict.fromkeys()`, or `collections.Ordered... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_maintain_order(strings: List[str]) -> List[str]:
"""
Removes duplicates from a list of strings while maintaining the original order of appearance.
Args:
strings (List[s... |
magic_evol_110k | 97,141 | Write a Python function to create a reversed copy of a given list. The function should not modify the original list and should return a new list that is the reverse of the input list. The code should start with:
```python
from typing import List
def reverse_list(input_list: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_list(input_list: List[int]) -> List[int]:
"""
Creates a reversed copy of the given list.
Args:
input_list (List[int]): The list to be reversed.
Returns:
List[int]: A... |
magic_evol_110k | 97,181 | Write a Python function to generate a list of prime numbers up to a specified value `n`. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The function should efficiently determine whether each number in the range is prime and collect all prime numbers up to `n`.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_primes(n: int) -> List[int]:
"""
Generate a list of prime numbers up to the specified value `n`.
Args:
n (int): The upper limit for generating prime numbers.
Returns:
... |
magic_evol_110k | 97,197 | Write a Python function to determine the type of a given input and check if it is a multidimensional list or dictionary. The function should classify the input as one of the following: boolean, list, dictionary, or other. If the input is a list or dictionary, the function should also determine if it is multidimensional... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union, List, Dict
def classify_and_check_multidimensional(input_data: Union[bool, List, Dict, int, str]) -> str:
"""
Classify the type of the input and check if it is a multidimensional list or dictionary.
... |
magic_evol_110k | 97,199 | Write a Python function to create a frequency map of characters in a given string, treating uppercase and lowercase letters as equivalent, and including all characters (letters, digits, and symbols). The function should return a dictionary where the keys are characters and the values are their respective frequencies in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def superior_frequency_map(test: str) -> Dict[str, int]:
"""
Create a frequency map of characters in a given string, treating uppercase and lowercase letters as equivalent.
Args:
test (str):... |
magic_evol_110k | 97,205 | Write a Python function to generate a three-dimensional array of a specified shape, where each entry is populated with a randomly selected float within a given inclusive range. The function should utilize the Numpy library for efficient array operations and random number generation.
The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def generate_random_array(shape: tuple, low: float, high: float) -> np.ndarray:
"""
Generates a three-dimensional array of the specified shape, where each entry is a randomly selected float within the given i... |
magic_evol_110k | 97,212 | Write a Python function to swap the values of two numerical variables using an intervening temporary variable. The function should take two parameters, `a` and `b`, and return a tuple containing the swapped values of `a` and `b`. The code should start with:
```python
def swap_values(a: int, b: int) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def swap_values(a: int, b: int) -> tuple:
"""
Swaps the values of two numerical variables using an intervening temporary variable.
Args:
a (int): The first numerical variable.
b (int): The second numerical v... |
magic_evol_110k | 97,213 | Write a Python function to compute the factorial of a given natural number `x` and return the result. The function should handle edge cases such as `x` being 0 or a negative number by returning 1, as the factorial of 0 is defined as 1, and factorials are not defined for negative numbers.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(x: int) -> int:
"""
Compute the factorial of a given natural number x.
The factorial of a non-negative integer x is the product of all positive integers less than or equal to x.
The factorial of 0 is defin... |
magic_evol_110k | 97,254 | Write a Python function to efficiently compute the nth Fibonacci number using dynamic programming (memoization or bottom-up approach) and another function to generate and print the first 'n' Fibonacci numbers. Ensure that the functions handle invalid inputs (e.g., negative numbers or non-integer types) by raising appro... | Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci(n: int) -> int:
"""
Compute the nth Fibonacci number using dynamic programming (bottom-up approach).
Args:
n (int): The position in the Fibonacci sequence to compute.
Returns:
int: The nth... |
magic_evol_110k | 97,255 | Write a Python function to normalize a given 2D numpy array so that all values range between 0 and 1. The function should handle edge cases where all values in the array are zero or when the maximum and minimum values are the same. The code should start with:
```python
import numpy as np
def normalize_array(arr: np.nd... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def normalize_array(arr: np.ndarray) -> np.ndarray:
"""
Normalize a given 2D numpy array so that all values range between 0 and 1.
Args:
arr (np.ndarray): A 2D numpy array to be normalized.
... |
magic_evol_110k | 97,268 | Write a Python function to return only the positive numbers from a given list, sorted in ascending order. The function should use a helper function to swap elements during the sorting process. The provided code snippet contains errors and an unfinished helper function that you must identify and rectify.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_positive_and_sort(l: List[int]) -> List[int]:
"""
Return only positive numbers in the list, sorted in ascending order.
Args:
l (List[int]): The input list of integers.
Returns:
... |
magic_evol_110k | 97,274 | Write a Python function to calculate the median salary of employees in an organization, grouped by department. The function should take a list of tuples where each tuple contains an employee ID, department name, and salary. The function should return a dictionary where the keys are department names and the values are t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def calculate_median_salaries(employees: List[Tuple[int, str, int]]) -> Dict[str, float]:
"""
Calculate the median salary of employees grouped by department.
Args:
employees (Li... |
magic_evol_110k | 97,276 | Write a Python function to transform an array of grouped strings into a single array of strings where each group is separated by a comma. The input array contains strings where each string represents a group of words separated by spaces. The function should return a single array of strings where each word from the orig... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def separate_groups_with_comma(arr: List[str]) -> List[str]:
"""
Transforms an array of grouped strings into a single array of strings where each group is separated by a comma.
Args:
arr (Li... |
magic_evol_110k | 97,280 | Write a Python function to determine and return a list of all prime numbers within a given range `[start, end]`. The function should efficiently check for prime numbers using loops and conditional statements. The code should start with:
```python
from typing import List
def find_primes_in_range(start: int, end: int) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def find_primes_in_range(start: int, end: int) -> List[int]:
"""
Returns a list of all prime numbers within the given range [start, end].
Args:
start (int): The starting number o... |
magic_evol_110k | 97,308 | Write a Python function to generate a list of tuples where each tuple contains an element from the input list and its corresponding index. The function should then print each tuple in the list.
The code should start with:
```python
from typing import List, Tuple
def generate_indexed_tuples(input_list: List[int]) -> L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def generate_indexed_tuples(input_list: List[int]) -> List[Tuple[int, int]]:
"""
Generates a list of tuples where each tuple contains an element from the input list and its corresponding index.
... |
magic_evol_110k | 97,309 | Write a Python function to filter and sort a list of dictionaries based on specified conditions. Each dictionary represents a record with keys 'C', 'D', 'E', 'F', and 'G'. The function should filter out records where the value of 'C' is less than or equal to 500, the value of 'D' is in the list ['apple', 'orange', 'ban... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Any
from datetime import datetime
def filter_and_sort_records(records: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
"""
Filters and sorts a list of dictionaries based on specified conditions.
... |
magic_evol_110k | 97,312 | Write a Python function to compute the factorial of each digit in a given integer and return the results as a list. The function should handle both positive and negative integers, treating the digits of the absolute value of the number. The code should start with:
```python
import math
from typing import List
def fact... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
from typing import List
def factorial_of_digits(number: int) -> List[int]:
"""
Compute the factorial of each digit in the given integer and return the results as a list.
Args:
number (int): The integer ... |
magic_evol_110k | 97,318 | Write a Python function to find all unique elements in a list and count their occurrences. The list can contain both integers and strings. The function should return a dictionary where the keys are the unique elements and the values are their respective counts.
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 count_unique_elements(lst: List[int | str]) -> Dict[int | str, int]:
"""
Counts the occurrences of each unique element in a list.
Args:
lst (List[int | str]): The list of elements ... |
magic_evol_110k | 97,325 | Write a Python function to check if a given value exists in a multidimensional array and to count how many times the value appears. The function should return a tuple containing a boolean indicating whether the value is present and an integer representing the count of occurrences.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def check_and_count_value(array: List[List[int]], value: int) -> Tuple[bool, int]:
"""
Check if a given value exists in a multidimensional array and count how many times it appears.
Args:
... |
magic_evol_110k | 97,332 | Write a Python function to find and return the two nearest numerical values from a given list of at least two elements. The returned values should be in ascending order. The function should have a computational complexity better than O(n log n), where 'n' is the size of the list. The function should also handle outlier... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_closest_numbers(lst: List[int]) -> Tuple[int, int]:
"""
Finds and returns the two nearest numerical values from a given list of at least two elements.
The returned values are in ascen... |
magic_evol_110k | 97,340 | Write a Python function to generate a one-dimensional array of length 10, where each element is a randomly assigned integer between 1 and 10 (inclusive). The function should return this array.
The code should start with:
```python
from typing import List
import random
def generate_random_array() -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_random_array() -> List[int]:
"""
Generates a one-dimensional array of length 10, where each element is a randomly assigned integer between 1 and 10 (inclusive).
Returns:
... |
magic_evol_110k | 97,342 | Write a Python function to compute the prefix sum of a given sequence of numbers. The prefix sum of a sequence is a new sequence where each element at index `i` is the sum of all elements from the original sequence up to index `i`. The function should modify the input sequence in place and return it.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def prefix_sum(sequence: List[int]) -> List[int]:
"""
Computes the prefix sum of a given sequence of numbers.
The prefix sum of a sequence is a new sequence where each element at index `i`
is th... |
magic_evol_110k | 97,353 | Write a Python function to generate a unique 17-character string using a base-32 encoding scheme. The base-32 encoding should use a specific set of characters consisting of uppercase letters and digits '2' to '7'. The function should ensure that the generated string is unique by checking against a list of previously ge... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
import string
def generate_unique_base32_string(existing_strings: List[str] = None, length: int = 17) -> str:
"""
Generates a unique 17-character string using a base-32 encoding scheme.
... |
magic_evol_110k | 97,399 | Write a Python function to determine if a given number is an Armstrong number and if it is a perfect square. An Armstrong number is a number that is equal to the sum of its own digits each raised to the power of the number of digits. A perfect square is a number that can be expressed as the product of an integer with i... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def check_number_properties(n: int) -> tuple:
"""
Determines if a given number is an Armstrong number and a perfect square.
Args:
n (int): The number to check.
Returns:
tuple: A tuple conta... |
magic_evol_110k | 97,429 | Write a Python function to calculate the frequency of each character in a given string, ignoring spaces and punctuation, and treating characters in a case-insensitive manner. The function should return a dictionary where the keys are characters and the values are their respective frequencies.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def character_frequency(input_str: str) -> Dict[str, int]:
"""
Calculate the frequency of each character in a given string, ignoring spaces and punctuation, and treating characters in a case-insensitive ... |
magic_evol_110k | 97,430 | Write a Python function to calculate and return the cube of each element in a given list of integers. The function should iterate over the list and compute the cube of each element, storing the results in a new list. The function should then return this list of cubes.
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 calculate_cubes(num_list: List[int]) -> List[int]:
"""
Calculate the cube of each element in the given list of integers.
Args:
num_list (List[int]): A list of integers for which the cube... |
magic_evol_110k | 97,433 | 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.
Args:
lst (List[int]): The list of integers to be modified.
... |
magic_evol_110k | 97,435 | Write a Python function that performs a division operation between two variables `a` and `b`, and handles potential exceptions (`ZeroDivisionError` and `TypeError`) using a `try-except-else-finally` block. The function should print the type of exception caught in the `except` block and execute specific code in the `els... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_division(a, b):
"""
Safely performs a division operation between two variables a and b,
handling ZeroDivisionError and TypeError exceptions.
Args:
a (int or float): The numerator.
b (int or floa... |
magic_evol_110k | 97,474 | Write a Python function to calculate the number of ways to climb a staircase with `n` steps, where a person can take either 1 or 2 steps at a time. The function should use dynamic programming to efficiently compute the result.
The code should start with:
```python
def climb_stairs(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def climb_stairs(n: int) -> int:
"""
Calculate the number of ways to climb a staircase with `n` steps, where a person can take either 1 or 2 steps at a time.
Args:
n (int): The number of steps in the staircase.
... |
magic_evol_110k | 97,475 | Write a Python function to categorize a list of data elements based on predefined types. The function should take a list of data elements and a dictionary mapping each element to its type, and return a list of tuples where each tuple contains an element and its corresponding type.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
def categorize_data_elements(data_entities: List[str], entity_types: Dict[str, str]) -> List[Tuple[str, str]]:
"""
Categorizes a list of data elements based on predefined types.
Args:
... |
magic_evol_110k | 97,479 | Write a Python function to determine if a given string of brackets is correctly balanced and properly nested. The string consists of the following bracket types: `<`, `>`, `{`, `}`, `[`, `]`, `(`, `)`. The function should return `True` if the brackets are correctly balanced and nested, and `False` otherwise.
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_balanced_and_nested(brackets: str) -> bool:
"""
Determine if the given string of brackets is correctly balanced and properly nested.
Args:
brackets (str): The string of brackets to be checked.
Returns:
... |
magic_evol_110k | 97,485 | Write a Python function to search for elements in a dictionary and return a formatted string for each element found. The function should handle cases where the dictionary keys are invalid or missing. The code should start with:
```python
from typing import Dict, List, Union
def search_in_dict(num_dict: Dict[int, bool]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Union
def search_in_dict(num_dict: Dict[int, bool], search_list: List[int]) -> List[str]:
"""
Searches for each element in the search_list within the keys of num_dict and returns a list of formatt... |
magic_evol_110k | 97,490 | Write a Python function to clean up a list of emails and put them into a new list. The cleaning process involves the following steps:
1. Split each email into the local part and the domain part using the '@' symbol.
2. Remove any characters after the '+' symbol in the local part.
3. Remove any characters after the '.' ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clean_emails(emails: List[str]) -> List[str]:
"""
Cleans up a list of emails by removing characters after '+' in the local part and after '.' in the domain part.
Args:
emails (List[str])... |
magic_evol_110k | 97,495 | Write a Python function to return only even prime numbers from two given lists, merged and sorted in descending order. The function should include a helper function to check the primality of a number and another helper function to merge and sort the lists. The function should handle negative numbers and non-prime numbe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_even_prime_and_merge(l1: List[int], l2: List[int]) -> List[int]:
"""
Return only even prime numbers from both lists, merged and sorted in descending order.
Args:
l1 (List[int]): The ... |
magic_evol_110k | 97,499 | Write a Python function to convert a given string to its corresponding hexadecimal representation and back to the original string. Additionally, print the current timestamp using Python's `datetime` module. The function should be able to handle any string input and ensure that the conversion is reversible.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def string_to_hex(s: str) -> str:
"""
Convert a given string to its hexadecimal representation.
Args:
s (str): The input string to be converted.
Returns:
str: The hexadecimal representa... |
magic_evol_110k | 97,501 | Write a Python function to assemble a list of speech fragments into a single comprehensive sentence. Each fragment should be separated by a semicolon and a whitespace character. The function should handle an empty list by returning an empty string.
The code should start with:
```python
from typing import List
def ass... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def assemble_sentence(phrases: List[str]) -> str:
"""
Assembles a list of speech fragments into a single comprehensive sentence.
Each fragment is separated by a semicolon and a whitespace character.
... |
magic_evol_110k | 97,505 | Write a Python function to remove all occurrences of a specified element from a given list by its value and return the altered list. The function should handle cases where the element might not be present in the list. The code should start with:
```python
from typing import List
def remove_all_occurrences(lst: List[st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_all_occurrences(lst: List[str], element: str) -> List[str]:
"""
Removes all occurrences of a specified element from a given list and returns the altered list.
Args:
lst (List[str]... |
magic_evol_110k | 97,543 | Write a Python function to find the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm. The function should be efficient and handle both positive and negative integers. The code should start with:
```python
def gcd(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def gcd(a: int, b: int) -> int:
"""
Calculate the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
... |
magic_evol_110k | 97,563 | Write a Python function to create a new 2D array with the same dimensions as a given 2D array, but with all its elements initialized to zero. The function should not modify the original 2D array. The code should start with:
```python
from typing import List
def create_zero_filled_array(original_array: List[List[int]])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import copy
def create_zero_filled_array(original_array: List[List[int]]) -> List[List[int]]:
"""
Creates a new 2D array with the same dimensions as the given 2D array, but with all elements initialized ... |
magic_evol_110k | 97,578 | Write a Python function to identify and return all the indices where each duplicate character appears in a given string. If a character does not have any duplicates, exclude it from the result. The function should optimize for time complexity.
The code should start with:
```python
from typing import Dict, List
def fi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def find_duplicate_indices(string: str) -> Dict[str, List[int]]:
"""
Finds and returns all indices where each duplicate character appears in the given string.
Args:
string (str): The i... |
magic_evol_110k | 97,595 | Write a Python function to convert a given string to an integer without using the built-in `int()` function. The function should handle strings containing negative numbers and return the appropriate negative integer value. The function should also be able to handle strings with leading zeros. The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
def string_to_int(s: str) -> int:
"""
Converts a given string to an integer without using the built-in int() function.
Handles negative numbers and leading zeros.
Args:
s (str): The string to be converted to an ... |
magic_evol_110k | 97,596 | Write a Python function to construct a regular expression pattern that matches all distinct sentence formations starting with the phrase "I like" and ending with either a full stop, exclamation mark, or question mark, while excluding any sentences that contain the word "dislike". The function should return the list of ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def find_sentences(text: List[str]) -> List[str]:
"""
Finds all distinct sentence formations starting with "I like" and ending with either a full stop, exclamation mark, or question mark,
w... |
magic_evol_110k | 97,601 | Write a Python function to compute the arithmetic average of a given array composed of real numerical elements. The function should handle arrays with mixed data types, considering only the real numbers (integers and floats) for the calculation. If the array is empty or contains no real numbers, the function should ret... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def arithmetic_average(array: List[float]) -> float:
"""
Computes the arithmetic average of a given array composed of real numerical elements.
Args:
array (List[float]): The array of real nu... |
magic_evol_110k | 97,605 | Write a Python function to identify the elements in a given 3D array that appear only once and determine their positions in the array. The function should return the results in a dictionary format, where keys represent the unique elements and the values are tuples containing the position of each unique element. The pos... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
def find_unique_elements_3d(arr: List[List[List[int]]]) -> Dict[int, Tuple[int, int, int]]:
"""
Identify the elements in a given 3D array that appear only once and determine their positions.... |
magic_evol_110k | 97,606 | Write a Python function to find the last odd number in a given list that is not a multiple of 5 and is less than 20. The function should also consider negative numbers and zero. The code should start with:
```python
from typing import List
def find_last_odd_number(data: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_last_odd_number(data: List[int]) -> int:
"""
Find the last odd number in the list that is not a multiple of 5 and is less than 20.
Args:
data (List[int]): The list of integers to se... |
magic_evol_110k | 97,611 | Write a Python function to reverse a given list without using the built-in `reverse()` method or slicing. The function should use an iterative approach to reverse the list in place.
The code should start with:
```python
from typing import List
def reverse_list_in_place(lst: List[int]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_list_in_place(lst: List[int]) -> None:
"""
Reverses the given list in place without using the built-in reverse() method or slicing.
Args:
lst (List[int]): The list to be reversed... |
magic_evol_110k | 97,612 | Write a Python function to perform a generalized multi-partition search technique, specifically a quinary search, within a sorted sequence of integers. The sequence may contain missing integers and errors in sequential order. The function should handle the scenario when the array isn't properly sorted or doesn't follow... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def quinary_search(arr: List[int], x: int) -> Union[int, str]:
"""
Perform a quinary search to find the index of an element in a sorted array.
Args:
arr (List[int]): The array to sear... |
magic_evol_110k | 97,638 | Write a Python function to find the second highest even element in a given list of integers. If the list does not contain at least two even numbers, return a specific error message.
The code should start with:
```python
from typing import List
def second_highest_even_element(l: List[int]) -> int or str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def second_highest_even_element(l: List[int]) -> int or str:
"""
Find the second highest even element in a given list of integers.
Args:
l (List[int]): The list of integers to search for the... |
magic_evol_110k | 97,655 | Write a Python function to generate an Elasticsearch query that searches for entries in a database containing both the "location" attribute and the "review" attribute. The "location" attribute must explicitly indicate "Los Angeles", and the "review" attribute must contain a full sentence. Additionally, the search resul... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_elasticsearch_query() -> dict:
"""
Generates an Elasticsearch query that searches for entries in the database containing both the "location" attribute and the "review" attribute.
The "location" attribute must ex... |
magic_evol_110k | 97,660 | Write a Python function to calculate the Levenshtein distance between two strings, considering the maximum allowed string length is 1000 characters. The Levenshtein distance is defined as the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other.... | Here is the Python code to solve the given problem in the markdown block:
```python
def levenshtein_distance(s1: str, s2: str) -> int:
"""
Calculate the Levenshtein distance between two strings, considering the maximum allowed string length is 1000 characters.
Args:
s1 (str): The first string.
... |
magic_evol_110k | 97,663 | Write a Python function to calculate the Kronecker product of two given matrices using the NumPy package. The function should take two 2D lists as input and return the resulting Kronecker product as a 2D list.
The code should start with:
```python
from typing import List
import numpy as np
def kronecker_product(matri... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import numpy as np
def kronecker_product(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[List[int]]:
"""
Calculate the Kronecker product of two matrices.
Args:
matrix1 (List[List... |
magic_evol_110k | 97,673 | Write a Python function to calculate the absolute difference between the difference of the square of the sum of the digits and the sum of the squares of the digits for a given integer and its reverse. The function should start with:
```python
def digit_difference(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def digit_difference(n: int) -> int:
"""
Calculate the absolute difference between the difference of the square of the sum of the digits
and the sum of the squares of the digits for a given integer and its reverse.
Args... |
magic_evol_110k | 97,682 | Write a Python function to create an empty set and add the elements "A", "B", and "C" into it. Ensure that the function handles the addition of duplicate items correctly, ensuring the final set only contains unique elements. The function should start with:
```python
def create_and_add_to_set() -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def create_and_add_to_set() -> set:
"""
Creates an empty set and adds the elements "A", "B", and "C" to it.
Ensures that the set only contains unique elements, even if duplicate elements are added.
Returns:
set:... |
magic_evol_110k | 97,687 | Write a Python function to sort a given list of integers in descending order and return the sorted list. The function should handle an empty list gracefully and return it as is. The code should start with:
```python
from typing import List
def sort_descending(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def sort_descending(arr: List[int]) -> List[int]:
"""
Sorts the given list of integers in descending order and returns the sorted list.
Args:
arr (List[int]): The list of integers to be so... |
magic_evol_110k | 97,690 | Write a Python function to calculate the total price of books in a bookstore inventory that belong to a specific genre. The function should take a list of dictionaries representing the inventory, where each dictionary contains details about a book such as its ISBN, price, description, and genre. The function should als... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def total_price_by_genre(inventory: List[Dict[str, any]], genre: str) -> float:
"""
Calculate the total price of all books in the specified genre from the bookstore inventory.
Args:
in... |
magic_evol_110k | 97,693 | Write a Python function to create a dictionary where the keys are tuples of integers and the values are lists of floating-point numbers. The function should allow the user to specify the length of the tuple and the length of the list, as well as the default value for each element in the list. The function should return... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple, List
def create_data_structure(tuple_length: int, list_length: int, default_value: float) -> Dict[Tuple[int, ...], List[float]]:
"""
Creates a dictionary where the keys are tuples of integers and... |
magic_evol_110k | 97,694 | Write a Python function to compute the fiscal contribution on a given salary based on the following rules:
- If the salary is $10,000 or less, the fiscal contribution is $0.
- If the salary exceeds $10,000, the fiscal contribution is 15% of the amount that exceeds $10,000.
The function should start with:
```python
def... | Here is the Python code to solve the given problem in the markdown block:
```python
def compute_fiscal_contribution(salary: float) -> float:
"""
Computes the fiscal contribution on a given salary based on the following rules:
- If the salary is $10,000 or less, the fiscal contribution is $0.
- If the sa... |
magic_evol_110k | 97,700 | Write a Python function to calculate the sum of the digits of a given integer. The function should handle both positive and negative integers. The code should start with:
```python
def sum_of_digits(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_digits(n: int) -> int:
"""
Calculate the sum of the digits of a given integer.
Args:
n (int): The integer whose digits are to be summed.
Returns:
int: The sum of the digits of the integer.
... |
magic_evol_110k | 97,702 | Write a Python function to filter a list of strings such that only those strings that are composed entirely of alphabetic characters and have an even length are included in the result. The function should start with:
```python
from typing import List
def filter_strings(lst: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_strings(lst: List[str]) -> List[str]:
"""
Filters a list of strings to include only those that are composed entirely of alphabetic characters and have an even length.
Args:
lst (L... |
magic_evol_110k | 97,707 | Write a Python function to increment each alphabetic character in a given sentence by one position in the alphabet. Non-alphabetic characters should remain unchanged. The function should handle both uppercase and lowercase letters, wrapping around from 'z' to 'a' and from 'Z' to 'A'.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
def increment_alphabetic_characters(sentence: str) -> str:
"""
Increments each alphabetic character in the given sentence by one position in the alphabet.
Non-alphabetic characters remain unchanged.
Args:
senten... |
magic_evol_110k | 97,721 | Write a Python function to sort a list of tuples containing string and integer values. The sorting should be done in ascending order based on both the string component and the integer component. If two tuples have the same string component, they should be sorted by the integer component in descending order.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_tuples(lst: List[Tuple[str, int]]) -> List[Tuple[str, int]]:
"""
Sorts a list of tuples containing string and integer values.
The sorting is done in ascending order based on the strin... |
magic_evol_110k | 97,722 | Write a Python function to generate a list of prime numbers within a specified range [start, end]. The function should validate each number in the range to determine if it is a prime number and return a list of all prime numbers found within the range.
The code should start with:
```python
from typing import List
def... | 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 given 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 | 97,723 | Write a Python function to break down a given positive integer into its prime factors and count the frequency of each prime factor. The function should return a dictionary where the prime factors are the keys and their frequencies are the values. The function should handle edge cases such as negative numbers, zero, and... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import math
def is_prime(n: int) -> bool:
"""
Check whether a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, Fals... |
magic_evol_110k | 97,726 | Write a Python function to combine two dictionaries `A` and `B` into a new dictionary `C`, where `C` contains all the key-value pairs from both `A` and `B`. In case of key conflicts, the value from dictionary `A` should be preferred. The function should start with:
```python
from typing import Dict
def combine_dicts(A... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def combine_dicts(A: Dict[str, any], B: Dict[str, any]) -> Dict[str, any]:
"""
Combines two dictionaries `A` and `B` into a new dictionary `C`.
In case of key conflicts, the value from dictionary `A`... |
magic_evol_110k | 97,729 | Write a Python function to remove leading and trailing whitespace characters from a given text string. The function should handle various types of whitespace characters, including spaces, tabs, and newlines. The code should start with:
```python
def remove_whitespace(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_whitespace(text: str) -> str:
"""
Removes leading and trailing whitespace characters from the given text string.
Args:
text (str): The input text string from which to remove the whitespace characters.
... |
magic_evol_110k | 97,730 | Write a Python function to compute the element-wise difference between two multi-dimensional numerical arrays, denoted as "A" and "B". The dimensions of the input arrays should be at most 3x3. If the dimensions of the arrays do not match, pad the smaller array with zeroes to match the size of the larger one before comp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def element_wise_difference(A: List[List[int]], B: List[List[int]]) -> List[List[int]]:
"""
Compute the element-wise difference between two multi-dimensional numerical arrays A and B.
If the dimensio... |
magic_evol_110k | 97,737 | Write a Python function to implement the selection sort algorithm. The function should take a list of integers as input and return the sorted list in ascending order. The selection sort algorithm works by repeatedly finding the minimum element from the unsorted part of the list and putting it at the beginning. The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def selection_sort(input_list: List[int]) -> List[int]:
"""
Sorts a list of integers using the selection sort algorithm.
The selection sort algorithm works by repeatedly finding the minimum element
... |
magic_evol_110k | 97,755 | Write a Python function to generate a new array where each element is the result of multiplying the corresponding element in the input array by a given factor. The function should handle arrays of distinct integers and should be able to multiply by any positive integer factor.
The code should start with:
```python
fro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_array_elements(arr: List[int], factor: int) -> List[int]:
"""
Generates a new array where each element is the result of multiplying the corresponding element in the input array by the given ... |
magic_evol_110k | 97,758 | Write a Python function to determine if a given number `x` is a prime number. The function should return `True` if `x` is a prime number and `False` otherwise. The function should handle edge cases such as negative numbers, 0, 1, and even numbers greater than 2. The code should start with:
```python
def is_prime(x: int... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(x: int) -> bool:
"""
Determine if a given number `x` is a prime number.
Args:
x (int): The number to check for primality.
Returns:
bool: True if `x` is a prime number, False otherwise.
... |
magic_evol_110k | 97,767 | Write a Python function to transpose elements within a numerical list by a single position towards the left, maintaining the order of neighboring elements. The last element of the list should become the first one. The function should handle empty lists by returning them as is.
The code should start with:
```python
fro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def transpose_list(lst: List[int]) -> List[int]:
"""
Transposes elements within a numerical list by a single position to the left,
maintaining the order of neighboring elements. The last element of t... |
magic_evol_110k | 97,771 | Write a Python function to validate if all the dictionary keys are either all in lower case or all in upper case. The function should return `False` for dictionaries with keys that are either empty, show a mix of uppercase and lowercase letters, or include numerics and special characters. The function should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_dict_case(dct: dict) -> bool:
"""
Validate if all the dictionary keys are either all in lower case or all in upper case.
Return False for dictionaries with keys that are either empty, show a mix of uppercase and lo... |
magic_evol_110k | 97,809 | Write a Python function to create an n x n identity matrix using the `numpy` library. The function should take an integer `n` as input and return a 2D numpy array representing the identity matrix of size n x n.
The code should start with:
```python
import numpy as np
def create_identity_matrix(n: int) -> np.ndarray:
... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def create_identity_matrix(n: int) -> np.ndarray:
"""
Create an n x n identity matrix using the numpy library.
Args:
n (int): The size of the identity matrix.
Returns:
np.ndarray: A ... |
magic_evol_110k | 97,815 | Write a Python function to swap the case of each character in a given string. The function should convert all uppercase letters to lowercase and all lowercase letters to uppercase. Non-alphabetic characters should remain unchanged.
The code should start with:
```python
def swap_case(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def swap_case(s: str) -> str:
"""
Swaps the case of each character in the given string.
Args:
s (str): The input string to be processed.
Returns:
str: A new string with all uppercase letters changed to ... |
magic_evol_110k | 97,816 | Write a Python function to generate a meticulously ordered catalog (list) of continuous, whole numerical values starting from a given integer `start` and ending at a given integer `end` (inclusive). The function should handle cases where `start` is greater than `end` by returning an empty list. The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_catalog(start: int, end: int) -> List[int]:
"""
Generates a meticulously ordered catalog of continuous, whole numerical values
starting from `start` and ending at `end` (inclusive).
... |
magic_evol_110k | 97,820 | Write a Python function to extract even numbers from two given lists, merge them, and return the merged list sorted in descending order. The function should be named `get_even_and_merge` and should take two lists of integers as input. The function should return a list of integers.
The starter code is as follows:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_even_and_merge(l1: List[int], l2: List[int]) -> List[int]:
"""
Extract even numbers from both lists, merge them, and return the merged list sorted in descending order.
Args:
l1 (List... |
magic_evol_110k | 97,822 | Write a Python function to count the frequency of each distinct numeric element in a given list. The function should handle erroneous data such as non-numeric entries and empty lists. If the list is empty or contains only non-numeric entries, the function should return an empty dictionary. 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 frequency_counter(lst: List[float]) -> Dict[float, int]:
"""
Counts the frequency of each distinct numeric element in the given list.
Args:
lst (List[float]): The list of numeric v... |
magic_evol_110k | 97,824 | Write a Python function that processes a given list of integers, filtering out multiples of 5, and then prints the even numbers followed by the prime numbers from the filtered list. The function should start with:
```python
from typing import List
def filter_and_print_numbers(lst: List[int]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_and_print_numbers(lst: List[int]) -> None:
"""
Filters out multiples of 5 from the given list, prints the even numbers, and then prints the prime numbers.
Args:
lst (List[int]): T... |
magic_evol_110k | 97,831 | Write a Python function to reverse a given string while ignoring special characters (punctuation marks). The special characters should remain in their original positions after the reversal. The function should start with:
```python
def reverse_string_ignore_special(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string_ignore_special(s: str) -> str:
"""
Reverses a given string while ignoring special characters (punctuation marks).
Special characters remain in their original positions after the reversal.
Args:
... |
magic_evol_110k | 97,860 | Write a Python function to calculate the Euclidean distance between two points in a 2D plane. The function should take two tuples representing the coordinates of the points and return the distance as a floating-point number. The code should start with:
```python
def euclidean_distance(point1: tuple, point2: tuple) -> f... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def euclidean_distance(point1: tuple, point2: tuple) -> float:
"""
Calculate the Euclidean distance between two points in a 2D plane.
Args:
point1 (tuple): A tuple containing the coordinates (x1, y1) of... |
magic_evol_110k | 97,869 | Write a Python function to calculate the product of two given integers, ensuring that the function handles both positive and negative integers correctly. The function should return the product of the two integers.
The code should start with:
```python
def calculate_product(num1: int, num2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_product(num1: int, num2: int) -> int:
"""
Calculate the product of two given integers.
Args:
num1 (int): The first integer.
num2 (int): The second integer.
Returns:
int: The produc... |
magic_evol_110k | 97,871 | Write a Python function to compute the divergence between the maximum (apex) and minimum (nadir) integers within a given list. The function should also return the indices of the first occurrence of the apex and nadir integers. The function should handle scenarios where the list may contain identical integers, negative ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Optional
def compute_divergence_and_indices(arr: List[int]) -> Optional[Tuple[int, int, int]]:
"""
Computes the divergence between the maximum (apex) and minimum (nadir) integers in a list,
a... |
magic_evol_110k | 97,888 | Write a Python function to find the maximum count of distinct intersecting characters between two given strings. The function should take two strings as input and return the count of unique characters that appear in both strings.
The code should start with:
```python
def max_intersect_characters(string1: str, string2:... | Here is the Python code to solve the given problem in the markdown block:
```python
def max_intersect_characters(string1: str, string2: str) -> int:
"""
Calculate the maximum count of distinct intersecting characters between two strings.
Args:
string1 (str): The first string.
string2 (str):... |
magic_evol_110k | 97,901 | Write a Python function to remove all repeating characters from a given string, preserving the order of the first occurrence of each character. The function should return the modified string.
The code should start with:
```python
def remove_duplicates(input_str: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_duplicates(input_str: str) -> str:
"""
Removes all repeating characters from the given string, preserving the order of the first occurrence of each character.
Args:
input_str (str): The input string from ... |
magic_evol_110k | 97,904 | Write a Python function to calculate the difference between two times given in 24-hour format and return the difference in hours, minutes, and seconds. The function should handle cases where the second time is earlier than the first time, indicating that the second time is on the next day.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime, timedelta
def time_difference(time1: str, time2: str) -> tuple:
"""
Calculate the difference between two times given in 24-hour format and return the difference in hours, minutes, and seconds.
... |
magic_evol_110k | 97,911 | Write a Python function to create a new string from the given string by replacing each character with its opposite case. The function should correctly handle both uppercase and lowercase characters, and it should not modify non-alphabetic characters.
The code should start with:
```python
def reverse_case(s: str) -> st... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_case(s: str) -> str:
"""
Create a new string from the given string by replacing each character with its opposite case.
Non-alphabetic characters remain unchanged.
Args:
s (str): The input string to b... |
magic_evol_110k | 97,912 | Write a Python function to add two matrices and return the result as a new matrix. The function should handle sparse matrices efficiently, meaning it should only perform addition on non-zero elements to optimize performance. The matrices `a` and `b` are guaranteed to have the same dimensions.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def add_matrices(a: List[List[int]], b: List[List[int]]) -> List[List[int]]:
"""
Adds two matrices and returns the result as a new matrix.
The function handles sparse matrices efficiently by only per... |
magic_evol_110k | 97,915 | Write a Python function to create a dictionary that maps specific varieties of fruits to their respective quantities. The function should accept a list of tuples, where each tuple contains a fruit name and its quantity. The function should return a dictionary with the fruit names as keys and their quantities as values.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def create_fruit_quantities_dict(fruit_quantity_pairs: List[Tuple[str, int]]) -> Dict[str, int]:
"""
Creates a dictionary mapping specific varieties of fruits to their respective quantities.... |
magic_evol_110k | 97,924 | Write a Python function to determine the minimum number of single-character mutations required to transform a given gene sequence (`origin`) into another (`destination`), using a repository of valid gene sequences (`repository`). Each mutation must result in a gene sequence that is present in the repository. If no such... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import deque
def min_genetic_mutation(origin: str, destination: str, repository: List[str]) -> int:
"""
Calculate the minimum number of single-character mutations required to transform t... |
magic_evol_110k | 97,939 | Write a Python function to merge overlapping intervals from a given list of intervals. Each interval is represented as a list of two integers, where the first integer is the start of the interval and the second integer is the end of the interval. The function should return a new list of intervals where all overlapping ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_intervals(intervals: List[List[int]]) -> List[List[int]]:
"""
Merges overlapping intervals from a given list of intervals.
Args:
intervals (List[List[int]]): A list of intervals wh... |
magic_evol_110k | 97,945 | Write a Python function to determine if two given strings are anagrams of each other. The function should handle strings containing special characters and numbers. The function should return a boolean value indicating whether the two strings are anagrams. The code should start with:
```python
def are_anagrams(string1: ... | 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.
Args:
string1 (str): The first string to compare.
string2 (str): The second string to comp... |
magic_evol_110k | 97,959 | Write a Python function to determine if a given number is divisible by any prime number. The function should take two arguments: the number to be checked (`num`) and the prime number (`prime`) by which the divisibility is to be determined. The function should return a boolean value (`True` if the number is divisible by... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_divisible_by_prime(num: int, prime: int) -> bool:
"""
Determine if a given number is divisible by a specified prime number.
Args:
num (int): The number to be checked for divisibility.
prime (int): The... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.