source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
3,361
Write a Python function to analyze a list of integers and return the frequencies of numbers that are divisible by 3 and numbers that are not divisible by 3, along with the sum of all numbers divisible by 3 and the product of all numbers not divisible by 3. The function should handle negative numbers correctly and shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def analyze_numbers(numbers: List[int]) -> Tuple[int, int, int, int]: """ Analyzes a list of integers and returns the frequencies of numbers that are divisible by 3 and not divisible by 3, alo...
python_sharegpt_23k
3,375
Write a Python function to find the sum of all the odd numbers in a given array of integers. The function should be implemented recursively and have a time complexity of O(n), where n is the length of the array. The function should not use any built-in functions or libraries for summation or checking odd numbers. Addit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_odds(arr: List[int], index: int = 0, sum: int = 0) -> int: """ Recursively calculates the sum of all odd numbers in the given array. Args: arr (List[int]): The array of integers t...
python_sharegpt_23k
3,376
Write a Python function to perform a binary search on a sorted array and return the index of the first occurrence of the target element. If the target element is not found, return -1. The function should have the following signature: ```python from typing import List def binary_search_first_occurrence(arr: List[int], ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search_first_occurrence(arr: List[int], target: int) -> int: """ Perform a binary search on a sorted array to find the index of the first occurrence of the target element. Args: ...
python_sharegpt_23k
3,377
Write a Python function to count the number of unique elements in a given list with a time complexity of O(n^2) and without using any additional data structures. Additionally, you are not allowed to use any built-in functions or methods for finding unique elements. The code should start with: ```python def count_unique...
Here is the Python code to solve the given problem in the markdown block: ```python def count_unique_elements(lst: list) -> int: """ Counts the number of unique elements in a given list with a time complexity of O(n^2) and without using additional data structures or built-in functions. Args: lst (l...
python_sharegpt_23k
3,379
Write a Python function to add an item to a given list with the following additional requirements: 1. The function should check if the given item already exists in the list. If it does, the function should not add the item and return an appropriate error message. 2. The function should check if the given item is of the...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union, Optional def add_item_to_list(lst: List[int], item: int, index: Optional[int] = None) -> Union[List[int], str]: """ Adds an item to a list with additional checks and constraints. Args: ...
python_sharegpt_23k
3,390
Write a Python function to determine if a given string is a palindrome without using any built-in string manipulation functions or methods, and without using any extra data structures such as arrays or lists. The code should start with: ```python def is_palindrome(s: str) -> bool: ```
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 without using any built-in string manipulation functions or methods, and without using any extra data structures. Args: s (str):...
python_sharegpt_23k
3,392
Write a Python function to reverse an array of length `n` in-place with a time complexity of O(n^2) and using only constant extra space. The function should not use any built-in functions or data structures such as arrays or lists. The code should start with: ```python def reverse_array_in_place(arr): ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_array_in_place(arr): """ Reverses an array of length n in-place with a time complexity of O(n^2) and using only constant extra space. Args: arr (list): The array to be reversed. Returns: lis...
python_sharegpt_23k
3,401
Write a Python function to convert a binary number represented as a string to its decimal equivalent without using any built-in functions or libraries that directly convert binary to decimal, and without using loops, recursion, or bitwise operators. The code should start with: ```python def binary_to_decimal(binary: s...
Here is the Python code to solve the given problem in the markdown block: ```python def binary_to_decimal(binary: str) -> int: """ Converts a binary number represented as a string to its decimal equivalent. Args: binary (str): The binary number to convert, represented as a string. Returns: ...
python_sharegpt_23k
3,402
Write a Python function to reverse a string only if it contains at least one uppercase letter, one lowercase letter, one digit, and one special character. The special characters can be any non-alphanumeric character. The function should have a time complexity of O(n) and a space complexity of O(n), where n is the lengt...
Here is the Python code to solve the given problem in the markdown block: ```python import string def reverse_string_with_criteria(input_str: str) -> str: """ Reverses the input string if it contains at least one uppercase letter, one lowercase letter, one digit, and one special character. If the string do...
python_sharegpt_23k
3,406
Write a Python function to perform an iterative binary search on a sorted array to find the index of the first occurrence of a target element. If the target element is not found, the function should return -1. The function should handle arrays with duplicate elements and should have a time complexity of O(log n) and a ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search_first_occurrence(arr: List[int], target: int) -> int: """ Perform an iterative binary search to find the index of the first occurrence of a target element in a sorted array. Args: ...
python_sharegpt_23k
3,410
Write a Python function to delete a given element from a list, ensuring that the element is present at least once. The list should not be modified if the element is not found. Additionally, the function should keep track of the number of times the element was deleted and return this count. The list can contain duplicat...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def delete_element(lst: List[int], element: int) -> Tuple[List[int], int]: """ Deletes all occurrences of a given element from a list and returns the modified list and the deletion count. Arg...
python_sharegpt_23k
3,411
Write a Python function to multiply two non-negative integers using only bitwise operators. The function should not use the multiplication operator or any other arithmetic operators. The code should start with: ```python def bitwise_multiply(a: int, b: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def bitwise_add(x: int, y: int) -> int: """ Helper function to perform bitwise addition of two integers. Args: x (int): The first integer. y (int): The second integer. Returns: int: The sum of t...
python_sharegpt_23k
3,412
Write a Python function to search for the first occurrence of a given element `x` in a sorted vector `arr` with duplicate elements. The function should return the index of the first occurrence of `x` if it exists in the vector, otherwise it should return `-1`. The search should be performed with a time complexity of O(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def search_first_occurrence(arr: List[int], x: int) -> int: """ Searches for the first occurrence of a given element `x` in a sorted vector `arr` with duplicate elements. Returns the index of the fir...
python_sharegpt_23k
3,413
Write a Python function to transpose a given 2-dimensional array (matrix) efficiently. The function should handle matrices of any size, including those with non-integer elements, sparse matrices, negative elements, and matrices with duplicate elements. The function should have a time complexity less than O(n * m) and a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def transpose_matrix(matrix: List[List[any]]) -> List[List[any]]: """ Transposes a given 2-dimensional array (matrix) efficiently. Args: matrix (List[List[any]]): The input matrix to be tran...
python_sharegpt_23k
3,418
Write a Python function to calculate the sum of all unique numbers in a given array. The function should handle cases where the array contains duplicate numbers and should return `None` if the array has fewer than two elements. The time complexity of the solution should be O(n) and the space complexity should be O(1). ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def sum_unique_numbers(arr: List[int]) -> Optional[int]: """ Calculate the sum of all unique numbers in the given array. Args: arr (List[int]): The array of integers from which to ...
python_sharegpt_23k
3,425
Write a Python function to generate and print the first 1000 prime numbers using an optimized sieve algorithm. The function should implement the Sieve of Eratosthenes to efficiently generate prime numbers up to a specified limit. The function should then print the first 1000 primes found within this limit. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python def print_first_1000_primes(limit: int) -> None: """ Generates and prints the first 1000 prime numbers using the Sieve of Eratosthenes. Args: limit (int): The upper limit up to which prime numbers are generated. ...
python_sharegpt_23k
3,429
Write a Python function to determine whether a given positive integer is a prime number or not. The function should not use any built-in libraries or functions that directly check if a number is prime. Instead, implement your own algorithm with an efficient time complexity. The function should avoid trial division or b...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime(n: int) -> bool: """ Determines whether a given positive integer is a prime number. Args: n (int): The positive integer to check for primality. Returns: bool: True if the numbe...
python_sharegpt_23k
3,431
Write a Python function to print all prime numbers between a given range `[start, end]` in reverse order. The function should only print the prime numbers and skip all the non-prime numbers. The function should start with: ```python def print_primes_in_reverse(start: int, end: int) -> None: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def print_primes_in_reverse(start: int, end: int) -> None: """ Prints all prime numbers between the given range [start, end] in reverse order. Args: start (int): The starting number of the range (inclusive). ...
python_sharegpt_23k
3,432
Write a Python function to perform a binary search on a sorted list of integers to find the index of the first occurrence of a target integer. If the target integer is not found, the function should return -1. The function should handle cases where the target integer appears multiple times by returning the index of the...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search_first_occurrence(arr: List[int], target: int) -> int: """ Perform a binary search on a sorted list of integers to find the index of the first occurrence of a target integer. If the ...
python_sharegpt_23k
3,435
Write a Python function to filter out all prime numbers from a given array and return the filtered array sorted in ascending order. Additionally, the function should return the sum of all the remaining non-prime numbers in the filtered array. The function should have a time complexity of O(nlogn) or better. The code s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import math 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....
python_sharegpt_23k
3,448
Write a Python function to filter and sort prime numbers from a given list of numbers. The function should return a new list containing only the prime numbers, sorted in descending order, and should ignore any prime numbers that contain the digit '7'. 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 filter_and_sort_primes(numbers: List[int]) -> List[int]: """ Filters and sorts prime numbers from a given list of numbers. Prime numbers containing the digit '7' are ignored. Args: n...
python_sharegpt_23k
3,449
Write a Python function to find the largest prime number in an array of integers and return its index. If there are multiple largest prime numbers, return the index of the first occurrence. If the array is empty or contains only non-prime numbers, return -1 as the index and 0 as the largest prime number. The code shou...
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 number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ ...
python_sharegpt_23k
3,453
Write a Python function to check if an element is present in a given list or not. The function should return the index of the element if it is present in the list. The list can contain duplicate elements, and the function should return the index of the first occurrence of the element. The function should be case-insens...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_element_index(lst: List[Union[str, int]], element: Union[str, int]) -> int: """ Find the index of the first occurrence of an element in a list. The search is case-insensitive for string e...
python_sharegpt_23k
3,457
Write a Python function to perform a binary search on a sorted array and return the index of the target item if it is found, or -1 if it is not found. The function should handle edge cases such as an empty array or an item not present in the array. The code should start with: ```python from typing import List def bin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search(arr: List[int], item: int) -> int: """ Perform a binary search on a sorted array to find the index of the target item. Args: arr (List[int]): A sorted list of integers. ...
python_sharegpt_23k
3,468
Write a Python function to remove all duplicate characters from a given string, maintaining the order of the remaining characters, and treating uppercase and lowercase characters as duplicates. The function should also ensure that no character appears more than once in the resulting string. The code should start with: ...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_duplicates(string: str) -> str: """ Removes all duplicate characters from the given string, maintaining the order of the remaining characters, and treating uppercase and lowercase characters as duplicates. Ar...
python_sharegpt_23k
3,471
Write a Python function to find the number of times a given target element appears in an array and return the indices at which the target element occurs. The array can contain both positive and negative integers, and its length can be up to 10 million elements. The target element can be any integer value. The time comp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def findOccurrences(array: List[int], target: int) -> List[int]: """ Find the number of times a given target element appears in an array and return the indices at which it occurs. Args: arra...
python_sharegpt_23k
3,477
Write a Python function that takes two parameters, a number and a string, and returns an array with those two values in it. The function should perform the following validations: 1. The string parameter should be checked if it is a valid string and if it contains only alphabetical characters. If the string is not valid...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(num: int) -> bool: """ Check if a number is a prime number. Args: num (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if num < 2: ...
python_sharegpt_23k
3,479
Write a Python function to categorize elements of a given list into four separate lists based on their type and divisibility by 3. The function should return a tuple containing these four lists: 1. `numbers_divisible_by_3`: Contains integers divisible by 3. 2. `numbers_not_divisible_by_3`: Contains integers not divisib...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def categorize_elements(arr: List) -> Tuple[List[int], List[int], List[str], List[List]]: """ Categorizes elements of a given list into four separate lists based on their type and divisibility by ...
python_sharegpt_23k
3,484
Write a Python function to filter and print the values from a given dictionary, excluding keys that contain the letter 'a' or end with the letter 's'. For the remaining keys, print their corresponding values, data types, and the number of characters in the values. The code should start with: ```python from typing impo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def filter_and_print_values(data: Dict) -> None: """ Filters and prints the values from a dictionary, excluding keys that contain the letter 'a' or end with the letter 's'. For the remaining keys, pr...
python_sharegpt_23k
3,489
Write a Python function to convert a list of time strings in 24-hour format to the corresponding 12-hour format based on a given time zone offset. The time strings are in the format "HH:MM:SS". The function should handle the conversion of each time string to the adjusted time in 12-hour format, considering the provided...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from datetime import datetime, timedelta def convert_times_to_12_hour_format(times: List[str], offset: int) -> List[str]: """ Convert a list of time strings in 24-hour format to the corresponding 12-hour...
python_sharegpt_23k
3,493
Write a Python function to find the index of the smallest prime number in a given array of positive integers. The function should return the index of the smallest prime number. If no prime number is found, the function should return `None`. The code should start with: ```python from typing import List, Optional import...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional import math 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 otherwi...
python_sharegpt_23k
3,494
Write a Python function to generate a tuple of exactly `n` even numbers that satisfy the following constraints: 1. The tuple must contain only even values. 2. The size of the tuple must be exactly `n`. 3. The values in the tuple must be sorted in descending order. 4. The sum of all values in the tuple must be greater t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple import random def generate_even_tuple(n: int) -> Tuple[int]: """ Generates a tuple of exactly `n` even numbers that satisfy the following constraints: 1. The tuple must contain only even values. ...
python_sharegpt_23k
3,497
Write a Python function to calculate the sum of all numbers in a given set, excluding any numbers that are divisible by 3. The function should handle the case when the set is empty and return 0 in such cases. The function should have a time complexity of O(n), where n is the size of the set. The set can contain duplica...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set def calculate_sum_excluding_divisible_by_3(my_set: Set[int]) -> int: """ Calculate the sum of all numbers in a given set, excluding any numbers that are divisible by 3. Args: my_set (Set[int]...
python_sharegpt_23k
3,498
Write a Python function to find the index of the first occurrence of the item with the maximum value in a given array of positive integers. If there are multiple occurrences of the maximum value, return the index of the occurrence with the lowest index value. If there are no occurrences of the maximum value, return -1....
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_first_max_index(arr: List[int]) -> int: """ Find the index of the first occurrence of the item with the maximum value in a given array of positive integers. If there are multiple occurrences...
python_sharegpt_23k
3,499
Write a Python function to iterate through an array and print out the indices and values of each element, along with the indices and values of the previous two elements and the next two elements in the array. The function should handle wrapping around the array, meaning the previous elements of the first element should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_extended_array(array: List[int]) -> None: """ Iterates through an array and prints the indices and values of each element, along with the indices and values of the previous two elements and...
python_sharegpt_23k
3,503
Write a Python function to calculate the sum of all unique numbers in a given list. The function should handle both integers and floats, including negative numbers. The function should have a time complexity of O(n), where n is the length of the input list. The code should start with: ```python from typing import List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_unique_numbers(lst: List[float]) -> float: """ Calculate the sum of all unique numbers in the given list. Args: lst (List[float]): The list of numbers (integers and floats) from whic...
python_sharegpt_23k
3,509
Write a Python function to check if a given string consists of unique, lowercase alphabets that are in lexicographical order. The function should return a boolean value indicating whether the string meets these criteria. The function should have a time complexity of O(n) and a space complexity of O(1). The input string...
Here is the Python code to solve the given problem in the markdown block: ```python def is_lexicographically_unique_lowercase(s: str) -> bool: """ Checks if a given string consists of unique, lowercase alphabets that are in lexicographical order. Args: s (str): The input string to be checked. ...
python_sharegpt_23k
3,511
Write a Python function to capitalize the first letter of each string in a list and convert the rest of the letters to lowercase. The function should handle strings with special characters or numbers by ignoring them and only applying the capitalization to alphabetic characters. The function should also handle empty st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def capitalize_strings(strings: List[str]) -> List[str]: """ Capitalizes the first letter of each string in the list and converts the rest of the letters to lowercase. Special characters and numbers ...
python_sharegpt_23k
3,517
Write a Python function to compare two objects based on their age, name, and address. The function should return 0 if the objects are equal, a positive number if the first object is larger, and a negative number if the second object is larger. The comparison should follow these rules: 1. If the age of the first object ...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_objects(obj1: dict, obj2: dict) -> int: """ Compares two objects based on their age, name, and address. Args: obj1 (dict): The first object to compare. obj2 (dict): The second object to compare. ...
python_sharegpt_23k
3,526
Write a Python function to print out each element of a given list in reverse order. The list must contain at least 10 elements and should only include prime numbers. The function should start with: ```python from typing import List def print_prime_numbers_in_reverse(prime_numbers: List[int]) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_prime_numbers_in_reverse(prime_numbers: List[int]) -> None: """ Prints each element of a given list of prime numbers in reverse order. Args: prime_numbers (List[int]): A list of pr...
python_sharegpt_23k
3,527
Write a Python function to find the common elements between two lists, `lst1` and `lst2`, and return a new list containing these common elements. The function should not use any built-in Python functions or libraries such as `numpy` or `itertools`. Additionally, the function should have a time complexity of O(n) where ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_common_elements(lst1: List[int], lst2: List[int]) -> List[int]: """ Find the common elements between two lists and return a new list containing these common elements. The function handles li...
python_sharegpt_23k
3,532
Write a Python function to count the number of unique words in a given string, ignoring punctuation marks and case sensitivity. A word is defined as a sequence of characters separated by whitespace (spaces, tabs, or newlines). The function should also ignore any duplicate words and only count each unique word once. Th...
Here is the Python code to solve the given problem in the markdown block: ```python def count_unique_words(string: str) -> int: """ Counts the number of unique words in a given string, ignoring punctuation and case sensitivity. Args: string (str): The input string from which to count unique words. ...
python_sharegpt_23k
3,538
Write a Python function that takes a list of integers and returns a new list with each number squared. The function should be implemented using functional programming techniques. The time complexity of the function should be O(n), where n is the length of the input list. The space complexity of the function should also...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def apply_function(numbers: List[int], function) -> List[int]: """ Applies a given function to each element in the list and returns a new list with the results. Args: numbers (List[int]): Th...
python_sharegpt_23k
3,541
Write a Python function to find the maximum subarray sum for a given array of integers. The function should have a time complexity of O(n), where n is the number of elements in the array, and it should use a constant amount of space. The subarray must consist of at least one element. The function should not modify the ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_subarray_sum(arr: List[int]) -> int: """ Find the maximum subarray sum for a given array of integers. The function uses Kadane's Algorithm to achieve a time complexity of O(n) and a space co...
python_sharegpt_23k
3,546
Write a Python function to sort a list of unique integers in ascending order using the Bubble Sort algorithm. The function should ensure that the list contains at least 10 unique elements and should be optimized to minimize the number of comparisons and swaps made during the sorting process. The time complexity of the ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def optimized_bubble_sort(arr: List[int]) -> List[int] or str: """ Sorts a list of unique integers in ascending order using the optimized Bubble Sort algorithm. Args: arr (List[int]): The li...
python_sharegpt_23k
3,547
Write a Python function to convert a given three-digit decimal number to its hexadecimal equivalent without using any built-in conversion functions or libraries. The function should handle both positive and negative three-digit numbers. If the input is not a valid three-digit number, the function should raise a `ValueE...
Here is the Python code to solve the given problem in the markdown block: ```python def decimal_to_hexadecimal(number: int) -> str: """ Converts a given three-digit decimal number to its hexadecimal equivalent. Args: number (int): The three-digit decimal number to convert. Returns: str...
python_sharegpt_23k
3,549
Write a Python function to count the number of unique odd numbers that are greater than 10 and less than 100 in a given array of integers. The function should exclude any negative numbers and should be implemented using a nested loop structure. The solution should have a time complexity of O(n), where n is the size of ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_unique_odd_numbers(arr: List[int]) -> int: """ Counts the number of unique odd numbers that are greater than 10 and less than 100 in a given array of integers. Excludes any negative numbers...
python_sharegpt_23k
3,554
Write a Python function to sort an array of numbers from least to greatest without using any built-in sorting functions or libraries. The input array will always contain at least 2 numbers and at most \(10^6\) numbers. All numbers in the array will be distinct and will be in the range of \(-10^9\) to \(10^9\). Addition...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def custom_sort(arr: List[int]) -> List[int]: """ Sorts an array of numbers from least to greatest using the Merge Sort algorithm. Args: arr (List[int]): The array of numbers to be sorted. ...
python_sharegpt_23k
3,559
Write a Python function that takes an English sentence as input and generates a response that includes a unique ID. The unique ID should be a combination of the current date and time, in the format of "YYYY-MM-DD_HH:MM:SS". Additionally, the function should handle the following requirements: 1. The function should ens...
Here is the Python code to solve the given problem in the markdown block: ```python import datetime import hashlib def generate_unique_response(sentence: str) -> str: """ Generates a unique response for the given sentence, including a unique ID and a hashed version of the sentence. Args: sentence ...
python_sharegpt_23k
3,564
Write a Python function to find the nth prime number greater than 100. The function should efficiently determine the nth prime number with a time complexity less than O(n^2). The code should start with: ```python def nth_prime_greater_than_100(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(num: int) -> bool: """ Helper function to check if a number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. ""...
python_sharegpt_23k
3,569
Write a Python function to repeat each element in a given array of strings a number of times equal to its length, without using any built-in methods or functions for repetition. The function should handle edge cases such as empty strings in the array and arrays with multiple elements of the same length. The function sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def repeat_elements(alphabet: List[str]) -> List[str]: """ Repeats each element in the given array of strings a number of times equal to its length. Args: alphabet (List[str]): The array of ...
python_sharegpt_23k
3,572
Write a Python function to reverse the order of elements in a given list of integers in place. The function should meet the following requirements: 1. The function should have a time complexity of O(n), where n is the length of the list. 2. You are not allowed to use any additional data structures or libraries. 3. You ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_list_in_place(lst: List[int]) -> None: """ Reverses the order of elements in a given list of integers in place. Args: lst (List[int]): The list of integers to be reversed. R...
python_sharegpt_23k
3,574
Write a Python function that takes a list as input and returns a new list with all integer elements sorted in descending order without using the built-in `sorted()` function or any other sorting algorithm. The input list may contain non-integer elements. You are only allowed to use the `set` module in Python to solve t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_descending(input_list: List) -> List: """ Sorts the integer elements of the input list in descending order without using built-in sorting functions. Args: input_list (List): The inp...
python_sharegpt_23k
3,577
Write a Python function `sum_columns(arr)` that takes a 2D array (list of lists) as input and returns a list containing the sums of all columns. The function must ensure that the time complexity is O(n), where n is the total number of elements in the array. The function should handle arrays of varying dimensions correc...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_columns(arr: List[List[int]]) -> List[int]: """ Calculate the sums of all columns in a given 2D array. Args: arr (List[List[int]]): A 2D array (list of lists) where each inner list r...
python_sharegpt_23k
3,580
Write a Python function to process a given sentence by performing the following steps: 1. Convert the sentence to lowercase. 2. Remove any punctuation marks from the sentence. 3. Split the sentence into individual words. 4. Find and remove any duplicate words from the sentence. 5. Sort the unique words in alphabetical ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import string def process_sentence(sentence: str) -> str: """ Processes a given sentence to find unique words, remove duplicates, and sort them alphabetically. Args: sentence (str): The inpu...
python_sharegpt_23k
3,583
Write a Python function to reverse a given string without using any built-in functions or methods for string manipulation (e.g., `reverse()`, `slice()`, etc.). You can only use basic string operations and loops. Additionally, your solution should be case-sensitive, meaning that uppercase and lowercase letters should be...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses the given string without using any built-in functions or methods for string manipulation. Args: s (str): The input string to be reversed. Returns: str: Th...
python_sharegpt_23k
3,591
Write a Python function to remove all duplicate elements from a given list of integers and return the distinct elements sorted in non-decreasing order. The function should handle lists with lengths between 1 and 1000. The code should start with: ```python from typing import List def removeDuplicatesAndSort(nums: List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def removeDuplicatesAndSort(nums: List[int]) -> List[int]: """ Removes all duplicate elements from the given list of integers and returns the distinct elements sorted in non-decreasing order. Args: ...
python_sharegpt_23k
3,593
Write a Python function to search a list of strings for a specific string that may contain wildcards, represented by asterisks (`*`), which can match any number of characters (including zero). The function should return the index of the first occurrence of the matching string. If no match is found, the function should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_matching_string(string_list: List[str], search_term: str) -> int: """ Searches a list of strings to find the first occurrence of a string that matches a search term with wildcards. Args: ...
python_sharegpt_23k
3,595
Write a Python function to compute the number of ways to select `k` items from a list of `n` options, where each option has a unique ID. The function should use a recursive approach to count the number of valid combinations. The code should start with: ```python from typing import List, NamedTuple class Option(NamedTu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, NamedTuple class Option(NamedTuple): id: int def compute_ways(options: List[Option], k: int) -> int: """ Compute the number of ways to select k items from a list of options, where each option has a...
python_sharegpt_23k
3,597
Write a Python function to count the total number of lowercase letters in a given string, ignoring all special characters, numbers, and uppercase letters. The function must not use any built-in Python string methods or functions (such as `str.islower()` or `str.count()`). Instead, use only basic Python syntax and contr...
Here is the Python code to solve the given problem in the markdown block: ```python def count_lowercase_letters(string: str) -> int: """ Counts the total number of lowercase letters in the given string, ignoring all special characters, numbers, and uppercase letters. Args: string (str): The input s...
python_sharegpt_23k
3,603
Write a Python function to calculate the greatest common divisor (GCD) of two positive integers, A and B, without using the modulus operator (%) or any other division-related operator. The function should have a time complexity of O(log(min(A, B))) or better. The code should start with: ```python def gcd_without_mod(A:...
Here is the Python code to solve the given problem in the markdown block: ```python def gcd_without_mod(A: int, B: int) -> int: """ Calculate the greatest common divisor (GCD) of two positive integers A and B without using the modulus operator or any other division-related operator. Args: A (in...
python_sharegpt_23k
3,604
Write a Python function to perform bubble sort on an array of integers in ascending order. The function should not use any built-in sorting functions or libraries. The input array can contain duplicate elements and may have a length of up to 10^6. Your implementation should have a time complexity of O(n^2), where n is ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers in ascending order using the bubble sort algorithm. Args: arr (List[int]): The array of integers to be sorted. ...
python_sharegpt_23k
3,608
Implement a variation of the cocktail sort algorithm to sort a given array of integers in ascending order while preserving the order of duplicate elements as they appeared in the original array. Additionally, keep track of the number of swaps performed during the sorting process and print the intermediate sorted arrays...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def cocktail_sort_with_duplicates(arr: List[int]) -> List[int]: """ Sorts the given array using a variation of the cocktail sort algorithm, preserving the order of duplicate elements. Additionally, i...
python_sharegpt_23k
3,611
Write a Python function to count the number of unique positive elements in a given list and return the sorted list of these unique positive elements. The function should ensure that the input list is sorted in non-decreasing order before processing. The code should start with: ```python from typing import List def un...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def unique_positive_elements(arr: List[int]) -> List[int]: """ Returns a sorted list of unique positive elements from the given list. Args: arr (List[int]): The input list of integers. ...
python_sharegpt_23k
3,614
Write a Python function to determine whether a given string is a palindrome, ignoring special characters, whitespace, numbers, and punctuation marks. The function should handle strings of length up to \(10^6\) characters efficiently with a time complexity of \(O(n)\), where \(n\) is the length of the input string. The...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(string: str) -> bool: """ Determines whether a given string is a palindrome, ignoring special characters, whitespace, numbers, and punctuation marks. The function is case-insensitive. Args: str...
python_sharegpt_23k
3,621
Write a Python function to traverse a given 2D array in a zigzag pattern and calculate the sum of all the elements accessed in this pattern. The zigzag pattern starts from the top-left corner and moves right, then diagonally down-left, then right again, and so on, until all elements are accessed. The function should ha...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def zigzag_sum(arr: List[List[int]]) -> int: """ Traverse a 2D array in a zigzag pattern and calculate the sum of all elements accessed. Args: arr (List[List[int]]): The 2D array to traverse...
python_sharegpt_23k
3,624
Write a Python function to multiply two numbers without using the multiplication operator. The algorithm should have a time complexity of O(log N), where N is the larger of the two numbers. Additionally, the algorithm should have a space complexity of O(1), meaning it should not use any additional memory apart from the...
Here is the Python code to solve the given problem in the markdown block: ```python def multiply_without_operator(a: int, b: int) -> int: """ Multiplies two integers without using the multiplication operator. Args: a (int): The first integer to be multiplied. b (int): The second integer to ...
python_sharegpt_23k
3,626
Write a Python function to create a dictionary where the keys are prime numbers between 1 and 100 and the values are lists containing the corresponding key and its squared value. The function should start with: ```python from typing import Dict, List def create_prime_dict() -> Dict[int, List[int]]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, 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. """ ...
python_sharegpt_23k
3,638
Write a Python function to determine whether a given number is a prime number using the Sieve of Eratosthenes algorithm. If the number is not prime, the function should return the smallest prime factor of the number. The function should efficiently handle numbers up to \(10^9\) and should be optimized for performance. ...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime_with_smallest_factor(n: int) -> int: """ Determine whether a given number is a prime number using the Sieve of Eratosthenes algorithm. If the number is not prime, return the smallest prime factor of...
python_sharegpt_23k
3,640
Write a Python function that takes a list of positive integers as input and returns a list containing only the prime numbers from the input list. If the input is not a list of positive integers, the function should raise a `TypeError`. The time complexity of the function should be less than or equal to O(n * sqrt(m)), ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math 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 oth...
python_sharegpt_23k
3,643
Write a Python function to find the length of the longest increasing subsequence (LIS) in a given list of positive integers. An increasing subsequence is a sequence of elements where each element is greater than the previous element. The function should use a dynamic programming approach to solve the problem efficientl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_increasing_subsequence(nums: List[int]) -> int: """ Calculate the length of the longest increasing subsequence in a given list of positive integers. Args: nums (List[int]): A lis...
python_sharegpt_23k
3,644
Write a Python function to double each element in a given list, remove any duplicates, and then filter the resulting list to include only elements that are divisible by 3. The resulting list should be sorted in descending order. Additionally, implement a function that returns the sum of all the elements in the resultin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def double_and_filter(lst: List[int]) -> List[int]: """ Doubles each element in the list, removes duplicates, filters for elements divisible by 3, and sorts the resulting list in descending order. ...
python_sharegpt_23k
3,647
Write a Python function to generate an array of all prime numbers less than a given number `n`, excluding the prime numbers 2, 3, 5, and 7. The function should return a list of these prime numbers. The code should start with: ```python from typing import List def generate_primes_less_than_n(n: 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 <...
python_sharegpt_23k
3,656
Write a Python function to extract all prime numbers from a given list, sort them in descending order, and return both the sorted list of prime numbers and the sum of these prime numbers. If there are no prime numbers in the list, return an empty list and a sum of 0. The code should start with: ```python from typing i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple 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. """ ...
python_sharegpt_23k
3,664
Write a Python function to sort a given list of numbers such that prime numbers are sorted in descending order and non-prime numbers are placed at the beginning of the list in descending order. The function should use an optimized primality test to determine if a number is prime. 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 math def is_prime(n: int) -> bool: """ Check if a number is prime using an optimized method. Args: n (int): The number to check for primality. Returns: bool: True if the ...
python_sharegpt_23k
3,666
Write a Python function to count down from a given number `n` to 0 and print the numbers in reverse order. Additionally, print only the even numbers. The function should handle the case where `n` is less than 0 by printing an error message. The code should start with: ```python def countdown_and_print_evens(n: int) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python def countdown_and_print_evens(n: int) -> None: """ Counts down from a given number `n` to 0 and prints only the even numbers in reverse order. If `n` is less than 0, prints an error message. Args: n (int): The s...
python_sharegpt_23k
3,667
Write a Python function to delete the last occurrence of a specified value from a given list without using any built-in functions or methods. The function should return a new list with the specified value removed, if it exists. If the value is not found in the list, the original list should be returned unchanged. The f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def delete_last_occurrence(input_list: List[int], value: int) -> List[int]: """ Deletes the last occurrence of a specified value from a given list and returns a new list. If the value is not found, t...
python_sharegpt_23k
3,673
Write a Python function to hide specified words in a given text by replacing them with a specified symbol, such as asterisks (*). The function should be case-insensitive and should only replace exact word matches, preserving punctuation and special characters in the input text. The code should start with: ```python im...
Here is the Python code to solve the given problem in the markdown block: ```python import re def hide_words(text: str, words_to_hide: list, symbol: str = '*') -> str: """ Hides specified words in a given text by replacing them with a specified symbol. Args: text (str): The input text in which to ...
python_sharegpt_23k
3,675
Write a Python function to sort a dictionary containing names and ages of people by the sum of the length of the names and ages in descending order. If two or more people have the same sum of lengths, sort them alphabetically by name in ascending order. The solution should have a time complexity of O(n log n) and a spa...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dictionary_by_length(dictionary: Dict[str, int]) -> Dict[str, int]: """ Sorts a dictionary containing names and ages by the sum of the length of the names and ages in descending order. If tw...
python_sharegpt_23k
3,680
Write a Python function to recursively replace all occurrences of 0 with 1 in a given list, including nested lists. The function should preserve the original structure of the list and should not use any additional data structures or variables. The function should only use recursion and not any built-in Python functions...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def replace_zeros(input_list: Union[List, int]) -> Union[List, int]: """ Recursively replaces all occurrences of 0 with 1 in a given list, including nested lists. Args: input_list (Un...
python_sharegpt_23k
3,682
Write a Python function `sum_and_average` that takes in an array of integers and returns the sum and average of all the elements in the array. The function should not use any built-in functions or libraries to calculate the sum or average, and it should have a time complexity of O(n) and a space complexity of O(1). Th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def sum_and_average(arr: List[int]) -> Tuple[int, float]: """ Calculate the sum and average of all elements in the given array of integers. Args: arr (List[int]): The array of integer...
python_sharegpt_23k
3,683
Write a Python function to create a dictionary with unique keys representing names and values representing ages. The names must be at least 8 characters long and contain at least one special character or number. The ages must be between 21 and 65 (inclusive) and should be divisible by 5. The function should ensure that...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict import random import string def create_unique_name_age_dict() -> Dict[str, int]: """ Creates a dictionary with unique keys representing names and values representing ages. The names must be at least ...
python_sharegpt_23k
3,684
Write a Python function to determine if one array is a subsequence of another array. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. The function should have a time complexity of O(n), where n is the length of th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_subsequence(arr1: List[int], arr2: List[int]) -> bool: """ Determines if one array is a subsequence of another array. Args: arr1 (List[int]): The first array of integers. arr2...
python_sharegpt_23k
3,690
Write a Python function to find the maximum value in a list of integers using recursion and binary search. The function should adhere to the following constraints: - The length of the list should be between 1 and 10^6. - The integers in the list can range from -10^9 to 10^9. - You are not allowed to use any built-in fu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_recursively(lst: List[int]) -> int: """ Find the maximum value in a list of integers using recursion and binary search. Args: lst (List[int]): The list of integers from which to...
python_sharegpt_23k
3,702
Write a Python function to extract all numeric values from a given string. The function should handle various types of numeric values including integers, floating-point numbers, and numbers in scientific notation. The function should also handle strings containing multiple numbers separated by non-numeric characters. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def extract_numeric_values(string: str) -> List[float]: """ Extracts all numeric values from a given string and returns them as a list of floats. The function handles integers, floating-po...
python_sharegpt_23k
3,719
Write a Python function to find the maximum element in a list without using the built-in `max()` function, loops, or recursion. The list may contain negative numbers and may be very large (up to \(10^6\) elements). The time complexity of your solution should be \(O(n)\) and the space complexity should be \(O(1)\). The ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from functools import reduce def find_max_element(lst: List[int]) -> int: """ Find the maximum element in a list without using the built-in max() function, loops, or recursion. Args: lst (Li...
python_sharegpt_23k
3,720
Write a Python function to find the index of the first occurrence of a given integer in a list. The function should have a time complexity of O(n) and should not use any built-in functions or methods. If the item is not found in the list, the function should return -1. 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 find_first_occurrence(my_list: List[int], item_to_find: int) -> int: """ Find the index of the first occurrence of a given integer in a list. Args: my_list (List[int]): The list of integ...
python_sharegpt_23k
3,722
Write a Python function named `find_primes` that takes a list of integers as input and returns a new list containing only the prime numbers from the original list. The function should be efficient and correctly identify prime numbers using a suitable algorithm. The function should maintain the order of prime numbers as...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def find_primes(nums: List[int]) -> List[int]: """ Returns a list of prime numbers from the given list of integers. Args: nums (List[int]): A list of integers from which to extra...
python_sharegpt_23k
3,723
Write a Python function to replace all vowels in a given string with a specified character. The function should handle both uppercase and lowercase vowels and maintain the original case of the vowels in the output string. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the ...
Here is the Python code to solve the given problem in the markdown block: ```python def replace_vowels(string: str, replace_char: str) -> str: """ Replaces all vowels in the given string with the specified character. Args: string (str): The input string in which vowels need to be replaced. ...
python_sharegpt_23k
3,729
Write a Python function to find all prime numbers between two given integers (inclusive). The function should handle various edge cases such as negative input integers, non-integer inputs, and cases where the starting number is greater than the ending number. Additionally, the function should return an empty list if th...
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. ...
python_sharegpt_23k
3,731
Write a Python function to find the maximum element in a 2D array of size n x m, where n is the number of rows and m is the number of columns. The array contains both positive and negative integers. The algorithm should have a time complexity of O(n*m) and a space complexity of O(1). The function should use a single lo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_element(arr: List[List[int]]) -> int: """ Find the maximum element in a 2D array of size n x m. Args: arr (List[List[int]]): A 2D list of integers. Returns: int: Th...
python_sharegpt_23k
3,732
Write a Python function to calculate the nth Fibonacci number efficiently using an iterative approach with memoization. The function should handle large values of n (up to 10^6) without causing a stack overflow error. The function should also include error handling for cases where n is a negative integer or where the f...
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci(n: int) -> int: """ Calculate the nth Fibonacci number using an iterative approach with memoization. Args: n (int): The position in the Fibonacci sequence to calculate. Returns: int: The n...
python_sharegpt_23k
3,733
Write a Python function to find the maximum number in a given array. If the array is empty or contains non-integer elements, return `None`. The function should not use any built-in functions or methods to find the maximum number, and it should have a time complexity of O(n), where n is the length of the array. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_maximum(arr: List[int]) -> Optional[int]: """ Find the maximum number in a given array of integers. Args: arr (List[int]): The array of integers from which to find the max...
python_sharegpt_23k
3,734
Write a Python function to convert dates in a given string from the format 'dd/mm/yyyy' to 'mm/dd/yyyy' using regex. The function should validate the input string to ensure it contains only valid dates in the specified format, handle cases where the input string may contain invalid dates or dates in a different format,...
Here is the Python code to solve the given problem in the markdown block: ```python import re from typing import List def convert_dates_to_mmddyyyy(input_string: str) -> List[str]: """ Convert dates in a given string from the format 'dd/mm/yyyy' to 'mm/dd/yyyy' using regex. Args: input_string (str...
python_sharegpt_23k
3,738
Write a Python function to calculate the sum of all positive even numbers from a given list. The function should not use the built-in `sum()` function or any other external libraries. The function should have a time complexity of O(n), where n is the length of the list. Additionally, the function should ignore any dupl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_sum_positive_even_numbers(numbers: List[int]) -> int: """ Calculates the sum of all positive even numbers from a given list. Args: numbers (List[int]): The list of numbers to p...
python_sharegpt_23k
3,741
Write a Python function to count the number of unique strings in a given list of integers and strings. The function should have a time complexity of O(n) and a space complexity of O(n). The list may contain duplicate strings and integers. The code should start with: ```python from typing import List def count_unique_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_unique_strings(list_elements: List[object]) -> int: """ Counts the number of unique strings in a given list of integers and strings. Args: list_elements (List[object]): A list cont...
python_sharegpt_23k
3,742
Write a Python function to validate an email address based on the following criteria: 1. The email must include at least one uppercase letter and one number in the username part. 2. The email must not contain the domain "gmail.com" or "yahoo.com". 3. The email must be in a valid email format. The function should retur...
Here is the Python code to solve the given problem in the markdown block: ```python import re def validate_email(email: str) -> bool: """ Validates an email address based on the following criteria: 1. The email must include at least one uppercase letter and one number in the username part. 2. The email...
python_sharegpt_23k
3,745
Write a Python function to convert a list of numbers into a dictionary where each key is a number from the list and the corresponding value is the square of that number. The function should handle any errors that may occur, such as invalid input types or empty lists. The function 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 convert_to_squared_dict(numbers: List[int]) -> Dict[int, int]: """ Converts a list of integers into a dictionary where each key is an integer from the list and the value is its square. Arg...
python_sharegpt_23k
3,748
Write a Python function to merge k sorted linked lists into a single sorted linked list. The function should have a time complexity of O(n log k), where n is the total number of nodes in all the linked lists and k is the number of linked lists. The function should not use any extra space to store the entire merged list...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import heapq class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def mergeKLists(lists: List[ListNode]) -> ListNode: """ Merge k sorted linked lists...
python_sharegpt_23k
3,751
Write a Python function to calculate the average of the sum of all odd prime numbers in a given array. The input array can contain both positive and negative integers. If the array is empty or contains no odd prime numbers, the function should return an appropriate error message. 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 math def is_prime(num: int) -> bool: """ Check if a number is a prime number. Args: num (int): The number to check. Returns: bool: True if the number is prime, False othe...