source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
magic_evol_110k | 92,152 | Write a Python function to remove duplicate elements from a given list while preserving the order of the first occurrence of each element. The function should utilize list comprehension for the removal process. The code should start with:
```python
from typing import List
def remove_duplicates_preserve_order(input_lis... | 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 duplicate elements from the given list while preserving the order of their first occurrence.
Args:
inp... |
magic_evol_110k | 92,164 | Write a Python function to remove all whitespace characters from a given string. The function should handle various types of whitespace characters, including spaces, tabs, and newlines. The code should start with:
```python
def remove_all_whitespace(input_str: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def remove_all_whitespace(input_str: str) -> str:
"""
Removes all whitespace characters from the given string.
Args:
input_str (str): The input string from which to remove whitespace characters.
Retu... |
magic_evol_110k | 92,204 | Write a Python function to combine a list of phrases into a single sentence, with each phrase separated by a semicolon and a space. The function should handle an empty list by returning an empty string. The code should start with:
```python
from typing import List
def combine_phrases(phrases: List[str]) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def combine_phrases(phrases: List[str]) -> str:
"""
Combines a list of phrases into a single sentence, with each phrase separated by a semicolon and a space.
Args:
phrases (List[str]): A lis... |
magic_evol_110k | 92,217 | Write a Python function to perform a linear search on a given list and return the index of the target element if found, otherwise return -1. The function should handle lists of integers and be efficient for small to moderately sized lists.
The code should start with:
```python
from typing import List
def linear_searc... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def linear_search(arr: List[int], target: int) -> int:
"""
Perform a linear search on a given list to find the index of the target element.
Args:
arr (List[int]): The list of integers to sea... |
magic_evol_110k | 92,221 | Write a Python function to generate a list of 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 or equal to `n`.
The code should start with:
```python
from typing import List
def generate_primes(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_primes(n: int) -> List[int]:
"""
Generate a list of prime numbers up to a given limit n using the Sieve of Eratosthenes algorithm.
Args:
n (int): The upper limit up to which pri... |
magic_evol_110k | 92,254 | Write a Python function to filter elements from a given list based on a specified condition. The function should return a new list containing only the elements that satisfy the condition. The condition should be defined as a separate function that takes an element as input and returns a boolean value.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable
def filter_elements(arr: List[int], condition: Callable[[int], bool]) -> List[int]:
"""
Filters elements from the given list based on a specified condition.
Args:
arr (List[int]): ... |
magic_evol_110k | 92,256 | Write a Python function to generate a unique sequence of 12 characters containing only the letters 'x', 'y', and 'z'. The sequence must include at least one of each letter and no three of the same letters occur consecutively. The function should return the generated sequence as a string.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_unique_sequence() -> str:
"""
Generates a unique sequence of 12 characters containing only 'x', 'y', and 'z'.
The sequence includes at least one of each letter and no three of the same letters occ... |
magic_evol_110k | 92,266 | Write a Python function to compute the Least Common Multiple (LCM) of two given positive integers. The function should use the Euclidean algorithm to find the Greatest Common Divisor (GCD) and then use the GCD to calculate the LCM. The code should start with:
```python
def compute_lcm(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def compute_lcm(a: int, b: int) -> int:
"""
Compute the Least Common Multiple (LCM) of two positive integers.
Args:
a (int): The first positive integer.
b (int): The second positive integer.
Returns:
... |
magic_evol_110k | 92,274 | Write a Python function to determine if two input strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should handle strings with spaces and should be case-insensitive.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(str1: str, str2: str) -> bool:
"""
Determines if two input strings are anagrams of each other.
Args:
str1 (str): The first input string.
str2 (str): The second input string.
Returns:
... |
magic_evol_110k | 92,279 | Write a Python function to identify and return all narcissistic numbers that are less than or equal to a given integer input. A narcissistic number (also known as a pluperfect number, an Armstrong number, or a plus perfect number) is a number that is the sum of its own digits each raised to the power of the number of d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_narcissistic_numbers(n: int) -> List[int]:
"""
Identifies and returns all narcissistic numbers that are less than or equal to a given integer input.
Args:
n (int): The upper limit t... |
magic_evol_110k | 92,291 | Write a Python function to remove all occurrences of a specified numerical value from a given list and return the modified list. The function should handle various edge cases, such as an empty list or a list where the specified value does not exist.
The code should start with:
```python
from typing import List
def re... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_all_instances(input_list: List[int], filter_value: int) -> List[int]:
"""
Removes all occurrences of a specified numerical value from a given list and returns the modified list.
Args:
... |
magic_evol_110k | 92,315 | Write a Python function to calculate the date of a specified number of days from today. The function should return the date as a string in the format "YYYY-MM-DD".
The code should start with:
```python
from datetime import datetime, timedelta
def get_future_date(days: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime, timedelta
def get_future_date(days: int) -> str:
"""
Calculate the date of a specified number of days from today and return it as a string in the format "YYYY-MM-DD".
Args:
days (int)... |
magic_evol_110k | 92,326 | Write a Python function to find all prime numbers in a given list of integers and return both the list of prime numbers and their sum. The function should use helper functions to check if a number is prime and to iterate over the list. The code should start with:
```python
from typing import List, Tuple
def find_prime... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def is_prime(n: int) -> bool:
"""
Check if a given number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False ot... |
magic_evol_110k | 92,333 | Write a Python function to sort a list of tuples, where each tuple contains a movie name and its release year, in reverse chronological order based on the release year. The function should return the sorted list.
The code should start with:
```python
from typing import List, Tuple
def sort_movies_by_year(movies: List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_movies_by_year(movies: List[Tuple[str, int]]) -> List[Tuple[str, int]]:
"""
Sorts a list of movie tuples by their release year in reverse chronological order.
Args:
movies (L... |
magic_evol_110k | 92,341 | Write a Python function to extract the first five elements from a given list of integers that are not divisible by 3. The function should return a list containing these elements. The code should start with:
```python
from typing import List
def get_first_five_non_divisible_by_three(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 get_first_five_non_divisible_by_three(numbers: List[int]) -> List[int]:
"""
Extracts the first five elements from a given list of integers that are not divisible by 3.
Args:
numbers (Lis... |
magic_evol_110k | 92,353 | Write a Python function to merge two lists of integers such that the even-numbered indexed elements come from the first list and the odd-numbered indexed elements come from the second list. If any list runs short, append the remaining elements from the other list in their original order. The function should not use any... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Merges two lists such that the even-numbered indexed elements come from the first list
and the odd-numbered indexed elements come... |
magic_evol_110k | 92,363 | Write a Python function to generate a list of prime numbers up to a given number `n` and another function to identify and return the prime factors of a given number `m` from that list of primes. The code should start with:
```python
from typing import List
def generate_primes(n: int) -> List[int]:
"""
Generate... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_primes(n: int) -> List[int]:
"""
Generate a list of prime numbers up to a given number n.
Args:
n (int): The upper limit for generating prime numbers.
Returns:
List... |
magic_evol_110k | 92,381 | Write a Python function to determine the maximum value between two given integers `a` and `b`. The function should return the larger of the two values. The code should start with:
```python
def get_maximum(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_maximum(a: int, b: int) -> int:
"""
Returns the maximum value between two given integers.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
int: The maximum value b... |
magic_evol_110k | 92,395 | Write a Python function to convert a list of hexadecimal numbers into their corresponding binary representations. Each hexadecimal number should first be converted to a decimal number, and then the decimal number should be converted to a binary string. The binary string should not include the "0b" prefix.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def hex_to_binary(hex_values: List[str]) -> List[str]:
"""
Converts a list of hexadecimal numbers into their corresponding binary representations.
Args:
hex_values (List[str]): A list of hex... |
magic_evol_110k | 92,421 | Write a Python function that takes three separate arrays as input. The function should return `True` if every element in the second array is present at least once in the first array and no element of the third array is present in the first array. If these conditions are not met, the function should return `False`. The ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def custom_contains(array1: List[int], array2: List[int], array3: List[int]) -> bool:
"""
Returns True if every element in array2 is present at least once in array1 and no element of array3 is present in... |
magic_evol_110k | 92,423 | Write a Python function to calculate the sum of numbers from 1 to a given number `n`. The function should be efficient and handle edge cases such as `n` being 0 or negative. The code should start with:
```python
def sum_of_numbers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_numbers(n: int) -> int:
"""
Calculate the sum of numbers from 1 to the given number n.
Args:
n (int): The upper limit of the range for which the sum is to be calculated.
Returns:
int: The sum... |
magic_evol_110k | 92,427 | Write a Python function to parse a string containing multiple key-value pairs separated by commas into a dictionary. The keys and values are separated by an "=" sign. The function should handle possible whitespace around the "=" sign and ensure that the parser can handle both integers and floating point numbers. The co... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def parse_string_to_dict(s: str) -> dict:
"""
Parses a string containing multiple key-value pairs separated by commas into a dictionary.
The keys and values are separated by an "=" sign. The function handles possi... |
magic_evol_110k | 92,436 | Write a Python function to compute the sum of a list of integers and additionally return the smallest and the largest number in the list. The function should be optimized for performance and correctness. The code should start with:
```python
from typing import List, Tuple
def sum_and_extremes(lst: List[int]) -> Tuple[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sum_and_extremes(lst: List[int]) -> Tuple[int, int, int]:
"""
Computes the sum of a list of integers and returns the sum along with the smallest and largest numbers in the list.
Args:
... |
magic_evol_110k | 92,438 | Write a Python function to generate a dictionary containing individual words as keys and their respective frequency of appearances as values from a given string. The function should ignore case and punctuation, and only consider alphanumeric characters for counting word frequency. The code should start with:
```python
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import re
def word_frequency(string: str) -> Dict[str, int]:
"""
Generate a dictionary containing individual words as keys and their respective frequency of appearances as values.
The function ignore... |
magic_evol_110k | 92,440 | Write a Python function to filter and return a list of even numbers from a given list of integers. The function should iterate over the input list, check if each number is even, and collect all even numbers into a new list. The function should start with:
```python
from typing import List
def filter_even_numbers(numbe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_even_numbers(numbers: List[int]) -> List[int]:
"""
Filters and returns a list of even numbers from the given list of integers.
Args:
numbers (List[int]): The list of integers to f... |
magic_evol_110k | 92,441 | Write a Python function to sort an array of integers of length N (where N ≤ 4) using a custom implementation of the Quick Sort algorithm, and then find the longest sequence of consecutive integers in the sorted array. A sequence is defined as two or more numbers that follow each other in order (e.g., [4, 5, 6, 7]). If ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_and_find_longest_sequence(arr: List[int]) -> List[int]:
"""
Sorts the given array using Quick Sort and finds the longest sequence of consecutive integers.
Args:
arr (List[int]): The... |
magic_evol_110k | 92,443 | Write a Python function to create a dictionary from two lists, one containing keys and the other containing 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 both lists. The function should start with:
```pyt... | 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[int], values: List[str]) -> Dict[int, str]:
"""
Creates a dictionary from two lists, one containing keys and the other containing values.
If the lists are ... |
magic_evol_110k | 92,449 | Write a Python function to compute the sum of the first `n` even numbers. The function should take an integer `n` as input and return the sum of the first `n` even numbers. The code should start with:
```python
def sum_of_first_n_even_numbers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_first_n_even_numbers(n: int) -> int:
"""
Compute the sum of the first n even numbers.
Args:
n (int): The number of even numbers to sum.
Returns:
int: The sum of the first n even numbers.
... |
magic_evol_110k | 92,466 | Write a Python function to determine whether two given phrases consist of entirely identical sets of words, considering the word frequency. The function should return `True` if the phrases have the same words with the same frequencies, and `False` otherwise. The code should start with:
```python
def compare_word_sets_f... | Here is the Python code to solve the given problem in the markdown block:
```python
def compare_word_sets_frequency(phrase1: str, phrase2: str) -> bool:
"""
Determine whether the two input phrases consist of identical sets of words, with the same word frequency.
Args:
phrase1 (str): The first phras... |
magic_evol_110k | 92,467 | Write a Python function to generate a CSS stylesheet that aligns text vertically and sets the background color to a light blue hue. The function should take a single argument, `selector`, which is a string representing the CSS selector for the elements to be styled. The function should return a string containing the CS... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_vertical_text_stylesheet(selector: str) -> str:
"""
Generates a CSS stylesheet that aligns text vertically and sets the background color to a light blue hue.
Args:
selector (str): The CSS selector for t... |
magic_evol_110k | 92,488 | Write a Python function to remove all duplicates from a given array of strings while preserving the order of the first occurrence of each string. The function should be efficient and handle large input sizes.
The code should start with:
```python
from typing import List
def remove_duplicates_preserve_order(input_arra... | 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_array: List[str]) -> List[str]:
"""
Removes duplicates from the given array of strings while preserving the order of the first occurrence of each string.
A... |
magic_evol_110k | 92,513 | Write a Python function to remove duplicate entries from a tuple and reorder the entries in ascending order. The function should be optimized for time complexity. The code should start with:
```python
def remove_duplicates_and_reorder(tup: tuple) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_duplicates_and_reorder(tup: tuple) -> tuple:
"""
Removes duplicate entries from a tuple and reorders the entries in ascending order.
Args:
tup (tuple): The input tuple from which duplicates will be remove... |
magic_evol_110k | 92,526 | Write a Python function to calculate the total sales made by each salesman in a given list of sales transactions. Each transaction is represented as a tuple containing the salesman's ID and the sale amount. The function should return a dictionary where the keys are the salesman IDs and the values are the total sales am... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def calculate_total_sales(transactions: List[Tuple[int, float]]) -> Dict[int, float]:
"""
Calculate the total sales made by each salesman from a list of transactions.
Args:
tran... |
magic_evol_110k | 92,545 | Write a Python function to compute and return the product of all odd-valued elements in a given list of integers. The function should handle cases where the list is empty or contains no odd numbers.
The code should start with:
```python
from typing import List
def product_of_odds(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def product_of_odds(numbers: List[int]) -> int:
"""
Compute and return the product of all odd-valued elements in the given list of integers.
Args:
numbers (List[int]): A list of integers fro... |
magic_evol_110k | 92,549 | Write a Python function to create a structured NumPy array from two sequences of numerical values and verify that each element in the structured array matches its prescribed data type. The first sequence is a list of integers, and the second sequence is a list of random float values between 0 and 1. The function should... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List
def create_and_verify_structured_array(sequence1: List[int], sequence2: List[float]) -> np.ndarray:
"""
Create a structured NumPy array from two sequences and verify that each element ... |
magic_evol_110k | 92,554 | Write a Python function to eliminate recurring elements from a numerical array while preserving the initial order of distinct elements. The function should handle negative numbers and floating point values and should not use any built-in array or list manipulation functions or libraries. The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def eliminate_duplicates(arr: List[float]) -> List[float]:
"""
Eliminates recurring elements from a numerical array while preserving the initial order of distinct elements.
Args:
arr (List[f... |
magic_evol_110k | 92,556 | Write a Python function to generate the Fibonacci sequence up to a specified number of terms using a while loop. The function should return a list containing the Fibonacci sequence.
The code should start with:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the Fibonacci sequence up to the nth term.
Args:
n (int): The number of terms in the Fibonacci sequence to generate.
Returns:
... |
magic_evol_110k | 92,557 | Write a Python function that takes an integer `x` as input and returns a value based on the following rules:
- If `x` is greater than 5, return `x` multiplied by 2.
- If `x` is less than or equal to 5, return `x` multiplied by 3.
The function should handle both positive and negative integers, as well as zero. The code... | Here is the Python code to solve the given problem in the markdown block:
```python
def my_fun(x: int) -> int:
"""
Returns a value based on the input integer x.
If x is greater than 5, the function returns x multiplied by 2.
If x is less than or equal to 5, the function returns x multiplied by 3.
... |
magic_evol_110k | 92,566 | Write a Python function to flatten a nested list and return a single list containing all the elements from the nested list in a depth-first manner. The function should handle lists with varying levels of nesting.
The code should start with:
```python
from typing import List, Any
def flatten_nested_list(nested_list: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def flatten_nested_list(nested_list: List[Any]) -> List[Any]:
"""
Flattens a nested list and returns a single list containing all elements in a depth-first manner.
Args:
nested_list (Li... |
magic_evol_110k | 92,570 | Write a Python function to flatten a nested dictionary into a single-level dictionary. The keys in the final dictionary should represent the hierarchy of the input dictionaries, with each level separated by a period ("."). The function should handle dictionaries of varying depth and should be able to handle any level o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def flatten_nested_dict(d: Dict, parent_key: str = '', sep: str = '.') -> Dict:
"""
Flattens a nested dictionary into a single-level dictionary.
Args:
d (Dict): The nested dictionary to be f... |
magic_evol_110k | 92,579 | Write a Python function that takes two parameters: a text string `prefix` and a list `lst`. The function should prepend the `prefix` to each string element in the list `lst` and return the modified list. Non-string elements in the list should remain unchanged.
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 prepend_prefix_to_strings(prefix: str, lst: List[object]) -> List[object]:
"""
Prepends the given prefix to each string element in the list and returns the modified list.
Non-string elements in t... |
magic_evol_110k | 92,586 | Write a Python function to classify a list of books based on the author's nationality. The function should take a list of dictionaries, where each dictionary represents a book with keys `title` and `author`. The function should return a dictionary where the keys are the nationalities of the authors and the values are l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def classify_books_by_nationality(books: List[Dict[str, str]]) -> Dict[str, List[Dict[str, str]]]:
"""
Classify a list of books based on the author's nationality.
Args:
books (List[Dic... |
magic_evol_110k | 92,603 | Write a Python function to count the number of distinct lexical items (words) in each of two given sentences. The function should handle punctuation and case sensitivity by converting all text to lowercase and removing punctuation. The function should return a tuple containing the count of distinct words for each sente... | Here is the Python code to solve the given problem in the markdown block:
```python
import string
def count_distinct_lexical_items(sentence1: str, sentence2: str) -> tuple:
"""
Counts the number of distinct lexical items (words) in each of two given sentences.
Args:
sentence1 (str): The first sent... |
magic_evol_110k | 92,605 | Write a Python function to determine the parity (even or odd) of each integer in a given list of integers. The function should return a dictionary where the keys are the integers from the list and the values are strings indicating whether the integer is "even" or "odd".
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, Dict
def find_parity(data: List[int]) -> Dict[int, str]:
"""
Determines the parity (even or odd) of each integer in the given list.
Args:
data (List[int]): A list of integers for which to d... |
magic_evol_110k | 92,608 | Write a Python function `greetings_generator` that takes two arguments: a string `message` and an integer `n`. The function should return a new string consisting of the input message concatenated `n` times, with each concatenation separated by a newline character. Implement two versions of this function: one using a lo... | Here is the Python code to solve the given problem in the markdown block:
```python
def greetings_generator_loop(message: str, n: int) -> str:
"""
Generates a string by concatenating the input message `n` times, separated by newline characters.
Args:
message (str): The message to be concatenated.
... |
magic_evol_110k | 92,609 | Write a Python function to determine if a given number `b` (where `b` is less than 2000) is the cube of a prime number. The function should return `True` if `b` is the cube of a prime number, and `False` otherwise. The function should be efficient and correctly handle the constraints.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def is_cube_of_prime(b: int) -> bool:
"""
Determine if the given number `b` (where `b` < 2000) is the cube of a prime number.
Args:
b (int): The number to check.
Returns:
bool: True if `b` ... |
magic_evol_110k | 92,628 | Write a Python function to generate a table of addition of two numbers from a given list of tuples. Each tuple contains two integers, representing the numbers to be added. The function should return a list of tuples where each tuple contains the two original numbers and their sum.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def generate_addition_table(numbers: List[Tuple[int, int]]) -> List[Tuple[int, int, int]]:
"""
Generates a table of addition for a given list of tuples, where each tuple contains two integers.
... |
magic_evol_110k | 92,632 | Write a Python function to count the number of unique keys in a given dictionary. The function should handle dictionaries with any type of keys and values. The code should start with:
```python
from typing import Dict
def count_unique_keys(dictionary: Dict) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_unique_keys(dictionary: Dict) -> int:
"""
Counts the number of unique keys in a given dictionary.
Args:
dictionary (Dict): The dictionary from which to count the unique keys.
... |
magic_evol_110k | 92,634 | Write a Python function to determine if two given strings are scrambled versions of each other without using any pre-established library functionalities or data organization systems. The function should compare the character counts of both strings to determine if they are permutations of each other.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_scrambled_strings(s1: str, s2: str) -> bool:
"""
Determines if two strings are scrambled versions of each other by comparing their character counts.
Args:
s1 (str): The first string to compare.
s2 (s... |
magic_evol_110k | 92,637 | Write a Python function to convert a given integer to its binary representation without using Python's built-in `bin()` function. The function should handle both positive and negative integers. The binary representation should be in the form of a string, prefixed with '0b' for positive numbers and '-0b' for negative nu... | Here is the Python code to solve the given problem in the markdown block:
```python
def integer_to_binary(n: int) -> str:
"""
Converts a given integer to its binary representation without using the built-in bin() function.
Args:
n (int): The integer to be converted to binary.
Returns:
... |
magic_evol_110k | 92,643 | Write a Python function to accept a list of numbers as input and return a list of their absolute values, sorted in ascending order. The function should handle both positive and negative numbers, and the output should be a sorted list of their absolute values. The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sorted_absolute_values(numbers: List[int]) -> List[int]:
"""
Return a list of absolute values of the input numbers, sorted in ascending order.
Args:
numbers (List[int]): A list of intege... |
magic_evol_110k | 92,644 | Write a Python function to generate a list of all prime numbers within a given range `[start, end]`. The function should use an efficient algorithm to determine if a number is prime and should return a list of all prime numbers in the specified range.
The code should start with:
```python
from typing import List
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Check if a 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 | 92,650 | Write a Python function to simulate a simple event-driven system for a `JComboBox`-like component. The function should allow adding items to the combo box and registering a callback function that gets called whenever an item is selected. The function should also provide a method to select an item, which will trigger th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Callable, List
class ComboBox:
"""
A simple event-driven simulation of a JComboBox-like component.
Attributes:
items (List[str]): A list of items in the combo box.
selection_callback (Cal... |
magic_evol_110k | 92,660 | Write a Python function to determine if two given strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should handle case insensitivity and ignore spaces.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(string1: str, string2: str) -> bool:
"""
Determines if two given strings are anagrams of each other.
Args:
string1 (str): The first string to compare.
string2 (str): The second string to com... |
magic_evol_110k | 92,663 | Write a Python function to shuffle a given list in place and return the shuffled list. The function should use the Fisher-Yates (Knuth) shuffle algorithm to ensure a uniform random permutation of the list. The code should start with:
```python
from typing import List
def shuffle_list(input_list: List[int]) -> List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def shuffle_list(input_list: List[int]) -> List[int]:
"""
Shuffles the given list in place using the Fisher-Yates (Knuth) shuffle algorithm.
Args:
input_list (List[int]): The l... |
magic_evol_110k | 92,697 | Write a Python function to segregate a list of integers into prime and composite numbers. The function should return two lists: one containing all the prime numbers and the other containing all the composite numbers. The function should handle edge cases such as an empty list or a list containing only non-prime numbers... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def is_prime(num: int) -> bool:
"""
Check if a number is prime.
Args:
num (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""... |
magic_evol_110k | 92,702 | Write a Python function to identify and return the index of the highest integer in a given list of numerical values. The function should handle lists with multiple occurrences of the highest integer by returning the index of the first occurrence. The code should start with:
```python
from typing import List
def find_i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_index_of_max(lst: List[int]) -> int:
"""
Finds and returns the index of the highest integer in the given list.
If the list is empty, returns -1.
Args:
lst (List[int]): The list ... |
magic_evol_110k | 92,704 | Write a Python function to generate all possible subsets of a given set of elements, including the empty set and duplicate subsets of non-distinct elements. The function should maintain a time complexity below O(2^n * n), where n is the number of elements in the set. 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 generate_all_subsets(original_set: List[int]) -> List[List[int]]:
"""
Generate all possible subsets of a given set of elements, including the empty set and duplicate subsets of non-distinct elements.... |
magic_evol_110k | 92,705 | Write a Python function to scale a number using a non-linear scaling method based on the sigmoid function. The sigmoid function is defined as \( f(x) = \frac{1}{1 + e^{-x}} \). The function should allow for a customizable scaling factor. The code should start with:
```python
import math
def scale_with_sigmoid(num: flo... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def scale_with_sigmoid(num: float, factor: float = 0.5) -> float:
"""
Scales a number using a non-linear scaling method based on the sigmoid function.
The sigmoid function is defined as f(x) = 1 / (1 + e^(-x)).... |
magic_evol_110k | 92,706 | Write a Python function that generates a loop to print the phrase "Goodbye" a specified number of times. The function should accept an integer `n` as an argument, which indicates the number of times the phrase should be printed. If `n` is less than or equal to 0, the function should print nothing.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_goodbye(n: int) -> None:
"""
Prints the phrase "Goodbye" n times.
Args:
n (int): The number of times to print the phrase "Goodbye".
Returns:
None: This function does not return any value.
... |
magic_evol_110k | 92,727 | Write a Python function to remove duplicate elements from a given list while preserving the order of the first occurrence of each element. The function should return a new list with the duplicates removed.
The code should start with:
```python
from typing import List
def remove_duplicates(lst: List[int]) -> List[int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates(lst: List[int]) -> List[int]:
"""
Removes duplicate elements from the given list while preserving the order of the first occurrence of each element.
Args:
lst (List[int... |
magic_evol_110k | 92,731 | Write a Python function to generate a 2D array where each row is a Fibonacci sequence of a specified length. The number of rows and the length of each row should be defined by the user. The function should handle potential exceptions such as negative inputs.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci_2d_array(rows: int, columns: int) -> List[List[int]]:
"""
Generate a 2D array where each row is a Fibonacci sequence of the specified length.
Args:
rows (int): The num... |
magic_evol_110k | 92,733 | Write a Python function to extract all positive integers from a given list and sort them in ascending order without using built-in functions like `sort()` or `sorted()`. Implement a helper function `swap_elements` to facilitate the sorting process. The function 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 get_positive_and_sort(l: List[int]) -> List[int]:
"""
Returns only positive numbers from the list, sorted in ascending order.
Args:
l (List[int]): The input list of integers.
Return... |
magic_evol_110k | 92,735 | Write a Python function to calculate the mean temperature from a given list of temperature values. The function should handle the case where the list is empty by returning 0. The code should start with:
```python
from typing import List
def calculate_mean_temperature(temperatures: List[float]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_mean_temperature(temperatures: List[float]) -> float:
"""
Calculate the mean temperature from a list of temperature values.
Args:
temperatures (List[float]): A list of temperat... |
magic_evol_110k | 92,767 | Write a Python function that takes two arguments: an integer `n` and a lambda function `lambda_func`. The lambda function should calculate the cube of the given integer. The function should then return the absolute value of the difference between the cube of the given number and the number itself. The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
def manipulate_cube_result(n: int, lambda_func: callable) -> int:
"""
Calculate the absolute value of the difference between the cube of a given number and the number itself.
Args:
n (int): The integer whose cube an... |
magic_evol_110k | 92,769 | Write a Python function to calculate the accumulated total by individually adding the elements within a numerical array. The function should handle both positive and negative integers, as well as an empty array. The code should start with:
```python
from typing import List
def accumulate_total(array: List[int]) -> int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def accumulate_total(array: List[int]) -> int:
"""
Calculate the accumulated total by individually adding the elements within a numerical array.
Args:
array (List[int]): A list of integers t... |
magic_evol_110k | 92,784 | Write a Python function to calculate the total number of elements in a given nested list, including all elements within any sublists. The function should handle lists of arbitrary depth and complexity. The code should start with:
```python
from typing import List, Union
def count_elements_in_nested_list(nested_list: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def count_elements_in_nested_list(nested_list: List[Union[int, float, List]]) -> int:
"""
Calculate the total number of elements in a given nested list, including all elements within any sublists.... |
magic_evol_110k | 92,792 | Write a Python function to find the minimum number of disjoint time periods required to cover the entire range of a given series of time periods. Each time period is represented as a list of two integers `[start, end]`, where `start` is the beginning of the period and `end` is the end of the period. The function should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def min_disjoint_periods(periods: List[List[int]]) -> List[List[int]]:
"""
Find the minimum number of disjoint time periods required to cover the entire range of a given series of time periods.
Args... |
magic_evol_110k | 92,808 | Write a Python function to find the last odd number in a given list that is not a multiple of 5. If no such number exists, the function should return `None`. The function should take a list of integers as input and return an integer or `None`.
The code should start with:
```python
from typing import List, Optional
de... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_last_odd_non_mult_of_five(numbers: List[int]) -> Optional[int]:
"""
Find the last odd number in the given list that is not a multiple of 5.
Args:
numbers (List[int]): The ... |
magic_evol_110k | 92,809 | Write a Python function to find the first repeated element in a given list of elements. If no element is repeated, the function should return `None`. The function should efficiently track the elements that have been seen so far to ensure optimal performance.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_first_repeated_element(elements: List[int]) -> Optional[int]:
"""
Find the first repeated element in a given list of integers.
Args:
elements (List[int]): The list of inte... |
magic_evol_110k | 92,813 | Write a Python function to generate the first 25 elements of the Catalan sequence efficiently using dynamic programming. The Catalan sequence is defined by the recurrence relation:
\[ C(n) = \sum_{i=0}^{n-1} C(i) \times C(n-i-1) \]
with base cases \( C(0) = 1 \) and \( C(1) = 1 \).
The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_catalan_sequence(n: int) -> list:
"""
Generate the first n+1 Catalan numbers using dynamic programming.
Args:
n (int): The number of Catalan numbers to generate.
Returns:
list: A list conta... |
magic_evol_110k | 92,818 | Write a Python function to find the index of the final occurrence of a specific element in a given ordered array, which may include repeated elements. The function should not use any built-in Python methods for searching or sorting. The code should start with:
```python
def find_last_occurrence(arr, num):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_last_occurrence(arr, num):
"""
Find the index of the final occurrence of a specific element in an ordered array.
Args:
arr (list): The ordered array to search in.
num (int): The element to find the ... |
magic_evol_110k | 92,822 | Write a Python function to analyze a given dictionary of numerical lists. The function should return a dictionary containing the sum and average of the values for each key in the input dictionary. The function should handle dictionaries with varying lengths of lists and ensure that the calculations are accurate.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Union
def analyze_numerical_data(data: Dict[str, List[int]]) -> Dict[str, Dict[str, Union[int, float]]]:
"""
Analyzes a dictionary of numerical lists and returns a dictionary containing the sum an... |
magic_evol_110k | 92,827 | Write a Python function to implement the Quick Sort algorithm. The function should sort a list of integers in ascending order. The function should be recursive and use the last element of the list as the pivot. The code should start with:
```python
from typing import List
def quick_sort(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(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the Quick Sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
List... |
magic_evol_110k | 92,840 | Write a Python function to calculate the sum of all numeric values within a multidimensional list. The function should handle nested lists and ignore any non-numeric values. The code should start with:
```python
from typing import List, Union
def sum_multidimensional_list(lst: List[Union[int, float, List]]) -> Union[i... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Union
def sum_multidimensional_list(lst: List[Union[int, float, List]]) -> Union[int, float]:
"""
Calculate the sum of all numeric values within a multidimensional list.
Args:
lst (List[U... |
magic_evol_110k | 92,861 | Write a Python function to sort a list of integers from high to low using a custom sorting algorithm. The function should handle negative numbers and be efficient enough to handle lists with up to 10,000 elements. The function should not use built-in or library sorting functions. The code should start with:
```python
f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def custom_sort_high_to_low(nums: List[int]) -> List[int]:
"""
Sorts a list of integers from high to low using a custom Bubble Sort algorithm.
Args:
nums (List[int]): The list of integers to... |
magic_evol_110k | 92,862 | Write a Python function to generate a multiplication table for numbers from 1 to 10. The function should return a 2D list where each element at position `[i][j]` represents the product of `(i+1)` and `(j+1)`. The function should adhere to proper coding standards, including the use of loops and array manipulation.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_multiplication_table() -> List[List[int]]:
"""
Generates a multiplication table for numbers from 1 to 10.
Returns:
List[List[int]]: A 2D list where each element at position [i][... |
magic_evol_110k | 92,863 | Write a Python function to find the length of the longest increasing subsequence (LIS) in a given list of distinct integers. The function should return the length of the LIS.
The code should start with:
```python
from typing import List
def longest_increasing_subsequence(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_increasing_subsequence(arr: List[int]) -> int:
"""
Calculate the length of the longest increasing subsequence in a given list of distinct integers.
Args:
arr (List[int]): A list ... |
magic_evol_110k | 92,865 | Write a Python function to extract and validate email addresses from a given text document using Regular Expressions. The function should account for various domain extensions and country-specific codes. The function should return a list of valid email addresses found in the text.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def extract_valid_emails(text: str) -> List[str]:
"""
Extracts and validates email addresses from a given text document using Regular Expressions.
Args:
text (str): The text docume... |
magic_evol_110k | 92,868 | Write a Python function to determine if a given list of numbers (set1) is a subset of another list of numbers (set2) without any duplication. The function should return `True` if all elements of `set1` are present in `set2` without any duplicates, and `False` otherwise. 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 is_subset_without_duplicates(set1: List[int], set2: List[int]) -> bool:
"""
Determines if all elements of set1 are present in set2 without any duplication.
Args:
set1 (List[int]): The fi... |
magic_evol_110k | 92,872 | Write a Python function to sort a list of integer values in descending order. The function should raise a `TypeError` if the input is not a list or if any element in the list is not an integer. The function should start with:
```python
from typing import List
def sort_num(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_num(arr: List[int]) -> List[int]:
"""
Sorts a list of integer values in descending order.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
List[int]: ... |
magic_evol_110k | 92,876 | Write a Python function to generate an array of prime numbers of a given length `n`, where `n` is between 5 and 15 inclusive. The array should start from the prime number 3 and should exclude often repeated "twin prime numbers" (pairs of prime numbers that differ by 2, such as (3, 5), (5, 7), etc.). If `n` is not withi... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_prime_array(n: int) -> list[int] | str:
"""
Generate an array of prime numbers of length `n`, excluding often repeated twin prime numbers.
Args:
n (int): The length of the array to generate. Must be bet... |
magic_evol_110k | 92,882 | Write a Python function to count the number of alphabetic characters in a given string, excluding whitespace and punctuation. The function should be case-insensitive, meaning it should count both uppercase and lowercase letters as the same.
The code should start with:
```python
def count_alphabetic_characters(input_st... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_alphabetic_characters(input_string: str) -> int:
"""
Counts the number of alphabetic characters in a given string, excluding whitespace and punctuation.
Args:
input_string (str): The input string to count ... |
magic_evol_110k | 92,886 | Write a Python function named `assignDayValue` that takes two parameters: a string representing a day of the week and a boolean value. The function should dynamically create a variable with the name as the day of the week and assign it the given boolean value. Validate the input to only accept the seven days of the wee... | Here is the Python code to solve the given problem in the markdown block:
```python
def assignDayValue(day: str, value: bool) -> str:
"""
Dynamically creates a variable with the name as the day of the week and assigns it the given boolean value.
Args:
day (str): A string representing a day of the w... |
magic_evol_110k | 92,911 | Write a Python function to determine if a given string is a palindrome using the Floyd's Tortoise and Hare algorithm. The function should not use any character sequence manipulation functions (e.g., slicing, reversing) and should instead use two pointers to traverse the string from both ends towards the center. The fun... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_palindrome(s: str) -> bool:
"""
Determine if a given string is a palindrome using the Floyd's Tortoise and Hare algorithm.
Args:
s (str): The string to be checked for being a palindrome.
Returns:
... |
magic_evol_110k | 92,925 | Write a Python function to create a nested dictionary from a list of tuples. Each tuple contains two elements: the first element is the key for the external dictionary, and the second element is the key for the nested dictionary. The nested dictionary should contain the squares and cubes of the second element from the ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
def create_nested_dict(tuples: List[Tuple[str, int]]) -> Dict[str, Dict[int, Dict[str, int]]]:
"""
Creates a nested dictionary from a list of tuples. Each tuple contains two elements:
th... |
magic_evol_110k | 92,944 | Write a Python function to transform an HTML string that is provided in uppercase letters into its equivalent, all lowercase rendition. The function should handle any HTML tags and their contents, converting all uppercase characters to lowercase. The code should start with:
```python
def transform_html_to_lowercase(htm... | Here is the Python code to solve the given problem in the markdown block:
```python
def transform_html_to_lowercase(html_str: str) -> str:
"""
Transforms an HTML string that is provided in uppercase letters into its equivalent, all lowercase rendition.
Args:
html_str (str): The HTML string to be tr... |
magic_evol_110k | 92,945 | Write a Python function to count the number of occurrences of each element in a given list and identify the least and most frequent elements. If there are multiple elements with the same frequency, return any one of them. The function should also handle edge cases, such as an empty 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, Tuple, Dict, Union
def count_frequencies(numbers: List[int]) -> Union[str, Tuple[Dict[int, int], int, int]]:
"""
Count the number of occurrences of each element in the given list and identify the least ... |
magic_evol_110k | 92,973 | Write a Python function to sort a list of strings based on their lengths in ascending order. If two strings have the same length, they should remain in their original order. The function should take a list of strings as input and return the sorted list.
The code should start with:
```python
from typing import List
de... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_strings_by_length(string_list: List[str]) -> List[str]:
"""
Sorts a list of strings based on their lengths in ascending order.
If two strings have the same length, their relative order is pr... |
magic_evol_110k | 92,976 | Write a Python function to generate a random number sequence between 1 and 20 using the Metropolis-Hastings algorithm. The Metropolis-Hastings algorithm is a Markov Chain Monte Carlo (MCMC) method used to generate a sequence of samples from a probability distribution. The function should start with:
```python
from typi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def metropolis_hastings(iterations: int) -> List[int]:
"""
Generate a random number sequence between 1 and 20 using the Metropolis-Hastings algorithm.
Args:
iterations (int): T... |
magic_evol_110k | 92,983 | Write a Python function to count the occurrences of each unique number in a given three-dimensional matrix. The function should return a dictionary where the keys are the unique numbers found in the matrix, and the values are the counts of how many times each number appears.
The code should start with:
```python
from ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_unique_numbers(matrix: List[List[List[int]]]) -> Dict[int, int]:
"""
Counts the occurrences of each unique number in a three-dimensional matrix.
Args:
matrix (List[List[List[... |
magic_evol_110k | 92,989 | Write a Python function to sort a list using the insertion sort algorithm. The insertion sort algorithm works by iterating through the list and inserting each element into its correct position in the sorted part of the list. The code should start with:
```python
from typing import List
def insertion_sort(lst: List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def insertion_sort(lst: List[int]) -> List[int]:
"""
Sorts a list of integers using the insertion sort algorithm.
Args:
lst (List[int]): The list of integers to be sorted.
Returns:
... |
magic_evol_110k | 93,021 | Write a Python function to calculate the sum, mean, median, and mode of a given list of integers. The function should handle exceptions such as an empty list and non-integer elements. The list can contain up to 1,000,000 elements, requiring efficient coding.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
from collections import Counter
def calculate_statistics(numbers: List[int]) -> Tuple[int, float, float, int]:
"""
Calculate the sum, mean, median, and mode of a given list of integers.
Args:... |
magic_evol_110k | 93,023 | Write a Python function to convert a given sentence into its binary representation, where each character is represented by its 8-bit binary code. The function should return a single string where each binary code is separated by a space. The code should start with:
```python
def sentence_to_binary(sentence: str) -> str:... | Here is the Python code to solve the given problem in the markdown block:
```python
def sentence_to_binary(sentence: str) -> str:
"""
Converts a given sentence into its binary representation, where each character is represented by its 8-bit binary code.
Args:
sentence (str): The input sentence to b... |
magic_evol_110k | 93,032 | Write a Python function to print the contents of a list in reverse order without using the `reverse()` method or slicing. Additionally, calculate the product of the reversed list elements and return the result. The function should start with:
```python
from typing import List
def reverse_and_product(arr: List[int]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_and_product(arr: List[int]) -> int:
"""
Prints the contents of the list in reverse order and returns the product of its elements.
Args:
arr (List[int]): The list of integers to p... |
magic_evol_110k | 93,045 | Write a Python function to compute the product of numbers from 1 to n, considering only odd numbers if n is odd and even numbers if n is even. The function should use a while loop to achieve this.
The code should start with:
```python
def compute_product(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def compute_product(n: int) -> int:
"""
Computes the product of numbers from 1 to n, considering only odd numbers if n is odd and even numbers if n is even.
Args:
n (int): The upper limit of the range of numbers to ... |
magic_evol_110k | 93,049 | Write a Python function to filter out and return a list of odd numbers from a given dataset while maintaining the original sequence. The dataset is a list of integers. The function should start with:
```python
from typing import List
def filter_odd_numbers(dataset: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_odd_numbers(dataset: List[int]) -> List[int]:
"""
Filters out and returns a list of odd numbers from the given dataset while maintaining the original sequence.
Args:
dataset (List... |
magic_evol_110k | 93,053 | Write a Python function to calculate the maximum profit that can be obtained by performing at most two transactions on a given list of stock prices. Each transaction consists of buying and selling the stock, and you must sell the stock before you can buy it again. The code should start with:
```python
from typing impor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_profit_two_transactions(prices: List[int]) -> int:
"""
Calculate the maximum profit that can be obtained by performing at most two transactions on a given list of stock prices.
Args:
... |
magic_evol_110k | 93,078 | Write a Python function to compute the additive summation of two distinct numerical entities using a lambda function. The function should take two parameters, `n1` and `n2`, and return their sum. The function should be named `add_numbers`.
The code should start with:
```python
def add_numbers(n1: int, n2: int) -> int:... | Here is the Python code to solve the given problem in the markdown block:
```python
def add_numbers(n1: int, n2: int) -> int:
"""
Computes the additive summation of two distinct numerical entities using a lambda function.
Args:
n1 (int): The first numerical entity.
n2 (int): The second nume... |
magic_evol_110k | 93,084 | Write a Python function to filter out all negative numbers from a given matrix. The matrix is represented as a list of lists, where each inner list represents a row in the matrix. The function should return a new matrix containing only the non-negative numbers from the original matrix.
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 filter_negative_numbers(matrix: List[List[int]]) -> List[List[int]]:
"""
Filters out all negative numbers from the given matrix.
Args:
matrix (List[List[int]]): A 2D list representing th... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.