source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
12,177
Write a Python function to calculate the sum of a list of numbers, excluding any numbers that are multiples of 3 and ignoring any negative numbers. The function should only consider numbers greater than or equal to zero. The code should start with: ```python from typing import List def sum_of_list_excluding_multiples...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_list_excluding_multiples_of_3(numbers: List[int]) -> int: """ Calculate the sum of a list of numbers, excluding any numbers that are multiples of 3 and ignoring any negative numbers. Args...
python_sharegpt_23k
12,183
Write a Python function to convert time between seconds, minutes, and hours. The function should handle conversions in both directions (e.g., seconds to minutes, minutes to hours, hours to minutes, etc.). The input should be limited to non-negative integers. The function should return a string formatted as specified in...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_time(time: int, unit: str) -> str: """ Converts time between seconds, minutes, and hours. Args: time (int): The time value to convert. Must be a non-negative integer. unit (str): The unit of the ...
python_sharegpt_23k
12,190
Write a Python function to convert a given hexadecimal string to its decimal equivalent and then to its binary representation. The function should validate the input to ensure it is a valid hexadecimal value, handle both uppercase and lowercase letters, and reject any input containing invalid characters beyond 0-9 and ...
Here is the Python code to solve the given problem in the markdown block: ```python def hex_to_binary(hex_value: str) -> str: """ Convert a given hexadecimal string to its binary representation. Args: hex_value (str): The hexadecimal string to convert. Returns: str: The binary represen...
python_sharegpt_23k
12,196
Write a Python function to calculate the edit distance between two given strings, considering only the following operations: insertions, deletions, and substitutions. The function should have a time complexity of O(n^2), where n is the length of the longer string. The function should start with: ```python def edit_dist...
Here is the Python code to solve the given problem in the markdown block: ```python def edit_distance(str1: str, str2: str) -> int: """ Calculate the edit distance between two strings using dynamic programming. The edit distance is defined as the minimum number of operations (insertions, deletions, and sub...
python_sharegpt_23k
12,207
Write a Python function to find the index of a given number in a sorted array of length n using a recursive binary search approach. The array will contain distinct integers and will be in ascending order. The algorithm should have a time complexity of O(log n) and should use only constant extra space. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_index_of_target(arr: List[int], target: int) -> int: """ Find the index of a given target number in a sorted array using a recursive binary search approach. Args: arr (List[int]): A...
python_sharegpt_23k
12,212
Write a Python function to find and return a list of all perfect square numbers between 1 and a given integer N, inclusive. The function should efficiently handle large values of N. Additionally, the function should print each number from 1 to N, but only after checking if it is a perfect square. The code should start...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def find_perfect_squares(N: int) -> List[int]: """ Finds and returns a list of all perfect square numbers between 1 and N, inclusive. Additionally, prints each number from 1 to N. Ar...
python_sharegpt_23k
12,215
Write a Python function to sort a given list of integers in increasing order without using any built-in sorting functions or libraries. Implement a sorting algorithm of your choice and document it in comments within your code. Optimize your sorting algorithm for efficiency in terms of time complexity and space complexi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def custom_sort(nums: List[int]) -> List[int]: """ Sorts a given list of integers in increasing order using the Merge Sort algorithm. Args: nums (List[int]): The list of integers to be sorte...
python_sharegpt_23k
12,216
Write a Python function that takes a string as input and transforms all alphabetic characters of the string to upper case without using any built-in string manipulation functions or libraries. The function should return the modified string. The function should handle strings with any combination of upper case and lower...
Here is the Python code to solve the given problem in the markdown block: ```python def transform_to_upper(string: str) -> str: """ Transforms all alphabetic characters in the input string to upper case. Args: string (str): The input string to be transformed. Returns: str: The modified...
python_sharegpt_23k
12,220
Write a Python function to concatenate two strings after removing any leading or trailing whitespace from both strings. The function should also handle cases where one or both of the input strings are null or empty, and return an appropriate error message. The input strings can contain alphanumeric characters and speci...
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_strings(str1: str, str2: str) -> str: """ Concatenates two strings after removing any leading or trailing whitespace from both strings. If either of the input strings is null or empty, returns an appropriate ...
python_sharegpt_23k
12,221
Write a Python function to capitalize the first character of each word in a given string. The input string will always be in lowercase and will not contain any punctuation marks. The function should return a new string with each word capitalized. The code should start with: ```python def capitalize_words(input_string:...
Here is the Python code to solve the given problem in the markdown block: ```python def capitalize_words(input_string: str) -> str: """ Capitalizes the first character of each word in the given input string. Args: input_string (str): The input string consisting of multiple words separated by spaces...
python_sharegpt_23k
12,222
Write a Python function to convert an RGB color to a HEX color code without using any built-in functions or libraries for color conversions. The function should handle alpha values and return the HEX color code with the alpha value if it is not fully opaque. The function should also validate the input to ensure that th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def rgb_to_hex(rgb: Tuple[int, int, int, int]) -> str: """ Converts an RGB color to a HEX color code. If the alpha value is provided and not fully opaque, it includes the alpha value in the HEX colo...
python_sharegpt_23k
12,223
Write a Python function to verify whether an array of numbers is in strictly increasing order and contains only unique elements. The function should meet the following constraints: 1. The array must have at least 3 elements. 2. The array can contain both positive and negative numbers. 3. The array cannot contain any du...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_strictly_increasing_unique(arr: List[float]) -> bool: """ Verifies whether an array of numbers is in strictly increasing order and contains only unique elements. Args: arr (List[float...
python_sharegpt_23k
12,226
Write a Python function to calculate the sum of squares of a list of numbers, where each number is raised to the power of a given exponent. The function should also handle negative numbers and return an error message if any negative number is present in the list. The code should start with: ```python from typing import...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def sum_of_squares_with_exponent(numbers: List[int], exponent: int) -> Union[int, str]: """ Calculate the sum of squares of a list of numbers, where each number is raised to the power of a given e...
python_sharegpt_23k
12,230
Write a Python function to sort a list of integers in ascending order using the bubble sort algorithm. The function should handle lists that contain duplicate elements correctly. The code should start with: ```python from typing import List def bubble_sort(nums: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(nums: List[int]) -> List[int]: """ Sorts a list of integers in ascending order using the bubble sort algorithm. Args: nums (List[int]): The list of integers to be sorted. ...
python_sharegpt_23k
12,236
Write a Python function to determine if all elements in a given array are similarly oriented, meaning either all elements are positive, all are negative, or all are zero. The function should handle cases where the array is empty or contains only one element. The function should have a time complexity of O(n), where n i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_similarly_oriented(arr: List[float]) -> bool: """ Determines if all elements in the given array are similarly oriented, meaning either all elements are positive, all are negative, or all are zero....
python_sharegpt_23k
12,243
Write a Python function to find the minimum element in an array of positive integers without using any built-in functions or methods that directly provide the minimum element. The function must have a time complexity of O(n), where n is the number of elements in the array. The array will always contain at least one ele...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_minimum(arr: List[int]) -> int: """ Finds the minimum element in an array of positive integers without using any built-in functions or methods that directly provide the minimum element. Arg...
python_sharegpt_23k
12,244
Write a Python function to reverse an array in-place and then sort it in ascending order without using any built-in sorting functions or data structures. The array will contain only positive integers. The code should start with: ```python from typing import List def reverse_and_sort_array(arr: List[int]) -> List[int]:...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_and_sort_array(arr: List[int]) -> List[int]: """ Reverses the given array in-place and then sorts it in ascending order. Args: arr (List[int]): The array of positive integers to ...
python_sharegpt_23k
12,247
Write a Python function to convert a timestamp from epoch time to human-readable time. The timestamp is provided as a string in the format "yyyy-mm-dd HH:MM:SS". The function should return the human-readable time in the format "Month dd, yyyy HH:MM:SS AM/PM". The input timestamp string will always be valid and within a...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime def convert_timestamp_to_human_readable(timestamp: str) -> str: """ Converts a timestamp from epoch time to human-readable time. Args: timestamp (str): The input timestamp in the forma...
python_sharegpt_23k
12,253
Write a Python function to filter out prime numbers from a given list of integers. The function should have a time complexity of O(n^2), where n is the length of the input list. The function should start with: ```python from typing import List def filter_primes(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 filter_primes(numbers: List[int]) -> List[int]: """ Filters out prime numbers from a given list of integers. Args: numbers (List[int]): The list of integers to filter. Returns: ...
python_sharegpt_23k
12,256
Write a Python function to merge two dictionaries, `dict1` and `dict2`, into a new dictionary `combined_dict`. The function should handle the following cases: 1. If a key exists in both dictionaries and the corresponding values are lists, the lists should be concatenated in the `combined_dict`. 2. If a key exists in bo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def merge_dicts(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]: """ Merge two dictionaries into a new dictionary. Args: dict1 (Dict[Any, Any]): The first dictionary to ...
python_sharegpt_23k
12,257
Write a Python function to loop through a list of dictionaries and print the value of the "name" property for each dictionary. Handle the following cases: 1. If the "name" property is missing, print "Unknown". 2. If the "name" property exists but is an empty string, print "Empty". 3. Otherwise, print the value of the "...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def print_names(data: List[Dict[str, any]]) -> None: """ Loop through a list of dictionaries and print the value of the "name" property. If the "name" property is missing, print "Unknown". ...
python_sharegpt_23k
12,259
Write a Python function to append the elements of a second list to a first list. The second list should only contain prime numbers and must be sorted in descending order. The resulting list should not have any duplicate elements and should be sorted in ascending order. The total number of elements in the resulting list...
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. Returns: bool: True if the number is prime, False otherwise. ""...
python_sharegpt_23k
12,261
Write a Python function to calculate the median of a given array of numbers. The array will always have an odd number of elements, and you are not allowed to use any built-in functions or libraries to find the median. Additionally, you are not allowed to use any loops or recursion in your implementation. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_median(arr: List[int]) -> int: """ Calculate the median of a given array of numbers with an odd number of elements. Args: arr (List[int]): The array of integers with an odd number o...
python_sharegpt_23k
12,262
Write a Python function to calculate the sum of command line arguments provided to a script. The function should handle and display an error message if any of the arguments are not numeric. The code should start with: ```python import sys def sum_command_line_args(args: list) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python import sys def sum_command_line_args(args: list) -> float: """ Calculate the sum of numeric command line arguments and handle non-numeric inputs. Args: args (list): A list of strings representing the command line a...
python_sharegpt_23k
12,264
Write a Python function called `sum_of_even_numbers` that takes in a list of integers and returns the sum of all even numbers in the list using a for loop. The function should adhere to the following specifications: - The function should handle both positive and negative integers. - The function should ignore any non-i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_even_numbers(numbers: List[int]) -> int: """ Calculate the sum of all even numbers in the given list of integers. Args: numbers (List[int]): A list of integers. Returns: ...
python_sharegpt_23k
12,273
Write a Python function to print all prime numbers between 0 and 100. The function should correctly identify prime numbers and avoid printing any erroneous messages. The code should start with: ```python def print_primes_up_to_100(): ```
Here is the Python code to solve the given problem in the markdown block: : ```python def print_primes_up_to_100(): """ Prints all prime numbers between 0 and 100. This function iterates through each number from 0 to 100 and checks if it is a prime number. If a number is prime, it prints the number. ...
python_sharegpt_23k
12,276
Write a Python function to check if a given string represents a valid date in the format "MM/DD/YYYY", considering leap years. The function should return `True` if the date is valid and `False` otherwise. The code should start with: ```python def is_valid_date(date_str: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_valid_date(date_str: str) -> bool: """ Check if a given string represents a valid date in the format "MM/DD/YYYY". Args: date_str (str): The date string to validate. Returns: bool: True if the da...
python_sharegpt_23k
12,277
Write a Python function to determine the number of days in a given month for a specified calendar system. The function should handle different calendar systems such as the Gregorian, Julian, and Islamic calendars. It should also return an error message if an invalid month name or calendar system is provided. The functi...
Here is the Python code to solve the given problem in the markdown block: ```python def get_days_in_month(month: str, calendar_system: str = 'Gregorian') -> int or str: """ Returns the number of days in a given month for a specified calendar system. Args: month (str): The name of the month. ...
python_sharegpt_23k
12,278
Write a Python function to calculate the sum of all even numbers in a given list of integers. The function should return 0 if there are no even numbers in the list. Additionally, the function should only use a single loop and should not use any built-in functions or methods for checking if a number is even. The code s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_even_numbers(numbers: List[int]) -> int: """ Calculate the sum of all even numbers in the given list. Args: numbers (List[int]): A list of integers. Returns: int: The su...
python_sharegpt_23k
12,293
Write a Python function to find the second smallest element in a given list of integers. The function should not use any built-in sorting functions or data structures and must have a time complexity of O(n), where n is the length of the list. The function should iterate through the list only once. The code should star...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_second_smallest(nums: List[int]) -> int: """ Find the second smallest element in a list of integers. Args: nums (List[int]): The list of integers from which to find the second small...
python_sharegpt_23k
12,302
Write a Python function to replace each alphabetic character in a given string with the next consecutive character in the alphabet. The function should handle both uppercase and lowercase letters separately and wrap around from 'z' to 'a' or 'Z' to 'A' when necessary. Non-alphabetic characters should remain unchanged. ...
Here is the Python code to solve the given problem in the markdown block: ```python def replace_characters(string: str) -> str: """ Replace each alphabetic character in the input string with the next consecutive character in the alphabet. Handles both uppercase and lowercase letters separately and wraps aro...
python_sharegpt_23k
12,304
Write a Python function to calculate the sum of the elements of an array with float values, excluding any negative values and values greater than 100. The final sum should be rounded to two decimal places. The code should start with: ```python from typing import List def calculate_filtered_sum(arr: List[float]) -> flo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_filtered_sum(arr: List[float]) -> float: """ Calculate the sum of the elements of an array with float values, excluding any negative values and values greater than 100. The final sum is...
python_sharegpt_23k
12,311
Write a Python function to calculate the length of a given string without using the built-in `len()` function, loops, or recursion. The function should be efficient and leverage Python's built-in data structures and methods. The code should start with: ```python def calculate_string_length(string: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_string_length(string: str) -> int: """ Calculate the length of a given string without using the built-in `len()` function, loops, or recursion. Args: string (str): The input string whose length is to b...
python_sharegpt_23k
12,312
Write a Python function to remove all non-alphabetical characters from a given string, convert all uppercase letters to lowercase, and count the number of vowels remaining in the string. The function should return the count of vowels. The code should start with: ```python import re def count_vowels_in_cleaned_string(...
Here is the Python code to solve the given problem in the markdown block: ```python import re def count_vowels_in_cleaned_string(input_string: str) -> int: """ Removes all non-alphabetical characters from the given string, converts all uppercase letters to lowercase, and counts the number of vowels remaini...
python_sharegpt_23k
12,315
Write a Python function that takes a string as input and returns `True` if the string contains only digits and the number formed by the digits is a prime number. Otherwise, it should return `False`. The function should start with: ```python def is_string_prime(s: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_string_prime(s: str) -> bool: """ Determines if a string contains only digits and forms a prime number. Args: s (str): The input string to be checked. Returns: bool: True if the string contains o...
python_sharegpt_23k
12,317
Write a Python function to sort a dictionary of student names and their corresponding scores in descending order based on their scores. If multiple students have the same score, sort these students alphabetically by their names in ascending order. The function should return a new dictionary with the sorted students. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_students_by_scores(scores: Dict[str, int]) -> Dict[str, int]: """ Sorts a dictionary of student names and their scores in descending order based on their scores. If multiple students have th...
python_sharegpt_23k
12,318
Write a Python function to create a new list containing the tripled values of each number from a given list of numbers. The original list should not be modified. The solution should have a time complexity of O(n) and a space complexity of O(n). The solution should not use any built-in functions or methods that directly...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def triple_values(numbers: List[int]) -> List[int]: """ Creates a new list containing the tripled values of each number from the given list. Args: numbers (List[int]): The list of numbers to...
python_sharegpt_23k
12,319
Write a Python function to remove all empty strings from a given list while maintaining the order of the remaining elements. The function should not use any built-in functions or methods for list manipulation (e.g., `filter`, `remove`, `pop`, etc.). 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_empty_strings(input_list: List[str]) -> List[str]: """ Removes all empty strings from the given list while maintaining the order of the remaining elements. Args: input_list (List[...
python_sharegpt_23k
12,321
Write a Python function to generate the nth Fibonacci number using an iterative approach. The function should handle negative values of n by returning -1 for invalid inputs. Additionally, optimize the algorithm to have a time complexity of O(n). The code should start with: ```python def fibonacci(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci(n: int) -> int: """ Generate the nth Fibonacci number using an iterative approach. Args: n (int): The position in the Fibonacci sequence to generate. Returns: int: The nth Fibonacci number...
python_sharegpt_23k
12,324
Write a Python function to find the frequency of a given phrase in a text, considering case sensitivity, punctuation marks, and the position of the phrase in the text. The function should not count the phrase if it appears as a substring within another word. The code should start with: ```python import re def find_phr...
Here is the Python code to solve the given problem in the markdown block: ```python import re def find_phrase_frequency(text: str, phrase: str) -> int: """ Find the frequency of a given phrase in the text, considering case sensitivity, punctuation marks, and the position of the phrase in the text. The phra...
python_sharegpt_23k
12,330
Write a Python function to print all prime numbers in a given range `[1, n]` using a nested loop and a time complexity of O(n^2). The function should use the modulo operator to check for prime numbers. The code should start with: ```python def print_primes_in_range(n: int) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python def print_primes_in_range(n: int) -> None: """ Prints all prime numbers in the range [1, n] using a nested loop and the modulo operator. Args: n (int): The upper limit of the range (inclusive) to search for prime nu...
python_sharegpt_23k
12,336
Write a Python function to reverse the characters in each word of a sentence stored as a list in Python, using only constant extra space. The function should modify the input list in-place and return the modified list. The code should start with: ```python from typing import List def reverse_words_in_place(sentence: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_words_in_place(sentence: List[str]) -> List[str]: """ Reverse the characters in each word of a sentence stored as a list in Python, using only constant extra space. Args: sentenc...
python_sharegpt_23k
12,338
Write a Python function to convert a given string of space-separated integers into a list of unique integers sorted in ascending order. The function should handle any valid input string containing space-separated integers. The code should start with: ```python from typing import List def convert_string_to_sorted_uniq...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_string_to_sorted_unique_list(input_string: str) -> List[int]: """ Converts a string of space-separated integers into a list of unique integers sorted in ascending order. Args: in...
python_sharegpt_23k
12,341
Write a Python function to build a dictionary of word frequencies from a given input string, ignoring punctuation marks, converting all words to lowercase, and removing specified stop words. The function should return a dictionary where the keys are words and the values are their respective frequencies. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict import string def build_word_frequency_dict(input_string: str, stop_words: List[str]) -> Dict[str, int]: """ Builds a dictionary of word frequencies from a given input string, ignoring punctuation ...
python_sharegpt_23k
12,342
Write a Python function to convert a given string to uppercase using only basic string manipulation operations. The string may contain punctuation marks, special characters, and spaces. The solution should have a time complexity of O(n), where n is the length of the string. The code should start with: ```python def to...
Here is the Python code to solve the given problem in the markdown block: ```python def to_upper_case(s: str) -> str: """ Converts a given string to uppercase using only basic string manipulation operations. Args: s (str): The input string to be converted to uppercase. Returns: str: Th...
python_sharegpt_23k
12,343
Write a Python function to check if a given string of parentheses is balanced. A string is considered balanced if every opening parenthesis `(` has a corresponding closing parenthesis `)` and the parentheses are nested correctly. The function should return `True` if the string is balanced and `False` otherwise. The co...
Here is the Python code to solve the given problem in the markdown block: ```python def check_parentheses(input_string: str) -> bool: """ Check if a given string of parentheses is balanced. Args: input_string (str): The string of parentheses to be checked. Returns: bool: True if the pa...
python_sharegpt_23k
12,345
Write a Python function to swap three integer values without using additional variables. The function should take three integers as input and return the swapped values. The code should start with: ```python def swap_three_values(a: int, b: int, c: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def swap_three_values(a: int, b: int, c: int) -> tuple: """ Swaps the values of three integers without using additional variables. Args: a (int): The first integer. b (int): The second integer. c (...
python_sharegpt_23k
12,348
Write a Python function to compare two dictionaries and return `True` if they have the same set of keys and values, and `False` otherwise. The function should have a time complexity of O(n), where n is the number of key-value pairs in the dictionaries. Additionally, the function should be able to handle larger input si...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_dictionaries(dict1: dict, dict2: dict) -> bool: """ Compare two dictionaries and return True if they have the same set of keys and values, and False otherwise. Args: dict1 (dict): The first dictionary to...
python_sharegpt_23k
12,351
Implement the Bubble Sort algorithm to sort an array of integers in non-decreasing order. Your solution should have a time complexity of O(n^2), and should not use any built-in sorting functions or libraries. Additionally, you should handle cases where the input array is empty or contains duplicate elements. The input ...
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 non-decreasing order using the Bubble Sort algorithm. Args: arr (List[int]): The array of integers to be sorte...
python_sharegpt_23k
12,353
Write a Python function to count the number of characters in each word of a given sentence, excluding punctuation marks and special characters. The sentence may contain punctuation marks and special characters, which should be treated as separate words. The function should have a time complexity of O(n), where n is the...
Here is the Python code to solve the given problem in the markdown block: ```python def count_characters_in_words(sentence: str) -> list: """ Counts the number of characters in each word of a given sentence, excluding punctuation marks and special characters. Args: sentence (str): The input sentenc...
python_sharegpt_23k
12,354
Write a Python function to find the maximum and minimum numbers in a given list of integers without using any built-in functions or methods such as `max()`, `min()`, or sorting algorithms. The function should have a time complexity of O(n), where n is the length of the list. Additionally, the function should handle edg...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_max_min(numbers: List[int]) -> Tuple[int, int]: """ Find the maximum and minimum numbers in a given list of integers without using built-in functions or sorting algorithms. Args: ...
python_sharegpt_23k
12,356
Write a Python function to generate an HTML table with five columns and ten rows. Each cell in the table should contain a random number between 1 and 100. The table should have a header row with column names "ID", "Name", "Age", "Gender", and "Score". Additionally, the table should have alternating background colors fo...
Here is the Python code to solve the given problem in the markdown block: ```python import random def generate_html_table() -> str: """ Generates an HTML table with five columns and ten rows. Each cell contains a random number between 1 and 100. The table has a header row with column names "ID", "Name", "A...
python_sharegpt_23k
12,361
Write a Python function to check if a given list of elements is a palindrome. The function should consider negative numbers, decimal numbers, and non-numeric elements. The list can have a maximum length of 100 elements. The solution should have a time complexity of O(n), where n is the length of the list. The palindrom...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def is_palindrome_list(lst: List[Union[int, float, str]]) -> bool: """ Check if a given list of elements is a palindrome. The function considers negative numbers, decimal numbers, and non-num...
python_sharegpt_23k
12,362
Write a Python function to find the two smallest unique prime numbers in a given list of integers. The function should have a time complexity of O(n) and use constant space. The input list may contain duplicates. The code should start with: ```python from typing import List, Tuple def find_two_smallest_unique_primes(n...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_two_smallest_unique_primes(numbers: List[int]) -> Tuple[int, int]: """ Find the two smallest unique prime numbers in a given list of integers. Args: numbers (List[int]): The ...
python_sharegpt_23k
12,369
Write a Python function to validate an email address based on the following criteria: 1. The email address must match a specific format using a regular expression. 2. The domain name of the email address must have a valid top-level domain (TLD). 3. The email address must not be from a disposable email provider. The fu...
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 address must match a specific format. 2. The domain name of the email address must have a va...
python_sharegpt_23k
12,374
Write a Python function to determine if a given string is a valid IPv4 address. The function should return `True` if the string is a valid IPv4 address and `False` otherwise. A valid IPv4 address consists of four decimal numbers, separated by periods, where each decimal number is between 0 and 255. Leading zeros are no...
Here is the Python code to solve the given problem in the markdown block: ```python def is_valid_ipv4_address(ip_address: str) -> bool: """ Determines if the given string is a valid IPv4 address. Args: ip_address (str): The string to be validated as an IPv4 address. Returns: bool: True...
python_sharegpt_23k
12,375
Write a Python function to determine if all the numbers in a given list are prime numbers. The list can contain both positive and negative integers. The length of the list will be at most \(10^6\), and the input numbers can be as large as \(10^{12}\). The function should provide an efficient solution with a time comple...
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 given number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime,...
python_sharegpt_23k
12,380
Write a Python function to encrypt a given message using a Caesar cipher with a specified shift value, and another function to decrypt the encrypted message using the same shift value. The encryption and decryption functions should handle only lowercase alphabetic characters, leaving other characters unchanged. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_encrypt(message: str, shift: int) -> str: """ Encrypts a given message using a Caesar cipher with a specified shift value. Args: message (str): The message to be encrypted. shift (int): The number...
python_sharegpt_23k
12,383
Write a Python function to determine whether a given number is prime or not, without using any built-in functions or libraries. The function should efficiently check for primality by iterating only up to the square root of the number. The code should start with: ```python def is_prime(num: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(num: int) -> bool: """ Determine whether a given 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
12,387
Write a Python function to parse a string containing lines of key/value pairs and return a dictionary of the values paired with the keys. The keys should be case-sensitive. The string may contain duplicate keys, and in such cases, the value associated with the last occurrence of the key should be stored in the dictiona...
Here is the Python code to solve the given problem in the markdown block: ```python def parse_key_value_string(input_string: str) -> dict: """ Parses a string containing lines of key/value pairs and returns a dictionary. Args: input_string (str): The input string containing key/value pairs separate...
python_sharegpt_23k
12,402
Write a Python function to compute the sum of all positive elements in a given input array and return the result as a hexadecimal number. The input array can contain up to 1 million elements, each ranging from -1000 to 1000. The solution should have a time complexity of O(n) and a space complexity of O(1). The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_positive_to_hex(input_array: List[int]) -> str: """ Compute the sum of all positive elements in the input array and return the result as a hexadecimal number. Args: input_array (List...
python_sharegpt_23k
12,403
Write a Python function to determine whether a given string contains all unique characters. The function should not use any additional data structures and should have a time complexity of O(n). The code should start with: ```python def has_unique_characters(string: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def has_unique_characters(string: str) -> bool: """ Determines whether a given string contains all unique characters. This function uses a boolean list to track seen characters without using additional data structures, ...
python_sharegpt_23k
12,416
Write a Python function to convert a given number of bytes into kilobytes using only bitwise operations. The function should not use any arithmetic operators or built-in functions for the conversion. The input will be an integer representing the number of bytes, ranging from 1 to 1,000,000. The code should start with:...
Here is the Python code to solve the given problem in the markdown block: ```python def bytes_to_kilobytes(bytes: int) -> int: """ Converts a given number of bytes into kilobytes using only bitwise operations. Args: bytes (int): The number of bytes to convert, ranging from 1 to 1,000,000. Retu...
python_sharegpt_23k
12,422
Write a Python function to compute the average of a list of numbers recursively, without using the `sum()` function. The function should handle an empty list by returning 0, and should return `NaN` if the list contains any `NaN` values. The function should be implemented using a recursive approach to sum the elements o...
Here is the Python code to solve the given problem in the markdown block: ```python from math import isnan def compute_average(lst): """ Compute the average of a list of numbers recursively, without using the sum() function. If the list contains any NaN values, return NaN. If the list is empty, return 0. ...
python_sharegpt_23k
12,423
Write a Python function called `minL` that takes two lists of positive integers as input and returns the smallest element from both lists. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the total number of elements in the input lists. The input lists will always contain at...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def minL(list1: List[int], list2: List[int]) -> int: """ Returns the smallest element from two lists of positive integers. Args: list1 (List[int]): The first list of positive integers. ...
python_sharegpt_23k
12,427
Write a Python function to flatten a list of lists and sort the resulting list in ascending order. Each sublist can contain an arbitrary number of elements. The function should handle any number of sublists and any number of elements within each sublist. The code should start with: ```python from typing import List d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def flatten_and_sort_list(input_list: List[List[int]]) -> List[int]: """ Flattens a list of lists and sorts the resulting list in ascending order. Args: input_list (List[List[int]]): A list ...
python_sharegpt_23k
12,432
Write a Python function to split an array into two equally-sized subarrays, where each subarray is sorted in ascending order. The function should return a tuple containing the two subarrays. The function should have a time complexity of O(n log n) and a space complexity of O(1). 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, Tuple def split_and_sort_array(arr: List[int]) -> Tuple[List[int], List[int]]: """ Splits an array into two equally-sized subarrays, where each subarray is sorted in ascending order. Args: ...
python_sharegpt_23k
12,433
Write a Python function to find the two elements in an array that have the largest sum. If there are multiple pairs with the same largest sum, return the pair with the smallest element. The function should start with: ```python from typing import List def find_largest_sum_pair(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 find_largest_sum_pair(arr: List[int]) -> List[int]: """ Find the two elements in the array that have the largest sum. If there are multiple pairs with the same largest sum, return the pair with the s...
python_sharegpt_23k
12,434
Write a Python function to determine if a given number is prime without using any built-in prime number checking functions or libraries. The function should not use any mathematical formulas or algorithms commonly used to check for prime numbers, such as the Sieve of Eratosthenes. The function should have a time comple...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n: int) -> bool: """ Determines if a given number is prime without using built-in functions or common mathematical algorithms. Args: n (int): The number to check for primality. Returns: boo...
python_sharegpt_23k
12,436
Write a Python function to sort a list of positive integers in ascending order using a recursive approach. The function should not use any built-in sorting functions or methods and should have a time complexity of O(n^2). The function should be implemented using the recursive bubble sort algorithm. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def recursive_bubble_sort(arr: List[int]) -> List[int]: """ Sorts a list of positive integers in ascending order using a recursive bubble sort algorithm. Args: arr (List[int]): The list of p...
python_sharegpt_23k
12,438
Write a Python function to search for the first occurrence of a target number in a sorted array with possible duplicate elements. The function must have a time complexity of O(log n) and should not use any built-in search functions or libraries. Additionally, the function should not use any additional space apart from ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_first_occurrence(arr: List[int], target: int) -> int: """ Searches for the first occurrence of a target number in a sorted array with possible duplicate elements. Args: arr (List[in...
python_sharegpt_23k
12,442
Write a Python function to find the index of the first occurrence of a given value in a 2D array. The 2D array can contain duplicates and both positive and negative integers. If the value is not found, the function should return `[-1, -1]`. The code should start with: ```python from typing import List def find_index_i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_index_in_2d_array(arr: List[List[int]], value: int) -> List[int]: """ Find the index of the first occurrence of a given value in a 2D array. Args: arr (List[List[int]]): The 2D arra...
python_sharegpt_23k
12,446
Write a Python function to calculate the factorial of a given non-negative integer using an iterative approach. The function should not use any built-in functions or libraries for the factorial calculation. The code should start with: ```python def factorial_iterative(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def factorial_iterative(n: int) -> int: """ Calculate the factorial of a given non-negative integer using an iterative approach. Args: n (int): The non-negative integer for which to calculate the factorial. R...
python_sharegpt_23k
12,449
Write a Python function to convert a given string into its inverse form. The inverse form of a string is obtained by reversing the order of its characters. The function should handle strings of any length, including empty strings. The code should start with: ```python def inverse_string(input_string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def inverse_string(input_string: str) -> str: """ Converts a given string into its inverse form by reversing the order of its characters. Args: input_string (str): The string to be inverted. Returns: st...
python_sharegpt_23k
12,452
Write a Python function to retrieve the last three elements from a given array of integers. If the array has fewer than three elements, return all the elements in the array. The retrieved elements should be sorted in descending order. The code should start with: ```python from typing import List def retrieve_last_thr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def retrieve_last_three_elements(arr: List[int]) -> List[int]: """ Retrieves the last three elements from the given array of integers and returns them sorted in descending order. If the array has few...
python_sharegpt_23k
12,453
Write a Python function to filter and sort a given array of integers according to the following criteria: 1. Remove all negative numbers. 2. Remove all numbers that are divisible by 3. 3. If the input array is empty or does not contain any remaining numbers after filtering, return an empty array. 4. The output array sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_and_sort_array(arr: List[int]) -> List[int]: """ Filters and sorts a given array of integers according to the specified criteria. Args: arr (List[int]): The input array of integer...
python_sharegpt_23k
12,455
Write a Python function to compare two strings and return "yes" if they are equal and "no" if they are not equal. The comparison should be case-sensitive, handle whitespace characters, punctuation marks, special characters, and different character encodings. The function should not use any built-in string comparison fu...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_strings(str1: str, str2: str) -> str: """ Compares two strings for equality considering case sensitivity, whitespace, punctuation, special characters, and different character encodings. Args: str1 (str):...
python_sharegpt_23k
12,465
Write a Python function to sort a list of sublists in ascending order based on the product of their elements. Each sublist contains exactly three integers. The function should return the sorted list of sublists. The code should start with: ```python from typing import List def sort_sublists_by_product(sublists: List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_sublists_by_product(sublists: List[List[int]]) -> List[List[int]]: """ Sorts a list of sublists in ascending order based on the product of their elements. Args: sublists (List[List[...
python_sharegpt_23k
12,466
Write a Python function to count the number of unique integers in a given list. The function should remove any redundant items from the list and return the count of the unique integers. The function should adhere to the following constraints: - The input list may contain negative integers. - The input list may be empty...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_unique_integers(nums: List[int]) -> int: """ Counts the number of unique integers in the given list. Args: nums (List[int]): A list of integers from which to count unique integers....
python_sharegpt_23k
12,467
Write a Python function to optimize a loop that iterates over a multidimensional array and only processes elements that meet a specific condition. The function should accept a multidimensional array and a condition function as arguments, and return a list of elements that satisfy the condition. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable def filter_multidimensional_array(array: List[List[int]], condition: Callable[[int], bool]) -> List[int]: """ Filters a multidimensional array to return a list of elements that meet a specified...
python_sharegpt_23k
12,473
Write a Python function to remove all even numbers from a given list of integers. The function should use the `filter` function to achieve this. The function should start with: ```python from typing import List def remove_even_numbers(array: 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_even_numbers(array: List[int]) -> List[int]: """ Removes all even numbers from the given list of integers. Args: array (List[int]): The list of integers from which to remove even ...
python_sharegpt_23k
12,475
Write a Python function to calculate the sum of all digits of a given integer in O(log n) time complexity, where n is the given integer. The function should handle both positive and negative integers without converting the integer to a string. Additionally, it should handle edge cases such as when the integer is 0 or w...
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_digits(n: int) -> int: """ Calculate the sum of all digits of a given integer. Args: n (int): The integer whose digits are to be summed. Returns: int: The sum of all digits of the integer. ...
python_sharegpt_23k
12,476
Implement the merge sort algorithm in Python without using any loops or iteration constructs (such as for loops, while loops, or recursion). The merge sort algorithm should take an array of integers as input and sort the array in ascending order. Your implementation 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 List def merge_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers in ascending order using the merge sort algorithm. This implementation leverages Python's built-in `sorted` function to ach...
python_sharegpt_23k
12,480
Write a Python function to reverse the order of words in a given input string, ensuring that the output string does not contain any leading or trailing spaces. The function should handle multiple spaces between words and should not use any built-in string reversal functions. The code should start with: ```python def r...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_words_in_string(input_str: str) -> str: """ Reverses the order of words in the input string, ensuring no leading or trailing spaces. Args: input_str (str): The input string containing words to be reverse...
python_sharegpt_23k
12,484
Write a Python function to count the number of unique characters in a given string without using any additional data structures or built-in string or array manipulation functions. The function should only use basic operations and variables to solve the problem. The code should start with: ```python def count_unique_cha...
Here is the Python code to solve the given problem in the markdown block: ```python def count_unique_chars(string: str) -> int: """ Count the number of unique characters in a given string without using any additional data structures or built-in functions. Args: string (str): The input string to cou...
python_sharegpt_23k
12,487
Write a Python function to clean a given string by removing all characters except for alphabets (a-z, A-Z) and digits (0-9). The function should also remove any duplicate characters and return the modified string in ascending order of characters. Additionally, the function should remove any special characters (e.g., pu...
Here is the Python code to solve the given problem in the markdown block: ```python def clean_string(input_string: str) -> str: """ Cleans the input string by removing all characters except for alphabets (a-z, A-Z) and digits (0-9). Removes duplicate characters and returns the modified string in ascending o...
python_sharegpt_23k
12,501
Write a Python function to check if a given array is sorted in non-decreasing order. The array may contain duplicate elements. The function should have a time complexity of O(n log n) and a space complexity of O(1). The code should start with: ```python from typing import List def is_sorted_non_decreasing(arr: List[in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_sorted_non_decreasing(arr: List[int]) -> bool: """ Check if the given array is sorted in non-decreasing order. Args: arr (List[int]): The array to check. Returns: bool: T...
python_sharegpt_23k
12,502
Write a Python function to find the three most frequent words in a given paragraph. The paragraph can contain any number of words, and the words are case-insensitive. All non-alphabetic characters should be ignored. If two or more words have the same frequency, return them in lexicographically ascending order. The solu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def find_three_most_frequent_words(paragraph: str) -> List[str]: """ Find the three most frequent words in a given paragraph. Args: paragraph (str): The input paragraph containing ...
python_sharegpt_23k
12,507
Write a Python function to count the number of occurrences of each element in a given list of integers, ensuring that the solution has a time complexity of O(n) and a space complexity of O(k), where n is the number of elements in the list and k is the number of unique elements in the list. The function should use only ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_occurrences(numbers: List[int]) -> Dict[int, int]: """ Count the number of occurrences of each element in the given list of integers. Args: numbers (List[int]): The list of i...
python_sharegpt_23k
12,517
Write a Python function `concatenate_arrays` that takes in two lists `a` and `b`, and concatenates them into a new list `c` without using the built-in `+` operator. Instead, implement your own algorithm to concatenate the lists. Ensure that the length of `c` is equal to the sum of the lengths of `a` and `b`. Additional...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def concatenate_arrays(a: List[int], b: List[int]) -> List[int]: """ Concatenates two lists `a` and `b` into a new list `c` without using the built-in `+` operator. Args: a (List[int]): The ...
python_sharegpt_23k
12,524
Write a Python function to reverse each word in a given list of strings and return the reversed list, while also ignoring any strings that contain special characters or numbers. The function should use list comprehension for this task. The code should start with: ```python from typing import List def reverse_words_ig...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_words_ignore_special(list_of_strings: List[str]) -> List[str]: """ Reverses each word in the given list of strings and returns the reversed list, while ignoring any strings that contain s...
python_sharegpt_23k
12,529
Write a Python function to tokenize a given string into a list of strings, where each string represents a word in the original string. The function should handle punctuation marks, special characters, contractions, possessive forms, hyphenated words, and multiple consecutive whitespace characters correctly. The functio...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def tokenize_string(string: str) -> List[str]: """ Tokenizes a given string into a list of words, handling punctuation, special characters, contractions, possessive forms, hyphenated words, and...
python_sharegpt_23k
12,532
Write a Python function to classify each element in three given arrays as either prime or not prime. For each prime number, calculate the sum of all its divisors. Finally, sort the prime numbers based on the sum of their divisors in descending order. The solution should have a time complexity of O(n^2) or better and sh...
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. Returns: bool: True if the number is prime, False otherwise. ""...
python_sharegpt_23k
12,534
Write a Python function to safely divide two numbers, ensuring that division by zero is handled gracefully by raising a `ValueError`. The function should also handle cases where the inputs are not numeric by raising a `TypeError`. Additionally, the function should be optimized for performance and readability. The code...
Here is the Python code to solve the given problem in the markdown block: ```python def safe_divide(a, b): """ Safely divides two numbers, raising appropriate errors for invalid inputs or division by zero. Args: a (int or float): The numerator. b (int or float): The denominator. Return...
python_sharegpt_23k
12,540
Write a Python function to delete all occurrences of a specified item from a given list without using any built-in list manipulation functions or methods. The function should iterate through the list and construct a new list that excludes the specified item. 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 delete_all_occurrences(lst: List[str], item: str) -> List[str]: """ Deletes all occurrences of a specified item from a given list without using any built-in list manipulation functions or methods. ...
python_sharegpt_23k
12,542
Write a Python function to count the number of even elements that appear before any odd elements in a given array of integers. The array can contain both positive and negative integers. The function should efficiently handle arrays with a length of up to \(10^6\) and elements ranging from \(-10^9\) to \(10^9\). The co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_even_before_odd(arr: List[int]) -> int: """ Counts the number of even elements that appear before any odd elements in the given array. Args: arr (List[int]): The array of integers ...
python_sharegpt_23k
12,545
Write a Python function to convert a given decimal number to its corresponding hexadecimal value. The function should handle both positive and negative decimal numbers. Additionally, implement error handling to check if the input is a valid decimal number. The code should start with: ```python def decimal_to_hexadecima...
Here is the Python code to solve the given problem in the markdown block: ```python def decimal_to_hexadecimal(decimal: str) -> str: """ Converts a given decimal number to its corresponding hexadecimal value. Args: decimal (str): The decimal number to be converted, provided as a string. Return...
python_sharegpt_23k
12,548
Write a Python function to generate a random string of a specified length that includes at least one lowercase alphabet, one uppercase alphabet, one number, and one special character. The function should ensure that the generated string meets these criteria. The code should start with: ```python import random import s...
Here is the Python code to solve the given problem in the markdown block: ```python import random import string def generate_secure_random_string(length: int) -> str: """ Generates a random string of the specified length that includes at least one lowercase alphabet, one uppercase alphabet, one number, and...
python_sharegpt_23k
12,555
Write a Python function that processes a list of dictionaries and returns a list of tuples. Each tuple should contain the value of the "name" key and the length of that name. If a dictionary does not contain the key "name", the tuple should contain the string "Name not found" and the length of that string. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple def process_names(data: List[Dict[str, any]]) -> List[Tuple[str, int]]: """ Processes a list of dictionaries and returns a list of tuples. Each tuple contains the value of the "name" key and...
python_sharegpt_23k
12,556
Write a Python function to find all prime numbers up to a given positive integer `n` using the Sieve of Eratosthenes algorithm. The function should have a time complexity of O(n log log n), which is more efficient than the O(n^2) requirement in the given code snippet. The function should not use any external libraries ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def primes_up_to_n(n: int) -> List[int]: """ Returns a list of all prime numbers up to a given positive integer n using the Sieve of Eratosthenes algorithm. Args: n (int): The upper limit up...