source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 94,121 | Write a Python function to remove duplicate values from a given list of numerical values efficiently. The function should maintain the order of the first occurrence of each element. The code should start with:
```python
from typing import List
def remove_duplicates_preserve_order(num_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 remove_duplicates_preserve_order(num_list: List[int]) -> List[int]:
"""
Removes duplicate values from a list of numerical values while preserving the order of the first occurrence of each element.
... |
magic_evol_110k | 94,129 | Write a Python function to convert a hexadecimal string into its corresponding binary string representation. The function should handle both uppercase and lowercase hexadecimal characters and should return the binary string without the '0b' prefix that Python's `bin()` function includes.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_binary(hex_str: str) -> str:
"""
Convert a hexadecimal string to its corresponding binary string representation.
Args:
hex_str (str): The hexadecimal string to be converted.
Returns:
str: The... |
magic_evol_110k | 94,158 | Write a Python function to compute an array where each element at the i'th position is the product of all the elements of the given array except the one at the i'th position. The solution should not use division and should have a time complexity of O(n).
The code should start with:
```python
from typing import List
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def product_except_self(nums: List[int]) -> List[int]:
"""
Compute an array where each element at the i'th position is the product of all elements
of the given array except the one at the i'th positi... |
magic_evol_110k | 94,161 | Write a Python function to calculate the sum of all integers in a multi-tier nested list. The function should handle lists nested at any level. The code should start with:
```python
from typing import List, Union
def sum_of_nested_list(nested_list: List[Union[int, List]]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Union
def sum_of_nested_list(nested_list: List[Union[int, List]]) -> int:
"""
Calculate the sum of all integers in a multi-tier nested list.
Args:
nested_list (List[Union[int, List]]): A ... |
magic_evol_110k | 94,162 | Write a Python function to reverse the words in a given string while preserving the order of spaces between words and handling leading/trailing spaces. The function should correctly handle multiple spaces between words and ensure that the reversed string maintains the original spacing structure.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_words_in_string(s: str) -> str:
"""
Reverses the words in a given string while preserving the order of spaces between words and handling leading/trailing spaces.
Args:
s (str): The input string containin... |
magic_evol_110k | 94,202 | Write a Python function to identify and count the number of unique elements in a given list. The function should return the count of unique elements, not the total count of elements in the list. The code should start with:
```python
from typing import List
def count_unique_elements(lst: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_unique_elements(lst: List[int]) -> int:
"""
Counts the number of unique elements in a given list.
Args:
lst (List[int]): The list of integers from which to count unique elements.
... |
magic_evol_110k | 94,205 | Write a Python function to determine if a given integer is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding itself). The function should return `True` if the number is perfect and `False` otherwise. The code should start with:
```python
def is_perfect_n... | Here is the Python code to solve the given problem in the markdown block:
:
```python
def is_perfect_number(n: int) -> bool:
"""
Determines if a given integer is a perfect number.
A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding itself).
Args:
n... |
magic_evol_110k | 94,210 | Write a Python function to create and manage a student database using a dictionary. Each key in the dictionary represents a student's ID, and each value is a tuple containing the student's full legal name and age in years. The function should allow adding new students, updating existing student details, and retrieving ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple, Optional
def student_database() -> Dict[int, Tuple[str, int]]:
"""
Manages a student database using a dictionary. Each key is a student's ID, and each value is a tuple containing the student's fu... |
magic_evol_110k | 94,217 | Write a Python function to reverse the order of elements in a given list of integers. The function should return a new list with the elements in reverse order. The original list should not be modified. The code should start with:
```python
from typing import List
def reverse_list(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 reverse_list(arr: List[int]) -> List[int]:
"""
Reverses the order of elements in a given list of integers and returns a new list.
Args:
arr (List[int]): The list of integers to be reve... |
magic_evol_110k | 94,218 | Write a Python function to create a dictionary where each element of a given tuple acts as the key and its index as the value. The function should handle tuples of any length and return the resulting dictionary.
The code should start with:
```python
from typing import Tuple, Dict
def tuple_to_index_dict(tuple_input: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict
def tuple_to_index_dict(tuple_input: Tuple[int]) -> Dict[int, int]:
"""
Create a dictionary where each element of the given tuple acts as the key and its index as the value.
Args:
tup... |
magic_evol_110k | 94,224 | Write a Python function that takes a day of the week as input and prints "Happy [Day]!" if the input is a valid day of the week. If the input is not a valid day of the week, the function should print "Invalid day". The function should be case-insensitive and should handle any input string.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def happy_day(day: str) -> None:
"""
Prints "Happy [Day]!" if the input day is a valid day of the week.
Otherwise, prints "Invalid day".
Args:
day (str): The day of the week to validate and print a message for.
... |
magic_evol_110k | 94,226 | Write a Python function to find the smallest and largest numbers in a given array of integers without using built-in functions like `min()` and `max()`. The function should handle negative numbers and duplicates in the array. The code should start with:
```python
from typing import List, Tuple
def find_smallest_larges... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_smallest_largest(numbers: List[int]) -> Tuple[int, int]:
"""
Find the smallest and largest numbers in a given array of integers.
Args:
numbers (List[int]): The array of integ... |
magic_evol_110k | 94,239 | Write a Python function that assigns a specific value to a variable and validates the assignment. The function should take a variable as input, assign a predefined value to it, and return the modified variable. Additionally, write a validation function that checks if the variable has been correctly assigned the predefi... | Here is the Python code to solve the given problem in the markdown block:
```python
def assign_value(var, value):
"""
Assigns the given value to the provided variable and returns it.
Args:
var: The variable to which the value will be assigned.
value: The value to be assigned to the variable... |
magic_evol_110k | 94,242 | 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. If the lists are of different lengths, the function should handle this by only creating key-value pairs for the elements that have corresponding pairs in bot... | 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 given lists, where the first list contains the keys and the second list contains ... |
magic_evol_110k | 94,257 | Write a Python function to identify the rarest element(s) in a provided list. The function should handle various edge cases, such as multiple rarest elements and empty lists. Additionally, provide a piece of erroneous code and ask the candidate to identify and rectify errors present in that code.
The starter code for ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_rarest_elements(input_list: List[Union[int, str]]) -> Union[List[Union[int, str]], None]:
"""
Identify the rarest element(s) in the provided list.
Args:
input_list: A list of... |
magic_evol_110k | 94,258 | Write a Python function to calculate the volume of a pyramid given the area of its base and its height. The function should return the volume rounded to two decimal places. The code should start with:
```python
def pyramid_volume(base_area: float, height: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def pyramid_volume(base_area: float, height: float) -> float:
"""
Calculate the volume of a pyramid given the area of its base and its height.
Args:
base_area (float): The area of the base of the pyramid.
he... |
magic_evol_110k | 94,262 | Write a Python function that takes a list of strings and a single character as input, and returns a list of strings from the input list that contain the specified character. The function should be case-sensitive, meaning it should distinguish between uppercase and lowercase characters.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_strings_with_char(lst: List[str], char: str) -> List[str]:
"""
Returns a list of strings from the input list that contain the specified character.
Args:
lst (List[str]): A list of s... |
magic_evol_110k | 94,280 | Write a Python function that demonstrates the behavior of the "else" clause within a "for" loop. The function should iterate over a list of integers and check if a specific integer is present in the list. If the integer is found, it should print "Found" and break out of the loop. If the loop completes without finding t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_integer_in_list(lst: List[int], target: int) -> None:
"""
Demonstrates the behavior of the "else" clause within a "for" loop.
Args:
lst (List[int]): The list of integers to search t... |
magic_evol_110k | 94,295 | Write a Python function to convert a given list of tuples into a list of dictionaries. Each tuple in the list represents a key-value pair, and the function should convert these tuples into dictionaries. If a key appears more than once in the list, the value should be updated to the latest occurrence of that key.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def convert_tuples_to_dicts(list_of_tuples: List[Tuple[str, any]]) -> List[Dict[str, any]]:
"""
Converts a list of tuples into a list of dictionaries. Each tuple represents a key-value pair.... |
magic_evol_110k | 94,298 | Write a Python function to efficiently merge two pre-sorted arrays into a single sorted array in linear time complexity, O(n). The function should handle arrays of different lengths and ensure that the merged array maintains the sorted order.
The code should start with:
```python
from typing import List
def merge_sor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_arrays(A: List[int], B: List[int]) -> List[int]:
"""
Merges two pre-sorted arrays into a single sorted array in linear time.
Args:
A (List[int]): The first pre-sorted array.... |
magic_evol_110k | 94,305 | Write a Python function to detect specific palindromes in a list of disorganized words. The function should be case-insensitive and should disregard non-letter characters. The complexity of the solution should be at most O(n log n), where n is the total number of letters in all the words combined.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_nonletters(word: str) -> str:
"""
Removes all non-letter characters from the given word.
Args:
word (str): The word from which to remove non-letter characters.
Returns:
... |
magic_evol_110k | 94,310 | Write a Python function to calculate the arithmetic summation of all numerical values in a given list of integers. The function should handle lists of varying lengths, including empty lists. The code should start with:
```python
from typing import List
def arithmetic_summation(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def arithmetic_summation(numbers: List[int]) -> int:
"""
Calculate the arithmetic summation of all numerical values in a given list of integers.
Args:
numbers (List[int]): The list of intege... |
magic_evol_110k | 94,319 | Write a Python function to find the mode(s) in a list of numbers. If there are multiple modes, the function should return a list of all of them sorted in ascending order. The function should handle lists with numbers ranging from -10^6 to 10^6 and with lengths between 1 and 10^6 efficiently.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import Counter
def find_modes(numbers: List[int]) -> List[int]:
"""
Find the mode(s) in a list of numbers. If there are multiple modes, return a list of all of them sorted in ascending o... |
magic_evol_110k | 94,348 | Write a Python function to reverse the order of words in a given string containing ASCII characters only, while preserving the original case of each character. The function should handle strings with multiple spaces between words and leading/trailing spaces. The code should start with:
```python
def reverse_words_in_st... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_words_in_string(input_string: str) -> str:
"""
Reverses the order of words in a given string while preserving the original case of each character.
Handles multiple spaces between words and leading/trailing spaces... |
magic_evol_110k | 94,368 | Write a Python function that filters elements from a given list based on a provided predicate function. The function should return a new list containing only the elements that satisfy the predicate. The code should start with:
```python
from typing import List, Callable
def filter_elements(lst: List[int], pred: Callab... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable
def filter_elements(lst: List[int], pred: Callable[[int], bool]) -> List[int]:
"""
Filters elements from the given list based on the provided predicate function.
Args:
lst (List[in... |
magic_evol_110k | 94,370 | Write a Python function to calculate the product of a list of numbers, where the list could contain both integers and real numbers. The function should be robust enough to handle edge cases such as an empty list, single-number lists, or lists with zero. Your solution should be in Python and avoid using external librari... | Here is the Python code to solve the given problem in the markdown block:
```python
def product_of_list(items: list) -> float:
"""
Calculate the product of a list of numbers.
Args:
items (list): A list of numbers (integers or real numbers).
Returns:
float: The product of the numbers in... |
magic_evol_110k | 94,411 | Write a Python function to find the distinct elements in two given lists, `listA` and `listB`. The function should return two sets: one containing the elements that are unique to `listA` and the other containing the elements that are unique to `listB`. The function should start with:
```python
from typing import List, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Set
def find_distinct_elements(listA: List[int], listB: List[int]) -> (Set[int], Set[int]):
"""
Find the distinct elements in two lists.
Args:
listA (List[int]): The first list of integers.... |
magic_evol_110k | 94,414 | Write a Python function to refine and construct a more sophisticated version of the `locate_numbers` function. This function should output a sextuple `(a, b, c, d, e, f)` where:
- `a` signifies the lowest prime number.
- `b` represents the highest prime number.
- `c` embodies the smallest composite number.
- `d` charac... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Optional
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
... |
magic_evol_110k | 94,418 | Write a Python function to generate the first `n` terms of a Fibonacci sequence in a randomized order without repetition. The function should handle edge cases where `n` is negative, zero, or greater than the number of Fibonacci terms that a Python program can generate. 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
import random
def random_fibonacci_terms(n: int) -> List[int]:
"""
Generate the first n terms of a Fibonacci sequence in a randomized order without repetition.
Args:
n (int): The number of t... |
magic_evol_110k | 94,427 | Write a Python function to convert a binary input (in string format) to its octal equivalent (represented as a string) without using any built-in or external libraries. The function should handle error cases such as binary strings starting with more than one '0' and invalid characters. Additionally, the function should... | Here is the Python code to solve the given problem in the markdown block:
```python
def custom_binary_to_octal(binary_str: str) -> str:
"""
Convert a binary input (string) to its octal representation (string) without using any built-in or imported functions.
Args:
binary_str (str): The binary strin... |
magic_evol_110k | 94,428 | Write a Python function to recursively flatten a nested list, specifically a 2D matrix, into a single linear list. The function should handle lists of varying depths and ensure that all elements are included in the resulting list. The code should start with:
```python
from typing import List
def flatten_nested_list(ne... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def flatten_nested_list(nested_list: List) -> List[int]:
"""
Recursively flattens a nested list into a single linear list.
Args:
nested_list (List): The nested list to be flattened.
Ret... |
magic_evol_110k | 94,446 | Write a Python function to reverse a given string without using built-in functions or methods. The function should handle strings of any length, including empty strings. The code should start with:
```python
def reverse_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(s: str) -> str:
"""
Reverses a given string without using built-in functions or methods.
Args:
s (str): The input string to be reversed.
Returns:
str: The reversed string.
"""
... |
magic_evol_110k | 94,449 | Write a Python function to identify common elements from four distinct arrays, `a1`, `a2`, `a3`, and `a4`, that appear under the same index in all four arrays. The function should return an array of these common elements. The function should handle arrays of varying lengths and return common elements up to the length o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def find_common_elements(a1: List[Any], a2: List[Any], a3: List[Any], a4: List[Any]) -> List[Any]:
"""
Identifies common elements from four distinct arrays that appear under the same index in all fo... |
magic_evol_110k | 94,455 | Write a Python function to create a dictionary from a list of tuples, where each tuple contains exactly two elements: the first element as the key and the second element as the corresponding value. The function should handle any list of tuples, ensuring that each tuple has exactly two elements. If a tuple does not have... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def create_dictionary_from_tuples(pairs: List[Tuple[any, any]]) -> dict:
"""
Creates a dictionary from a list of tuples, where each tuple contains exactly two elements:
the first element as th... |
magic_evol_110k | 94,459 | Write a Python function to compute the prime factorization of a given integer greater than 1. The function should return a dictionary where the keys are the prime factors and the values are their respective powers. Additionally, the function should print the prime factorization in the form of `prime_factor^power * prim... | Here is the Python code to solve the given problem in the markdown block:
```python
def prime_factorization(n: int) -> dict:
"""
Compute the prime factorization of a given integer greater than 1.
Args:
n (int): The integer to factorize.
Returns:
dict: A dictionary where keys are prime ... |
magic_evol_110k | 94,475 | Write a Python function to implement the bubble sort algorithm for sorting an array of floating point numbers in ascending order. The function should modify the input list in place and return the sorted list.
The code should start with:
```python
from typing import List
def bubble_sort(float_nums: List[float]) -> Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(float_nums: List[float]) -> List[float]:
"""
Sorts an array of floating point numbers in ascending order using the bubble sort algorithm.
Args:
float_nums (List[float]): The ... |
magic_evol_110k | 94,478 | Write a Python function to encode a text string using the ROT13 cipher, which shifts each letter by 13 positions in the alphabet while maintaining case sensitivity and preserving non-alphabetic characters. Additionally, create a corresponding ROT13 decoding function to reverse the encoded string back to its original fo... | Here is the Python code to solve the given problem in the markdown block:
```python
def rot13_encode(text: str) -> str:
"""
Encodes the given text using the ROT13 cipher.
Args:
text (str): The text to be encoded.
Returns:
str: The encoded text.
"""
encoded_text = []
for ch... |
magic_evol_110k | 94,493 | Write a Python function to print the current date, time, and weekday in a specific format. The format should be: "Weekday, Month Day, Year - HH:MM:SS". For example, "Monday, October 9, 2023 - 14:30:45".
The code should start with:
```python
from datetime import datetime
def print_current_datetime():
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def print_current_datetime():
"""
Prints the current date, time, and weekday in the format: "Weekday, Month Day, Year - HH:MM:SS".
Example output: "Monday, October 9, 2023 - 14:30:45"
"""
... |
magic_evol_110k | 94,494 | Write a Python function to eliminate all occurrences of multiple spaces in a given text string and replace them with a single space. The function should handle any number of consecutive spaces, not just double spaces. The code should start with:
```python
import re
def eliminate_multiple_spaces(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def eliminate_multiple_spaces(text: str) -> str:
"""
Eliminates all occurrences of multiple spaces in the given text string and replaces them with a single space.
Args:
text (str): The input text string c... |
magic_evol_110k | 94,500 | Write a Python function to find all prime numbers up to a given limit `n` using the Sieve of Eratosthenes algorithm. The function should return a list of all prime numbers less than `n`.
The code should start with:
```python
from typing import List
def find_primes_up_to(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_primes_up_to(n: int) -> List[int]:
"""
Find all prime numbers up to a given limit n using the Sieve of Eratosthenes algorithm.
Args:
n (int): The upper limit up to which prime numbe... |
magic_evol_110k | 94,510 | Write a Python function to create a 3D matrix `C` of size `MxNxL` from a given 2D matrix `A` of size `MxN` and a vector `b` of size `L` such that each element `C[m, n, k]` is the product of the corresponding element `A[m, n]` and `b[k]`. The function should leverage NumPy for efficient array operations.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def create_3d_matrix(A: np.ndarray, b: np.ndarray) -> np.ndarray:
"""
Create a 3D matrix C of size MxNxL from a 2D matrix A of size MxN and a vector b of size L.
Each element C[m, n, k] is the product of ... |
magic_evol_110k | 94,521 | Write a Python function to find the penultimate minimum value in a given list of floating-point numbers. The function should handle duplicate values and return the second smallest unique value in the list. The code should start with:
```python
from typing import List
def penultimate_min_value(arr: List[float]) -> floa... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def penultimate_min_value(arr: List[float]) -> float:
"""
Find the penultimate minimum value in a list of floating-point numbers.
Args:
arr (List[float]): The list of floating-point numbers.... |
magic_evol_110k | 94,522 | Write a Python function to find the most common fruit name from a given list of fruit names. The function should return the fruit name that appears most frequently in the list. If there is a tie for the most common fruit, the function should return the first fruit name that reaches the maximum frequency.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import Counter
def most_common_fruit(fruit_list: List[str]) -> str:
"""
Find the most common fruit name from a given list of fruit names.
Args:
fruit_list (List[str]): A lis... |
magic_evol_110k | 94,538 | Write a Python function to manage the state of a window application. The function should save the window's size, position, and state when it is closed. If the window is closed in a minimized state, it should restore to the last visible state (either Normal or Maximized). The function should return a dictionary containi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def save_window_state(window_state: str, window_location: Tuple[int, int], window_size: Tuple[int, int], last_visible_state: str) -> Dict[str, str]:
"""
Saves the state of a window application, ha... |
magic_evol_110k | 94,540 | Write a Python function to identify and extract the smallest numerical element within a provided array. The function should handle arrays of integers and floating-point numbers. The code should start with:
```python
from typing import List, Union
def find_smallest_element(array: List[Union[int, float]]) -> Union[int, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_smallest_element(array: List[Union[int, float]]) -> Union[int, float, None]:
"""
Identify and extract the smallest numerical element within the provided array.
Args:
array (L... |
magic_evol_110k | 94,551 | Write a Python function to transform a given list of integers by applying a custom transformation function to each element. The custom transformation function should be provided as an argument to the main function. The main function should return the resulting list after applying the transformation to each element.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable
def transform_list(input_list: List[int], transform_func: Callable[[int], int]) -> List[int]:
"""
Transforms each element in the input list using the provided transformation function.
Args... |
magic_evol_110k | 94,554 | Write a Python function to replace all occurrences of a specified character in a given string with another specified character. The function should take three parameters: the input string, the character to be replaced, and the character to replace with. The function should return the modified string.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_character(input_string: str, old_char: str, new_char: str) -> str:
"""
Replace all occurrences of a specified character in a given string with another specified character.
Args:
input_string (str): The i... |
magic_evol_110k | 94,575 | Write a Python function to determine the length of the longest ascending subsequence within a given numerical array. An ascending subsequence is a sequence of array elements where each element is strictly greater than the previous element. The function should return the length of the longest such subsequence.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_ascending_subsequence(arr: List[int]) -> int:
"""
Determine the length of the longest ascending subsequence within a given numerical array.
Args:
arr (List[int]): The numerical a... |
magic_evol_110k | 94,579 | Write a Python function to identify and return a list of prime numbers from a given list of integers. A prime number is defined as a number greater than 1 that has no divisors other than 1 and itself. The function should efficiently determine whether each number in the list is prime and return only the prime numbers.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_prime_numbers(numbers: List[int]) -> List[int]:
"""
Identifies and returns a list of prime numbers from the given list of integers.
Args:
numbers (List[int]): A list of integers fro... |
magic_evol_110k | 94,593 | Write a Python function to calculate the number of successful shots or baskets Jess made in a basketball match, given the total points scored and the points per basket. The function should return the number of baskets as an integer.
The code should start with:
```python
def calculate_number_of_baskets(total_points: in... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_number_of_baskets(total_points: int, points_per_basket: int) -> int:
"""
Calculate the number of successful shots or baskets made in a basketball match.
Args:
total_points (int): The total points score... |
magic_evol_110k | 94,597 | Write a Python function to create a lower triangular matrix from a given square matrix using the NumPy library. The function should take a square matrix as input and return a new matrix that is the lower triangular form of the input matrix. The lower triangular matrix should have all elements above the main diagonal se... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def lower_triangular_matrix(matrix: np.ndarray) -> np.ndarray:
"""
Transforms a given square matrix into its lower triangular form.
Args:
matrix (np.ndarray): A square matrix represented as a Num... |
magic_evol_110k | 94,599 | Write a Python function to calculate the maximum value in an array efficiently. The function should handle both non-empty and empty arrays. For non-empty arrays, it should return the maximum value. For empty arrays, it should return `None`.
The code should start with:
```python
from typing import List, Optional
def f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_max_value(array: List[int]) -> Optional[int]:
"""
Calculate the maximum value in an array efficiently.
Args:
array (List[int]): The array of integers from which to find th... |
magic_evol_110k | 94,606 | Write a Python function to iterate over a given list and print each element along with its index. The function should handle lists of any length and any type of elements. The code should start with:
```python
from typing import List, Any
def print_elements_with_index(mylist: List[Any]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Any
def print_elements_with_index(mylist: List[Any]) -> None:
"""
Prints each element of the given list along with its index.
Args:
mylist (List[Any]): The list of elements to be printed ... |
magic_evol_110k | 94,614 | Write a Python function to disassemble a specified common spoken phrase into a collection of distinct words. The function should take a string as input and return a set of unique words found in the phrase. The code should start with:
```python
from typing import Set
def disassemble_phrase(phrase: str) -> Set[str]:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
import string
def disassemble_phrase(phrase: str) -> Set[str]:
"""
Disassembles a specified common spoken phrase into a collection of distinct words.
Args:
phrase (str): The input phrase to b... |
magic_evol_110k | 94,629 | Write a Python function to determine if a given sentence is a permutation of the aphorism "You can't judge a book by its cover", considering variations in case sensitivity and syntactic symbols. The function should return `True` if the sentence is a permutation of the aphorism, and `False` otherwise.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from collections import Counter
def is_permutation_of_aphorism(sentence: str) -> bool:
"""
Determines if the given sentence is a permutation of the aphorism "You can't judge a book by its cover".
Args:
se... |
magic_evol_110k | 94,637 | Write a Python function to determine if the first string contains the second string as a substring without using any built-in substring, contains, or equivalent methods. The function should be case insensitive and return the starting and ending indices of the substring in the original string if it exists. If the substr... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_substring_indices(s1: str, s2: str) -> tuple[int, int] | str:
"""
Determines if the first string contains the second string as a substring and returns the starting and ending indices.
Args:
s1 (str): The ma... |
magic_evol_110k | 94,642 | Write a Python function to perform a binary search on a sorted 2D matrix to find a given target element. The matrix has the following properties:
1. Integers in each row are sorted from left to right.
2. The first integer of each row is greater than the last integer of the previous row.
The function should return `Tru... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search_2d(matrix: List[List[int]], target: int) -> bool:
"""
Perform a binary search to find a target element in a sorted 2D matrix.
Args:
matrix (List[List[int]]): A 2D list of i... |
magic_evol_110k | 94,647 | Write a Python function to count the frequency of each unique character in a given string. The function should return a dictionary where the keys are the characters from the string and the values are the counts of those characters. The code should start with:
```python
from typing import Dict
def character_frequency(i... | 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]:
"""
Counts the frequency of each unique character in the given string.
Args:
input_string (str): The string for which to count c... |
magic_evol_110k | 94,653 | Write a Python function to determine if two given strings are palindromes without using Python's built-in string reversal functions or any other built-in functions that directly solve the problem. The function should return a tuple indicating whether each string is a palindrome.
The code should start with:
```python
d... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_palindromes(string1: str, string2: str) -> tuple:
"""
Determines if two given strings are palindromes without using built-in string reversal functions.
Args:
string1 (str): The first string to check.
... |
magic_evol_110k | 94,660 | Write a Python function to perform division of two large integers without using any inbuilt mathematical operators (`/`, `*`, `-`, `+`) or libraries. The function should handle both positive and negative integers and return the quotient as an integer.
The code should start with:
```python
def divide_large_integers(div... | Here is the Python code to solve the given problem in the markdown block:
```python
def divide_large_integers(dividend: int, divisor: int) -> int:
"""
Perform division of two large integers without using any inbuilt mathematical operators.
Args:
dividend (int): The number to be divided.
div... |
magic_evol_110k | 94,673 | Write a Python function to calculate the number of trips Rita needs to make to transfer a given number of rocks, given the number of rocks she can carry in each trip. The function should handle cases where the number of rocks per trip is zero or negative, returning `None` in such cases. The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_trips(total_rocks: int, rocks_per_trip: int) -> int:
"""
Calculate the number of trips Rita needs to make to transfer a given number of rocks.
Args:
total_rocks (int): The total number of rocks to be t... |
magic_evol_110k | 94,684 | Write a Python function to count the number of even and odd digits in a given integer. The function should return a tuple where the first element is the count of even digits and the second element is the count of odd digits. The function should handle both positive and negative integers.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def even_odd_count(num: int) -> tuple:
"""
Counts the number of even and odd digits in a given integer.
Args:
num (int): The integer to analyze.
Returns:
tuple: A tuple where the first element is the co... |
magic_evol_110k | 94,688 | Write a Python function to calculate the average of the smallest and largest values from a given list of integers. The function should use the `numpy` library to find the minimum and maximum values in the list. The code should start with:
```python
from typing import List
import numpy as np
def average_of_extremes(arr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import numpy as np
def average_of_extremes(arr: List[int]) -> float:
"""
Calculate the average of the smallest and largest values from a given list of integers.
Args:
arr (List[int]): The li... |
magic_evol_110k | 94,689 | Write a Python function to sort a given list of integers in descending order. The function should return the sorted list. The code should start with:
```python
from typing import List
def sort_descending(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 a given list of integers in descending order.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
List... |
magic_evol_110k | 94,690 | Write a Python function to reconstruct the original text from a list of discrete lexical elements (words) while preserving their original sequential organization. The function should handle various edge cases, such as empty lists or lists with single elements.
The code should start with:
```python
from typing import L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reconstruct_text(lexical_elements: List[str]) -> str:
"""
Reconstructs the original text from a list of discrete lexical elements (words).
Args:
lexical_elements (List[str]): A list of s... |
magic_evol_110k | 94,695 | Write a Python function to count the occurrences of the word "carrot" (case-insensitive) in a given string. The function should use regular expressions to find matches and return the total count of matches. The string can contain alphanumeric characters and symbols.
The code should start with:
```python
import re
def... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def count_carrots(s: str) -> int:
"""
Counts the occurrences of the word "carrot" (case-insensitive) in the given string.
Args:
s (str): The input string to search for the word "carrot".
Returns:
... |
magic_evol_110k | 94,721 | Write a Python function to decompress a deeply nested list into a single-level sequence. The function should handle lists that are nested arbitrarily deep. The provided erroneous code attempts to solve the problem but fails when the list is more than two levels deep. Your task is to debug and amend the provided code to... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def flat_list(nested_list: List[Any]) -> List[Any]:
"""
Decompress a deeply nested list into a single-level sequence.
Args:
nested_list (List[Any]): The nested list to be flattened.
... |
magic_evol_110k | 94,741 | Write a Python function to generate all positive pairs (A, B) where A and B are coprime to each other and their product equals a given prime number Y. The function should start with:
```python
from typing import List, Tuple
def generate_coprime_pairs(Y: int) -> List[Tuple[int, int]]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import math
def generate_coprime_pairs(Y: int) -> List[Tuple[int, int]]:
"""
Generates all positive pairs (A, B) where A and B are coprime to each other and their product equals a given prime numb... |
magic_evol_110k | 94,769 | Write a Python function to convert an octal number to its equivalent hexadecimal representation. The function should take an octal number as input and return its hexadecimal equivalent as a string. The code should start with:
```python
def octal_to_hexadecimal(octal: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def octal_to_hexadecimal(octal: int) -> str:
"""
Convert an octal number to its equivalent hexadecimal representation.
Args:
octal (int): The octal number to be converted.
Returns:
str: The hexadecimal ... |
magic_evol_110k | 94,772 | Write a Python function to subtract two bidimensional matrices. The function should handle matrices of the same dimensions and return the resulting matrix after subtraction. The code should start with:
```python
from typing import List
def subtract_matrices(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def subtract_matrices(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[List[int]]:
"""
Subtracts two bidimensional matrices of the same dimensions.
Args:
matrix1 (List[List[int]])... |
magic_evol_110k | 94,777 | Write a Python function to detect if the balance of a bank account falls below zero at any point given a list of deposit and withdrawal operations. The function should return `True` if the balance falls below zero at any point, otherwise it should return `False`. The function should handle edge cases such as an empty l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def below_zero(operations: List[int]) -> bool:
"""
Detects if the balance of a bank account falls below zero at any point given a list of deposit and withdrawal operations.
Args:
operations ... |
magic_evol_110k | 94,782 | Write a Python function to remove extra spaces from a given string, ensuring that there is exactly one space between each word and no leading or trailing spaces. The function should handle various edge cases, such as strings with multiple consecutive spaces, leading and trailing spaces, and empty strings.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_extra_spaces(input_string: str) -> str:
"""
Removes extra spaces from a given string, ensuring that there is exactly one space between each word and no leading or trailing spaces.
Args:
input_string (str)... |
magic_evol_110k | 94,799 | Write a Python function to sort a dictionary based on the ascending order of its values. The function should take a dictionary as input and return a new dictionary with the same keys but sorted by their corresponding values in ascending order.
The code should start with:
```python
from typing import Dict
def sort_dic... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_value(input_dict: Dict[str, int]) -> Dict[str, int]:
"""
Sorts a dictionary by its values in ascending order.
Args:
input_dict (Dict[str, int]): The dictionary to be sorted.... |
magic_evol_110k | 94,803 | Create a Python function to implement a custom encryption and decryption algorithm that encodes and decodes a string of characters including special characters and numbers. The encryption should be reversible, meaning that if the string is encrypted and then decrypted, the initial string is recovered. The algorithm sho... | Here is the Python code to solve the given problem in the markdown block:
```python
def encrypt(text: str, key: str) -> str:
"""
Encrypts the given text using a custom encryption algorithm based on the provided key.
Args:
text (str): The text to be encrypted.
key (str): The key used for enc... |
magic_evol_110k | 94,804 | Write a Python function to calculate the precision, recall, and F1 score of a binary classification model without using any external libraries. The function should take two lists as input: `actual` and `predicted`, where each list contains binary values (0 or 1) representing the actual and predicted labels, respectivel... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def evaluate_binary_model(actual: List[int], predicted: List[int]) -> Tuple[float, float, float]:
"""
Calculate the precision, recall, and F1 score of a binary classification model.
Args:
... |
magic_evol_110k | 94,808 | Write a Python function to calculate the factorial of a given non-negative integer `n`. The function should correctly handle edge cases such as `n = 0` and should be efficient in its computation. The code should start with:
```python
def factorial(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int:
"""
Calculate the factorial of a given non-negative integer n.
Args:
n (int): The non-negative integer for which to calculate the factorial.
Returns:
int: The factorial of ... |
magic_evol_110k | 94,811 | Write a Python function to print all even numbers less than a given number `n`. The function should iterate through the range from 0 to `n-1` and print each even number followed by the string "is an even number". The code should be refactored and optimized to avoid any logical or syntactic errors.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_even_numbers(n: int):
"""
Prints all even numbers less than the given number `n`.
Args:
n (int): The upper limit (exclusive) for the range of numbers to check.
Returns:
None: The function prin... |
magic_evol_110k | 94,820 | Write a Python function to transform a list of integers and handle bad inputs. The function should create a new list where each element is transformed based on the following rules:
- If the element is an even integer, it should be squared.
- If the element is an odd integer, it should be cubed.
- If the element is not ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def transform_list(input_list: List[int]) -> List[int]:
"""
Transforms a list of integers based on the following rules:
- Even integers are squared.
- Odd integers are cubed.
- Non-integer el... |
magic_evol_110k | 94,835 | Write a Python function to split a given list into two sublists of equal size. If the length of the list is odd, the first sublist should contain the extra element. The function should return a tuple containing the two sublists.
The code should start with:
```python
from typing import List, Tuple
def split_array_into... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def split_array_into_halves(arr: List[int]) -> Tuple[List[int], List[int]]:
"""
Splits a given list into two sublists of equal size. If the length of the list is odd, the first sublist contains th... |
magic_evol_110k | 94,836 | Write a Python function to process a 2D array and determine whether each element is a prime number, a negative number, or not a number. The function should handle both integers and strings that can be converted to integers. If the element is zero or negative, it should be considered a special case and handled according... | 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:
"""
Helper function to check if a number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.... |
magic_evol_110k | 94,842 | Write a Python function to compute all prime numbers within a given numerical range `[start, end]`. The function should return a list of all prime numbers in that range. The code should start with:
```python
from typing import List
def find_primes_in_range(start: int, end: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise.
... |
magic_evol_110k | 94,845 | Write a Python function to create a new list by capitalizing all the items in a given list of strings. The function should handle lists of varying lengths and ensure that each string in the list is properly capitalized. The code should start with:
```python
from typing import List
def capitalize_list_items(string_list... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def capitalize_list_items(string_list: List[str]) -> List[str]:
"""
Creates a new list by capitalizing all the items in the given list of strings.
Args:
string_list (List[str]): The list of ... |
magic_evol_110k | 94,864 | Write a Python function to compute the edit distance (Levenshtein distance) between two given words using dynamic programming techniques. The edit distance is the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one word into the other. The function should use a 2D l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def edit_distance_dp(str1: str, str2: str) -> int:
"""
Compute the edit distance (Levenshtein distance) between two given words using dynamic programming.
Args:
str1 (str): The first word.
... |
magic_evol_110k | 94,867 | Write a Python function to extract email addresses from a list of strings using regular expressions. The function should be able to handle various formats of email addresses and should return a list of all extracted email addresses.
The code should start with:
```python
from typing import List
import re
def extract_e... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def extract_emails(text_list: List[str]) -> List[str]:
"""
Extracts email addresses from a list of strings using regular expressions.
Args:
text_list (List[str]): A list of strings... |
magic_evol_110k | 94,886 | Write a Python function to find and return a list of all prime numbers between a given range `[start, end]`. The function should use a helper function to check if a number is prime. The code should start with:
```python
from typing import List
def find_primes_in_range(start: int, end: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
if n <... |
magic_evol_110k | 94,888 | Write a Python function to iteratively transform a provided list such that each constituent element is amplified to be twice of its original value. The function should return the transformed list. The code should start with:
```python
from typing import List
def double_list_elements(my_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 double_list_elements(my_list: List[int]) -> List[int]:
"""
Transforms a provided list such that each element is doubled.
Args:
my_list (List[int]): The list of integers to be transformed... |
magic_evol_110k | 94,908 | Write a Python function to count the number of prime numbers in a given list of integers. The function should utilize a helper function to determine if a number is prime. The code should start with:
```python
from typing import List
def count_primes_in_list(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Check if a given number is a prime number.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False ... |
magic_evol_110k | 94,913 | Write a Python function to convert a number from a given base (either octal, decimal, or hexadecimal) to its binary representation. The function should accept the number as a string and the base as an integer. The function should return the binary representation as a string.
The code should start with:
```python
def n... | Here is the Python code to solve the given problem in the markdown block:
```python
def number_to_binary(x: str, base: int) -> str:
"""
Convert a number from a given base (8, 10, or 16) to its binary representation.
Args:
x (str): The number to convert, provided as a string.
base (int): The... |
magic_evol_110k | 94,921 | Write a Python function to convert a given date and time string from one format to another. The input format is 'Day-Month-Year Hours:Minutes' (e.g., '19-03-2020 17:30'), and the output format should be 'Day-MonthName-Year and Hours:Minutes' (e.g., '19-March-2020 and 17:30'). The time should remain in a 24-hour format.... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def convert_datetime_format(date_time_str: str) -> str:
"""
Converts a given date and time string from 'Day-Month-Year Hours:Minutes' format to 'Day-MonthName-Year and Hours:Minutes' format.
A... |
magic_evol_110k | 94,923 | Write a Python function to determine the primality and parity of a given number, and if the number is composite, return its prime factors. The function should return a tuple containing three elements: a string indicating whether the number is "Prime" or "Composite", a string indicating whether the number is "Even" or "... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def check_number_properties(n: int) -> Tuple[str, str, List[int]]:
"""
Determine the primality and parity of a given number, and if the number is composite, return its prime factors.
Args:
... |
magic_evol_110k | 94,931 | Write a Python function to recursively calculate the sum of all numbers from 1 to `n`, where `n` is a positive integer. Additionally, implement error handling to ensure that `n` is a positive integer. The function should raise a `ValueError` if `n` is not a positive integer.
The code should start with:
```python
def r... | Here is the Python code to solve the given problem in the markdown block:
```python
def recursive_sum(n: int) -> int:
"""
Recursively calculates the sum of all numbers from 1 to n.
Args:
n (int): A positive integer.
Returns:
int: The sum of all numbers from 1 to n.
Raises:
... |
magic_evol_110k | 94,937 | Write a Python function to find and return the second largest element in a given list of integers. The function should handle edge cases such as an empty list, a list with only one element, and a list with all identical elements. The function should return `None` if the second largest element does not exist.
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_second_largest(lst: List[int]) -> Optional[int]:
"""
Find and return the second largest element in a given list of integers.
Args:
lst (List[int]): The list of integers fr... |
magic_evol_110k | 94,944 | Write a Python function to shuffle a given array in place. The function should modify the original array and return it. The shuffling should be done using the Fisher-Yates (Knuth) shuffle algorithm, which ensures that each permutation of the array is equally likely.
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
import random
def shuffle_array(arr: List[int]) -> List[int]:
"""
Shuffles the given array in place using the Fisher-Yates (Knuth) shuffle algorithm.
Args:
arr (List[int]): The array to be s... |
magic_evol_110k | 94,949 | Write a Python function to add two numbers and return the result. The function should be reusable and should handle any two integers provided as input. The code should start with:
```python
def add_two_numbers(num1: int, num2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def add_two_numbers(num1: int, num2: int) -> int:
"""
Adds two integers and returns the result.
Args:
num1 (int): The first integer to be added.
num2 (int): The second integer to be added.
Returns:
... |
magic_evol_110k | 94,957 | Write a Python function to determine if a given list of integers is strictly ascending, meaning each element is strictly greater than the previous element. The function should return `True` if the list is strictly ascending, and `False` otherwise. The code should start with:
```python
from typing import List
def is_st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_strictly_ascending(arr: List[int]) -> bool:
"""
Determines if a given list of integers is strictly ascending.
Args:
arr (List[int]): The list of integers to check.
Returns:
... |
magic_evol_110k | 94,967 | Write a Python function to reverse a given string iteratively without using slicing or any built-in reverse functions. The function should start with:
```python
def reverse_string_iteratively(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string_iteratively(s: str) -> str:
"""
Reverses a given string iteratively without using slicing or built-in reverse functions.
Args:
s (str): The input string to be reversed.
Returns:
str: ... |
magic_evol_110k | 94,974 | Write a Python function to determine if there are three consecutive odd numbers in a given integer array that are also in ascending order. The function should return `True` if such a sequence exists, otherwise `False`.
The code should start with:
```python
from typing import List
def three_consecutive_odds_ascending(... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def three_consecutive_odds_ascending(arr: List[int]) -> bool:
"""
Determines if there are three consecutive odd numbers in the given array that are also in ascending order.
Args:
arr (List[i... |
magic_evol_110k | 94,979 | Write a Python function to filter an array of textual elements and strings within nested sub-arrays, returning only the entries that contain a specific symbol sequence determined by the user. The sequence can have a length up to 3 characters. The function should handle nested lists and ensure that only the strings cont... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def filter_strings_with_sequence(array: List[Union[str, List[str]]], sequence: str) -> List[str]:
"""
Filters an array of textual elements and strings within nested sub-arrays, returning only the ... |
magic_evol_110k | 94,986 | Write a Python function that identifies and counts the number of unique elements in a given list while maintaining the order of their occurrence in the original list. The function should return a list of tuples where each tuple consists of a unique element and its count. The function should not use any built-in functio... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def count_unique_elements(lst: List[int]) -> List[Tuple[int, int]]:
"""
Counts the number of unique elements in a given list while maintaining the order of their occurrence.
Args:
lst... |
magic_evol_110k | 94,990 | Write a Python function to check if a given element occurs at least 'n' times in an array. The function should return `True` if the element occurs at least 'n' times, otherwise `False`. The code should start with:
```python
from typing import List
def check_element_occurrence(array: List[int], element: int, n: int) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def check_element_occurrence(array: List[int], element: int, n: int) -> bool:
"""
Check if the given element occurs at least 'n' times in the array.
Args:
array (List[int]): The array in whi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.