source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
8,658
Write a Python function to determine if a given number is a prime number. The function should return `True` if the number is prime and `False` otherwise. The function should be efficient and handle edge cases such as numbers less than 2. 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: """ Determines if a given number is a prime number. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. "...
python_sharegpt_23k
8,660
Write a Python function to convert a given string into Pig Latin. The function should follow these rules: 1. If the word starts with a vowel (a, e, i, o, u), simply add "ay" to the end of the word. 2. If the word starts with a consonant, move the consonant cluster (all consonants before the first vowel) to the end of t...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_pig_latin(string: str) -> str: """ Convert a given string into Pig Latin. Args: string (str): The input string to be converted. Returns: str: The transformed string in Pig Latin. Rul...
python_sharegpt_23k
8,662
Write a Python function to calculate the average and the sum of a list of numbers using a tuple to return both values. The function should handle an empty list by returning `None` for both the average and the sum. The code should start with: ```python from typing import List, Tuple, Optional def calculate_avg_and_sum(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Optional def calculate_avg_and_sum(numbers: List[int]) -> Optional[Tuple[float, int]]: """ Calculate the average and the sum of a list of numbers. Args: numbers (List[int]): A list o...
python_sharegpt_23k
8,673
Write a Python function to capitalize all the words in a given string, except for specific words that should remain in lowercase. The specific words to exclude from capitalization are "and" and "the". The function should handle multiple spaces between words and leading/trailing spaces. The code should start with: ```p...
Here is the Python code to solve the given problem in the markdown block: ```python def capitalize_words_except_specific_words(string: str) -> str: """ Capitalizes all the words in a given string, except for the words "and" and "the" which remain in lowercase. Args: string (str): The input string c...
python_sharegpt_23k
8,674
Write a Python function to generate a dataset of random numbers within a specified range and sort it in ascending order. The function should accept three parameters: the number of elements to generate, the lower bound of the range, and the upper bound of the range. The function should return the sorted list of random n...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_and_sort_dataset(num_elements: int, lower_bound: int, upper_bound: int) -> List[int]: """ Generate a dataset of random numbers within a specified range and sort it in ascending...
python_sharegpt_23k
8,676
Write a Python function to create a new dictionary by adding the values of two given dictionaries. The keys in the dictionaries are positive integers, and the values are multiples of 5. The resulting dictionary should only include keys that are prime numbers and have values that are not divisible by 10. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict 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
8,683
Write a Python function to sort a given list of strings in alphabetical order with a time complexity of O(n log n) and a space complexity of O(n). The function should be efficient enough to handle a large list of strings. The code should start with: ```python from typing import List def sort_strings(list_of_strings: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_strings(list_of_strings: List[str]) -> List[str]: """ Sorts a given list of strings in alphabetical order with a time complexity of O(n log n) and a space complexity of O(n). Args: ...
python_sharegpt_23k
8,684
Write a Python function to compute the Nth Fibonacci number efficiently with a time complexity of O(N) and a space complexity of O(1). The function should handle any positive integer N less than or equal to 1000. 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: """ Compute the Nth Fibonacci number using an iterative approach with O(N) time complexity and O(1) space complexity. Args: N (int): The position in the Fibonacci sequence to compute. M...
python_sharegpt_23k
8,687
Write a Python function to sort an array of numbers in descending order using the bubble sort algorithm. The array may contain duplicates, negative numbers, and floating-point numbers. The final sorted array should have all the duplicates grouped together, with negative numbers placed before positive numbers. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort_descending(arr: List[float]) -> List[float]: """ Sorts an array of numbers in descending order using the bubble sort algorithm. Args: arr (List[float]): The array of numbers ...
python_sharegpt_23k
8,689
Write a Python function to create a dictionary from two lists of equal length. The keys of the dictionary should be the elements of the first list, and the values should be the elements of the second list. The function should handle lists of any length and return an error message if the lists are not of equal length. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Union def create_dictionary(list1: List[any], list2: List[any]) -> Union[Dict[any, any], str]: """ Creates a dictionary from two lists of equal length. The keys of the dictionary are the elements ...
python_sharegpt_23k
8,690
Write a Python function that iterates over a given list and prints each item, but skips any items that are divisible by a specified integer `divisor`. The function should start with: ```python from typing import List def print_items_skip_divisible(items: List[int], divisor: int) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_items_skip_divisible(items: List[int], divisor: int) -> None: """ Prints each item in the list, skipping any items that are divisible by the specified divisor. Args: items (List[in...
python_sharegpt_23k
8,691
Write a Python function to reverse a list and print the first and last elements of the original list. The original list should remain unchanged after the reversal. The code should start with: ```python from typing import List def reverse_list(lst: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_list(lst: List[int]) -> List[int]: """ Returns a new list with the elements in reverse order of the input list. The original list remains unchanged. Args: lst (List[int]): Th...
python_sharegpt_23k
8,692
Write a Python function to sort a given list of numbers such that all odd numbers are placed at the beginning of the list, and all even numbers are sorted in descending order and placed after the odd numbers. The function should start with: ```python from typing import List def sort_numbers_with_odds_first(numbers: Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_numbers_with_odds_first(numbers: List[int]) -> List[int]: """ Sorts a list of numbers such that all odd numbers are placed at the beginning, and all even numbers are sorted in descending ord...
python_sharegpt_23k
8,693
Write a Python function to find the student with the highest score from a given dictionary of student names and their scores. The function should return the name of the student with the highest score. If there are multiple students with the same highest score, return the name of any one of them. The code should start ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Union def find_top_student(student_scores: Dict[str, int]) -> Union[str, None]: """ Find the student with the highest score from a given dictionary of student names and their scores. Args: ...
python_sharegpt_23k
8,694
Write a Python function to delete the last occurrence of a specified value from a list without using any built-in functions or methods. The function should return the modified list. If the specified value is not found in the list, the function should return the original list without any modifications. The input list ca...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def delete_last_occurrence(lst: List[int], value: int) -> List[int]: """ Deletes the last occurrence of a specified value from a list and returns the modified list. If the value is not found, the ori...
python_sharegpt_23k
8,699
Write a Python function to print the characters of a given string in reverse order using a nested loop. The outer loop should iterate over the string in reverse order, and the inner loop should print each character from the current position of the outer loop to the end of the string. The function should start with: ```...
Here is the Python code to solve the given problem in the markdown block: : ```python def print_reverse_nested(s: str) -> None: """ Prints the characters of the given string in reverse order using a nested loop. The outer loop iterates over the string in reverse order, and the inner loop prints each ch...
python_sharegpt_23k
8,700
Write a Python function to compute the sum of the elements in a given list of integers. The function should handle lists of any length, including empty lists. The code should start with: ```python from typing import List def compute_sum(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def compute_sum(numbers: List[int]) -> int: """ Computes the sum of the elements in a given list of integers. Args: numbers (List[int]): The list of integers to sum. Returns: in...
python_sharegpt_23k
8,703
Write a Python function to calculate the product of two non-negative integers using only bitwise operators and without using the multiplication operator. The function should take two integers as input and return their product. 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_multiply(a: int, b: int) -> int: """ Calculate the product of two non-negative integers using only bitwise operators. Args: a (int): The first non-negative integer. b (int): The second non-negati...
python_sharegpt_23k
8,704
Write a Python function to find the largest number in a given list of integers without using any built-in functions or methods to find the maximum value. The function should iterate through the list and keep track of the largest number encountered so far. 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 find_largest_number(arr: List[int]) -> int: """ Find the largest number in a given list of integers without using any built-in functions or methods. Args: arr (List[int]): The list of in...
python_sharegpt_23k
8,706
Write a Python function to find and return a list of all even numbers within a given range `[start, end]`. The function should handle both inclusive and exclusive ranges. If the `end` value is not provided, the function should default to a range from `start` to `100,000`. The code should start with: ```python from typ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_even_numbers(start: int, end: Optional[int] = None) -> List[int]: """ Find and return a list of all even numbers within a given range [start, end]. Args: start (int): The ...
python_sharegpt_23k
8,708
Write a Python function to create an array of size `n` and assign elements to it based on a specific pattern: the first element should be 1, the second element should be the square of the first element, the third element should be the cube of the second element, and so on. The function should return the array. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def create_pattern_array(n: int) -> List[int]: """ Create an array of size n and assign elements to it based on a specific pattern: the first element should be 1, the second element should be the squ...
python_sharegpt_23k
8,709
Write a Python function to convert a given list into a NumPy array, find the sum of all elements, and then sort the array in descending order. Finally, return the sorted array. The function should start with: ```python from typing import List import numpy as np def process_array(lst: List[int]) -> np.ndarray: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import numpy as np def process_array(lst: List[int]) -> np.ndarray: """ Convert a given list into a NumPy array, find the sum of all elements, and sort the array in descending order. Args: l...
python_sharegpt_23k
8,713
Write a Python function to implement the Quicksort algorithm to sort a list of integers in descending order. The implementation should not use any built-in sorting functions or libraries, and it should achieve a time complexity of less than O(n^2) and a space complexity of less than O(n). The function should start with...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def quicksort_descending(arr: List[int]) -> List[int]: """ Sorts a list of integers in descending order using the Quicksort algorithm. Args: arr (List[int]): The list of integers to be sorte...
python_sharegpt_23k
8,715
Write a Python function to find the most common element(s) in a given list of integers. If there are multiple elements with the same maximum frequency, return all of them. 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 impo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def most_common(nums: List[int]) -> List[int]: """ Find the most common element(s) in a list of integers. Args: nums (List[int]): The list of integers to analyze. Returns: List[...
python_sharegpt_23k
8,718
Write a Python function to determine whether a given string is a palindrome or not. The function should be case-insensitive, ignore any whitespace characters, and ignore any punctuation marks. The function should handle strings with both uppercase and lowercase letters, whitespace characters, and punctuation marks. You...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(s: str) -> bool: """ Determine whether a given string is a palindrome. The function is case-insensitive, ignores whitespace characters, and ignores punctuation marks. Args: s (str): The input ...
python_sharegpt_23k
8,719
Write a Python function to calculate the sum of all prime numbers within a given range [1, n]. The function should efficiently determine if a number is prime and then sum all prime numbers up to n. The code should start with: ```python def sum_of_primes_up_to(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_primes_up_to(n: int) -> int: """ Calculate the sum of all prime numbers up to a given number n. Args: n (int): The upper limit of the range [1, n] to find the sum of primes. Returns: int: The...
python_sharegpt_23k
8,725
Write a Python function to reverse the order of nodes in a singly linked list. The function should have a time complexity of O(n) and use constant extra space. You are not allowed to create a new linked list or use any additional data structures. The function should start with: ```python def reverse_linked_list(head: O...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Optional class Node: def __init__(self, value): self.value = value self.next = None def reverse_linked_list(head: Optional[Node]) -> Optional[Node]: """ Reverses the order of nodes in a s...
python_sharegpt_23k
8,732
Write a Python function to determine if two given strings are anagrams of each other. The function should return a boolean value (`True` if they are anagrams, `False` otherwise). The function should have a time complexity of O(n log n), where n is the length of the strings, and a space complexity of O(1). The function ...
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(str1: str, str2: str) -> bool: """ Determines if two given strings are anagrams of each other. Args: str1 (str): The first string to compare. str2 (str): The second string to compare. R...
python_sharegpt_23k
8,734
Write a Python function to implement a merge sort algorithm that can handle negative numbers and has a time complexity of O(n log n). The function should take a list of integers as input and return the sorted list. The code should start with: ```python from typing import List def merge_sort(arr: List[int]) -> List[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the merge sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: List...
python_sharegpt_23k
8,738
Write a Python function to sort a list of integers in descending order using the Bubble Sort algorithm without using any built-in sorting functions or methods. The function should start with: ```python from typing import List def bubble_sort_descending(arr: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort_descending(arr: List[int]) -> List[int]: """ Sorts a list of integers in descending order using the Bubble Sort algorithm. Args: arr (List[int]): The list of integers to be s...
python_sharegpt_23k
8,741
Write a Python function to find the maximum element in a given list without using the built-in `max()` function. The function should iterate through the list and keep track of the maximum value encountered. The code should start with: ```python from typing import List def find_max_element(numbers: List[int]) -> int: `...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_element(numbers: List[int]) -> int: """ Find the maximum element in a list of integers without using the built-in max() function. Args: numbers (List[int]): A list of integers f...
python_sharegpt_23k
8,749
Write a Python function to find the nth smallest number in an unsorted list of integers. 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 find_nth_smallest_number(nums: List[int], n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def find_nth_smallest_number(nums: List[int], n: int) -> int: """ Find the nth smallest number in an unsorted list of integers. Args: nums (List[int]): The unsorted list of integers. ...
python_sharegpt_23k
8,750
Write a Python function to calculate the nth Fibonacci number using a recursive approach with memoization to achieve a time complexity of O(n) and a space complexity of O(n). The Fibonacci sequence is defined as follows: the first two numbers in the sequence are 0 and 1, and each subsequent number is the sum of the two...
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci(n: int, memo: dict = None) -> int: """ Calculate the nth Fibonacci number using a recursive approach with memoization. Args: n (int): The position in the Fibonacci sequence to calculate. memo (...
python_sharegpt_23k
8,751
Write a Python function to generate a list of all prime numbers between a given range `[start, end]`. The function should return a list of prime numbers. The code should start with: ```python from typing import List def generate_primes_in_range(start: int, end: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def generate_primes_in_range(start: int, end: int) -> List[int]: """ Generate a list of all prime numbers between the given range [start, end]. Args: start (int): The starting nu...
python_sharegpt_23k
8,753
Write a Python function to convert a string of dates from the format 'dd/mm/yyyy' to 'mm/dd/yyyy' using regular expressions. The string can contain up to 10,000 dates. The function should handle the conversion efficiently and return the modified string. The code should start with: ```python import re def convert_date...
Here is the Python code to solve the given problem in the markdown block: ```python import re def convert_date_format(input_string: str) -> str: """ Converts dates in a string from 'dd/mm/yyyy' format to 'mm/dd/yyyy' format using regular expressions. Args: input_string (str): The input string cont...
python_sharegpt_23k
8,756
Write a Python function to find the median of a list of numbers in a single pass, without using any built-in libraries or functions. The function should return the median as a floating-point number. The input list may not be sorted and may contain both positive and negative integers. The function should handle both eve...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_median_in_single_pass(nums: List[int]) -> float: """ Finds the median of a list of numbers in a single pass without using any built-in libraries or functions. Args: nums (List[int])...
python_sharegpt_23k
8,758
Write a Python function to calculate the sum of numbers from a given list without using 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. The code should start with: ```python from typing import List def calculate_sum(n...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_sum(numbers: List[int]) -> int: """ Calculate the sum of numbers in a given list without using the built-in sum() function. Args: numbers (List[int]): A list of integers for wh...
python_sharegpt_23k
8,767
Write a Python function to find the smallest and largest numbers in an unsorted list with a time complexity of O(n log n), without using any built-in sorting functions. The function should use a divide-and-conquer approach to achieve this. The code should start with: ```python from typing import List, Tuple def find_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_smallest_largest(arr: List[int]) -> Tuple[int, int]: """ Find the smallest and largest numbers in an unsorted list with a time complexity of O(n log n), without using any built-in sor...
python_sharegpt_23k
8,769
Write a Python function to calculate the symmetric difference of two sets and return the count of distinct elements in the symmetric difference set. Both sets should have a minimum of 5 elements and a maximum of 10 elements. All elements in the sets should be positive integers between 1 and 1000. The code should start...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set def symmetric_difference_count(set1: Set[int], set2: Set[int]) -> int: """ Calculate the symmetric difference of two sets and return the count of distinct elements in the symmetric difference set. Ar...
python_sharegpt_23k
8,772
Write a Python function to check if a given string contains balanced parentheses. The string can contain other characters besides parentheses. You need to consider three types of parentheses: round brackets `()`, square brackets `[]`, and curly brackets `{}`. A string is considered balanced if every opening parenthesis...
Here is the Python code to solve the given problem in the markdown block: ```python def is_balanced_parentheses(string: str) -> bool: """ Checks if a given string contains balanced parentheses. Args: string (str): The string to check for balanced parentheses. Returns: bool: True if the...
python_sharegpt_23k
8,775
Write a Python function to sort a list of numbers from largest to smallest. The function should handle lists of any length and should be efficient. The code should start with: ```python from typing import List def sort_descending(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 sort_descending(numbers: List[int]) -> List[int]: """ Sorts a list of numbers from largest to smallest. Args: numbers (List[int]): The list of numbers to be sorted. Returns: ...
python_sharegpt_23k
8,777
Write a Python function to convert a list of strings, where each string represents a positive integer, into a list of integers and then calculate their sum. The function should handle lists with up to \(10^6\) elements efficiently. The code should start with: ```python from typing import List def sum_of_string_intege...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_string_integers(lst: List[str]) -> int: """ Converts a list of string representations of positive integers into integers and calculates their sum. Args: lst (List[str]): A list of...
python_sharegpt_23k
8,781
Write a Python function to calculate the sum of two numbers and return the result. The function should handle the following scenarios: 1. If either of the inputs is not a number (e.g., a string or a list), the function should return `None`. 2. If both inputs are numbers, the function should return their sum. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python def add_two_numbers(x, y): """ Calculate the sum of two numbers and return the result. Args: x (int or float): The first number. y (int or float): The second number. Returns: int, float, or None...
python_sharegpt_23k
8,782
Write a Python function to filter out the odd numbers from a given list of integers and return them sorted in descending order. The function should handle an empty list and ensure that only odd numbers are included in the result. The code should start with: ```python from typing import List def filter_and_sort_odd_nu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_and_sort_odd_numbers(numbers: List[int]) -> List[int]: """ Filters out the odd numbers from the given list of integers and returns them sorted in descending order. Args: numbers (...
python_sharegpt_23k
8,784
Write a Python function to find the maximum value in a numeric array using recursion. The array may contain negative numbers. You can assume that the array will always have at least one element. The function should be efficient and capable of handling large arrays with thousands of elements. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_recursive(arr: List[int]) -> int: """ Find the maximum value in a numeric array using recursion. Args: arr (List[int]): The array of integers from which to find the maximum valu...
python_sharegpt_23k
8,801
Implement the merge sort algorithm to sort a given array of integers in ascending order. The array will contain at least 10,000 elements. The code should start with: ```python from typing import List def merge_sort(arr: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts a given array of integers in ascending order using the merge sort algorithm. Args: arr (List[int]): The array of integers to be sorted....
python_sharegpt_23k
8,804
Write a Python function to generate an array of 10 unique integers between -100 and 100, ensuring that the sum of all the numbers in the array is less than 500. The function should return the generated array. The code should start with: ```python from typing import List import random def generate_unique_array() -> Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_unique_array() -> List[int]: """ Generates an array of 10 unique integers between -100 and 100, ensuring that the sum of all numbers is less than 500. Returns: Lis...
python_sharegpt_23k
8,808
Write a Python function to count the number of occurrences of a given value `x` in an array `arr` with a time complexity of O(n). The function should iterate through the array only once and should not use any built-in methods or libraries to solve the problem. The array `arr` can contain up to 10^6 elements, and the va...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_occurrences(arr: List[int], x: int) -> int: """ Counts the number of occurrences of a given value `x` in an array `arr`. Args: arr (List[int]): The array in which to count the occu...
python_sharegpt_23k
8,809
Write a Python function to generate a two-dimensional array of size N x N, where N is an integer between 3 and 10 (inclusive), with all elements initialized to 1. The function should ensure that the time complexity is O(N^2). The code should start with: ```python from typing import List def generate_2d_array(N: int) ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_2d_array(N: int) -> List[List[int]]: """ Generate a two-dimensional array of size N x N with all elements initialized to 1. Args: N (int): The size of the array. Must be an inte...
python_sharegpt_23k
8,815
Write a Python function to count the number of distinct words in a given sentence, ignoring case sensitivity and excluding any punctuation marks. The function should return the count of distinct words. The code should start with: ```python from typing import List import string def count_distinct_words(sentence: str) ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import string def count_distinct_words(sentence: str) -> int: """ Counts the number of distinct words in a given sentence, ignoring case sensitivity and excluding punctuation marks. Args: se...
python_sharegpt_23k
8,819
Write a Python function to transform a given list such that each even number is replaced by its square and each odd number is replaced by its cube. The list can contain up to \(10^6\) elements. The function should be efficient and handle large lists effectively. 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 def transform_list(lst: List[int]) -> List[int]: """ Transforms a list such that each even number is replaced by its square and each odd number is replaced by its cube. Args: lst (List[int])...
python_sharegpt_23k
8,821
Write a Python function to initialize a 2D array of size n x n with random integers between 1 and 100. The function should ensure that the time complexity is O(n^2) and the space complexity is O(n^2). The code should start with: ```python from typing import List import random def initialize_2d_array(n: int) -> List[Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def initialize_2d_array(n: int) -> List[List[int]]: """ Initializes a 2D array of size n x n with random integers between 1 and 100. Args: n (int): The size of the 2D array (n ...
python_sharegpt_23k
8,822
Write a Python function to replace every element in a given 2D array with the greatest element on its row. The input array will have at most 10 rows and 10 columns, and all elements will be non-negative integers less than or equal to 100. The function should use dynamic programming to solve this problem efficiently. Th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def replace_with_greatest(arr: List[List[int]]) -> List[List[int]]: """ Replace every element in the given 2D array with the greatest element on its row. Args: arr (List[List[int]]): The inp...
python_sharegpt_23k
8,825
Write a Python function to determine if a given day of the week and time fall within a specified range of hours on weekdays. The function should return a specific message if the conditions are met and a different message otherwise. The function should accept the day of the week as a string and the current hour as an in...
Here is the Python code to solve the given problem in the markdown block: ```python def check_weekday_time(day_of_week: str, current_hour: int) -> str: """ Determine if the given day of the week and time fall within a specified range on weekdays. Args: day_of_week (str): The day of the week as a st...
python_sharegpt_23k
8,826
Write a Python function that processes a list of integers and returns a new list containing only the even numbers from the original list. If an element is odd, the function should skip it and continue to the next element using the `continue` statement. 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_even_numbers(numbers: List[int]) -> List[int]: """ Filters out the even numbers from the given list of integers. Args: numbers (List[int]): A list of integers to be processed. ...
python_sharegpt_23k
8,828
Write a Python function to find the common elements between two sorted lists. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the length of the longer list. The function should return a list of common elements in ascending order. The code should start with: ```python from ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_common_elements(list1: List[int], list2: List[int]) -> List[int]: """ Finds the common elements between two sorted lists with O(n) time complexity and O(1) space complexity. Args: l...
python_sharegpt_23k
8,831
Write a Python function to calculate the amount of tax to be paid based on the inputs of income, country, and marital status. The tax rates and income brackets for each country are as follows: **Ireland:** - Single: - Income up to 20000: 20% tax rate - Income between 20001 and 50000: 25% tax rate - Income above...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_tax(income: float, country: str, marital_status: str) -> float: """ Calculate the amount of tax to be paid based on the income, country, and marital status. Args: income (float): The income amount. ...
python_sharegpt_23k
8,833
Write a Python function to check if two given strings are anagrams. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. In this case, consider all characters in the strings, including spaces and punctuation marks, and take their case into account. Return `True` if the strings are...
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(s1: str, s2: str) -> bool: """ Check if two strings are anagrams. Args: s1 (str): The first string to compare. s2 (str): The second string to compare. Returns: bool: True if the...
python_sharegpt_23k
8,834
Write a Python function to reverse the order of elements in a given array without using any built-in functions or libraries. The input array will always contain at least 5 elements and at most 100 elements. The function should start with: ```python from typing import List def reverse_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_array(arr: List[int]) -> List[int]: """ Reverses the order of elements in a given array without using any built-in functions or libraries. Args: arr (List[int]): The input array ...
python_sharegpt_23k
8,835
Write a Python function to replace characters in a given string with their corresponding HTML entities based on their ASCII values. If the ASCII value of a character is less than 128, it should be replaced with its corresponding HTML entity. Otherwise, the character should remain unchanged. The function should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python def replace_html_entities(string: str) -> str: """ Replace characters in the given string with their corresponding HTML entities based on ASCII values. Characters with ASCII values less than 128 are replaced with their corre...
python_sharegpt_23k
8,836
Write a Python function to collapse repeating continuous characters in a given string. The function should return a new string where all consecutive repeating characters are reduced to a single occurrence, maintaining the original order of characters. The input string will only contain lowercase alphabetic characters. ...
Here is the Python code to solve the given problem in the markdown block: ```python def collapse_repeating_chars(s: str) -> str: """ Collapses repeating continuous characters in a given string. Args: s (str): The input string containing only lowercase alphabetic characters. Returns: st...
python_sharegpt_23k
8,839
Write a Python function to access the nth element from a list of integers. The function should handle cases where the list might be shorter than n elements by returning `None`. The function should also handle cases where n is negative by returning `None`. 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, Optional def get_nth_element(lst: List[int], n: int) -> Optional[int]: """ Access the nth element from a list of integers. Args: lst (List[int]): The list of integers from which to access t...
python_sharegpt_23k
8,840
Write a Python function to calculate the area and circumference of a circle given its radius. The function should return both the area and the circumference as a tuple. The code should start with: ```python import math def circle_properties(radius: float) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: : ```python import math def circle_properties(radius: float) -> tuple: """ Calculate the area and circumference of a circle given its radius. Args: radius (float): The radius of the circle. Returns: tuple: A tup...
python_sharegpt_23k
8,841
Write a Python function to calculate the sum of all elements in a given list of integers. The function should correctly handle both positive and negative integers, as well as an empty list. The code should start with: ```python from typing import List def calculate_sum(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_sum(numbers: List[int]) -> int: """ Calculate the sum of all elements in a given list of integers. Args: numbers (List[int]): A list of integers whose sum needs to be calculate...
python_sharegpt_23k
8,842
Write a Python function to calculate the sum of all numbers in a given list, excluding any numbers that are divisible by 3 or 5. The function should start with: ```python from typing import List def sum_excluding_divisibles(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_excluding_divisibles(numbers: List[int]) -> int: """ Calculate the sum of all numbers in the given list, excluding any numbers that are divisible by 3 or 5. Args: numbers (List[int])...
python_sharegpt_23k
8,844
Write a Python function to find and return a list of all prime numbers within a given range [start, end]. The function should handle both ascending and descending ranges. The code should start with: ```python from typing import List def find_primes_in_range(start: int, end: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def is_prime(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 pri...
python_sharegpt_23k
8,848
Write a Python function to insert a given value at the end of an array without using any built-in Python functions or methods. The function should handle the insertion by manipulating the array directly. The code should start with: ```python from typing import List def insert_value_at_end(array: List[int], value: int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def insert_value_at_end(array: List[int], value: int) -> List[int]: """ Inserts a given value at the end of an array without using any built-in Python functions or methods. Args: array (List...
python_sharegpt_23k
8,849
Write a Python function to find the maximum element in a list of integers using a recursive approach. The function should follow these steps: 1. If the list is empty, return `None`. 2. If the list contains only one element, return that element. 3. Divide the list into two halves. 4. Recursively find the maximum element...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_max_recursive(lst: List[int]) -> Optional[int]: """ Recursively finds the maximum element in a list of integers. Args: lst (List[int]): The list of integers from which to ...
python_sharegpt_23k
8,853
Write a Python function to filter out and return a list of prime numbers from a given list of integers. The function should efficiently determine if a number is prime by checking divisibility up to the square root of the number. The code should start with: ```python from typing import List def get_prime_numbers(numbe...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_prime_numbers(numbers: List[int]) -> List[int]: """ Filters and returns a list of prime numbers from the given list of integers. Args: numbers (List[int]): A list of integers from wh...
python_sharegpt_23k
8,856
Write a Python function to convert a given string such that all lowercase characters are transformed to uppercase and all uppercase characters are transformed to lowercase. Characters that are neither lowercase nor uppercase (e.g., numbers, special characters) should remain unchanged. The function should maintain the o...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_case(input_string: str) -> str: """ Converts all lowercase characters in the input string to uppercase and all uppercase characters to lowercase. Non-alphabetic characters remain unchanged. Args: inp...
python_sharegpt_23k
8,862
Write a Python function to implement a binary search algorithm that finds the index of a given goal value in a sorted list. The function should take two parameters: `arr` (the sorted list) and `goal` (the value to search for). The function should return the index of `goal` if it is present in the list, or -1 if it is n...
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], goal: int) -> int: """ Implements a binary search algorithm to find the index of a given goal value in a sorted list. Args: arr (List[int]): The sorted list...
python_sharegpt_23k
8,867
Write a Python function to construct a dictionary from two given lists, `key_arr` and `value_arr`. The keys in the dictionary should be the elements from `key_arr`, and the values should be the corresponding elements from `value_arr`. The function should ensure that the dictionary is constructed efficiently, even for l...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def construct_dictionary(key_arr: List[int], value_arr: List[str]) -> Dict[int, str]: """ Constructs a dictionary from two lists, `key_arr` and `value_arr`. Args: key_arr (List[int]): ...
python_sharegpt_23k
8,869
Write a Python function to classify and print the data types of given pieces of data. The function should take a list of strings as input and print the data type of each item in the list. The function should handle the case where the input strings might represent different types of data (e.g., strings, numbers, etc.). ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def classify_data_types(data: List[str]) -> None: """ Classify and print the data types of given pieces of data. Args: data (List[str]): A list of strings representing pieces of data. R...
python_sharegpt_23k
8,873
Write a Python function to validate whether a given string is a valid IPv4 address. The function should return a boolean value indicating whether the input string is a valid IPv4 address. An IPv4 address consists of four decimal numbers separated by periods, where each decimal number must be between 0 and 255, inclusiv...
Here is the Python code to solve the given problem in the markdown block: ```python def validate_IPv4(IP: str) -> bool: """ Validates whether the given string is a valid IPv4 address. An IPv4 address consists of four decimal numbers separated by periods. Each decimal number must be between 0 and 255, inclu...
python_sharegpt_23k
8,874
Write a Python function to find all elements that appear more than once in a given array. The function should return the elements in ascending order and should also remove any duplicate elements from the result. Additionally, you should not use any built-in functions or libraries to solve this problem. The input array ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_duplicates(arr: List[int]) -> List[int]: """ Find all elements that appear more than once in the given array and return them in ascending order. Duplicate elements are removed from the resul...
python_sharegpt_23k
8,880
Write a Python function to determine if two given strings are anagrams of each other, considering only alphanumeric characters and ignoring spaces and punctuation marks. The function should return a boolean value indicating whether the two strings are anagrams. The code should start with: ```python def are_anagrams(st...
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(str1: str, str2: str) -> bool: """ Determines if two strings are anagrams of each other, ignoring spaces and punctuation marks. Args: str1 (str): The first string to compare. str2 (str): The...
python_sharegpt_23k
8,882
Write a Python function to calculate the Levenshtein distance between two given strings. The Levenshtein distance is defined as the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into another. The function should start with: ```python def levenshtein_dis...
Here is the Python code to solve the given problem in the markdown block: ```python def levenshtein_distance(s1: str, s2: str) -> int: """ Calculate the Levenshtein distance between two strings. The Levenshtein distance is the minimum number of single-character edits (insertions, deletions, or substitu...
python_sharegpt_23k
8,883
Write a Python function to encode a text string using the Caesar cipher with a variable shift. The function should handle both uppercase and lowercase letters, maintain the positions of special characters, and wrap around the alphabet if the shift value exceeds the number of letters in the alphabet. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher_encode(text: str, shift: int) -> str: """ Encodes a text string using the Caesar cipher with a variable shift. Args: text (str): The text string to be encoded. shift (int): The number of po...
python_sharegpt_23k
8,884
Write a Python function to sort a given list of numbers in descending order using the merge sort algorithm, which has a time complexity of O(nlogn). The function should be efficient and handle various edge cases, such as an empty list or a list with a single element. 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 def merge_sort_descending(arr: List[int]) -> List[int]: """ Sorts a given list of numbers in descending order using the merge sort algorithm. Args: arr (List[int]): The list of numbers to be...
python_sharegpt_23k
8,886
Write a Python function to calculate the sum of all numbers in a given list using a loop. The function should adhere to the following constraints: - The time complexity of the solution should be O(n), where n is the number of elements in the list. - The space complexity of the solution should be O(1), meaning it should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_numbers(nums: List[int]) -> int: """ Calculate the sum of all numbers in the given list. Args: nums (List[int]): The list of integers to sum. Returns: int: The sum of...
python_sharegpt_23k
8,887
Write a Python function to find and return all common elements between two lists, removing duplicates and sorting the result in ascending order. The function should have a time complexity of O(n) and should not use any built-in functions or libraries for set operations, sorting, or list operations. 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_common_elements(list1: List[int], list2: List[int]) -> List[int]: """ Find all common elements between two lists, remove duplicates, and sort the result in ascending order. Args: li...
python_sharegpt_23k
8,889
Write a Python function to remove all even elements and duplicates from a given list while preserving the original order of the elements. The input list should contain at least 10 elements. The function should start with: ```python from typing import List def remove_even_duplicates(lst: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_even_duplicates(lst: List[int]) -> List[int]: """ Removes all even elements and duplicates from the given list while preserving the original order. Args: lst (List[int]): The inpu...
python_sharegpt_23k
8,890
Write a Python function to remove all duplicate elements from a given array while keeping track of the count of each unique element. The function should return the unique elements in descending order based on their count. The code should start with: ```python from typing import List def remove_duplicates_and_sort_by_c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import Counter def remove_duplicates_and_sort_by_count(array: List[int]) -> List[int]: """ Removes all duplicate elements from the given array and returns the unique elements sorted ...
python_sharegpt_23k
8,895
Write a Python function to filter out elements from a given list based on a custom condition. The function should take two arguments: a list of integers and a function that defines the filtering condition. The function should return a new list containing only the elements that satisfy the condition. The code should st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable def custom_filter(lst: List[int], condition: Callable[[int], bool]) -> List[int]: """ Filters elements from the given list based on the provided condition function. Args: lst (List...
python_sharegpt_23k
8,900
Write a Python function to traverse a given matrix in a spiral order and return the sum of all the elements in the matrix. The traversal should start from the top-left corner and proceed in a spiral pattern (right, down, left, up) until all elements are visited. 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 def spiral_sum(matrix: List[List[int]]) -> int: """ Traverse a given matrix in a spiral order and return the sum of all elements. Args: matrix (List[List[int]]): A 2D list representing the m...
python_sharegpt_23k
8,902
Write a Python function to generate the first n terms of the Fibonacci sequence and return them as a list. The function should start with: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: """ Generate the first n terms of the Fibonacci sequence. Args: n (int): The number of terms to generate. Returns: List[int]: A list...
python_sharegpt_23k
8,906
Write a Python function that takes a list of integers as input and returns the sum of elements that are strictly greater than the previous element in the list. The function should start with: ```python from typing import List def sum_if_larger_than_previous(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_if_larger_than_previous(arr: List[int]) -> int: """ Calculate the sum of elements in the list that are strictly greater than the previous element. Args: arr (List[int]): The list of ...
python_sharegpt_23k
8,909
Write a Python function to generate a list of elements from 0 to `n-1` in ascending order, where each element is repeated `k` times. The function should be efficient and use list comprehension for the implementation. The code should start with: ```python from typing import List def generate_repeated_list(n: int, k: i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_repeated_list(n: int, k: int) -> List[int]: """ Generates a list of elements from 0 to n-1, where each element is repeated k times. Args: n (int): The upper limit of the range (...
python_sharegpt_23k
8,913
Write a Python function to find the maximum sum of a subsequence from a given array of positive integers, with the constraint that no two numbers in the sequence are adjacent to each other. The function should start with: ```python from typing import List def max_sum_non_adjacent(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_sum_non_adjacent(arr: List[int]) -> int: """ Calculate the maximum sum of a subsequence from a given array of positive integers, with the constraint that no two numbers in the sequence are ad...
python_sharegpt_23k
8,918
Write a Python function to calculate the sum of all the numbers in a given array without using any built-in functions or methods that directly calculate the sum of an array (such as the `sum()` function or the `reduce()` method). The array can contain both positive and negative integers. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_sum(arr: List[int]) -> int: """ Calculate the sum of all numbers in the given array without using built-in sum functions or methods. Args: arr (List[int]): The array of integer...
python_sharegpt_23k
8,922
Write a Python function that takes an array of keys and an object (dictionary) as parameters. The function should iterate through each key in the array and check if the key exists in the object. If the key exists, the function should append the corresponding value from the object to a new array. Finally, the function s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def find_matching_values(array: List[int], obj: Dict[int, str]) -> List[str]: """ Finds and returns the values from the dictionary that correspond to the keys in the array. Args: array...
python_sharegpt_23k
8,925
Write a Python function to reverse a given string using recursion. The function should take a string as input and return the reversed string. The input string will always be alphanumeric and can have a maximum length of 100 characters. The function should not use any iterative constructs like loops or the `[::-1]` slic...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string_recursive(s: str) -> str: """ Reverses a given string using recursion. Args: s (str): The input string to be reversed. It will always be alphanumeric and can have a maximum length of 100 character...
python_sharegpt_23k
8,926
Write a Python function to reverse a doubly linked list. The function should take the head of the doubly linked list as input and return the new head of the reversed list. Each node in the doubly linked list has `data`, `next`, and `prev` attributes. The `next` attribute points to the next node in the list, and the `pr...
Here is the Python code to solve the given problem in the markdown block: ```python class Node: def __init__(self, data=None): self.data = data self.next = None self.prev = None def reverse_doubly_linked_list(head: Node) -> Node: """ Reverses a doubly linked list and returns the new...
python_sharegpt_23k
8,928
Write a Python function to calculate the sum of all even numbers in a given list of integers. The function should return the sum of the even numbers. The code should start with: ```python from typing import List def sum_of_even_numbers(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def sum_of_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: T...
python_sharegpt_23k
8,931
Write a Python function to determine if two given strings are anagrams, considering the function to be case-insensitive and ignoring non-alphabetic characters. The function should start with: ```python def are_anagrams(string1: str, string2: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(string1: str, string2: str) -> bool: """ Determines if two given strings are anagrams, ignoring case and non-alphabetic characters. Args: string1 (str): The first string to compare. string2 ...
python_sharegpt_23k
8,933
Write a Python function to access and return the element at a specified index `k` from a given tuple `T`. The index `k` is a positive integer that is less than or equal to the length of the tuple. If `k` is out of bounds, the function should return `None`. The code should start with: ```python from typing import Tuple...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Optional def get_element_at_index(T: Tuple, k: int) -> Optional[int]: """ Accesses and returns the element at index k from the given tuple T. If k is out of bounds or not a positive integer, return...
python_sharegpt_23k
8,934
Write a Python function to find the largest and smallest numbers in a given list of integers. The function should return a tuple containing the largest and smallest numbers. The code should start with: ```python from typing import List, Tuple def find_largest_smallest(numbers: List[int]) -> Tuple[int, int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Tuple def find_largest_smallest(numbers: List[int]) -> Tuple[int, int]: """ Find the largest and smallest numbers in a given list of integers. Args: numbers (List[int]): A list of integer...
python_sharegpt_23k
8,935
Write a Python function to count the number of unique words in a given string, considering case sensitivity and punctuation marks. Words with different capitalization or words followed by punctuation marks should be treated as different words. The function should start with: ```python from typing import List def count...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_unique_words(text: str) -> int: """ Count the number of unique words in a given string, considering case sensitivity and punctuation marks. Args: text (str): The input string to co...
python_sharegpt_23k
8,936
Write a Python function that takes an array of strings and returns an array of tuples. Each tuple should contain the first and last word of the corresponding string in the input array. The function should handle strings with leading or trailing whitespace, multiple consecutive spaces, and strings that contain only one ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def extract_first_last_words(arr: List[str]) -> List[Tuple[str, str]]: """ Extracts the first and last words from each string in the input array. Args: arr (List[str]): An array of st...
python_sharegpt_23k
8,937
Write a Python function to find the highest number in a given list of integers. If the list is empty, the function should return `None` and print an error message indicating that the list is empty. The code should start with: ```python from typing import List, Optional def find_highest_number(numbers: List[int]) -> O...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_highest_number(numbers: List[int]) -> Optional[int]: """ Finds the highest number in a given list of integers. If the list is empty, prints an error message and returns None. ...