source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
9,203
Write a Python function to generate the first `n` numbers of the Fibonacci sequence and calculate the sum of these numbers. The function should return both the Fibonacci sequence and the sum of its elements. The code should start with: ```python from typing import List, Tuple def fibonacci_sequence_and_sum(n: int) ->...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def fibonacci_sequence_and_sum(n: int) -> Tuple[List[int], int]: """ Generate the first n numbers of the Fibonacci sequence and calculate their sum. Args: n (int): The number of Fibon...
python_sharegpt_23k
9,204
Write a Python function to count the number of prime numbers in a given array of integers. The function should use a helper function to determine if a number is prime. The code should start with: ```python from typing import List import math def count_primes(arr: List[int]) -> int: ```
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
9,208
Write a Python function to count the number of unique words in a given text, considering case insensitivity. The function should split the text into words, convert them to lowercase, and then count the unique words. The code should start with: ```python def count_unique_words(text: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_unique_words(text: str) -> int: """ Counts the number of unique words in a given text, considering case insensitivity. Args: text (str): The input text from which to count unique words. Returns: ...
python_sharegpt_23k
9,211
Write a Python function to generate a list of all prime numbers up to a given number `n` using the Sieve of Eratosthenes algorithm. The function should handle edge cases where `n` is less than 2 and return an appropriate error message. The function should be optimized to have a time complexity of O(n log(log n)) and sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union import math def generate_primes(n: int) -> Union[List[int], str]: """ Generate a list of all prime numbers up to a given number `n` using the Sieve of Eratosthenes algorithm. Args: n ...
python_sharegpt_23k
9,212
Write a Python function to generate a list of prime numbers between 2 and a given positive integer `n` (where `n` is greater than 2) using the Sieve of Eratosthenes algorithm. The function should efficiently mark non-prime numbers and return the list of prime numbers. The code should start with: ```python from typing ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_primes(n: int) -> List[int]: """ Generate a list of prime numbers between 2 and n using the Sieve of Eratosthenes algorithm. Args: n (int): The upper limit for generating prime ...
python_sharegpt_23k
9,213
Write a Python function to generate a random string of a specified length consisting of letters (both uppercase and lowercase) and numbers, without using any built-in functions or libraries. The function should start with: ```python def generate_random_string(length: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def generate_random_string(length: int) -> str: """ Generate a random string of the specified length consisting of letters (both uppercase and lowercase) and numbers. Args: length (int): The length of the random str...
python_sharegpt_23k
9,214
Write a Python function to count the number of occurrences of a given character in a string. The function should be case-sensitive and count occurrences of the character as part of a larger substring. The function should handle strings with special characters and spaces. The output should be the count of occurrences of...
Here is the Python code to solve the given problem in the markdown block: ```python def count_character_occurrences(string: str, char: str) -> int: """ Counts the number of occurrences of a given character in a string. Args: string (str): The string in which to count the occurrences. char (...
python_sharegpt_23k
9,218
Write a Python function to find the largest sum of any two distinct numbers in a given list of integers. The function should return the largest sum. The code should start with: ```python from typing import List def get_largest_sum(num_list: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_largest_sum(num_list: List[int]) -> int: """ Find the largest sum of any two distinct numbers in the given list. Args: num_list (List[int]): The list of integers from which to find t...
python_sharegpt_23k
9,220
Write a Python function to filter and return a new dictionary containing only the key-value pairs from the given dictionary where the value is greater than a specified threshold. The function should start with: ```python from typing import Dict def filter_dict_by_value(input_dict: Dict[str, int], threshold: int) -> Di...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def filter_dict_by_value(input_dict: Dict[str, int], threshold: int) -> Dict[str, int]: """ Filters the input dictionary and returns a new dictionary containing only the key-value pairs where the val...
python_sharegpt_23k
9,221
Write a Python function to sum all the even values in a given dictionary. If there are no even values in the dictionary, return 0. The function should start with: ```python from typing import Dict def sum_even_values(dictionary: Dict[str, int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sum_even_values(dictionary: Dict[str, int]) -> int: """ Sum all the even values in the given dictionary. Args: dictionary (Dict[str, int]): A dictionary with string keys and integer valu...
python_sharegpt_23k
9,222
Write a Python function to generate the first n Fibonacci numbers efficiently with a time complexity of O(n). The function should handle edge cases such as when n is less than or equal to zero. The code should start with: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: """ Generate the first n Fibonacci numbers. Args: n (int): The number of Fibonacci numbers to generate. Returns: List[int]: A list c...
python_sharegpt_23k
9,229
Write a Python function to display the elements of a given list as characters corresponding to their ASCII values, without using any built-in Python functions or methods such as `print()`, `len()`, `chr()`, or `ord()`. The function should start with: ```python def display_elements_as_characters(my_list): ```
Here is the Python code to solve the given problem in the markdown block: ```python def display_elements_as_characters(my_list): """ Displays the elements of the given list as characters corresponding to their ASCII values, without using any built-in Python functions or methods such as `print()`, `len()`, `...
python_sharegpt_23k
9,230
Write a Python function to generate a list of all odd numbers between two given integers, `start` and `end`, inclusive. The function should handle negative numbers and ensure that `start` is less than or equal to `end`. If the inputs are invalid (i.e., `start` is greater than `end`), the function should return an empty...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_odd_numbers(start: int, end: int) -> List[int]: """ Generate a list of all odd numbers between the given start and end values (inclusive). Args: start (int): The starting integer of ...
python_sharegpt_23k
9,231
Write a Python function to calculate the Fibonacci sequence up to the n-th number efficiently. The function should have a time complexity of O(n) and a space complexity of O(1). The function should return a list containing the Fibonacci sequence up to the n-th number. The code should start with: ```python from typing ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def fibonacci_sequence(n: int) -> List[int]: """ Calculate the Fibonacci sequence up to the n-th number efficiently. Args: n (int): The number up to which the Fibonacci sequence should be ca...
python_sharegpt_23k
9,233
Write a Python function that runs a loop from 0 to a given number `n`, and returns a list of all loop indices that are divisible by a given divisor `d`. The function should handle edge cases such as `n` being negative or zero, and `d` being zero. The code should start with: ```python from typing import List def get_d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_divisible_indices(n: int, d: int) -> List[int]: """ Returns a list of indices from 0 to n (inclusive) that are divisible by d. Args: n (int): The upper limit of the range (inclusive)...
python_sharegpt_23k
9,237
Write a Python function to merge two sorted arrays of integers, `arr1` and `arr2`, of size `n` and `m` respectively, into a new sorted array of size `n + m`. The function should handle the following cases: 1. If either `arr1` or `arr2` is empty, the function should return the non-empty array as the result. 2. If `arr1`...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]: """ Merges two sorted arrays of integers into a new sorted array without duplicates. Args: arr1 (List[int]): The first...
python_sharegpt_23k
9,241
Write a Python function to filter and return a list of odd numbers from 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 filter_odd_numbers(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_odd_numbers(numbers: List[int]) -> List[int]: """ Filters and returns a list of odd numbers from the given list of integers. Args: numbers (List[int]): A list of integers from whi...
python_sharegpt_23k
9,243
Write a Python function to find the longest common prefix among a given set of strings. The function should have a time complexity of O(n * m), where n is the number of strings in the set and m is the length of the longest string. The function should start with: ```python from typing import List def longest_common_pre...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_common_prefix(strings: List[str]) -> str: """ Find the longest common prefix among a given set of strings. Args: strings (List[str]): A list of strings to find the longest common...
python_sharegpt_23k
9,245
Write a Python function to return a new list with each item multiplied by 2 in an existing list, but the program should also exclude any negative numbers from the final list. The function should be named `multiply_and_exclude_negative` and should take a single parameter, a list of integers. The function should return a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def multiply_and_exclude_negative(lst: List[int]) -> List[int]: """ Returns a new list with each item multiplied by 2, excluding any negative numbers. Args: lst (List[int]): The input list o...
python_sharegpt_23k
9,246
Write a Python function to implement the Sieve of Eratosthenes algorithm to efficiently find all prime numbers up to a given limit. The function should return a list of all prime numbers up to the specified limit. The code should start with: ```python from typing import List def find_primes_up_to_limit(limit: int) ->...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_primes_up_to_limit(limit: int) -> List[int]: """ Find all prime numbers up to a given limit using the Sieve of Eratosthenes algorithm. Args: limit (int): The upper limit up to which...
python_sharegpt_23k
9,250
Write a Python function to check if all numbers in a given list are prime. The function should return `True` if all numbers in the list are prime, and `False` otherwise. The code should start with: ```python from typing import List def are_all_numbers_prime(numbers: List[int]) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a given number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise...
python_sharegpt_23k
9,253
Write a Python function to reverse the order of words in a given string while also ensuring that each word is reversed as well. The function should handle any string input, including strings with multiple spaces between words and leading/trailing spaces. The code should start with: ```python def reverse_and_reverse_wor...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_and_reverse_words(s: str) -> str: """ Reverses the order of words in a given string while also reversing each word. Args: s (str): The input string to be processed. Returns: str: A string wi...
python_sharegpt_23k
9,264
Write a Python function to reverse a given string without using any built-in string manipulation functions or data structures. The function should have a time complexity of O(n), where n is the length of the input string. The code should start with: ```python def reverse_string(input_string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def reverse_string(input_string: str) -> str: """ Reverses the input string without using any built-in string manipulation functions or data structures. Args: input_string (str): The string to be reversed. Re...
python_sharegpt_23k
9,271
Write a Python function to check if a specific item exists in a list of lists. The function should return `True` if the item is found in any of the sublists, and `False` otherwise. The code should start with: ```python from typing import List, Any def item_exists_in_list_of_lists(my_list: List[List[Any]], item: Any) -...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def item_exists_in_list_of_lists(my_list: List[List[Any]], item: Any) -> bool: """ Check if a specific item exists in a list of lists. Args: my_list (List[List[Any]]): A list of lists c...
python_sharegpt_23k
9,272
Write a Python function to find the numbers that are present in the first list but missing in the second list. The function should take two lists as input and return a new list containing the missing numbers. The code should start with: ```python from typing import List def find_missing_numbers(list1: List[int], list2...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_missing_numbers(list1: List[int], list2: List[int]) -> List[int]: """ Find the numbers that are present in the first list but missing in the second list. Args: list1 (List[int]): Th...
python_sharegpt_23k
9,277
Write a Python function to find and return all prime numbers within a given range `[start, end]`. The function should use a helper function to determine if a number is prime. The code should start with: ```python from typing import List def find_primes_in_range(start: int, end: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(num: int) -> bool: """ Helper function to determine if a number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is p...
python_sharegpt_23k
9,278
Write a Python function to clone/copy a nested dictionary, preserving the original structure and values. The function should handle arbitrary levels of nesting and should not modify the original dictionary. The code should start with: ```python from typing import Any, Dict def clone_nested_dict(original_dict: Dict[Any...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Dict def clone_nested_dict(original_dict: Dict[Any, Any]) -> Dict[Any, Any]: """ Clones a nested dictionary, preserving the original structure and values. Args: original_dict (Dict[Any, Any]...
python_sharegpt_23k
9,280
Write a Python function to merge two arrays and return a new array that contains all the unique items from both arrays, sorted in ascending order. The function should ensure that the resulting array does not contain any duplicates and should have a time complexity of O(n log n), where n is the total number of elements ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_and_sort_arrays(array1: List[int], array2: List[int]) -> List[int]: """ Merges two arrays and returns a new array with all unique items from both arrays, sorted in ascending order. Args: ...
python_sharegpt_23k
9,282
Write a Python function to update the elements of a list in-place by applying a given transformation function. The list can have up to 1,000,000 elements, and the elements are in the range of 0 to 100,000. The transformation function should be applied to each element of the list. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable def update_list_inplace(lst: List[int], transform_func: Callable[[int], int]) -> None: """ Updates the elements of a list in-place by applying a given transformation function. Args: ...
python_sharegpt_23k
9,283
Write a Python function to calculate the Euclidean distance between two points in a multi-dimensional space. The points are represented as lists of coordinates. The function should use NumPy for efficient computation. The code should start with: ```python from typing import List import numpy as np def euclidean_distan...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import numpy as np def euclidean_distance(point1: List[float], point2: List[float]) -> float: """ Calculate the Euclidean distance between two points in a multi-dimensional space. Args: poin...
python_sharegpt_23k
9,286
Write a Python function to retrieve elements from a given array between the second index (inclusive) and the fourth index (inclusive), and ensure that the sum of these elements is greater than or equal to 100. If the sum is less than 100, return an empty list. The code should start with: ```python from typing import L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def retrieve_elements_with_sum_check(array: List[int]) -> List[int]: """ Retrieve elements from the second index to the fourth index (inclusive) in the given array, and ensure that the sum of these e...
python_sharegpt_23k
9,290
Write a Python function to check if the parentheses in a given string are balanced. The string may contain other characters apart from parentheses. The function should return `True` if the parentheses are balanced and `False` otherwise. The code should start with: ```python def is_balanced_parentheses(s: str) -> bool: ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_balanced_parentheses(s: str) -> bool: """ Check if the parentheses in the given string are balanced. Args: s (str): The string to check for balanced parentheses. Returns: bool: True if the parent...
python_sharegpt_23k
9,291
Write a Python function to find the most frequent word in a given sentence without using any built-in functions or libraries for string manipulation or counting occurrences. The function should handle sentences with multiple spaces between words and should be case-sensitive. The code should start with: ```python def f...
Here is the Python code to solve the given problem in the markdown block: ```python def find_most_frequent_word(sentence: str) -> str: """ Finds the most frequent word in a given sentence without using any built-in functions or libraries for string manipulation or counting occurrences. Args: senten...
python_sharegpt_23k
9,294
Write a Python function to reverse a given string without using any in-built string manipulation functions and with a time complexity of O(n). The function should handle any string input, including empty strings and strings with special characters. The code should start with: ```python def reverse_string(s: str) -> str...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses the given string without using in-built string manipulation functions and with a time complexity of O(n). Args: s (str): The input string to be reversed. Returns:...
python_sharegpt_23k
9,296
Write a Python function to process a list of numbers by removing all negative numbers, doubling the remaining numbers, and sorting the doubled numbers in descending order. The function should return the sorted list of doubled numbers. The code should start with: ```python from typing import List def process_numbers(n...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def process_numbers(numbers: List[int]) -> List[int]: """ Process a list of numbers by removing all negative numbers, doubling the remaining numbers, and sorting the doubled numbers in descending ord...
python_sharegpt_23k
9,298
Write a Python function to swap the values of two integers without using a temporary variable. The function should take two integers as input and return a tuple containing the swapped values. The code should start with: ```python def swap_integers(x: int, y: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def swap_integers(x: int, y: int) -> tuple: """ Swaps the values of two integers without using a temporary variable. Args: x (int): The first integer. y (int): The second integer. Returns: tuple...
python_sharegpt_23k
9,300
Write a Python function to strip HTML tags from a given HTML string, ensuring that nested tags are handled correctly. The function should recursively remove all HTML tags until no tags remain in the string. The code should start with: ```python import re def strip_html_tags(html: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python import re def strip_html_tags(html: str) -> str: """ Strips all HTML tags from the given HTML string, including nested tags. Args: html (str): The HTML string from which to strip tags. Returns: str: Th...
python_sharegpt_23k
9,303
Write a Python function that takes two strings as arguments and returns a list containing all unique characters that appear in either string, sorted in the order they first appear in the combined string. Duplicate characters should be excluded from the result. The code should start with: ```python from typing import L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def unique_characters_in_order(string_1: str, string_2: str) -> List[str]: """ Returns a list of unique characters that appear in either of the two input strings, maintaining the order of their first...
python_sharegpt_23k
9,305
Write a Python function to calculate the minimum number of operations required to transform one string into another using the following operations: 1. Insert a character (cost: 1) 2. Delete a character (cost: 1) 3. Replace a character (cost: 1) The function should start with: ```python def min_edit_distance(string1: s...
Here is the Python code to solve the given problem in the markdown block: ```python def min_edit_distance(string1: str, string2: str) -> int: """ Calculate the minimum number of operations required to transform one string into another. The operations allowed are: 1. Insert a character (cost: 1) 2. D...
python_sharegpt_23k
9,308
Write a Python function to calculate the factorial of a given non-negative integer `n`. The function should be efficient and handle edge cases such as `n` being 0 or a negative integer. The code should start with: ```python def factorial(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def factorial(n: int) -> int: """ Calculate the factorial of a given non-negative integer n. Args: n (int): The non-negative integer for which to calculate the factorial. Returns: int: The factorial o...
python_sharegpt_23k
9,309
Write a Python function to find the maximum value in an array without using any built-in functions, ensuring a time complexity of O(n) and a space complexity of O(1). The function should handle edge cases such as an empty array and arrays with negative numbers. 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, Optional def find_maximum(arr: List[int]) -> Optional[int]: """ Find the maximum value in an array without using any built-in functions. Args: arr (List[int]): The array of integers from wh...
python_sharegpt_23k
9,312
Write a Python function to determine if a given string is a palindrome, ignoring spaces, punctuation, and case differences. A palindrome is a sequence of characters that reads the same backward as forward. The function should return `True` if the string is a palindrome and `False` otherwise. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python import string def is_palindrome(s: str) -> bool: """ Determine if a given string is a palindrome, ignoring spaces, punctuation, and case differences. Args: s (str): The input string to check. Returns: ...
python_sharegpt_23k
9,314
Write a Python function to print the even numbers within a given range `[start, end]` inclusive. The function should take two integer parameters, `start` and `end`, and print the even numbers in that range. If `start` is greater than `end`, the function should print an empty line. The code should start with: ```python...
Here is the Python code to solve the given problem in the markdown block: ```python def print_even_numbers(start: int, end: int) -> None: """ Prints the even numbers within the given range [start, end] inclusive. Args: start (int): The starting number of the range. end (int): The ending num...
python_sharegpt_23k
9,315
Write a Python function to reverse the elements of a given list in-place without using any additional data structures. The function should modify the original list and return it. The code should start with: ```python from typing import List def reverse_in_place(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_in_place(arr: List[int]) -> List[int]: """ Reverses the elements of the given list in-place. Args: arr (List[int]): The list of integers to be reversed. Returns: L...
python_sharegpt_23k
9,322
Write a Python function to calculate and return a list of ASCII values for each character in a given string. The function should handle any string input and return a list of integers representing the ASCII values of each character in the string. The code should start with: ```python from typing import List def get_as...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_ascii_values(input_string: str) -> List[int]: """ Calculate and return a list of ASCII values for each character in the given string. Args: input_string (str): The input string for w...
python_sharegpt_23k
9,326
Write a Python function that prints the word 'hello' 10 times, with every other occurrence capitalized starting from the second iteration. The function should not return any value; it should only print the output. The code should start with: ```python def print_alternating_hello(): ```
Here is the Python code to solve the given problem in the markdown block: ```python def print_alternating_hello(): """ Prints the word 'hello' 10 times, with every other occurrence capitalized starting from the second iteration. This function does not return any value; it only prints the output. """ ...
python_sharegpt_23k
9,327
Write a Python function to print all the lowercase letters of the alphabet in reverse order using a while loop. The function should not take any parameters and should not return any value. Instead, it should directly print the letters to the console. The code should start with: ```python def print_lowercase_alphabet_r...
Here is the Python code to solve the given problem in the markdown block: ```python def print_lowercase_alphabet_reverse(): """ Prints all the lowercase letters of the alphabet in reverse order. This function uses a while loop to iterate from the ASCII value of 'z' down to the ASCII value of 'a', conve...
python_sharegpt_23k
9,332
Write a Python function to remove all occurrences of a specified element from a given list. The function should return a new list that contains all elements from the original list except the specified element. The code should start with: ```python from typing import List def remove_element(arr: List[int], element: int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_element(arr: List[int], element: int) -> List[int]: """ Removes all occurrences of a specified element from a given list. Args: arr (List[int]): The list from which to remove the ...
python_sharegpt_23k
9,337
Write a Python function to print the index and item of a given list, but with the following additional conditions: 1. Only print the index and item if the item is a string. 2. Print the index in ascending order, starting from 1. 3. Only print the index and item if the index is an odd number. The function should start ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_odd_indexed_strings(my_list: List[any]) -> None: """ Prints the index and item of a list if the item is a string and the index is odd, starting from 1. Args: my_list (List[any]): T...
python_sharegpt_23k
9,339
Write a Python function to calculate the sum of all odd numbers from 0 to a given positive integer `n` using a while loop. The function should start with: ```python def sum_of_odds(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_odds(n: int) -> int: """ Calculate the sum of all odd numbers from 0 to a given positive integer n. Args: n (int): The upper limit of the range (inclusive). Returns: int: The sum of all odd n...
python_sharegpt_23k
9,346
Write a Python function to calculate the sum of positive numbers in each row of a given two-dimensional array. The function should handle negative numbers by ignoring them in the sum calculation. The code should start with: ```python from typing import List def sum_positive_numbers_in_rows(arr: List[List[int]]) -> Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_positive_numbers_in_rows(arr: List[List[int]]) -> List[int]: """ Calculate the sum of positive numbers in each row of a given two-dimensional array. Args: arr (List[List[int]]): A tw...
python_sharegpt_23k
9,347
Write a Python function to calculate the sum of all elements in a given array of numbers. If any element in the array is a negative number, the function should raise a `ValueError` with a custom error message. The function should start with: ```python from typing import List def sum_array_with_check(numbers: List[int]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_array_with_check(numbers: List[int]) -> int: """ Calculate the sum of all elements in a given array of numbers. If any element in the array is a negative number, raise a ValueError with a cus...
python_sharegpt_23k
9,348
Write a Python function to sort a given list of strings in descending order based on their lexicographical order. The function should take a list of strings as input and return the sorted list. The code should start with: ```python from typing import List def sort_strings_descending(strings: List[str]) -> List[str]: `...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_strings_descending(strings: List[str]) -> List[str]: """ Sorts a given list of strings in descending order based on their lexicographical order. Args: strings (List[str]): The list ...
python_sharegpt_23k
9,351
Write a Python function to determine and return the longer string between two given strings. The function should have a time complexity of O(1) and should not use any built-in functions or libraries that directly determine the length of the strings. You may use any other built-in functions or libraries. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python def find_longer_string(first_str: str, second_str: str) -> str: """ Determines and returns the longer string between two given strings. Args: first_str (str): The first string to compare. second_str (str): T...
python_sharegpt_23k
9,357
Write a Python function to calculate the factorial of a given non-negative integer using a while loop. The function should handle invalid inputs such as negative numbers and non-integer values by returning appropriate error messages. The code should start with: ```python def calculate_factorial(num: int) -> int or str...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_factorial(num: int) -> int or str: """ Calculate the factorial of a given non-negative integer using a while loop. Args: num (int): The non-negative integer for which to calculate the factorial. R...
python_sharegpt_23k
9,359
Write a Python function to calculate the sum of all numbers in a given list. The function should handle lists of integers and floating-point numbers. The code should start with: ```python from typing import List def calculate_sum(numbers: List[float]) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_sum(numbers: List[float]) -> float: """ Calculate the sum of all numbers in a given list. Args: numbers (List[float]): A list of numbers (integers or floating-point numbers). ...
python_sharegpt_23k
9,360
Write a Python function to implement an optimized version of insertion sort that can efficiently sort a large array of integers in ascending order. The input array can contain duplicate values and may have a length up to \(10^6\). The implementation should have a time complexity of \(O(n^2)\) and a space complexity of ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def optimized_insertion_sort(arr: List[int]) -> List[int]: """ Sorts the input array of integers in ascending order using an optimized insertion sort algorithm. Args: arr (List[int]): The ar...
python_sharegpt_23k
9,362
Write a Python function to check if all strings in a given array contain at least one digit and one uppercase letter. The function should return `True` if all strings meet the criteria, otherwise it should return `False`. The code should start with: ```python from typing import List def check_strings(arr: List[str]) ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def check_strings(arr: List[str]) -> bool: """ Check if all strings in the given array contain at least one digit and one uppercase letter. Args: arr (List[str]): The array of strings to be ...
python_sharegpt_23k
9,365
Write a Python function to determine whether two strings are anagrams of each other without using built-in Python functions or libraries for string manipulation and sorting. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly o...
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(str1: str, str2: str) -> bool: """ Determine whether two strings are anagrams of each other. Args: str1 (str): The first string to compare. str2 (str): The second string to compare. Ret...
python_sharegpt_23k
9,367
Write a Python function that takes a string as an argument and returns the first character of the string in uppercase. The function should handle cases where the string may contain leading or trailing whitespace and should remove any leading or trailing whitespace before converting the first character to uppercase. If ...
Here is the Python code to solve the given problem in the markdown block: ```python def capitalize_first_character(string: str) -> str: """ Returns the first character of the given string in uppercase, after removing any leading or trailing whitespace. If the string is empty after stripping whitespace, retu...
python_sharegpt_23k
9,369
Write a Python function to calculate the length of a given list, considering the following requirements: 1. The function should handle lists of any data type, including nested lists. 2. The function should handle empty lists and return a length of 0. 3. The function should handle lists with duplicate elements correctly...
Here is the Python code to solve the given problem in the markdown block: ```python def get_list_length(lst): """ Calculate the length of a given list, considering nested lists and circular references. Args: lst (list): The list whose length is to be calculated. Returns: int: The lengt...
python_sharegpt_23k
9,373
Write a Python function to find and return all prime numbers between a given range `[start, end]` and also count the total number of prime numbers found within that range. The function should return a tuple containing a list of prime numbers and the count of prime numbers. The code should start with: ```python from ty...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_primes_in_range(start: int, end: int) -> Tuple[List[int], int]: """ Find all prime numbers within the given range [start, end] and count them. Args: start (int): The starting...
python_sharegpt_23k
9,378
Write a Python function to determine if one list is a subset of another list. A subset is defined as a set where all the elements of the second list are also present in the first list, and the first list may have additional elements. The function should have a time complexity of O(n), where n is the length of the secon...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_subset(A: List[int], B: List[int]) -> bool: """ Determines if the list B is a subset of the list A. Args: A (List[int]): The list to check against. B (List[int]): The list to ...
python_sharegpt_23k
9,382
Write a Python function to swap two numbers using a temporary variable without using any arithmetic or assignment operators. The function should take two integers as input and return a tuple containing the swapped values. The code should start with: ```python def swap_numbers(a: int, b: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def swap_numbers(a: int, b: int) -> tuple: """ Swaps two integers using a temporary variable without using any arithmetic or assignment operators. Args: a (int): The first integer. b (int): The second intege...
python_sharegpt_23k
9,383
Write a Python function to find both the maximum and minimum values among three given integers using the ternary operator. The function should return these values as a tuple. The code should start with: ```python def find_max_min(a: int, b: int, c: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def find_max_min(a: int, b: int, c: int) -> tuple: """ Finds the maximum and minimum values among three given integers using the ternary operator. Args: a (int): The first integer. b (int): The second intege...
python_sharegpt_23k
9,384
Write a Python function that performs a loop which terminates after exactly 10 iterations without using any comparison operators (such as `<`, `>`, `<=`, `>=`) inside the loop condition. The function should increment a counter and print the counter value during each iteration. The loop should stop after the 10th iterat...
Here is the Python code to solve the given problem in the markdown block: ```python def loop_without_comparisons(): """ Perform a loop that terminates after exactly 10 iterations without using any comparison operators. The function increments a counter and prints the counter value during each iteration. ...
python_sharegpt_23k
9,386
Write a Python function to detect if a given URL contains a query string parameter named "food" with the value "burger". The function should return `True` if the URL contains the specified query string parameter, otherwise `False`. The code should start with: ```python import re def has_food_burger_query(url: str) ->...
Here is the Python code to solve the given problem in the markdown block: ```python import re def has_food_burger_query(url: str) -> bool: """ Detects if the given URL contains a query string parameter named "food" with the value "burger". Args: url (str): The URL to be checked. Returns: ...
python_sharegpt_23k
9,389
Write a Python function to filter out prime numbers from a given list of integers. The function should return a new list containing only the prime numbers found in the original list. The code 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]): A list of integers from which to filter prime numb...
python_sharegpt_23k
9,392
Write a Python function to find the most common value in an array. The array will always contain at least 5 elements and the maximum size of the array is 100. The elements in the array are integers between -1000 and 1000. The function should have a time complexity of O(n). Return the most common value along with its fr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_most_common_value(arr: List[int]) -> Tuple[int, int]: """ Find the most common value in an array and return it along with its frequency. In case of ties, return the value with the hig...
python_sharegpt_23k
9,396
Write a Python function to multiply each element of a given array of integers by a specified target sum. The function should return a new array containing the results of these multiplications. The code should start with: ```python from typing import List def multiply_array_by_target_sum(arr: List[int], target_sum: int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def multiply_array_by_target_sum(arr: List[int], target_sum: int) -> List[int]: """ Multiplies each element of the given array by the specified target sum. Args: arr (List[int]): The array o...
python_sharegpt_23k
9,401
Write a Python function to generate a list of random numbers within a specified range and size. The function should allow the user to specify the range (inclusive) and the size of the list. The code should start with: ```python from typing import List import random def generate_random_numbers(size: int, lower_bound: i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_random_numbers(size: int, lower_bound: int, upper_bound: int) -> List[int]: """ Generates a list of random numbers within a specified range and size. Args: size (i...
python_sharegpt_23k
9,402
Write a Python function to create a dictionary with three keys, each having a list of values sorted in ascending order. The function should also support efficient lookup of values based on their indices in the lists. The function should start with: ```python from typing import Dict, List def create_sorted_dict(values1...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def create_sorted_dict(values1: List[int], values2: List[int], values3: List[int]) -> Dict[str, List[int]]: """ Create a dictionary with three keys, each having a list of values sorted in ascending...
python_sharegpt_23k
9,403
Write a Python function to convert a given decimal number between 0 and 255 to its binary and hexadecimal representations. The function should return a tuple containing the binary and hexadecimal representations as strings. The code should start with: ```python def convert_decimal_to_binary_hexadecimal(decimal: int) -...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_decimal_to_binary_hexadecimal(decimal: int) -> tuple: """ Convert a given decimal number between 0 and 255 to its binary and hexadecimal representations. Args: decimal (int): The decimal number to conver...
python_sharegpt_23k
9,408
Write a Python function to process a list of numbers and return the sum, average, maximum, minimum, and occurrences of numbers that are divisible by both 3 and 7. The function should start with: ```python from typing import List, Dict, Tuple def process_divisible_numbers(numbers: List[int]) -> Tuple[int, float, int, i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple def process_divisible_numbers(numbers: List[int]) -> Tuple[int, float, int, int, Dict[int, int]]: """ Process a list of numbers to find the sum, average, maximum, minimum, and occurrences of...
python_sharegpt_23k
9,413
Write a Python function to find the element-wise product of two arrays. The function should take two lists of integers as input and return a new list containing the products of corresponding elements from the input lists. If the input lists have different lengths, the function should return an error message. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_product(array1: List[int], array2: List[int]) -> List[int] or str: """ Find the element-wise product of two arrays. Args: array1 (List[int]): The first array of integers. ar...
python_sharegpt_23k
9,419
Write a Python function to generate an array of integers that contain all the prime numbers between 1 and a given number `n` using the Sieve of Eratosthenes algorithm. The function should return a list of prime numbers. The code should start with: ```python from typing import List def generate_primes(n: int) -> List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_primes(n: int) -> List[int]: """ Generate a list of prime numbers between 1 and n using the Sieve of Eratosthenes algorithm. Args: n (int): The upper limit to find prime numbers...
python_sharegpt_23k
9,428
Write a Python function that takes a dictionary containing the names and ages of a group of people and returns a list of strings in the format "Name: age". The function should handle any dictionary with string keys (names) and integer values (ages). The code should start with: ```python from typing import Dict, List ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def format_people_info(people: Dict[str, int]) -> List[str]: """ Formats a dictionary of names and ages into a list of strings in the format "Name: age". Args: people (Dict[str, int]):...
python_sharegpt_23k
9,429
Write a Python function to convert a list of words into a sorted set, removing any duplicate elements. The function should return the sorted set of unique words. The code should start with: ```python from typing import List, Set def convert_and_sort_words(words: List[str]) -> Set[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Set def convert_and_sort_words(words: List[str]) -> Set[str]: """ Converts a list of words into a sorted set, removing any duplicate elements. Args: words (List[str]): A list of words from ...
python_sharegpt_23k
9,430
Write a Python function to determine the maximum and minimum values in a given array of integers. The array can have duplicate values and can be of any length between 1 and 10^6. The function should handle edge cases such as an empty array and arrays with a single element. The code should start with: ```python from ty...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Optional def find_max_min(arr: List[int]) -> Optional[Tuple[int, int]]: """ Determine the maximum and minimum values in a given array of integers. Args: arr (List[int]): The array of...
python_sharegpt_23k
9,436
Write a Python function to check if two lists have the same elements regardless of their order. The elements in the lists will be strings consisting of lowercase letters only, and each element will have a length between 1 and 10 characters inclusive. The lists can have a maximum of 100 elements. If the lists have the s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def have_same_elements(list1: List[str], list2: List[str]) -> bool: """ Check if two lists have the same elements regardless of their order. Args: list1 (List[str]): The first list of string...
python_sharegpt_23k
9,442
Write a Python function to validate that a list of dates is in strictly increasing order and that each date is valid according to the Gregorian calendar system. The dates should be provided in the format "yyyy-mm-dd". The function should check for leap years and ensure that the number of days in each month is accurate....
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import datetime def validate_dates_increasing(dates: List[str]) -> bool: """ Validates that a list of dates is in strictly increasing order and that each date is valid according to the Gregorian calendar...
python_sharegpt_23k
9,444
Write a Python function to compare two strings and return the number of different characters at each corresponding position in the strings. 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 string. If the strings have different lengths, consider the e...
Here is the Python code to solve the given problem in the markdown block: ```python def count_differences(str1: str, str2: str) -> int: """ Counts the number of different characters at each corresponding position in two strings. Args: str1 (str): The first string to compare. str2 (str): The...
python_sharegpt_23k
9,445
Write a Python function to calculate the power of a number raised to the nth power using an efficient approach. The function should handle large exponents and optimize the calculation using the properties of exponents. The code should start with: ```python def efficient_power(base: int, exponent: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def efficient_power(base: int, exponent: int) -> int: """ Calculate the power of a number raised to the nth power using an efficient approach. Args: base (int): The base number, a positive integer greater than zero....
python_sharegpt_23k
9,453
Write a Python function to reverse a given string without using any built-in reverse functions or methods. The input string will have at most 1000 characters and will only consist of lowercase letters. The function should start with: ```python def reverse_string(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses the given string without using any built-in reverse functions or methods. Args: s (str): The input string to be reversed. It contains at most 1000 characters and only ...
python_sharegpt_23k
9,454
Write a Python function to remove any duplicate numbers from a given array of integers and sort the remaining elements in descending order. Additionally, the function should return an array that includes the count of each unique element in the original array. The code should start with: ```python from typing import Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def remove_duplicates_and_sort_with_count(arr: List[int]) -> Tuple[List[int], List[int]]: """ Removes duplicates from the given array, sorts the remaining elements in descending order, and ret...
python_sharegpt_23k
9,456
Write a Python function to generate the first `n` Fibonacci numbers using a single loop and no recursion. The function should handle edge cases where `n` is negative or zero by returning an empty list. The code should start with: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: """ Generate the first n Fibonacci numbers using a single loop and no recursion. Args: n (int): The number of Fibonacci numbers to generate. ...
python_sharegpt_23k
9,458
Write a Python function to generate a spiral order traversal of a given 2D array. The function should take a 2D list as input and return a list containing the elements of the 2D array in spiral order. The spiral order starts from the top-left corner and proceeds in a clockwise direction. 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 spiral_order_traversal(matrix: List[List[int]]) -> List[int]: """ Generate a spiral order traversal of a given 2D array. Args: matrix (List[List[int]]): A 2D list representing the input ...
python_sharegpt_23k
9,464
Write a Python function to remove all extra whitespace from a given sentence and count the number of words in the sentence. The function should return a tuple containing the modified sentence and the word count. The code should start with: ```python def remove_extra_whitespace_and_count_words(sentence: str) -> tuple: ...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_extra_whitespace_and_count_words(sentence: str) -> tuple: """ Removes all extra whitespace from the given sentence and counts the number of words. Args: sentence (str): The input sentence from which to re...
python_sharegpt_23k
9,466
Write a Python function to sort a given list of numbers in descending order without using any built-in sorting functions or libraries. The function should implement the Bubble Sort algorithm to achieve this. The code should start with: ```python from typing import List def sort_descending(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 sort_descending(nums: List[int]) -> List[int]: """ Sorts a given list of numbers in descending order using the Bubble Sort algorithm. Args: nums (List[int]): The list of numbers to be so...
python_sharegpt_23k
9,467
Write a Python function that takes in a list of integers and returns a set containing only the even numbers, without using any built-in Python functions or methods. The function should manually implement the logic to determine if a number is even and to add it to a set. The code should start with: ```python def get_ev...
Here is the Python code to solve the given problem in the markdown block: ```python def get_even_set(numbers): """ Extracts and returns a set of even numbers from the given list of integers. Args: numbers (list): A list of integers from which to extract even numbers. Returns: set: A se...
python_sharegpt_23k
9,469
Write a Python function to sort a given array of integers in descending order using a variation of the bubble sort algorithm. The algorithm should have a time complexity of O(n^2) and should be implemented without using any built-in sorting functions or libraries. The function should be able to handle arrays with up to...
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 given array of integers in descending order using a variation of the bubble sort algorithm. Args: arr (List[int]): The ar...
python_sharegpt_23k
9,470
Write a Python function to retrieve all elements in a given array that occur only once. The function should have a time complexity of O(n) where n is the number of elements in the array. The function should use constant space complexity, i.e., it should not create additional data structures that grow with the size of t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def get_unique_elements(arr: List[Any]) -> List[Any]: """ Retrieves all elements in the given array that occur only once. Args: arr (List[Any]): The input array containing elements of a...
python_sharegpt_23k
9,472
Write a Python function to generate a list of Fibonacci numbers up to a given limit `n`, where `n` is the number of Fibonacci numbers to generate. The function should have a time complexity of O(n). The code should start with: ```python from typing import List def generate_fibonacci_sequence(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_sequence(n: int) -> List[int]: """ Generate a list of Fibonacci numbers up to the given limit n. Args: n (int): The number of Fibonacci numbers to generate. Retur...
python_sharegpt_23k
9,475
Write a Python function to generate a list of all prime numbers within a given range `[start, end]`, excluding any specified numbers. The function should return the list of prime numbers. The code should start with: ```python from typing import List, Set def generate_prime_numbers(start: int, end: int, exclude: Set[i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Set 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. """ i...
python_sharegpt_23k
9,476
Write a Python function to determine if a given input string is a palindrome. The function should ignore any punctuation marks and spaces in the string, and it should be case-insensitive. The function should return `True` if the string is a palindrome and `False` otherwise. The code should start with: ```python import...
Here is the Python code to solve the given problem in the markdown block: ```python import string def is_palindrome(input_str: str) -> bool: """ Determine if the given input string is a palindrome, ignoring punctuation, spaces, and case sensitivity. Args: input_str (str): The input string to check...
python_sharegpt_23k
9,478
Write a Python function to remove duplicates from a list of strings while ignoring case sensitivity and removing any leading or trailing whitespace from each string. The function should return a list of unique strings in their original form (i.e., without converting them to lowercase or stripping whitespace). The code...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_ignore_case(strings: List[str]) -> List[str]: """ Removes duplicates from a list of strings while ignoring case sensitivity and removing leading/trailing whitespace. Returns a ...
python_sharegpt_23k
9,479
Write a Python function to compare two strings and return a boolean indicating their equality or inequality. You cannot use any built-in string comparison methods or operators such as `==`. Instead, you must implement your own algorithm to compare the strings character by character. The function should return `True` if...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_strings(string1: str, string2: str) -> bool: """ Compares two strings character by character to determine if they are equal. Args: string1 (str): The first string to compare. string2 (str): The s...
python_sharegpt_23k
9,483
Write a Python function to remove all empty strings from a given list of strings. The function should not use any built-in array manipulation methods such as `filter`, `reduce`, or `map`. 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 ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_empty_strings(arr: List[str]) -> List[str]: """ Removes all empty strings from the given list of strings. Args: arr (List[str]): The list of strings from which to remove empty str...
python_sharegpt_23k
9,484
Write a Python function to extract all possible subsequences of a specified length `n` from a given string `s`. The function should return a list of all the subsequences. The code should start with: ```python from typing import List def extract_subsequences(s: str, n: int) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def extract_subsequences(s: str, n: int) -> List[str]: """ Extract all possible subsequences of length n from the given string s. Args: s (str): The input string from which to extract subseq...
python_sharegpt_23k
9,486
Write a Python function to find the next palindrome number greater than a given integer `N`. A palindrome is a number that reads the same forward and backward. If `N` is already a palindrome, the function should find the next smallest palindrome greater than `N`. The code should start with: ```python def find_next_pal...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(num: int) -> bool: """ Check if a given number is a palindrome. Args: num (int): The number to check. Returns: bool: True if the number is a palindrome, False otherwise. """ # ...