source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 101,024 | Write a Python function to create a dictionary from a list of tuples where each tuple contains a name and an age. The function should return the dictionary with names as keys and ages as values.
The code should start with:
```python
from typing import List, Tuple, Dict
def create_age_dictionary(people: List[Tuple[str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def create_age_dictionary(people: List[Tuple[str, int]]) -> Dict[str, int]:
"""
Creates a dictionary from a list of tuples where each tuple contains a name and an age.
Args:
peo... |
magic_evol_110k | 101,029 | Write a Python function to remove spaces, punctuation, and convert all uppercase characters to lowercase from a given string. Additionally, check if the modified string is a palindrome or not. The function should return a tuple containing the modified string and a boolean indicating whether the modified string is a pal... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
import re
def clean_and_check_palindrome(s: str) -> Tuple[str, bool]:
"""
Cleans the given string by removing spaces, punctuation, and converting all characters to lowercase.
Additionally, checks if... |
magic_evol_110k | 101,038 | Write a Python function to reverse the order of words in a given string. The function should handle strings with multiple spaces between words and leading/trailing spaces. The code should start with:
```python
def reverse_words_order(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_words_order(s: str) -> str:
"""
Reverses the order of words in a given string.
Args:
s (str): The input string containing words to be reversed.
Returns:
str: A string with the words in rever... |
magic_evol_110k | 101,051 | Write a Python function to compute the area of a triangle given the length of a side and the corresponding perpendicular height. The function should validate the inputs to ensure they are positive numbers. If the inputs are invalid, the function should return an appropriate error message.
The code should start with:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
def triangle_area(a: float, h: float) -> float or str:
"""
Compute the area of a triangle given the length of a side and the corresponding perpendicular height.
Args:
a (float): The length of the side of the triangl... |
magic_evol_110k | 101,062 | Write a Python function to determine if a given single-character string represents a vowel. The function should return `True` if the character is a vowel (either uppercase or lowercase), and `False` otherwise. The function should handle edge cases such as non-alphabetic characters and should be case-insensitive.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_vowel(char: str) -> bool:
"""
Determines if a given single-character string represents a vowel.
Args:
char (str): The single-character string to check.
Returns:
bool: True if the character is a v... |
magic_evol_110k | 101,064 | Write a Python function to compute the product of all numerical elements in a given list. The function should handle lists with both positive and negative integers, as well as zero. The code should start with:
```python
from typing import List
def compute_product(array: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def compute_product(array: List[int]) -> int:
"""
Compute the product of all numerical elements in the given list.
Args:
array (List[int]): The list of integers to compute the product from.
... |
magic_evol_110k | 101,068 | Write a Python function to generate the Fibonacci sequence up to a specified number `n` where `n` is a positive integer. The function should return a list containing the Fibonacci sequence up to the `n`-th term. If `n` is less than 1, the function should return an empty list.
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 generate_fibonacci(n: int) -> List[int]:
"""
Generate the Fibonacci sequence up to the n-th term.
Args:
n (int): The number of terms in the Fibonacci sequence to generate.
Returns:
... |
magic_evol_110k | 101,071 | Write a Python function that removes leading and trailing whitespace from a given string and reduces multiple consecutive whitespace characters within the string to a single whitespace. The function should not use Python's built-in functions such as `strip()`, `split()`, or regular expressions. Instead, implement the s... | Here is the Python code to solve the given problem in the markdown block:
```python
def clean_string(text: str) -> str:
"""
Removes leading and trailing whitespace from the given string and reduces multiple consecutive
whitespace characters within the string to a single whitespace.
Args:
text (... |
magic_evol_110k | 101,077 | Write a Python function to find the intersection of two sets of integers. The function should take two sets as input and return a new set containing the elements that are present in both sets. The code should start with:
```python
from typing import Set
def find_intersection(set1: Set[int], set2: Set[int]) -> Set[int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
def find_intersection(set1: Set[int], set2: Set[int]) -> Set[int]:
"""
Find the intersection of two sets of integers.
Args:
set1 (Set[int]): The first set of integers.
set2 (Set[int])... |
magic_evol_110k | 101,095 | Write a Python function to calculate the total number of days an individual has existed, considering leap years and the variances between different months. The function should take a date of birth as input and return the total number of days from that date to today.
The code should start with:
```python
from datetime ... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import date
def calculate_age_in_days(birth_date: date) -> int:
"""
Calculate the total number of days an individual has existed from their date of birth to today.
Args:
birth_date (date): The date of... |
magic_evol_110k | 101,112 | Write a Python function to convert a binary number represented as a string to its decimal (base 10) representation. The function should handle binary strings of any length, including those with leading zeros. The code should start with:
```python
def binary_to_decimal(binary_string: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_decimal(binary_string: str) -> int:
"""
Converts a binary number represented as a string to its decimal (base 10) representation.
Args:
binary_string (str): The binary number to be converted, represent... |
magic_evol_110k | 101,118 | Write a Python function to perform binary insertion sort on a list of integers. The function should use the binary search algorithm to determine the correct position for inserting each element, thereby optimizing the insertion process. The code should start with:
```python
from typing import List
import bisect
def bin... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import bisect
def binary_insertion_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the binary insertion sort algorithm.
Args:
arr (List[int]): The list of integers to... |
magic_evol_110k | 101,121 | Write a Python function to find the largest prime factor of a given positive integer `n`. The function should efficiently compute the largest prime factor using a combination of division and iteration. The code should start with:
```python
def largest_prime_factor(n: int) -> int:
```
| 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 positive integer n.
Args:
n (int): The positive integer for which to find the largest prime factor.
Returns:
int: Th... |
magic_evol_110k | 101,131 | Create a Python function that takes a list of strings and a target string as input, and returns the index of the target string in the list if it exists, otherwise returns -1. The function should handle cases where the list is empty or the target string is not found.
The code should start with:
```python
from typing im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_string_index(strings: List[str], target: str) -> int:
"""
Find the index of the target string in the given list of strings.
Args:
strings (List[str]): A list of strings to search th... |
magic_evol_110k | 101,145 | Write a Python function to simulate the process of pasting text into a document using a simplified version of the OpenOffice API. The function should take a document object and the text to be pasted as input, and it should simulate the process of setting the text property of the document object to the given text. The f... | Here is the Python code to solve the given problem in the markdown block:
```python
def paste_text_into_document(document: dict, text: str) -> dict:
"""
Simulates the process of pasting text into a document using a simplified version of the OpenOffice API.
Args:
document (dict): A dictionary repres... |
magic_evol_110k | 101,155 | Write a Python function to generate a matrix of integers with exactly two rows and four columns. The function should allow customization of the starting integer and the step size between consecutive integers in each row. The matrix should be returned as a list of lists.
The code should start with:
```python
from typin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_matrix(start: int, step: int) -> List[List[int]]:
"""
Generates a matrix of integers with exactly two rows and four columns.
Args:
start (int): The starting integer for the firs... |
magic_evol_110k | 101,165 | Write a Python function that squares an input number and, if the original input number is prime, performs prime factorization of the square. The function should be implemented as an anonymous function using a lambda expression. Ensure optimal time complexity.
The code should start with:
```python
from typing import Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
import math
# Function to check if a number is prime
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check.
Returns:
bool: True... |
magic_evol_110k | 101,167 | Write a Python function to correctly evaluate a given mathematical expression by adjusting the placement of brackets to ensure the expression is evaluated in the intended order. The function should take a string representing the mathematical expression as input and return the evaluated result as a float.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
def evaluate_expression(expression: str) -> float:
"""
Evaluates a given mathematical expression by adjusting the placement of brackets to ensure the correct order of operations.
Args:
expression (str): A string rep... |
magic_evol_110k | 101,172 | Write a Python function to determine if two given input strings contain the same unique words with the same frequency, ignoring case and any non-alphanumeric characters. The function should return `True` if the two phrases have identical sets of unique words with the same frequency, and `False` otherwise.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import re
def compare_word_sets(phrase1: str, phrase2: str) -> bool:
"""
Determine if two provided phrases have identical sets of unique words with the same frequency, ignoring case and non-alphanumeric ... |
magic_evol_110k | 101,175 | Write a Python function to calculate the minimum value in a 2D list (list of lists) without using external libraries like NumPy. The function should iterate through the 2D list and find the minimum value efficiently.
The code should start with:
```python
from typing import List
def find_min_in_2d_list(array: List[Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_min_in_2d_list(array: List[List[int]]) -> int:
"""
Calculate the minimum value in a 2D list (list of lists).
Args:
array (List[List[int]]): A 2D list containing integers.
Retur... |
magic_evol_110k | 101,190 | Write a Python function to enrich a given dictionary with additional key-value pairs. The function should take a dictionary and a list of tuples, where each tuple contains a key and a value, and update the dictionary with these new key-value pairs. The function should return the updated dictionary.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def enrich_dictionary(original_dict: Dict[str, any], new_entries: List[Tuple[str, any]]) -> Dict[str, any]:
"""
Enrich the given dictionary with additional key-value pairs.
Args:
... |
magic_evol_110k | 101,201 | Write a Python function to remove all numbers from a given list that are multiples of 11. The function should return a new list containing only the numbers that are not multiples of 11.
The code should start with:
```python
from typing import List
def remove_multiples_of_11(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 remove_multiples_of_11(numbers: List[int]) -> List[int]:
"""
Removes all numbers from the given list that are multiples of 11.
Args:
numbers (List[int]): The list of integers from which ... |
magic_evol_110k | 101,211 | Write a Python function to find the shortest string from a given list of strings. If multiple strings have the same length, return the one with the least number of consonants. If the list is empty, return `None`. The function should be efficient and handle various edge cases.
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, Optional
def count_consonants(s: str) -> int:
"""Count the number of consonants in a string."""
return sum(c.lower() in 'bcdfghjklmnpqrstvwxyz' for c in s)
def shortest_string(strings: List[str]) -> Op... |
magic_evol_110k | 101,247 | Write a Python function to determine the sum of all the odd elements in a given array of integers. The function must be efficient and should take less than O(n) time. The code should start with:
```python
from typing import List
def sum_of_odd_elements(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_odd_elements(arr: List[int]) -> int:
"""
Calculate the sum of all odd elements in the given array of integers.
The function is designed to be efficient and should take less than O(n) time.... |
magic_evol_110k | 101,253 | Write a Python function to calculate the percentage of completed tasks given the total number of tasks and the number of completed tasks. The function should handle edge cases such as zero total tasks and negative values for completed tasks. The code should start with:
```python
def calculate_progress_percentage(total:... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_progress_percentage(total: int, completed: int) -> float:
"""
Calculate the percentage of completed tasks given the total number of tasks and the number of completed tasks.
Args:
total (int): The total... |
magic_evol_110k | 101,256 | Write a Python function to find all prime numbers within a given range [n, m] inclusive. The function should be optimized to check the divisibility of numbers only up to their square root. The function should handle cases where n is less than 2 by adjusting n to 2, as prime numbers start from 2.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def primes_in_range(n: int, m: int) -> List[int]:
"""
Returns a list of prime numbers within the range [n, m] inclusive.
Args:
n (int): The lower bound of the range (inclusive).
... |
magic_evol_110k | 101,259 | Write a Python function to compute the average of a given list of numbers and print the result to the console. The function should handle an empty list by printing a message indicating that the list is empty.
The code should start with:
```python
from typing import List
def compute_and_print_average(numbers: List[flo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def compute_and_print_average(numbers: List[float]) -> None:
"""
Computes the average of a given list of numbers and prints the result to the console.
If the list is empty, prints a message indicatin... |
magic_evol_110k | 101,278 | Write a Python function to create a two-dimensional matrix of dimensions `n` by `m` populated solely with zero values. The function should return the matrix. The code should start with:
```python
from typing import List
def create_zero_matrix(n: int, m: int) -> List[List[int]]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_zero_matrix(n: int, m: int) -> List[List[int]]:
"""
Create a two-dimensional matrix of dimensions n by m filled with zero values.
Args:
n (int): The number of rows in the matrix.
... |
magic_evol_110k | 101,281 | Write a Python function that generates a series of prime numbers within a given range ceiling using the Sieve of Eratosthenes algorithm. The function should yield each prime number instead of returning a list of primes. The code should start with:
```python
def generate_primes(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def generate_primes(n: int) -> int:
"""
Generates prime numbers up to a given range ceiling using the Sieve of Eratosthenes algorithm.
Args:
n (int): The range ceiling up to which prime numbers are to be generated.
... |
magic_evol_110k | 101,287 | Write a Python function to demonstrate the usage of `break` and `continue` statements within a `for` loop. The function should iterate over a range of numbers and print each number, but it should skip printing the number 5 using the `continue` statement and stop the loop entirely when it encounters the number 7 using t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def demonstrate_break_and_continue(n: int) -> List[int]:
"""
Demonstrates the usage of 'break' and 'continue' statements within a 'for' loop.
The loop iterates over a range of numbers from 0 to n-1, ... |
magic_evol_110k | 101,295 | Write a Python function to convert a binary string to its decimal (base-10) equivalent. The function should accept a single input parameter, which is a binary string, and return the corresponding decimal integer. The function should handle binary strings of any length, including those with leading zeros.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_decimal(binary_string: str) -> int:
"""
Converts a binary string to its decimal (base-10) equivalent.
Args:
binary_string (str): The binary string to be converted. It should consist only of '0's and '1... |
magic_evol_110k | 101,332 | Write a Python function to construct a clockwise spiral pathway through a given bidimensional matrix composed of integral numeric values. The function should return a list of elements in the order they are encountered when traversing the matrix in a spiral manner, starting from the top-left corner and moving right, dow... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def spiral_pathway(matrix: List[List[int]]) -> List[int]:
"""
Constructs a clockwise spiral pathway through a given bidimensional matrix.
Args:
matrix (List[List[int]]): A 2D list of integer... |
magic_evol_110k | 101,339 | Write a Python function to flatten a given tri-dimensional array into a one-dimensional list. The tri-dimensional array is characterized by its `p` layers, `m` horizontal lines, and `n` vertical lines. The function should start with:
```python
from typing import List
def flatten_3d_array(matrix: List[List[List[int]]])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def flatten_3d_array(matrix: List[List[List[int]]]) -> List[int]:
"""
Flattens a given tri-dimensional array into a one-dimensional list.
Args:
matrix (List[List[List[int]]]): The tri-dimens... |
magic_evol_110k | 101,367 | Write a Python function to determine the prime factors of a given input number efficiently. The function should be optimized to handle very large numbers and minimize computational resources. The solution must also include a comprehensive evaluation of its time and space complexity. The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def prime_factors(n: int) -> List[int]:
"""
Determine the prime factors of a given input number efficiently.
Args:
n (int): The number for which to find the prime factors.
Returns:
... |
magic_evol_110k | 101,383 | Write a Python function to remove duplicates from a given list while preserving the order of the first occurrence of each element. The function should return a new list with unique elements in the order they appeared in the original list.
The code should start with:
```python
from typing import List
def remove_duplic... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_preserve_order(input_list: List[int]) -> List[int]:
"""
Removes duplicates from the given list while preserving the order of the first occurrence of each element.
Args:
... |
magic_evol_110k | 101,390 | Write a Python function to find the k lowest even numbers from a given list of integers. The function should return a list containing the k lowest even numbers in ascending order. If the number of even numbers in the list is less than k, the function should return all the even numbers present in the list.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_k_lowest_even_numbers(numbers: List[int], k: int) -> List[int]:
"""
Finds the k lowest even numbers from a given list of integers.
Args:
numbers (List[int]): The list of integers fr... |
magic_evol_110k | 101,393 | Write a Python function to determine if a given circle overlaps with any of the given axis-aligned rectangles. The circle is represented by its radius and the coordinates of its center (`x_center`, `y_center`). Each rectangle is represented by the coordinates of its bottom-left corner (`x1`, `y1`) and its top-right cor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_circle_overlapping_rectangles(radius: int, x_center: int, y_center: int, rectangles: List[List[int]]) -> bool:
"""
Determine if a given circle overlaps with any of the given axis-aligned rectangle... |
magic_evol_110k | 101,397 | Write a Python function to perform floor division on two given integers and return the result. The function should handle cases where the divisor is zero by returning a specific error message.
The code should start with:
```python
def floor_division(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def floor_division(x: int, y: int) -> int:
"""
Perform floor division on two integers and return the result.
If the divisor is zero, return an error message.
Args:
x (int): The dividend.
y (int): The div... |
magic_evol_110k | 101,401 | Write a Python function to determine whether a given number `n` is prime, and return either `x` or `y` based on the result. If `n` is a prime number, return `x`; otherwise, return `y`. The function should be efficient and handle edge cases such as non-positive integers.
The code should start with:
```python
def is_pri... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(n: int) -> bool:
"""
Determine if a given number `n` is a prime number.
Args:
n (int): The number to check for primality.
Returns:
bool: True if `n` is a prime number, False otherwise.
... |
magic_evol_110k | 101,424 | Write a Python function to merge two sorted arrays into a single sorted array efficiently. The function should use a two-pointer technique to achieve this without using the built-in `sort` method. The code should start with:
```python
from typing import List
def merge_sorted_arrays(arr1: List[int], arr2: List[int]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Merge two sorted arrays into a single sorted array using the two-pointer technique.
Args:
arr1 (List[int]): The fi... |
magic_evol_110k | 101,431 | Write a Python function to calculate the average age of a cohort of subjects given their ages in a list. The function should handle cases where the list might be empty by returning `None` in such scenarios. The code should start with:
```python
from typing import List, Optional
def calculate_average_age(ages: List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def calculate_average_age(ages: List[int]) -> Optional[float]:
"""
Calculate the average age of a cohort of subjects given their ages in a list.
Args:
ages (List[int]): A list of i... |
magic_evol_110k | 101,450 | Write a Python function to merge two dictionaries and convert the resulting dictionary's keys into a set, ensuring that the set contains only unique keys. The function should handle cases where the dictionaries have overlapping keys, and the resulting set should reflect the uniqueness of the keys.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Set
def merge_dicts_to_set(dict1: Dict[str, int], dict2: Dict[str, int]) -> Set[str]:
"""
Merges two dictionaries and returns a set of unique keys from the merged dictionary.
Args:
dict1 (D... |
magic_evol_110k | 101,459 | Write a Python function to process a list of arguments, excluding the first one, and return them as a new list. The function should handle cases where the input list is empty or contains only one element.
The code should start with:
```python
from typing import List
def exclude_first_argument(args: List[str]) -> List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def exclude_first_argument(args: List[str]) -> List[str]:
"""
Returns a list of arguments excluding the first one.
Args:
args (List[str]): A list of string arguments.
Returns:
L... |
magic_evol_110k | 101,482 | Write a Python function to find all the numbers between 0 and a given upper limit `n` that are divisible by both 3 and 5. Additionally, the function should calculate and return the average of these numbers. Ensure the function is efficient, especially considering large values of `n`.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_divisible_and_average(n: int) -> float:
"""
Finds all numbers between 0 and n that are divisible by both 3 and 5, and calculates their average.
Args:
n (int): The upper limit of the range (inclusive).
... |
magic_evol_110k | 101,499 | Write a Python function to find all prime numbers within a given range `[min_value, max_value]` and return them in ascending order. The function should handle invalid ranges by raising a `ValueError`. The code should start with:
```python
def find_prime_numbers(min_value: int, max_value: int) -> list:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_prime_numbers(min_value: int, max_value: int) -> list:
"""
Find all prime numbers within the given range [min_value, max_value] and return them in ascending order.
Args:
min_value (int): The lower bound of ... |
magic_evol_110k | 101,501 | Write a Python function to find the matching range for a given value `x` from a list of ranges. Each range is represented as a string in the format "start-end" (e.g., "15-17"). The function should return the range string that contains the value `x`.
The code should start with:
```python
from typing import List, Option... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_matching_range(ranges: List[str], x: int) -> Optional[str]:
"""
Find the matching range for a given value `x` from a list of ranges.
Args:
ranges (List[str]): A list of ra... |
magic_evol_110k | 101,514 | Write a Python function to find the distinct elements that appear in both input lists, sorted in ascending order using a custom sorting function and without using Python's built-in list functions for removing duplicates. The function should start with:
```python
from typing import List
def shared_elements(list1: List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def shared_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Return a sorted list of unique elements that are present in both input lists using a custom sorting function and without using bu... |
magic_evol_110k | 101,518 | Write a Python function to generate the first `n` Fibonacci numbers and then reverse the sequence without using any built-in reverse functions or additional libraries. The function should start with:
```python
def generate_and_reverse_fibonacci(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_and_reverse_fibonacci(n: int) -> List[int]:
"""
Generates the first n Fibonacci numbers and returns the sequence in reverse order.
Args:
n (int): The number of Fibonacci numbers... |
magic_evol_110k | 101,521 | Write a Python function to calculate the total value of the integers present within a given list. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def calculate_total(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_total(numbers: List[int]) -> int:
"""
Calculate the total value of the integers present within the given list.
Args:
numbers (List[int]): A list of integers for which the total... |
magic_evol_110k | 101,531 | Write a Python function to flatten a given 2D matrix into a 1D list while maintaining the order of elements. The function should take a list of lists (matrix) as input and return a single list containing all elements from the matrix in row-major order.
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 flatten_matrix(matrix: List[List[int]]) -> List[int]:
"""
Flattens a given 2D matrix into a 1D list while maintaining the order of elements in row-major order.
Args:
matrix (List[List[in... |
magic_evol_110k | 101,547 | Write a Python function to calculate the sum of all prime numbers less than a given positive integer `n`. The function should return the total sum. The code should start with:
```python
def sum_of_primes_less_than_n(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(num: int) -> bool:
"""
Helper function to check if a number is prime.
Args:
num (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise.
""... |
magic_evol_110k | 101,549 | Write a Python function that takes a sequence of characters as input and returns a dictionary where the keys are words that have a length greater than five characters, and the values are their respective frequencies in the sequence. The function should handle punctuation and case sensitivity appropriately.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import re
def word_frequency_greater_than_five(sequence: str) -> Dict[str, int]:
"""
Returns a dictionary where keys are words longer than five characters and values are their frequencies in the sequence... |
magic_evol_110k | 101,552 | Write a Python function to verify if a given string consists solely of alphabetic characters (both uppercase and lowercase). The function should return `True` if the string contains only alphabetic characters, and `False` otherwise. The function should handle strings with spaces and special characters correctly by retu... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_alphabetic_string(s: str) -> bool:
"""
Verify if a given string consists solely of alphabetic characters (both uppercase and lowercase).
Args:
s (str): The string to be checked.
Returns:
bool: Tr... |
magic_evol_110k | 101,567 | Write a Python function to find and return all prime numbers up to a given number `n` using the Sieve of Eratosthenes algorithm. The function should be efficient and handle the input range effectively.
The code should start with:
```python
from typing import List
def sieve_of_eratosthenes(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sieve_of_eratosthenes(n: int) -> List[int]:
"""
Calculate all prime numbers up to a given number n using the Sieve of Eratosthenes algorithm.
Args:
n (int): The upper limit of the range ... |
magic_evol_110k | 101,584 | Write a Python function to calculate the Least Common Multiple (LCM) of four integers (w, x, y, z) efficiently. The function should handle negative integers and zero by returning `None` for such cases. The function should achieve this in O(log N) time complexity, where N is the maximum value among the inputs.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def lcm_of_four(w: int, x: int, y: int, z: int) -> int:
"""
Calculate the Least Common Multiple (LCM) of four integers (w, x, y, z).
Args:
w (int): The first integer.
x (int): The second integer... |
magic_evol_110k | 101,608 | Write a Python function to generate a sequence of distinct random numbers between a given range `[start, end]`. The sequence should include all the numbers from `start` to `end` exactly once. Validate the output by ensuring that every number appears only once in the sequence.
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
import random
def generate_unique_random_sequence(start: int, end: int) -> List[int]:
"""
Generates a sequence of distinct random numbers between `start` and `end` (inclusive).
Args:
start (... |
magic_evol_110k | 101,622 | Write a Python function to find the indices of a provided element in a 5x5 2D array. If the element is present multiple times, return all of its indices. If the element is not present in the array, return an appropriate message. The function should be able to handle any type of element, including integers, strings, and... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Union
def find_element_indices(arr: List[List[Union[int, str]]], element: Union[int, str]) -> Union[List[Tuple[int, int]], str]:
"""
Find the indices of a provided element in a 5x5 2D array.
... |
magic_evol_110k | 101,623 | Write a Python function that checks if a given integer `x` exists in a list of integers. The list may contain non-integer items, which should be corrected by converting them to integers if possible. Additionally, `x` may be provided as a string, which should also be converted to an integer before checking. The function... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def check_existence(x: Union[int, str], lst: List[Union[int, str]]) -> None:
"""
Checks if a given integer `x` exists in a list of integers. Handles erroneous inputs by converting strings to integ... |
magic_evol_110k | 101,624 | Write a Python function to compute the greatest common divisor (GCD) of two given positive integers using the Euclidean algorithm. The function should handle cases where the numbers are prime. The code should start with:
```python
def gcd(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def gcd(x: int, y: int) -> int:
"""
Compute the greatest common divisor (GCD) of two positive integers using the Euclidean algorithm.
Args:
x (int): The first positive integer.
y (int): The second positive i... |
magic_evol_110k | 101,627 | Write a Python function to find the longest, consecutive, palindrome substring from an alphanumeric string input. The function should return the longest palindrome substring found in the input string.
The code should start with:
```python
def longest_palindrome_substring(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def longest_palindrome_substring(s: str) -> str:
"""
Finds the longest, consecutive, palindrome substring from an alphanumeric string input.
Args:
s (str): The input string from which to find the longest palindrome ... |
magic_evol_110k | 101,632 | Write a Python function to reverse and print the elements of a given list. The function should take a list of integers as input and print each element in reverse order. The code should start with:
```python
from typing import List
def print_reverse_list(arr: List[int]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_reverse_list(arr: List[int]) -> None:
"""
Prints the elements of the given list in reverse order.
Args:
arr (List[int]): The list of integers to be printed in reverse order.
R... |
magic_evol_110k | 101,643 | Write a Python function to determine if a given integer `n` is even or odd. The function should return the string `'even'` if `n` is divisible by 2 without any remainder, and `'odd'` otherwise. The function should start with:
```python
def even_or_odd(n: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def even_or_odd(n: int) -> str:
"""
Determines if the given integer `n` is even or odd.
Args:
n (int): The integer to be checked.
Returns:
str: 'even' if `n` is divisible by 2 without any remainder, oth... |
magic_evol_110k | 101,681 | Write a Python function to create a nested dictionary based on a given mapping of specified keys to respective subkeys and their corresponding values. The function should take a dictionary `mapped_keys_values` as input, where each key maps to another dictionary of subkeys and their values. The function should return a ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def create_nested_dict(mapped_keys_values: Dict[str, Dict[str, int]]) -> Dict[str, Dict[str, int]]:
"""
Creates a nested dictionary based on the given mapping of keys to subkeys and their values.
Ar... |
magic_evol_110k | 101,694 | Write a Python function to generate a list of prime numbers up to a given upper limit using the Sieve of Eratosthenes algorithm. The function should efficiently mark non-prime numbers and return a list of prime numbers within the specified limit.
The code should start with:
```python
from typing import List
def sieve... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sieve_of_eratosthenes(upper_limit: int) -> List[int]:
"""
Generate a list of prime numbers up to the given upper limit using the Sieve of Eratosthenes algorithm.
Args:
upper_limit (int):... |
magic_evol_110k | 101,700 | Write a Python function to delete all occurrences of the prime numbers 3 and 5 from a given list and replace them with their squared values. The function should modify the list in place and return the modified list.
The code should start with:
```python
from typing import List
def replace_primes(lst: List[int]) -> Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def replace_primes(lst: List[int]) -> List[int]:
"""
Replace all occurrences of the prime numbers 3 and 5 in the given list with their squared values.
Args:
lst (List[int]): The list of inte... |
magic_evol_110k | 101,714 | Write a Python function that takes in a number and an array of numbers as arguments. The function should use a correctly named identifier to store the number, then find and return the sum of the number and all the numbers in the array. The identifier must start with an underscore followed by the letter 'a'.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_values(num: int, num_array: List[int]) -> int:
"""
Calculate the sum of a given number and all numbers in a given array.
Args:
num (int): The number to be added to the sum of the arr... |
magic_evol_110k | 101,717 | Write a Python function to generate and return the first N Fibonacci numbers along with their positions in the sequence. The function should validate that the input N is a positive integer and return an error message if it is not. The function should be optimized to handle large values of N efficiently. The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def generate_fibonacci_with_positions(n: int) -> List[Tuple[int, int]]:
"""
Generates the first N Fibonacci numbers along with their positions in the sequence.
Args:
n (int): The numb... |
magic_evol_110k | 101,721 | Write a Python function to calculate the new mean, new range, and new standard deviation of a dataset after a uniform price increase. The dataset represents the prices of items in a souvenir kiosk, and the price increase is applied to all items uniformly. The function should take the old mean, old range, old standard d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
import numpy as np
def calculate_new_stats(old_mean: float, old_range: float, old_std_dev: float, increase: float) -> Tuple[float, float, float]:
"""
Calculate the new mean, new range, and new standard ... |
magic_evol_110k | 101,727 | Write a Python function to repeat each element in a given list of strings twice. The function should take a list of strings as input and return a new list where each string is repeated twice.
The code should start with:
```python
from typing import List
def repeat_elements_twice(digits: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def repeat_elements_twice(digits: List[str]) -> List[str]:
"""
Repeats each element in the given list of strings twice.
Args:
digits (List[str]): A list of strings where each string is to be... |
magic_evol_110k | 101,732 | Write a Python function to find all unique combinations of elements from a given list, ensuring that each combination is unique and that the function handles large input arrays efficiently. The function should avoid repetition of equivalent combinations and should return a set of tuples representing these unique combin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Set, Tuple
from itertools import combinations
def unique_combinations(input_list: List[int]) -> Set[Tuple[int]]:
"""
Finds all unique combinations of elements from the given list.
Args:
inp... |
magic_evol_110k | 101,741 | Write a Python function to split a given sentence into its fundamental word components using a specified delimiter. The function should handle different delimiters and return a list of words. The code should start with:
```python
from typing import List
def split_sentence(sentence: str, delimiter: str = ' ') -> List[s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def split_sentence(sentence: str, delimiter: str = ' ') -> List[str]:
"""
Splits a given sentence into its fundamental word components using a specified delimiter.
Args:
sentence (str): The ... |
magic_evol_110k | 101,746 | Write a Python function to check whether a string has all unique characters, considering only alphabetic characters and ignoring case sensitivity (i.e., treating 'a' and 'A' as the same character). The function should return `True` if all characters in the string are unique, and `False` otherwise.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
def has_unique_chars(s: str) -> bool:
"""
Check whether a string has all unique characters, considering only alphabetic characters and ignoring case sensitivity.
Args:
s (str): The input string to check for unique c... |
magic_evol_110k | 101,755 | Write a Python function to find the k smallest elements from a given list of integers. The function should efficiently handle cases where k is larger than the length of the list, and it should return the k smallest elements in ascending order.
The code should start with:
```python
from typing import List
def find_k_s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import heapq
def find_k_smallest(nums: List[int], k: int) -> List[int]:
"""
Find the k smallest elements from the given list of integers.
Args:
nums (List[int]): The list of integers from wh... |
magic_evol_110k | 101,808 | Write a Python function to encrypt a given message using a Caesar cipher with a specified shift value. The Caesar cipher shifts each letter in the message by a fixed number of positions down the alphabet. Non-alphabet characters should remain unchanged. The function should handle both uppercase and lowercase letters an... | Here is the Python code to solve the given problem in the markdown block:
```python
def caesar_cipher(message: str, shift: int) -> str:
"""
Encrypts a given message using a Caesar cipher with the specified shift value.
Args:
message (str): The message to be encrypted.
shift (int): The numbe... |
magic_evol_110k | 101,809 | Write a Python function to determine if a given integer is divisible by 3 without any remainder. The function should return a boolean value (`True` if the number is divisible by 3, `False` otherwise). The code should start with:
```python
def is_divisible_by_3(n: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_divisible_by_3(n: int) -> bool:
"""
Determines if a given integer is divisible by 3 without any remainder.
Args:
n (int): The integer to check for divisibility by 3.
Returns:
bool: True if the nu... |
magic_evol_110k | 101,817 | Write a Python function to compute the sum of integers in a given 2D array. Each inner array can contain 1 to 5 integers. If the input 2D array is empty, raise a `ValueError` with the message "Array is empty." The function should start with:
```python
from typing import List
def sum_of_2d_array(two_d_array: List[List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_2d_array(two_d_array: List[List[int]]) -> int:
"""
Compute the sum of integers in a given 2D array. Each inner array can contain 1 to 5 integers.
If the input 2D array is empty, raise a Va... |
magic_evol_110k | 101,818 | Write a Python function to invert the elements of a specified list in situ, without resorting to instantiation of a new list or array. The function should use a two-pointer approach to swap elements from the beginning and the end of the list until the middle is reached. 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 invert_list_in_place(lst: List[int]) -> None:
"""
Inverts the elements of a specified list in situ, without resorting to instantiation of a new list or array.
Args:
lst (List[int]): The ... |
magic_evol_110k | 101,851 | Write a Python function to compute the factorial of a given non-negative integer `n` using memoization to optimize the time complexity. The function should cache previously computed factorial values to avoid redundant calculations. The code should start with:
```python
def factorial_memoized(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def factorial_memoized(n: int) -> int:
"""
Compute the factorial of a given non-negative integer `n` using memoization.
Args:
n (int): The non-negative integer for which to compute the factorial.
Returns:
... |
magic_evol_110k | 101,863 | Write a Python function to determine if a given tuple contains only unique elements. The function should return `True` if all elements in the tuple are unique, and `False` otherwise. The function should handle tuples of any length, including empty tuples.
The code should start with:
```python
from typing import Tuple,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Any
def are_all_elements_unique(tup: Tuple[Any, ...]) -> bool:
"""
Determines if all elements in the given tuple are unique.
Args:
tup (Tuple[Any, ...]): The tuple to check for unique elem... |
magic_evol_110k | 101,871 | Write a Python function to find the second smallest integer among four given integers. The function should be optimized to minimize the number of comparisons and should handle negative numbers and zero. The code should start with:
```python
def find_second_smallest(x1: int, x2: int, x3: int, x4: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_second_smallest(x1: int, x2: int, x3: int, x4: int) -> int:
"""
Finds the second smallest integer among four given integers.
Args:
x1 (int): The first integer.
x2 (int): The second integer.
... |
magic_evol_110k | 101,872 | Write a Python function to replace the last non-zero element in a given list with another specified element. The function should handle both sequence and non-sequence lists. The function should start with:
```python
from typing import List
def replace_last_non_zero_element(lst: List[int], element: int) -> List[int]:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def replace_last_non_zero_element(lst: List[int], element: int) -> List[int]:
"""
Replace the last non-zero element in the given list with the specified element.
Args:
lst (List[int]): The l... |
magic_evol_110k | 101,883 | Write a Python function to calculate the frequency of each unique character in a given string. The function should return a dictionary where the keys are the unique characters and the values are their respective frequencies. The code should start with:
```python
from typing import Dict
def character_frequency(input_st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def character_frequency(input_string: str) -> Dict[str, int]:
"""
Calculate the frequency of each unique character in the given string.
Args:
input_string (str): The input string for which c... |
magic_evol_110k | 101,888 | Write a Python function to format a given list of strings into a specified output structure. The function should concatenate the strings with a space and then wrap the result in square brackets, followed by a newline character, and finally append a period. The code should start with:
```python
from typing import List
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def format_strings(input_strings: List[str]) -> str:
"""
Formats a given list of strings into a specified output structure.
The function concatenates the strings with a space, wraps the result in sq... |
magic_evol_110k | 101,909 | Write a Python function to reshape a given 1D list into a 2D list with specified dimensions. The function should ensure that the reshaped matrix has the correct number of elements as in the original list. If the reshape operation is not possible due to mismatch in the number of elements, the function should return `Non... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def reshape_list(vector: List[int], rows: int, cols: int) -> Optional[List[List[int]]]:
"""
Reshape a given 1D list into a 2D list with specified dimensions.
Args:
vector (List[int... |
magic_evol_110k | 101,921 | Write a Python function to merge two ascending-ordered arrays of integers into a single, consolidated, and arranged series without using any pre-defined sorting or merging functions. The function should efficiently combine the two arrays by iterating through them and appending the smallest element from either array to ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Merges two ascending-ordered arrays of integers into a single, consolidated, and arranged series.
Args:
arr1 (List... |
magic_evol_110k | 101,923 | Write a Python function to create a dictionary from two given lists, where the first list contains the keys and the second list contains the corresponding values. Ensure that the function handles cases where the lists are of different lengths by ignoring the extra elements in the longer list. The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_dict_from_lists(keys: List[str], values: List[int]) -> Dict[str, int]:
"""
Creates a dictionary from two lists, where the first list contains the keys and the second list contains the co... |
magic_evol_110k | 101,963 | Write a Python function to sort an array of numeric elements in descending order using a recursive QuickSort algorithm. The function should not use any built-in sorting functions. The code should start with:
```python
from typing import List
def quick_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 quick_sort_descending(arr: List[int]) -> List[int]:
"""
Sorts an array of numeric elements in descending order using a recursive QuickSort algorithm.
Args:
arr (List[int]): The array of ... |
magic_evol_110k | 102,001 | Write a Python function to eliminate repetitive elements within a two-dimensional array consisting of integers while maintaining the original order of the subarrays. The function should ensure that each element appears only once across all subarrays. The code should start with:
```python
from typing import List
def el... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def eliminate_repetitive_elements(arr: List[List[int]]) -> List[List[int]]:
"""
Eliminates repetitive elements within a two-dimensional array while maintaining the original order of the subarrays.
A... |
magic_evol_110k | 102,008 | Write a Python function to calculate the differential between corresponding elements of two lists of integers. If the lists are not of the same length, the function should return a specific error message. The function should start with:
```python
from typing import List
def calculate_differentials(x: List[int], y: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_differentials(x: List[int], y: List[int]) -> List[int] or str:
"""
Calculate the differential between corresponding elements of two lists of integers.
Args:
x (List[int]): The ... |
magic_evol_110k | 102,025 | Write a Python function to iterate over a list of items and return a new list where each item is processed independently. The processing involves converting each item to uppercase and appending the word "ITEM" before each item. The function should handle lists of any length and any type of string items.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def process_items(items: List[str]) -> List[str]:
"""
Processes each item in the input list by converting it to uppercase and prepending "ITEM" to it.
Args:
items (List[str]): A list of stri... |
magic_evol_110k | 102,061 | Write a Python function to identify the nth term in a series where each term is generated by the sum of the two previous terms, but only even numbers are accepted. The function should handle negative, positive, and zero values, and raise an error for invalid inputs (e.g., non-integer numbers or numbers less than or equ... | Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci_evens(n: int) -> int:
"""
Returns the nth term in a series where each term is generated by the sum of the two previous terms,
but only even numbers are accepted.
Args:
n (int): The position of the ... |
magic_evol_110k | 102,081 | Write a Python function to update the value of a specific key in a dictionary based on the presence of another key. If the key "c" is present in the dictionary, update its value to "cherries". Otherwise, update the value of the key "a" to "apples". The function should start with:
```python
from typing import Dict
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def update_dict_value(my_dict: Dict[str, str]) -> Dict[str, str]:
"""
Update the value of a specific key in the dictionary based on the presence of another key.
If the key "c" is present in the dict... |
magic_evol_110k | 102,086 | Write a Python function to calculate the product of all numeric elements in a given list. The list may contain integers, floating-point numbers, and non-numeric data. Implement error handling to skip non-numeric elements and continue calculating the product of the remaining numeric elements. The function should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def product_of_numeric_elements(num_list: List[float]) -> float:
"""
Calculate the product of all numeric elements in the given list.
Args:
num_list (List[float]): The list containing numeri... |
magic_evol_110k | 102,097 | Write a Python function to convert a given integer into its Roman numeral representation. The function should handle integers from 1 to 3999, which is the range of Roman numerals typically used in classical antiquity. The code should start with:
```python
def int_to_roman(num: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def int_to_roman(num: int) -> str:
"""
Converts a given integer into its Roman numeral representation.
Args:
num (int): The integer to be converted, ranging from 1 to 3999.
Returns:
str: The Roman numer... |
magic_evol_110k | 102,115 | Write a Python function to determine if an array of integers is symmetric. An array is symmetric if it reads the same backward as forward. The function should return `True` if the array is symmetric and `False` otherwise. The code should start with:
```python
from typing import List
def is_symmetric(arr: List[int]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_symmetric(arr: List[int]) -> bool:
"""
Determine if an array of integers is symmetric.
Args:
arr (List[int]): The array of integers to check for symmetry.
Returns:
bool: ... |
magic_evol_110k | 102,131 | Write a Python function to find the mode (the number that appears most frequently) in a list of numbers efficiently. The function should handle large inputs efficiently and return the correct mode. Assume there is only one mode in the list.
The code should start with:
```python
from typing import List
def find_mode(n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_mode(numbers: List[int]) -> int:
"""
Finds the mode (the number that appears most frequently) in a list of numbers.
Args:
numbers (List[int]): A list of integers from which to find ... |
magic_evol_110k | 102,140 | Write a Python function to extract and return the details of the secondary element from a given one-dimensional, map-like data structure. The data structure is a dictionary where each key maps to another dictionary containing details like name, age, and city. The function should handle cases where the secondary element... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Optional
def get_secondary_element_details(data: Dict[str, Dict[str, str]]) -> Optional[Dict[str, str]]:
"""
Extracts and returns the details of the secondary element from a given one-dimensional, map-l... |
magic_evol_110k | 102,141 | Write a Python function to sort a given array of numerical elements in descending order. The function should return the sorted array. 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 array of numerical elements in descending order.
Args:
arr (List[int]): The array of numerical elements to be sorted.
... |
magic_evol_110k | 102,160 | Write a Python function to find and return the 3 lowest even numbers and the 3 highest odd numbers from a given dataset without using any built-in or third-party sorting functions. The dataset is a list of integers. The function should start with:
```python
from typing import List, Tuple
def find_lowest_even_highest_o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_lowest_even_highest_odd(dataset: List[int]) -> Tuple[List[int], List[int]]:
"""
Finds the 3 lowest even numbers and the 3 highest odd numbers from the given dataset.
Args:
da... |
magic_evol_110k | 102,168 | Write a Python function to determine if two given expressions are composed of the same permutations of distinct phrases, disregarding case and punctuation. The function should return `True` if the phrases are composed of the same unique words in any order, and `False` otherwise.
The code should start with:
```python
i... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def compare_word_permutations(phrase1: str, phrase2: str) -> bool:
"""
Determine if two given expressions are composed of the same permutations of distinct phrases,
disregarding case and punctuation.
Args:
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.