source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
15,347
Write a Python function to trim a string by removing leading and trailing whitespace characters, and also remove any consecutive whitespace characters within the string. The string may contain punctuation marks and special characters, which should be preserved in the final result. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python import re def trim_string(input_string: str) -> str: """ Trims a string by removing leading and trailing whitespace characters, and also removes any consecutive whitespace characters within the string. Punctuation marks and...
python_sharegpt_23k
15,348
Write a Python function to parse a list of numbers from a given string, where the string may contain duplicates and negative numbers. The function should ensure that the parsed numbers are sorted in descending order and remove any numbers that are divisible by 3. 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 parse_and_filter_numbers(s: str) -> List[int]: """ Parses a list of numbers from a given string, removes duplicates, sorts them in descending order, and removes any numbers that are divisible by ...
python_sharegpt_23k
15,351
Write a Python function to generate the Fibonacci sequence up to a given index `n` and compute the sum of all Fibonacci numbers up to that index. The function should handle negative indices by returning an empty sequence and a sum of 0. The function should also correctly handle the base cases for indices 0 and 1. The ...
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 Fibonacci sequence up to the given index n and compute the sum of all Fibonacci numbers up to that index. Arg...
python_sharegpt_23k
15,352
Write a Python function to calculate the product of two positive integers without using the multiplication operator (`*`) or any built-in multiplication functions. The function should have a time complexity of O(log n), where n is the value of the larger integer, and a space complexity of O(1). The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python def multiply_without_operator(x: int, y: int) -> int: """ Calculate the product of two positive integers without using the multiplication operator (*). Args: x (int): The first positive integer. y (int): The...
python_sharegpt_23k
15,355
Write a Python function to filter out even numbers from a given list of integers and return a new list containing only the odd numbers. The function should not use any built-in functions or methods for filtering, such as `filter`, `lambda`, or list comprehensions. The function 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 filter_odd_numbers(nums: List[int]) -> List[int]: """ Filters out even numbers from the given list of integers and returns a new list with only the odd numbers. Args: nums (List[int]): T...
python_sharegpt_23k
15,357
Write a Python function to compute the exclusive OR (XOR) of two binary numbers represented as strings. The function should return the result as a list of strings, where each string represents a bit of the resulting binary number. The function should only use bitwise operators and have a time complexity of O(n), where ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def xor_binary_numbers(a: str, b: str) -> List[str]: """ Computes the exclusive OR (XOR) of two binary numbers represented as strings. Args: a (str): The first binary number as a string. ...
python_sharegpt_23k
15,359
Write a Python function to rotate a given 2D array 90 degrees clockwise using a recursive approach. The function should not use any built-in functions or libraries, and it should only use basic Python operations and data structures. The function should handle arrays with duplicate values. 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 rotate_2d_array_recursive(matrix: List[List[int]]) -> List[List[int]]: """ Rotates a given 2D array 90 degrees clockwise using a recursive approach. Args: matrix (List[List[int]]): The 2...
python_sharegpt_23k
15,361
Write a Python function to transpose a 2D array from column-major format to row-major format. The array is a square matrix where each element is a string representing a binary number. The function should convert each binary number to its corresponding decimal value and transpose the matrix accordingly. The time complex...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def transpose_binary_matrix(matrix: List[List[str]]) -> List[List[int]]: """ Transposes a 2D array from column-major format to row-major format and converts each binary string to its corresponding decima...
python_sharegpt_23k
15,370
Write a Python function to check if a given string contains only prime numbers and output the largest prime number found in the string. If the string contains non-prime numbers or non-digit characters, the function should return `None`. The function should start with: ```python def largest_prime_in_string(input_string:...
Here is the Python code to solve the given problem in the markdown block: ```python 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, False otherwise. """ if num ...
python_sharegpt_23k
15,375
Write a Python function to calculate the total number of seconds in a given number of hours and minutes. The function should validate the input to ensure that both hours and minutes are non-negative integers, with hours not exceeding 24 and minutes not exceeding 60. If the input is invalid, the function should return t...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_total_seconds(hours: int, minutes: int) -> int or str: """ Calculate the total number of seconds in a given number of hours and minutes. Args: hours (int): The number of hours, must be a non-negative i...
python_sharegpt_23k
15,377
Write a Python function to remove all duplicate characters from a given string while maintaining the original order of the characters. The string may contain any printable ASCII characters including alphanumeric characters, special characters, and punctuation. The function should handle multiple occurrences of the same...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_duplicates(string: str) -> str: """ Removes all duplicate characters from the given string while maintaining the original order of characters. Args: string (str): The input string from which duplicates ar...
python_sharegpt_23k
15,378
Write a Python function that takes a string as input and returns a string where each character of the input string is repeated five times, with a comma and space in between each repetition. The function should have a time complexity of O(n), where n is the length of the input string. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python def repeat_characters(string: str) -> str: """ Repeats each character in the input string five times, with a comma and space in between each repetition. Args: string (str): The input string whose characters are to b...
python_sharegpt_23k
15,382
Write a Python function to populate an array with numbers from 1 to 100, excluding any numbers that are divisible by both 2 and 3. The function should return the populated array. The code should start with: ```python from typing import List def populate_array_with_exclusions() -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def populate_array_with_exclusions() -> List[int]: """ Populate an array with numbers from 1 to 100, excluding any numbers that are divisible by both 2 and 3. Returns: List[int]: A list cont...
python_sharegpt_23k
15,389
Write a Python function to reverse a given string while ignoring leading and trailing whitespace, treating uppercase and lowercase characters as equal, and handling special characters and numbers. The function should not use any built-in string manipulation functions or libraries, and should only use basic string opera...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(string: str) -> str: """ Reverses a given string while ignoring leading and trailing whitespace, treating uppercase and lowercase characters as equal, and handling special characters and numbers. The f...
python_sharegpt_23k
15,392
Write a Python function to replace the word "Hello" with "Goodbye" in a given string, ensuring that the replacement is case-sensitive and only occurs if "Hello" appears at the beginning of a sentence (i.e., capitalized, followed by a comma, and preceded by a space). Additionally, if the word "Hello" appears multiple ti...
Here is the Python code to solve the given problem in the markdown block: ```python import re def replace_hello_with_goodbye(sentence: str) -> str: """ Replaces the word "Hello" with "Goodbye" in a given string, ensuring that the replacement is case-sensitive and only occurs if "Hello" appears at the begin...
python_sharegpt_23k
15,393
Write a Python function to compare two strings for equality without using any built-in string comparison functions or operators (such as `==`, `!=`, or `strcmp`). The function must implement its own algorithm to compare the strings character by character and must have a time complexity of O(n), where n is the length of...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_strings(str1: str, str2: str) -> bool: """ Compares two strings for equality without using any built-in string comparison functions or operators. Args: str1 (str): The first string to compare. st...
python_sharegpt_23k
15,398
Write a Python function to find the maximum value and its index in a given array of integers using a recursive approach. The function should return a tuple containing the maximum value and its index in the original sequence. The code should start with: ```python from typing import List, Tuple def find_max_value_recur...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_max_value_recursive(arr: List[int]) -> Tuple[int, int]: """ Find the maximum value and its index in a given array of integers using a recursive approach. Args: arr (List[int]...
python_sharegpt_23k
15,402
Write a Python function to calculate the sum of squares of a list of numbers. The function should be optimized for performance using Cython, and you should provide both the Python and Cython implementations. Additionally, include a detailed explanation of how each language handles memory management and provide code exa...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_squares_python(numbers: List[int]) -> int: """ Calculate the sum of squares of a list of integers using pure Python. Args: numbers (List[int]): A list of integers. Returns: ...
python_sharegpt_23k
15,405
Write a Python function to divide a given list into two equal halves and return them as a tuple of two lists. The input list will always have an even number of elements. The code should start with: ```python from typing import List, Tuple def divide_list_into_halves(lst: List[int]) -> Tuple[List[int], List[int]]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Tuple def divide_list_into_halves(lst: List[int]) -> Tuple[List[int], List[int]]: """ Divides a given list into two equal halves and returns them as a tuple of two lists. Args: lst (List[...
python_sharegpt_23k
15,413
Write a Python function to calculate the sum of the first n prime numbers. The function should take an integer `n` as input and return the sum of the first `n` prime numbers. The function should start with: ```python def sum_of_first_n_primes(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python 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, False otherwise. """ if num ...
python_sharegpt_23k
15,416
Write a Python function to retrieve the value of a variable from a given environment, which is represented as a nested dictionary. The variable should be a string representation of the keys to access the value, using dot notation for nested dictionaries. The function should handle potential errors gracefully by returni...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Dict, Optional def get_value_from_environment(env: Dict[str, Any], variable: str) -> Optional[int]: """ Retrieve the value of a variable from a nested dictionary environment using a string representation...
python_sharegpt_23k
15,420
Write a Python function to find the maximum difference between any two numbers in a given array. The array can contain negative numbers and float values, and it should have a length of at least 3. The function should efficiently compute the maximum difference. 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 find_max_difference(arr: List[int]) -> float: """ Find the maximum difference between any two numbers in the given array. Args: arr (List[int]): The array of numbers (can contain negativ...
python_sharegpt_23k
15,425
Write a Python function to generate a list of prime numbers within a given range [start, end] (inclusive) using a recursive approach. The function should not use any built-in library functions to check for prime numbers. The code should start with: ```python from typing import List def generate_primes_in_range(start: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int, i: int = 2) -> bool: """ Recursively checks if a number is prime. Args: n (int): The number to check for primality. i (int): The current divisor to check (defaul...
python_sharegpt_23k
15,427
Write a Python function to return the character at the specified index in a given string, handling out-of-bounds index errors gracefully. Additionally, if the index is negative, return the character starting from the end of the string. If the index is a float, round it down to the nearest integer before finding the cha...
Here is the Python code to solve the given problem in the markdown block: ```python def get_character_at_index(s: str, index: float) -> str: """ Returns the character at the specified index in the given string, handling out-of-bounds index errors gracefully. If the index is negative, it returns the characte...
python_sharegpt_23k
15,428
Write a Python function to reverse a list of integers without using the built-in `reverse()` method, the `[::-1]` slicing syntax, or any temporary data structures such as lists or arrays. The function should only use basic operations like swapping elements, indexing, and iteration to achieve the reverse order. The cod...
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]: """ Reverses a list of integers in place without using built-in reverse methods or temporary data structures. Args: lst (List[int]): The list o...
python_sharegpt_23k
15,429
Write a Python function to find and return the positions of all zero elements in a given matrix. The matrix will always have at least one zero element. If no zero element is found, return an empty list. The matrix can have at most 100 rows and 100 columns. 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_zero_positions(matrix: List[List[int]]) -> List[List[int]]: """ Find and return the positions of all zero elements in a given matrix. Args: matrix (List[List[int]]): A 2D list repre...
python_sharegpt_23k
15,436
Write a Python function to transpose a given square matrix. The matrix is represented as a list of lists, where each inner list represents a row of the matrix. The transpose of a matrix is obtained by swapping its rows with columns. The function should handle matrices of size ranging from 1x1 to 10x10, with elements be...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def transpose_matrix(matrix: List[List[int]]) -> List[List[int]]: """ Transposes a given square matrix. Args: matrix (List[List[int]]): The input square matrix represented as a list of lists...
python_sharegpt_23k
15,442
Write a Python function to sort a given list in descending order while ignoring any duplicate values. The function should ensure that the time complexity of the sorting algorithm is O(n log n) and should not use any built-in sorting functions or libraries. 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 sort_descending_unique(my_list: List[int]) -> List[int]: """ Sorts the given list in descending order while ignoring any duplicate values. The sorting algorithm has a time complexity of O(n log n...
python_sharegpt_23k
15,443
Write a Python function to calculate the sum of unique elements in a given list of integers. The list may contain both positive and negative integers, and may have duplicates. The sum should only include the unique elements in the list. The function should handle edge cases such as an empty list, a list with only one e...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_unique_elements(my_list: List[int]) -> int: """ Calculate the sum of unique elements in a given list of integers. Args: my_list (List[int]): The list of integers from which to cal...
python_sharegpt_23k
15,444
Write a Python function to create a dictionary consisting of the names of the seven dwarfs and a list of their ages, sorted in descending order. The solution should have a time complexity of O(n log n), where n is the number of dwarfs. The code should start with: ```python from typing import Dict, List def sort_dwarf...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def sort_dwarfs_ages(dwarfs: Dict[str, List[int]]) -> Dict[str, List[int]]: """ Create a dictionary consisting of the names of the seven dwarfs and a list of their ages, sorted in descending order....
python_sharegpt_23k
15,450
Write a Python function to determine the larger of two given positive integers, ensuring both integers are prime numbers within the range of 1 to 100, inclusive. If any of the integers are not prime numbers or are outside the specified range, the function should raise a `ValueError` with a descriptive error message. T...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(num: int) -> bool: """ Check 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
15,452
Write a Python function to calculate the nth Fibonacci number using memoization to optimize the recursive approach. The function should use a dictionary to store previously computed Fibonacci numbers to avoid redundant calculations. The code should start with: ```python def fibonacci_memoized(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci_memoized(n: int) -> int: """ Calculate the nth Fibonacci number using memoization to optimize the recursive approach. Args: n (int): The position in the Fibonacci sequence to calculate. Returns: ...
python_sharegpt_23k
15,461
Write a Python function to calculate the Fibonacci number at a given index using an iterative approach without using recursion or any loops. The function should leverage matrix exponentiation to achieve this efficiently. The code should start with: ```python from typing import List def fibonacci_matrix(index: int) ->...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def fibonacci_matrix(index: int) -> int: """ Calculate the Fibonacci number at a given index using matrix exponentiation. Args: index (int): The index of the Fibonacci number to calculate. ...
python_sharegpt_23k
15,472
Write a Python function to compute the square root of a positive integer number `N` (where `N > 0`), and return both the exact square root and the rounded square root. The function should handle cases where the square root is not an integer. The code should start with: ```python import math def compute_square_root(N:...
Here is the Python code to solve the given problem in the markdown block: ```python import math def compute_square_root(N: int) -> tuple: """ Compute the square root of a positive integer N and return both the exact and rounded square roots. Args: N (int): A positive integer greater than 0. R...
python_sharegpt_23k
15,476
Write a Python function `multiply_without_operator` that takes two integers as input and returns their product without using the multiplication operator (`*`). The function should handle negative numbers and should not use any built-in Python functions for multiplication. The function should have the following signatur...
Here is the Python code to solve the given problem in the markdown block: ```python def multiply_without_operator(num_1: int, num_2: int) -> int: """ Multiplies two integers without using the multiplication operator (*). Args: num_1 (int): The first integer. num_2 (int): The second integer....
python_sharegpt_23k
15,477
Write a Python function to delete all occurrences of a specified element from a given list while maintaining the relative order of the remaining elements. The function should handle cases where the element to be deleted appears multiple times in the list. The code should start with: ```python from typing import List d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def delete_element(arr: List[int], element: int) -> List[int]: """ Deletes all occurrences of the specified element from the given list while maintaining the relative order of the remaining elements. ...
python_sharegpt_23k
15,478
Write a Python function to find the total number of elements in a given list, including elements in nested lists, without using any built-in functions or methods. The function should recursively count all elements, including those within nested lists. The code should start with: ```python def count_elements(lst): ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_elements(lst): """ Counts the total number of elements in a given list, including elements in nested lists. Args: lst (list): The list to count elements from, which may contain nested lists. Returns: ...
python_sharegpt_23k
15,483
Write a Python function to sort a given list of numbers in ascending order using the Bubble Sort algorithm. The function should not use any built-in sorting functions or methods. The solution should be implemented using only basic programming constructs and algorithms. Additionally, the algorithm should have a time com...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(numbers: List[int]) -> List[int]: """ Sorts a given list of numbers in ascending order using the Bubble Sort algorithm. Args: numbers (List[int]): The list of numbers to be s...
python_sharegpt_23k
15,485
Write a Python function to remove all occurrences of a given element from a list of integers and return the number of times the element was removed. The function should modify the original list in place and return an integer representing the count of removals. 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 remove_element_and_count(arr: List[int], remove_element: int) -> int: """ Removes all occurrences of a given element from a list of integers and returns the number of times the element was removed. ...
python_sharegpt_23k
15,492
Write a Python function to reverse a given list of numbers and return a new list containing only the prime numbers from the reversed list. The function should start with: ```python from typing import List def reverse_and_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 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, False other...
python_sharegpt_23k
15,494
Write a Python function to filter out and return only the positive integers from a given list of integers, maintaining their original order. If there are no positive integers in the input list, the function should return an empty list. The function should have a time complexity of O(n), where n is the length of the inp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_positive_integers(lst: List[int]) -> List[int]: """ Filters out and returns only the positive integers from the given list, maintaining their original order. Args: lst (List[int]): T...
python_sharegpt_23k
15,498
Write a Python function to determine if a given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward. The function should return a boolean value indicating whether the input string is a palindrome or not. The function should have a time...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(s: str) -> bool: """ Determines if a given string is a palindrome. Args: s (str): The input string to check. Returns: bool: True if the input string is a palindrome, False otherwise. ...
python_sharegpt_23k
15,502
Write a Python function to calculate the sum of the values in a given list using a for loop. You are not allowed to use the `sum()` function or any built-in functions to calculate the sum. Additionally, you are not allowed to use the multiplication operator or any other arithmetic operation more than once. You must man...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def manual_sum(lst: List[int]) -> int: """ Calculate the sum of the values in a given list using a for loop. Args: lst (List[int]): The list of integers to sum. Returns: int: Th...
python_sharegpt_23k
15,508
Write a Python function to reverse the characters in a given string and return the reversed string. The function should only use built-in Python functions and should not use any third-party libraries or packages. The code should start with: ```python def reverse_string(word: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(word: str) -> str: """ Reverses the characters in the given string and returns the reversed string. Args: word (str): The input string to be reversed. Returns: str: The reversed strin...
python_sharegpt_23k
15,512
Write a Python function to generate a tryptic joke about a popular movie, utilizing wordplay, puns, and references to popular culture. The function should take a movie title, a hero, a villain, a weapon, and a team as inputs and return a list of three jokes. Each joke should be structured in a way that incorporates the...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import random def generate_tryptic_joke(movie: str, hero: str, villain: str, weapon: str, team: str) -> List[Tuple[str, str, str, str, str]]: """ Generates a tryptic joke about a popular movie, ut...
python_sharegpt_23k
15,514
Write a Python function to generate a random code that consists of four characters: two uppercase letters followed by two numbers. The letters represent the initials of a program name, the first number represents the number of trees in an outdoor classroom, and the second number represents the total number of students ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple import random import string def generate_outdoor_classroom_code() -> Tuple[str, int, int]: """ Generates a random code for an outdoor classroom that consists of four characters: two uppercase letter...
python_sharegpt_23k
15,515
Write a Python function to generate a string that emphasizes a given word or phrase using the "epizeuxis" rhetorical device, which involves repeating the word or phrase in quick succession. The function should allow customization of the number of repetitions and the punctuation used for emphasis. The code should start ...
Here is the Python code to solve the given problem in the markdown block: ```python def emphasize_with_epizeuxis(phrase: str, repetitions: int = 3, punctuation: str = "!") -> str: """ Generates a string that emphasizes a given word or phrase using the "epizeuxis" rhetorical device. Args: phrase (st...
python_sharegpt_23k
15,523
Write a Python function to correct common typos in a given text using regular expressions. The function should identify and correct specific typos such as missing letters, transposed letters, and extra letters. The function should return the corrected text. The code should start with: ```python import re def correct_...
Here is the Python code to solve the given problem in the markdown block: ```python import re def correct_typos(text: str) -> str: """ Corrects common typos in a given text using regular expressions. Args: text (str): The input text containing typos. Returns: str: The corrected text w...
python_sharegpt_23k
15,531
Write a Python function that applies a given mathematical formula to each element in a list of integers using the `map()` function. The mathematical formula should be defined as a separate function. The function should return the transformed list. The code should start with: ```python from typing import List def appl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def complex_formula(num: int) -> int: """ A complex mathematical formula applied to each element in the list. Args: num (int): The integer to which the formula is applied. Returns: ...
python_sharegpt_23k
15,534
Write a Python function to calculate the sum of the squares of a list of numbers. The function should be efficient and capable of handling lists of varying lengths, complexities, and data types. Additionally, consider the potential impacts of utilizing different programming languages, libraries, and frameworks on the o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_squares(lst: List[int]) -> int: """ Calculate the sum of the squares of a list of integers. Args: lst (List[int]): A list of integers for which the sum of squares is to be calcula...
python_sharegpt_23k
15,536
Write a Python function to extract unique elements from a given list while preserving the order of their first appearance. The function should take a list of elements as input and return a list of unique elements in the order they first appear in the input list. The code should start with: ```python from typing import...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def extract_unique_elements(input_list: List[int]) -> List[int]: """ Extracts unique elements from the given list while preserving the order of their first appearance. Args: input_list (List...
python_sharegpt_23k
15,539
Write a Python function to generate a random sequence of 10 characters according to the following rules: 1. The first character is always an uppercase letter. 2. The next three characters are digits between 0 and 9. 3. The next four characters are lowercase letters. 4. The last two characters are either the special cha...
Here is the Python code to solve the given problem in the markdown block: ```python import random import string def generate_random_sequence() -> str: """ Generates a random sequence of 10 characters according to the following rules: 1. The first character is always an uppercase letter. 2. The next thr...
python_sharegpt_23k
15,540
Write a Python function to convert a traditional Italian tiramisu recipe into a vegan version by modifying the ingredient list. The function should replace non-vegan ingredients with their vegan alternatives while maintaining the classic taste of the dish. 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 convert_to_vegan_tiramisu(ingredients: List[str]) -> List[str]: """ Converts a traditional Italian tiramisu recipe into a vegan version by replacing non-vegan ingredients with vegan alternatives. ...
python_sharegpt_23k
15,545
Write a Python function to calculate the sales tax and deduct it from a given subtotal. The function should take the subtotal and the tax rate as inputs and return the total amount after deducting the sales tax. The code should start with: ```python def calculate_total_after_tax(subtotal: float, tax_rate: float) -> flo...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_total_after_tax(subtotal: float, tax_rate: float) -> float: """ Calculate the total amount after deducting the sales tax from the given subtotal. Args: subtotal (float): The initial amount before tax. ...
python_sharegpt_23k
15,547
Write a Python function to find the missing word in a sentence using a list of sunrise times. The function should take a list of sunrise times in string format and a target date in string format, and return the missing word in the sentence "The sun rose _____ the horizon on [target date]." The missing word should be th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import datetime def find_missing_word(sunrise_times: List[str], target_date: str) -> str: """ Finds the missing word in the sentence "The sun rose _____ the horizon on [target date]." using a list of...
python_sharegpt_23k
15,549
Write a Python function to add a suffix to a given word and return the new word. The function should handle cases where the suffix is an empty string or the word is an empty string. The code should start with: ```python def add_suffix(word: str, suffix: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def add_suffix(word: str, suffix: str) -> str: """ Adds a suffix to a given word and returns the new word. Args: word (str): The base word to which the suffix will be added. suffix (str): The suffix to be ad...
python_sharegpt_23k
15,552
Write a Python function to determine whether a given number is even or odd. The function should return a string indicating "Even" or "Odd". The code should start with: ```python def is_even_or_odd(number: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_even_or_odd(number: int) -> str: """ Determine whether the given number is even or odd. Args: number (int): The number to be checked. Returns: str: A string indicating "Even" if the number is eve...
python_sharegpt_23k
15,554
Write a Python function to generate a random zodiac sign belonging to the fire element. The function should return the name of the zodiac sign as a string. The code should start with: ```python from typing import List import random def get_random_fire_sign() -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List import random def get_random_fire_sign() -> str: """ Generates a random zodiac sign belonging to the fire element. Returns: str: The name of a randomly selected fire element zodiac sign. ...
python_sharegpt_23k
15,557
Write a Python function to describe a place that holds special significance to you. The function should include the name of the place, its location, a brief description, sensory experiences that made it memorable, and any historical or cultural significance of the location. The function should return a dictionary conta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def describe_special_place() -> Dict: """ Describes a place that holds special significance, including its name, location, description, sensory experiences, and historical/cultural significance. Ret...
python_sharegpt_23k
15,559
Write a Python function to filter and list out the specialized kitchen equipment required for molecular gastronomy dishes based on a given list of equipment. The function should also allow filtering by a keyword to include only equipment that contains the keyword. 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 filter_molecular_gastronomy_equipment(equipment_list: List[str], keyword: str = None) -> List[str]: """ Filters and lists out the specialized kitchen equipment required for molecular gastronomy dishe...
python_sharegpt_23k
15,567
Write a Python function to reverse the words in a given string while maintaining the order of the words. For example, if the input string is "Hello world this is a test", the output should be "test a is this world Hello". The function should handle strings with multiple spaces between words and leading/trailing spaces....
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_words_in_string(s: str) -> str: """ Reverses the words in the given string while maintaining the order of the words. Args: s (str): The input string containing words to be reversed. Returns: ...
python_sharegpt_23k
15,577
Write a Python function that takes two integers as input and returns their sum. Additionally, the function should print the sum using the `print` statement. The function should be named `sum_two_numbers` and should start with: ```python def sum_two_numbers(num1: int, num2: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_two_numbers(num1: int, num2: int) -> int: """ Calculate the sum of two integers and print the result. Args: num1 (int): The first integer. num2 (int): The second integer. Returns: int: T...
python_sharegpt_23k
15,580
Write a Python function to sort a list of objects by their color (in the order: red, green, blue) and then by their size (from small to large). Each object is represented as a dictionary with keys: `name`, `color`, `size`, and `rgb`. The function should return the sorted list of objects. Additionally, the function shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def sort_objects_by_color_and_size(objects: List[Dict[str, any]]) -> List[Dict[str, any]]: """ Sorts a list of objects by their color (in the order: red, green, blue) and then by their size (from s...
python_sharegpt_23k
15,581
Write a Python function that takes two arguments: an integer `x` and a list of integers `y`, and returns a list of integers that are the result of multiplying `x` with each element in `y`. Additionally, write a function to calculate the sum of the resulting list. The code should start with: ```python from typing import...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def multiply_elements(x: int, y: List[int]) -> List[int]: """ Multiplies each element in the list `y` by the integer `x`. Args: x (int): The integer to multiply each element in the list by. ...
python_sharegpt_23k
15,582
Write a Python function to generate a classification puzzle involving nocturnal mammals that live in underground burrows in the African savannah. The function should return a nested dictionary containing information about the burrow dimensions and details about the mammals. The outer dictionary should include keys 'bur...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def generate_classification_puzzle(mammals: List[Dict[str, str]]) -> Dict[str, any]: """ Generates a classification puzzle for nocturnal mammals that live in underground burrows in the African sava...
python_sharegpt_23k
15,584
Write a Python function to calculate the sum of the squares of all the odd numbers between 1 and a given positive integer `n`, inclusive. The function should return a list of tuples, where each tuple contains an odd number, its square, and the running sum of the squares up to that number. The function should also ensur...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def sum_of_squares_of_odds(n: int) -> List[Tuple[int, int, int]]: """ Calculate the sum of the squares of all the odd numbers between 1 and n, inclusive. Returns a list of tuples where each tu...
python_sharegpt_23k
15,603
Write a Python function to generate a random five-word sentence describing a day. The sentence should be structured as follows: an adjective, a noun, a verb, another adjective, and another noun. The function should take no arguments and return the generated sentence as a string. The code should start with: ```python f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_random_sentence() -> str: """ Generates a random five-word sentence describing a day. The sentence structure is: adjective, noun, verb, adjective, noun. Returns: ...
python_sharegpt_23k
15,609
Write a Python function to shift all the letters in a given string two characters ahead in the alphabet. For example, if the input string is "apple", the output should be "crrng". The function should handle both uppercase and lowercase letters and wrap around the alphabet if necessary (e.g., 'z' should become 'b' and '...
Here is the Python code to solve the given problem in the markdown block: ```python def shift_letters_by_two(word: str) -> str: """ Shifts all the letters in the given string two characters ahead in the alphabet. Non-alphabetic characters remain unchanged. Args: word (str): The input string to ...
python_sharegpt_23k
15,613
Write a Python function that generates a LaTeX formula representing the sentence "She who enjoys jogging on the seashore" using a given subject. The function should also incorporate a table of synonyms for "run" and "beach" that it can utilize. The function should start with: ```python from typing import Dict def gene...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict import random def generate_latex_formula(subject: str, synonyms: Dict[str, list]) -> str: """ Generates a LaTeX formula representing the sentence "She who enjoys jogging on the seashore" using a given su...
python_sharegpt_23k
15,615
Write a Python function to sort a list of words in alphabetical order, ignoring case and excluding duplicates. The function should take a list of strings as input and return a sorted list of unique words in lowercase. The code should start with: ```python from typing import List def sort_words_ignore_case(words: List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_words_ignore_case(words: List[str]) -> List[str]: """ Sorts a list of words in alphabetical order, ignoring case and excluding duplicates. Args: words (List[str]): A list of words t...
python_sharegpt_23k
15,619
Write a Python function to convert a given temperature in Celsius to Fahrenheit using the formula `(Celsius * 9/5) + 32`. The function should be able to handle both positive and negative temperatures. Additionally, create a function that generates a table of Fahrenheit equivalents for Celsius temperatures ranging from ...
Here is the Python code to solve the given problem in the markdown block: ```python def celsius_to_fahrenheit(celsius: float) -> float: """ Convert a given temperature in Celsius to Fahrenheit. Args: celsius (float): The temperature in Celsius to be converted. Returns: float: The tempe...
python_sharegpt_23k
15,620
Write a Python function to invert the order of words in a given sentence. The function should take a string as input and return a new string with the words in reverse order. The code should start with: ```python def invert_sentence_order(sentence: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def invert_sentence_order(sentence: str) -> str: """ Inverts the order of words in a given sentence. Args: sentence (str): The input sentence whose words need to be inverted. Returns: str: A new sentenc...
python_sharegpt_23k
15,622
Write a Python function to determine whether a given sentence is a pangram. A pangram is a sentence that contains every letter of the alphabet at least once. The function should take a string as input and return a boolean value indicating whether the string is a pangram or not. The function should be case-insensitive a...
Here is the Python code to solve the given problem in the markdown block: ```python def is_pangram(sentence: str) -> bool: """ Determines whether a given sentence is a pangram. A pangram is a sentence that contains every letter of the alphabet at least once. This function is case-insensitive and ignore...
python_sharegpt_23k
15,629
Write a Python function to generate a random string of a specified length using a combination of uppercase letters, lowercase letters, and digits. The function should allow the user to specify the length of the string and should return the generated string. 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 import random import string def generate_random_string(length: int) -> str: """ Generates a random string of the specified length using a combination of uppercase letters, lowercase letters, and digits. ...
python_sharegpt_23k
15,637
Write a Python function to extract all valid email addresses from a given text string. The function should use regular expressions to identify and return a list of all email addresses found in the text. The code should start with: ```python from typing import List import re def extract_emails(text: str) -> List[str]: ...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List import re def extract_emails(text: str) -> List[str]: """ Extracts all valid email addresses from a given text string. Args: text (str): The text string from which to extract email address...
python_sharegpt_23k
15,638
Write a Python function to reverse an array of integers that includes both positive and negative integers. The function should take a list of integers as input and return the reversed list. The code 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 an array of integers in place. Args: arr (List[int]): The array of integers to be reversed. Returns: List[int]: The ...
python_sharegpt_23k
15,640
Write a Python function to calculate the time difference in seconds between the current date and time and the exact moment when Neil Armstrong first set foot on the Moon's surface, considering the time zone differences. The function should also return a list of fascinating yet less popular facts or events linked to the...
Here is the Python code to solve the given problem in the markdown block: ```python import datetime from typing import List def time_difference_to_moon_landing() -> (float, List[str]): """ Calculate the time difference in seconds between the current date and time and the exact moment when Neil Armstrong first ...
python_sharegpt_23k
15,644
Write a Python function to extract product names and brands from a given paragraph using regular expressions. The function should be able to identify product names like "iPhone 12 Pro Max" and "Watch Series 6" and brand names like "Apple". The code should start with: ```python from typing import List, Tuple import re ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import re def extract_products_and_brands(paragraph: str) -> Tuple[List[str], List[str]]: """ Extracts product names and brands from a given paragraph using regular expressions. Args: ...
python_sharegpt_23k
15,646
Write a Python function to generate a random color in RGB format and provide a clue based on the dominant color component (red, green, or blue) to help solve a riddle. The riddle is: "I am vast and constantly shifting, my magnificence is limitless, I display serene nature yet fierce intensity, and I am teeming with lif...
Here is the Python code to solve the given problem in the markdown block: ```python import random def generate_color_clue() -> tuple: """ Generates a random color in RGB format and provides a clue based on the dominant color component to help solve a riddle. The riddle is: "I am vast and constantly shifti...
python_sharegpt_23k
15,647
Write a Python function to arrange a list of words in alphabetical order and then output the resulting sentence as a string. The function should take a list of words as input and return the sorted sentence. The code should start with: ```python from typing import List def sort_sentence(words: List[str]) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_sentence(words: List[str]) -> str: """ Arrange a list of words in alphabetical order and return the resulting sentence as a string. Args: words (List[str]): A list of words to be so...
python_sharegpt_23k
15,648
Write a Python function to extract all numerical values from a given string while removing all HTML elements. The function should return a list of these numerical values. The code should start with: ```python from typing import List import re def extract_numbers_from_string(input_string: str) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def extract_numbers_from_string(input_string: str) -> List[str]: """ Extracts all numerical values from a given string while removing all HTML elements. Args: input_string (str): T...
python_sharegpt_23k
15,652
Write a Python function to extract all bigrams (consecutive pairs of words) from a given text. The function should return a list of tuples where each tuple contains a pair of words. The code should start with: ```python from typing import List, Tuple def extract_bigrams(text: str) -> List[Tuple[str, str]]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Tuple def extract_bigrams(text: str) -> List[Tuple[str, str]]: """ Extracts all bigrams (consecutive pairs of words) from the given text. Args: text (str): The input text from which to ex...
python_sharegpt_23k
15,659
Write a Python function to generate a random number between 1 and 100 that is not divisible by 5. The function should ensure that the generated number meets this criterion. The code should start with: ```python import random def generate_random_number() -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python import random def generate_random_number() -> int: """ Generates a random number between 1 and 100 that is not divisible by 5. Returns: int: A random number between 1 and 100 that is not divisible by 5. """ ...
python_sharegpt_23k
15,660
Write a Python function to generate a personalized letter of recommendation for a candidate, incorporating their professional achievements, personal qualities, work ethic, and leadership abilities. The letter should be properly addressed to the intended recipient and include the recommender's contact information for fo...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_letter_of_recommendation(recipient: str, position: str, length_of_time: str, professional_achievements: str, personal_qualities: str, work_ethic_and_leadership_abilities: str, recommender_name: str, recommender_contact_info...
python_sharegpt_23k
15,662
Write a Python function to generate a 30-minute high-intensity interval training (HIIT) workout plan that incorporates running and cycling. The workout should consist of 5 cycles, each with a duration of 6 minutes. In each cycle, the client should alternate between running and cycling for 30 seconds each, with a 30-sec...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_hiit_workout_plan(): """ Generates a 30-minute high-intensity interval training (HIIT) workout plan. The workout consists of 5 cycles, each lasting 6 minutes. In each cycle, the client alternates between ru...
python_sharegpt_23k
15,664
Write a Python function to filter out all odd numbers from a given list and then sort the remaining even numbers in descending order. The function should return the sorted list of even numbers. The code should start with: ```python from typing import List def sort_evens_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 sort_evens_descending(arr: List[int]) -> List[int]: """ Filters out all odd numbers from the input list and sorts the remaining even numbers in descending order. Args: arr (List[int]): T...
python_sharegpt_23k
15,671
Write a Python function to calculate the age of a person when they completed a specific work, given their birth year and the year they completed the work. The function should return the age as an integer. The code should start with: ```python def calculate_age_at_completion(birth_year: int, completion_year: int) -> in...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_age_at_completion(birth_year: int, completion_year: int) -> int: """ Calculate the age of a person when they completed a specific work. Args: birth_year (int): The birth year of the person. com...
python_sharegpt_23k
15,672
Write a Python function to generate a random French musical term from a predefined list of terms. The function should return the randomly selected term as a string. The code should start with: ```python from typing import List import random def generate_random_french_term(terms: List[str]) -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List import random def generate_random_french_term(terms: List[str]) -> str: """ Generates a random French musical term from a given list of terms. Args: terms (List[str]): A list of French mus...
python_sharegpt_23k
15,673
Write a Python function to generate a sentence that includes the words 'mango', 'colossal', and 'section' in a specific order. The sentence should always start with 'A colossal mango', followed by 'section' in the middle, and end with 'was found in the section'. The code should start with: ```python def generate_senten...
Here is the Python code to solve the given problem in the markdown block: : ```python def generate_sentence() -> str: """ Generates a sentence that includes the words 'mango', 'colossal', and 'section' in a specific order. The sentence structure is: "A colossal mango section was found in the section." ...
python_sharegpt_23k
15,676
Write a Python function to convert a given string to camelCase. The input string will be in snake_case format, where words are separated by underscores. The function should return the string converted to camelCase, where the first word is in lowercase and subsequent words start with an uppercase letter. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python def to_camel_case(snake_case_string: str) -> str: """ Converts a given snake_case string to camelCase. Args: snake_case_string (str): The input string in snake_case format. Returns: str: The converted s...
python_sharegpt_23k
15,680
Write a Python function to identify the top 3 bodies of water with the most severe water pollution, taking into account the population living in the vicinity of the body of water. The dataset is a list of dictionaries, where each dictionary contains the following fields: - "name": the name of the body of water - "regio...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def top_3_polluted_bodies_of_water(data: List[Dict[str, any]]) -> List[str]: """ Returns the names of the top 3 bodies of water with the most severe water pollution, taking into account the pop...
python_sharegpt_23k
15,682
Write a Python function to perform integer division and return both the quotient and the remainder. The function should handle both positive and negative dividends and divisors. The code should start with: ```python def integer_division(dividend: int, divisor: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def integer_division(dividend: int, divisor: int) -> tuple: """ Perform integer division and return both the quotient and the remainder. Args: dividend (int): The number to be divided. divisor (int): The num...
python_sharegpt_23k
15,694
Write a Python function to reverse a given string. The function should take a string as input and return the reversed version of the string. The code should start with: ```python def reverse_string(string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def reverse_string(string: str) -> str: """ Reverses the given string. Args: string (str): The input string to be reversed. Returns: str: The reversed version of the input string. """ # Use sl...
python_sharegpt_23k
15,695
Write a Python function that randomly selects an idiom from a given list of idioms and returns a tuple containing the idiom and its meaning. The function should handle a list of idioms and their meanings provided as a dictionary, where the keys are the idioms and the values are their meanings. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Tuple import random def get_random_idiom(idioms: Dict[str, str]) -> Tuple[str, str]: """ Randomly selects an idiom from a given dictionary of idioms and their meanings. Args: idioms (Dict[s...
python_sharegpt_23k
15,709
Write a Python function to convert a list of items into a grammatically correct sentence. The sentence should start with "I have ", followed by the items separated by commas, and the last item should be preceded by "and". The sentence should end with " in my basket." 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 list_to_sentence(items: List[str]) -> str: """ Converts a list of items into a grammatically correct sentence. Args: items (List[str]): A list of strings representing items. Returns...
python_sharegpt_23k
15,710
Write a Python function to generate an HTML string that displays a sentence containing the words "blue", "apple", and "school". The word "apple" should be displayed in blue font color, while the words "blue" and "school" should be displayed in black. The function should accept the words as input parameters and return t...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_html_sentence(blue_word: str, apple_word: str, school_word: str) -> str: """ Generates an HTML string that displays a sentence with specific words in different colors. Args: blue_word (str): The word to...
python_sharegpt_23k
15,714
Write a Python function to calculate the sum of all integers in a given list. The function should handle lists of any length, including empty lists. The function should return the sum of the integers in the list. The code should start with: ```python from typing import List def calculate_sum(numbers: List[int]) -> in...
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 integers in the given list. Args: numbers (List[int]): A list of integers. Returns: int: The sum of al...
python_sharegpt_23k
15,725
Write a Python function to normalize a given string by converting all characters to lowercase and removing any special characters or punctuation marks, while preserving the order of the remaining characters. The function should return the normalized string. The code should start with: ```python import re def normaliz...
Here is the Python code to solve the given problem in the markdown block: ```python import re def normalize_string(input_string: str) -> str: """ Normalizes the given string by converting all characters to lowercase and removing any special characters or punctuation marks, while preserving the order of the rem...
python_sharegpt_23k
15,726
Write a Python function to perform integer division and calculate the remainder of the division between two given integers. The function should return the quotient and print the remainder. The code should start with: ```python def integer_division_with_remainder(num1: int, num2: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def integer_division_with_remainder(num1: int, num2: int) -> int: """ Perform integer division of num1 by num2 and calculate the remainder. Print the remainder and return the quotient. Args: num1 (int): The divi...
python_sharegpt_23k
15,727
Write a Python function to generate a random story about a brave young girl and her adventure. The function should create a plot and characters for the story, and then print the story in a structured format. The story should include a protagonist (the brave young girl), an antagonist (a villain), and a series of plot p...
Here is the Python code to solve the given problem in the markdown block: ```python import random def generate_story(): """ Generates a random story about a brave young girl and her adventure. The story includes a protagonist (the brave young girl), an antagonist (a villain), and a series of plot poin...