source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
18,141
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 handle lists of varying lengths and ensure that the words are sorted in a case-insensitive manner. The code should start with: ```python from typing import List def sort_sent...
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: """ Sorts a list of words in alphabetical order (case-insensitive) and returns the resulting sentence as a string. Args: words (List[str]): A li...
python_sharegpt_23k
18,146
Write a Python function to select a random constellation from a predefined list of constellations that are associated with love, beauty, and eternity. The function should return the selected constellation as a string. Additionally, provide a function to generate a chorus line for a love song using the selected constell...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def select_constellation(constellations: List[str]) -> str: """ Selects a random constellation from a list of constellations associated with love, beauty, and eternity. Args: c...
python_sharegpt_23k
18,151
Write a Python function to find the highest number in a list of integers. The function should handle lists of any length and return an error message if the input list is empty or contains non-integer elements. If the input list contains duplicates, the function should return the highest duplicate value. The function sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_highest_number(my_list: List[int]) -> int or str: """ Find the highest number in a list of integers. Args: my_list (List[int]): The list of integers to search for the highest number...
python_sharegpt_23k
18,153
Write a Python function to generate a greeting message with a randomly selected name from a predefined list of names, and append an exclamation mark to the end of the greeting string. The function should return the greeting string. The code should start with: ```python from typing import List import random def genera...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_greeting(names: List[str]) -> str: """ Generates a greeting message with a randomly selected name from a list of names, and appends an exclamation mark to the end of the gr...
python_sharegpt_23k
18,159
Write a Python function to convert a given string to uppercase without using the built-in `upper()` or `capitalize()` methods. The function should handle all characters in the string, converting only lowercase letters (a-z) to their uppercase counterparts (A-Z) while leaving other characters unchanged. The code should...
Here is the Python code to solve the given problem in the markdown block: ```python def to_uppercase(string: str) -> str: """ Converts a given string to uppercase without using the built-in upper() or capitalize() methods. Args: string (str): The input string to be converted to uppercase. Retu...
python_sharegpt_23k
18,160
Write a Python function to find the product with the highest price from a given two-column table. The table is represented as a list of tuples, where each tuple contains a product name and its corresponding price. The function should return the name of the product with the highest price. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_most_expensive_product(table: List[Tuple[str, float]]) -> str: """ Find the product with the highest price from a given table. Args: table (List[Tuple[str, float]]): A list o...
python_sharegpt_23k
18,162
Write a Python function to add a new planet to a given list of planets in the Solar System, ensuring that the new planet follows the naming convention of classical mythology and is within the specified distance range from the sun. The distance range is from 0.39 AU (the distance of Mercury) to 39.5 AU (the distance of ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def add_new_planet(planets: List[str], new_planet: str, distance: float) -> List[str]: """ Adds a new planet to the list of planets in the Solar System if it meets the specified criteria. Args: ...
python_sharegpt_23k
18,163
Write a Python function to return the absolute value of the larger input among two numeric inputs. The function should support both negative numbers and decimals, and it should include comprehensive error handling. The function should raise a `TypeError` if any input is not numeric and a `ValueError` if both inputs are...
Here is the Python code to solve the given problem in the markdown block: ```python def max_abs(a: float, b: float) -> float: """ Returns the absolute value of the larger input among two numeric inputs. Parameters: a (float): A numeric input to compare. b (float): Another numeric input to compare. ...
python_sharegpt_23k
18,165
Write a Python function to process a dataset containing information about various bird species. The dataset is represented as a list of dictionaries, where each dictionary contains 20 different features for a bird, such as beak length, wing span, and body mass, along with a classification label for the bird species. Th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict import numpy as np def process_bird_dataset(birds: List[Dict[str, float]], num_features: int, birds_per_label: int) -> (np.ndarray, np.ndarray): """ Process a dataset containing information about v...
python_sharegpt_23k
18,172
Write a Python function to generate a random story about a person embarking on a journey to find a dragon. The story should contain at least one encounter with the dragon, and you should use the `random` module to randomly select elements for the story. Additionally, use f-strings to format the story output. The functi...
Here is the Python code to solve the given problem in the markdown block: ```python import random from typing import List def generate_random_story() -> str: """ Generates a random story about a person embarking on a journey to find a dragon. The story includes elements such as the protagonist's name, the...
python_sharegpt_23k
18,173
Write a Python function to efficiently remove duplicate elements from a given list of integers while preserving the order of the remaining elements. The function should be optimized for both time and space complexity. The code should start with: ```python from typing import List def remove_duplicates_preserve_order(ar...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_preserve_order(arr: List[int]) -> List[int]: """ Removes duplicate elements from the given list of integers while preserving the order of the remaining elements. Args: ...
python_sharegpt_23k
18,187
Write a Python function to find all pairs of elements from two given lists of natural numbers that sum up to a specified target value. Additionally, filter out pairs where both elements are not multiples of 3. The first list should have a length greater than or equal to the second list. The function should start with: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_pairs_with_conditions(list1: List[int], list2: List[int], target: int) -> List[Tuple[int, int]]: """ Find all pairs of elements from two lists that sum up to a specified target value. ...
python_sharegpt_23k
18,200
Write a Python function to count the occurrences of each character in a given string and return the result as a dictionary. The function should handle any string input, including empty strings and strings with special characters. The code should start with: ```python from typing import Dict def count_character_occurre...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def count_character_occurrences(s: str) -> Dict[str, int]: """ Count the occurrences of each character in the given string and return the result as a dictionary. Args: s (str): The input str...
python_sharegpt_23k
18,212
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 showing the Fahrenheit equivalent of temperatures ranging from 0...
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
18,213
Write a Python function to rank a list of cities based on their population in descending order. The function should take two lists as input: one containing the names of the cities and the other containing their corresponding populations. The function should return a list of city names sorted by their populations in des...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def rank_cities_by_population(cities: List[str], populations: List[int]) -> List[str]: """ Rank a list of cities based on their populations in descending order. Args: cities (List[str]): A l...
python_sharegpt_23k
18,217
Write a Python function to generate a random numerical sequence of exactly eight digits, where each digit follows a Gaussian distribution with a specified mean and standard deviation. The function should ensure that the generated digits are within the valid range of 0 to 9. The code should start with: ```python from t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random import math def generate_gaussian_sequence(mean: float, stddev: float) -> List[int]: """ Generates a random numerical sequence of exactly eight digits, where each digit follows a Gaussian d...
python_sharegpt_23k
18,223
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 optionally specify the characters to be included in the random string. If no characters are specified, the function should use the defa...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Optional, List import random import string def generate_random_string(length: int, characters: Optional[List[str]] = None) -> str: """ Generates a random string of the specified length using the given charact...
python_sharegpt_23k
18,243
Write a Python function to filter activities based on their intensity level and duration. The function should take a list of activities and an intensity level as input and return a list of activities that match the given intensity level and have a duration less than 30 minutes. The intensity levels and corresponding ac...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def filter_activities(activity_list: List[str], intensity_level: str) -> List[str]: """ Filters activities based on their intensity level and duration. Args: activity_list (List[str]):...
python_sharegpt_23k
18,251
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 output a table with three columns: the first column should contain the odd numbers, the second column should contain their squares, and the third column should co...
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_squares_of_odds(n: int) -> None: """ Calculate the sum of the squares of all the odd numbers between 1 and n, inclusive, and output a table with three columns: the odd numbers, their squares, and the running sum o...
python_sharegpt_23k
18,253
Write a Python function to generate a sorted list of unique integers in descending order from a given list of integers. The function should ensure that the resulting list contains only unique elements and is sorted in descending order. The code should start with: ```python from typing import List def generate_sorted_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_sorted_unique_list(input_list: List[int]) -> List[int]: """ Generates a sorted list of unique integers in descending order from a given list of integers. Args: input_list (List[...
python_sharegpt_23k
18,254
Write a Python function to format a given string such that specific words are colored using ANSI escape codes. The function should color the word "apple" in blue and the words "blue" and "school" in black. The function should return the formatted string. The code should start with: ```python def format_string_with_col...
Here is the Python code to solve the given problem in the markdown block: ```python def format_string_with_colors(input_str: str) -> str: """ Formats the given string such that the word "apple" is colored blue and the words "blue" and "school" are colored black. Args: input_str (str): The input str...
python_sharegpt_23k
18,255
Write a Python function to generate an anagram of at least four letters from a given word that includes at least one vowel and one consonant. The function should return a list of all such anagrams. The code should start with: ```python from typing import List import itertools def generate_anagrams(word: str) -> List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import itertools def generate_anagrams(word: str) -> List[str]: """ Generate anagrams of at least four letters from a given word that include at least one vowel and one consonant. Args: word...
python_sharegpt_23k
18,257
Write a Python function to generate a random Shakespearean insult along with its meaning. The function should randomly select an insult from a predefined list of insults and their meanings. The code should start with: ```python from typing import Tuple def generate_random_insult() -> Tuple[str, str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple import random def generate_random_insult() -> Tuple[str, str]: """ Generates a random Shakespearean insult along with its meaning. Returns: Tuple[str, str]: A tuple containing the random in...
python_sharegpt_23k
18,260
Write a Python function to find the largest number in a list of integers without using the built-in `max` function. The function should iterate through the list only once and handle edge cases such as an empty list or a list with only negative numbers. The code should start with: ```python from typing import List, Opti...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_largest_number(numbers: List[int]) -> Optional[int]: """ Find the largest number in a list of integers without using the built-in max function. The function iterates through the li...
python_sharegpt_23k
18,273
Write a Python function to generate a dictionary that shows the length of each word in a given sentence. The function should take a sentence as input and return a dictionary where the keys are the words from the sentence and the values are the lengths of those words. 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 Dict def word_lengths_in_sentence(sentence: str) -> Dict[str, int]: """ Generate a dictionary that shows the length of each word in the given sentence. Args: sentence (str): The sentence from whi...
python_sharegpt_23k
18,288
Write a Python function to multiply each element in a given list of integers by a specified factor. The function should return a new list with the modified elements. The input list and the factor should be provided as arguments to the function. The code should start with: ```python from typing import List def multipl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def multiply_list_elements(input_list: List[int], factor: int) -> List[int]: """ Multiplies each element in the input list by the specified factor and returns a new list with the results. Args: ...
python_sharegpt_23k
18,293
Write a Python function to calculate the total distance traveled by birds over a given number of days. The function should take a list of integers representing the distances traveled each day and return the total distance. The code should start with: ```python from typing import List def calculate_total_distance(dist...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_total_distance(distances: List[int]) -> int: """ Calculate the total distance traveled by birds over a given number of days. Args: distances (List[int]): A list of integers rep...
python_sharegpt_23k
18,303
Write a Python function to convert a list of phone numbers from the format "(XXX) XXX-XXXX" to the format "XXX-XXX-XXXX". The input should be a list of phone numbers in the original format, and the output should be a list of phone numbers in the new format. The function should handle any valid input in the specified fo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_phone_numbers(phone_numbers: List[str]) -> List[str]: """ Converts a list of phone numbers from the format "(XXX) XXX-XXXX" to "XXX-XXX-XXXX". Args: phone_numbers (List[str]): A ...
python_sharegpt_23k
18,307
Write a Python function to convert a given weight between kilograms and pounds, and another function to convert the weight of an object on Earth to its weight on the moon. The functions should be able to handle both directions of conversion (kilograms to pounds and pounds to kilograms) and provide the weight on the moo...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_weight(weight: float, from_unit: str, to_unit: str) -> float: """ Converts a given weight between kilograms and pounds. Args: weight (float): The weight to be converted. from_unit (str): The unit...
python_sharegpt_23k
18,315
Write a Python function to generate a personalized birthday wish message for animal lovers. The function should take the name of the person and their favorite animal as inputs and return a customized birthday message that includes an image of the favorite animal using HTML tags. If the animal is not in the predefined l...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_birthday_wish(name: str, animal: str) -> str: """ Generates a personalized birthday wish message for an animal lover. Args: name (str): The name of the person. animal (str): The favorite animal ...
python_sharegpt_23k
18,320
Write a Python function that takes a list of alphanumeric strings and returns the length of the longest word, defined as the sequence of characters delimited by whitespace, punctuation, or digits. The function should handle edge cases such as empty input lists, single-character words, and words with diacritical marks o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def longest_word_length(words: List[str]) -> int: """ Returns the length of the longest word in a list of alphanumeric strings, where a word is defined as a sequence of characters delimited...
python_sharegpt_23k
18,333
Write a Python function to calculate the area of a circle given its radius. The function should handle both positive and zero radius values. The code should start with: ```python import math def calculate_circle_area(radius: float) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python import math def calculate_circle_area(radius: float) -> float: """ Calculate the area of a circle given its radius. Args: radius (float): The radius of the circle. If negative, it is treated as zero. Returns: ...
python_sharegpt_23k
18,343
Write a Python function to convert a list of items into a 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 import List def list_t...
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 sentence. The sentence starts with "I have ", followed by the items separated by commas, and the last item prec...
python_sharegpt_23k
18,344
Write a Python function to convert a number from scientific notation to decimal notation. The function should take a string representing a number in scientific notation (e.g., "12.5e0") and return the number in decimal notation as a float. The function should handle both positive and negative exponents. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python def scientific_to_decimal(num: str) -> float: """ Converts a number from scientific notation to decimal notation. Args: num (str): A string representing a number in scientific notation (e.g., "12.5e0"). Returns...
python_sharegpt_23k
18,349
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
18,353
Write a Python function to generate a formal invitation for a networking event using Markdown syntax. The function should take event details as input parameters and return a formatted Markdown string. The event details include the event name, date and time, location, purpose, and RSVP instructions. The function should ...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_invitation(event_name: str, date_and_time: str, location: str, purpose: str, rsvp_email: str) -> str: """ Generates a formal invitation for a networking event using Markdown syntax. Args: event_name (st...
python_sharegpt_23k
18,355
Write a Python function to convert a Roman numeral string to its decimal equivalent. The function should take a dictionary of Roman numeral symbols and their corresponding values, and a string representing the Roman numeral to be converted. The function should return the decimal equivalent of the Roman numeral. The co...
Here is the Python code to solve the given problem in the markdown block: ```python def roman_to_decimal(numerals: dict, input_numeral: str) -> int: """ Convert a Roman numeral string to its decimal equivalent. Args: numerals (dict): A dictionary mapping Roman numeral symbols to their integer value...
python_sharegpt_23k
18,356
Write a Python function to remove all duplicate strings from an input array of strings, ensuring each element within the array is unique and not repeated. The function should maintain the order of the first occurrence of each string. The code should start with: ```python from typing import List def remove_duplicates(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates(arr: List[str]) -> List[str]: """ Removes all duplicate strings from the input array, ensuring each element is unique and maintaining the order of their first occurrence. Args:...
python_sharegpt_23k
18,358
Write a Python function to transform a given string such that all the vowels in the string are converted to uppercase. The function should handle both uppercase and lowercase vowels. The code should start with: ```python def uppercase_vowels(text: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def uppercase_vowels(text: str) -> str: """ Transforms all the vowels in the given string to uppercase. Args: text (str): The input string to be transformed. Returns: str: The transformed string with al...
python_sharegpt_23k
18,363
Write a Python function to calculate the sum of all odd numbers in a given list of integers. The function should handle lists of any length and should return the sum of the odd numbers. The code should start with: ```python from typing import List def sum_of_odd_numbers(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_odd_numbers(numbers: List[int]) -> int: """ Calculate the sum of all odd numbers in the given list. Args: numbers (List[int]): A list of integers. Returns: int: The s...
python_sharegpt_23k
18,365
Write a Python function to generate a random story about a frustrated robot navigating through a vast city where the AI systems are unreliable and causing chaos. The function should randomly select a scenario from a predefined list and return the complete story as a string. 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 import random def generate_frustrated_robot_story(robot_name: str, city_name: str, scenarios: List[str]) -> str: """ Generates a random story about a frustrated robot navigating through a vast city with ...
python_sharegpt_23k
18,367
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 any non-alphabetic characters should remain unchanged. The code should...
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. Args: word (str): The input string to be shifted. Returns: str: The new s...
python_sharegpt_23k
18,376
Write a Python function to sort a list of movie dictionaries by their release year and display the title, budget, and country of origin for each movie. The function should only display movies with a budget of at least $5 million. The output should be formatted in a table with columns for the movie title, budget, and co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def display_movies_by_release_date(movies: List[Dict[str, any]]) -> None: """ Sorts a list of movie dictionaries by their release year and displays the title, budget, and country of origin for each...
python_sharegpt_23k
18,379
Write a Python function to sort a list of chemical elements based on their atomic numbers. Each element is represented as a dictionary with keys 'name' and 'atomic_number'. The function should return a list of elements sorted in increasing order of atomic number. The code should start with: ```python from typing impor...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def sort_elements_by_atomic_number(elements: List[Dict[str, any]]) -> List[Dict[str, any]]: """ Sorts a list of chemical elements based on their atomic numbers. Args: elements (List[Di...
python_sharegpt_23k
18,380
Write a Python function to decrypt a message encoded with a Caesar cipher. The Caesar cipher is a type of substitution cipher where each letter in the plaintext is shifted a certain number of places down or up the alphabet. The function should take a ciphertext string and a key (an integer representing the number of po...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher_decrypt(ciphertext: str, key: int) -> str: """ Decrypts a message encoded with a Caesar cipher. Args: ciphertext (str): The encrypted message to be decrypted. key (int): The number of posit...
python_sharegpt_23k
18,381
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", the output should be "world Hello". The function should handle strings with multiple spaces between words and leading/trailing spaces. The code should start with: ...
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 their order. Args: s (str): The input string containing words to be reversed. Returns: str: A str...
python_sharegpt_23k
18,382
Write a Python function to enhance a given sentence by adding an HTML tag with a specified class to a specific word within the sentence. The function should replace the target word with an HTML-tagged version of the word. The code should start with: ```python def enhance_sentence_with_tag(sentence: str, target_word: st...
Here is the Python code to solve the given problem in the markdown block: ```python def enhance_sentence_with_tag(sentence: str, target_word: str, tag_class: str) -> str: """ Enhances a given sentence by adding an HTML span tag with a specified class to a specific word. Args: sentence (str): The or...
python_sharegpt_23k
18,392
Write a Python function to generate a sentence that includes a reference to a physical landmark. The function should accept a landmark name as an argument and return a formatted sentence. The sentence should be dynamically created using an f-string. The code should start with: ```python def generate_sentence(landmark:...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_sentence(landmark: str) -> str: """ Generates a sentence that includes a reference to a physical landmark. Args: landmark (str): The name of the physical landmark to be included in the sentence. Re...
python_sharegpt_23k
18,393
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_musical_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_musical_term(terms: List[str]) -> str: """ Generates a random French musical term from a given list of terms. Args: terms (List[str]): A list of Fren...
python_sharegpt_23k
18,403
Write a Python function to generate a comprehensive list of ten behavioral and emotional signs that indicate an unhealthy relationship. The function should include specific manifestations of controlling behavior, possessiveness, jealousy, and emotional abuse. The function should utilize a combination of string manipula...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_unhealthy_relationship_signs() -> List[str]: """ Generates a comprehensive list of ten behavioral and emotional signs that indicate an unhealthy relationship. Returns: List[str]...
python_sharegpt_23k
18,404
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
18,410
Write a Python function to generate a random word from a predefined list of English words that have the same meaning as the German word "Verantwortung". The function should then use this random word in a sentence. The list of words should include "Responsibility", "Accountability", "Duty", "Obligation", and "Liability"...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_sentence_with_random_word(words: List[str]) -> str: """ Generates a sentence using a random word from the provided list of English words. Args: words (List[str]): ...
python_sharegpt_23k
18,413
Write a Python function to determine if a given number is a prime number. The function should return `True` if the number is prime and `False` otherwise. The function should be efficient and handle edge cases such as negative numbers, 0, and 1. The code should start with: ```python def is_prime(n: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n: int) -> bool: """ Determine if a given number is a prime number. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. """ ...
python_sharegpt_23k
18,419
Write a Python function to extract the expiration date and security code from a given credit card string. The credit card string is in the format "XXXX-XXXX-XXXX-XXXX MM/YY CVV", where "X" represents a digit, "MM/YY" is the expiration date in the format of a two-digit month and two-digit year, and "CVV" is a three-digi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple import re def extract_credit_card_info(credit_card_string: str) -> Tuple[str, str]: """ Extracts the expiration date and security code from a given credit card string. Args: credit_card_str...
python_sharegpt_23k
18,423
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_to_word(word: str, suffix: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def add_suffix_to_word(word: str, suffix: str) -> str: """ Adds a suffix to a given word and returns the new word. Args: word (str): The word to which the suffix will be added. suffix (str): The suffix to be...
python_sharegpt_23k
18,429
Write a Python function to perform non-deterministic decision-making on a given dataset. The function should randomly select an item from the dataset, shuffle the dataset, and generate a random number within a specified range. The function should return a tuple containing the randomly selected item, the shuffled datase...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import random def non_deterministic_decision_making(dataset: List[int], min_range: int, max_range: int) -> Tuple[int, List[int], int]: """ Perform non-deterministic decision-making on a given data...
python_sharegpt_23k
18,430
Write a Python function to determine whether two given strings are anagrams of each other. Two strings are considered anagrams if they contain the same characters with the same frequencies, regardless of their order. The function should be case-insensitive and should ignore spaces. The code should start with: ```pytho...
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 given strings are anagrams of each other. Args: str1 (str): The first string to compare. str2 (str): The second string to compare. ...
python_sharegpt_23k
18,438
Write a Python function to compute the number of occurrences of each word in a given list and return the result in a table format. The function should handle inputs with a variety of data types such as integers and special characters, and sort them in descending order based on their frequency. Additionally, the functio...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple from collections import Counter def word_frequency_table(words: List[str]) -> List[Tuple[str, List[int], int]]: """ Computes the number of occurrences of each word in the input list and returns th...
python_sharegpt_23k
18,439
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
18,448
Write a Python function to generate a random zodiac sign belonging to the fire element. The function should return the name of the randomly selected fire zodiac sign. The code should start with: ```python from typing import List import random def get_random_fire_zodiac() -> 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_zodiac() -> str: """ Generates a random zodiac sign belonging to the fire element. Returns: str: The name of the randomly selected fire zodiac sign. """...
python_sharegpt_23k
18,459
Write a Python function to find the highest number in a list of integers. The function should handle lists of any length and return an error message if the input list is empty or contains non-integer elements. If the input list contains duplicates, the function should return the highest duplicate value. The function sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_highest_number(my_list: List[int]) -> int or str: """ Find the highest number in a list of integers. Args: my_list (List[int]): The list of integers to search for the highest number...
python_sharegpt_23k
18,469
Write a Python function to find the closest Kelvin temperature to a given target Kelvin temperature from a predefined dictionary of Kelvin to Fahrenheit conversion rates. The function should return the equivalent Fahrenheit temperature, rounded to the nearest hundredth. 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 Dict def find_closest_temperature(kelvin_fahrenheit: Dict[int, float], target_kelvin: int) -> float: """ Finds the closest Kelvin temperature to a given target Kelvin temperature and returns its equivalent Fa...
python_sharegpt_23k
18,471
Write a Python function that takes two lists of integers as input: one containing all the odd numbers and the other containing all the even numbers. The function should return a new list that contains all the odd numbers in descending order followed by all the even numbers in ascending order. Additionally, the function...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_and_display_numbers(odd_numbers: List[int], even_numbers: List[int]) -> List[int]: """ Sorts the odd numbers in descending order and the even numbers in ascending order, then concatenates th...
python_sharegpt_23k
18,476
Write a Python function to calculate the exact date that is a specified number of days after the current date. The function should take an integer `days` as input and return the future date as a `datetime.date` object. The code should start with: ```python import datetime def calculate_future_date(days: int) -> dateti...
Here is the Python code to solve the given problem in the markdown block: ```python import datetime def calculate_future_date(days: int) -> datetime.date: """ Calculate the exact date that is a specified number of days after the current date. Args: days (int): The number of days to add to the curr...
python_sharegpt_23k
18,477
Write a Python function to generate a haiku with a specific theme or subject. The haiku should follow the traditional 5-7-5 syllable structure and must include the specified theme in the generated haiku. The function should start with: ```python from typing import List def generate_haiku_with_theme(theme: 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_haiku_with_theme(theme: str) -> str: """ Generates a haiku with a specific theme. The haiku follows the traditional 5-7-5 syllable structure. Args: theme (str): Th...
python_sharegpt_23k
18,479
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 reversed. Returns: str: A new sentenc...
python_sharegpt_23k
18,485
Write a Python function to validate an IPv4 address and determine its class based on the first octet. The function should return a tuple containing a boolean indicating whether the IP address is valid and a string representing the class of the IP address. The function should adhere to the following rules: - The IP addr...
Here is the Python code to solve the given problem in the markdown block: ```python def validate_ipv4(ip_address: str) -> tuple: """ Validates an IPv4 address and determines its class. Args: ip_address (str): The IP address to validate. Returns: tuple: A tuple containing a boolean indi...
python_sharegpt_23k
18,491
Write a Python function that generates a random simile and a random metaphor from predefined lists and prints them to the console. The function should handle the case where the lists are empty by printing a default message. The code should start with: ```python from typing import List def generate_random_literary_devi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_random_literary_devices(similes: List[str], metaphors: List[str]) -> None: """ Generates and prints a random simile and a random metaphor from the provided lists. If either...
python_sharegpt_23k
18,498
Write a Python function to calculate the wattage of a bulb based on its voltage and amperage. Additionally, create a function to check if a bulb is compatible with a given socket by comparing the voltage of the bulb with the voltage rating of the socket. The code should start with: ```python def calculate_wattage(volta...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_wattage(voltage: float, amperage: float) -> float: """ Calculate the wattage of a bulb based on its voltage and amperage. Args: voltage (float): The voltage of the bulb in volts. amperage (floa...
python_sharegpt_23k
18,500
Write a Python function to generate a sentence that uses the words "defy" and "gravity" from a predefined list of verbs and nouns. The function should randomly select a verb and a noun from their respective lists and construct a sentence using the format "I will {verb} the {noun}." The code should start with: ```python...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_sentence(verbs: List[str], nouns: List[str]) -> str: """ Generates a sentence using a randomly selected verb and noun from the provided lists. Args: verbs (List[st...
python_sharegpt_23k
18,501
Write a Python function to calculate the height of an equilateral triangle given the length of one side. The function should use the mathematical formula for the height of an equilateral triangle, which is derived from the Pythagorean theorem. The code should start with: ```python import math def calculate_height_of_e...
Here is the Python code to solve the given problem in the markdown block: ```python import math def calculate_height_of_equilateral_triangle(side_length: float) -> float: """ Calculate the height of an equilateral triangle given the length of one side. The height of an equilateral triangle can be derived ...
python_sharegpt_23k
18,504
Write a Python function to generate a promotional tweet for outdoor camping gear. The function should randomly select a gear item, an adjective describing the gear, and a phrase to promote the gear. The tweet should be constructed in the format: "Phrase Adjective GearItem! Shop now at our website." The function should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_promotional_tweet(gear_items: List[str], adjectives: List[str], phrases: List[str]) -> str: """ Generates a promotional tweet for outdoor camping gear by randomly selecting a g...
python_sharegpt_23k
18,508
Write a Python function to measure the time it takes to print a string of varying lengths and to explore different formatting options such as font size and color. The function should also discuss potential memory constraints and optimization techniques for the string printing process. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python import time def measure_print_time_and_format(string: str, font_size: int = 12, color: str = 'black') -> float: """ Measures the time it takes to print a string and formats it with the specified font size and color. Args: ...
python_sharegpt_23k
18,509
Write a Python function to validate a list of email addresses using regular expressions. The function should return a list of boolean values indicating whether each email in the input list is valid or not. The code should start with: ```python from typing import List import re def validate_emails(emails: List[str]) ->...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def validate_emails(emails: List[str]) -> List[bool]: """ Validates a list of email addresses using a regular expression pattern. Args: emails (List[str]): A list of email addresse...
python_sharegpt_23k
18,511
Update the given Python 2 code snippet to Python 3 syntax, ensuring that the `print` statement uses parentheses and that the greeting string is stored in a variable. The task is to write a function that takes a greeting message as input and prints it using Python 3 syntax. The code should start with: ```python def pri...
Here is the Python code to solve the given problem in the markdown block: ```python #!/usr/bin/python3 # Greeting python program def print_greeting(greeting: str) -> None: """ Prints the given greeting message using Python 3 syntax. Args: greeting (str): The greeting message to be printed. Re...
python_sharegpt_23k
18,514
Write a Python function to generate a specified number of distinct LaTeX-formatted sentences describing a female's vocal performance, each showcasing a unique aspect of her performance such as tone, pitch, tempo, and style. The function should ensure that no two sentences are identical or similar to the examples given ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_vocal_performance_sentences(num_sentences: int) -> List[str]: """ Generates a specified number of distinct LaTeX-formatted sentences describing a female's vocal performance. ...
python_sharegpt_23k
18,515
Write a Python function to calculate the average of an array of integers. The function should handle cases where the array is empty by returning `None`. The code should start with: ```python from typing import List, Optional def calculate_average(arr: List[int]) -> Optional[float]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def calculate_average(arr: List[int]) -> Optional[float]: """ Calculate the average of an array of integers. Args: arr (List[int]): The array of integers for which to calculate the...
python_sharegpt_23k
18,524
Write a Python function to check if a given string contains any substring of length at least 3 that is a palindrome. The function should return `True` if such a substring exists, otherwise `False`. The code should start with: ```python def contains_palindrome_substring(s: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def contains_palindrome_substring(s: str) -> bool: """ Check if the given string contains any substring of length at least 3 that is a palindrome. Args: s (str): The input string to check for palindromic substrings....
python_sharegpt_23k
18,526
Write a Python function to create a new list with the same elements but in reverse order, excluding non-integer elements from the input list. The function must have a time complexity of O(n/2) and should return an empty list if there are no valid integers in the input list. Additionally, optimize the code for larger da...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_int_list(lst: List[int]) -> List[int]: """ Create a new list with the same integer elements but in reverse order, excluding non-integer elements. Args: lst (List[int]): The input...
python_sharegpt_23k
18,530
Write a Python function to check if a specific integer `n` is a prime number using the Sieve of Eratosthenes algorithm. The function should create a comprehensive table of all integers up to `n` and label all composites (non-primes) by identifying all multiples of each prime. Additionally, enhance the efficiency and pr...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n: int) -> bool: """ Check if a specific integer `n` is a prime number using the Sieve of Eratosthenes algorithm. Args: n (int): The integer to check for primality. Returns: bool: True if `...
python_sharegpt_23k
18,533
Write a Python function to count the number of each vowel in a given sentence and store the counts in a dictionary. The function should be case-insensitive, meaning it should treat 'A' and 'a' as the same vowel. The output dictionary should have vowels as keys and their respective counts as values. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def count_vowels(sentence: str) -> Dict[str, int]: """ Counts the number of each vowel in a given sentence and returns the counts in a dictionary. Args: sentence (str): The input sentence in...
python_sharegpt_23k
18,535
Write a Python function named `concatenate_words` that accepts a string named `text` as an argument. The function should split the input string into individual words and then concatenate them using underscores to create a single string. The output string should be returned by the function. Ensure that the output string...
Here is the Python code to solve the given problem in the markdown block: ```python import re def concatenate_words(text: str) -> str: """ Concatenates the words from the input string using underscores. Args: text (str): The input string to be processed. Returns: str: A string where t...
python_sharegpt_23k
18,536
Write a Python function to determine whether a given number is even or odd. The function should return a string indicating "Even" if the number is even and "Odd" if the number is 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 check. Returns: str: "Even" if the number is even, "Odd" if the number is...
python_sharegpt_23k
18,539
Write a Python function to find the second highest number in a given array of integers. The function should handle arrays with duplicate values and arrays with fewer than two elements. The code should start with: ```python from typing import List def find_second_highest(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_second_highest(arr: List[int]) -> int: """ Find the second highest number in a given array of integers. Args: arr (List[int]): The array of integers from which to find the second hi...
python_sharegpt_23k
18,541
Write a Python function to calculate the sum of the first `n` positive integers and another function to calculate the sum of the first `n` even positive integers. The functions should be efficient and avoid unnecessary computations. The code should start with: ```python def sum_of_first_n_integers(n: int) -> int: def ...
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_first_n_integers(n: int) -> int: """ Calculate the sum of the first n positive integers. Args: n (int): The number of positive integers to sum. Returns: int: The sum of the first n positive i...
python_sharegpt_23k
18,545
Write a Python function to calculate the number of times a piece of paper, initially 0.1 millimeters thick, needs to be folded to reach a specified thickness in meters. The function should take the target thickness in meters as an argument and return the number of folds required. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_folds_to_reach_thickness(target_thickness: float) -> int: """ Calculate the number of times a piece of paper, initially 0.1 millimeters thick, needs to be folded to reach a specified thickness in meters. A...
python_sharegpt_23k
18,561
Write a Python function to generate a random matrix of size `n` by `m` such that the sum of each row is a prime number. The function should ensure that each row sum is a prime number by repeatedly generating random integers for the row until a valid row is found. 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 import random def is_prime(n: int) -> bool: """ Check if a given number is a prime number. Args: n (int): The number to check for primality. Returns: bool: True if the number is...
python_sharegpt_23k
18,573
Create a Python function that generates a dictionary with five key-value pairs, where the values are all prime numbers. The keys must follow specific criteria: 1. The first key must be a palindrome and represent a type of animal often associated with intelligence. 2. The second key must be a combination of the chemical...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_prime_dictionary() -> dict: """ Generates a dictionary with five key-value pairs where the values are prime numbers. The keys follow specific criteria: 1. The first key is a palindrome representing an intell...
python_sharegpt_23k
18,581
Write a Python function to calculate the average heart rate (HR) and blood pressure (BP) from given data. The function should take two lists as input: one for heart rate data and one for blood pressure data. Each list contains numerical values representing the measurements taken at different times. The function should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Optional def calculate_average_hr_bp(hr_data: List[float], bp_data: List[float]) -> Optional[Tuple[float, float]]: """ Calculate the average heart rate (HR) and blood pressure (BP) from given dat...
python_sharegpt_23k
18,583
Write a Python function to efficiently identify and extract prime numbers from a given list of integers. The function should handle large lists without causing significant delays and should only return prime numbers, ignoring non-prime ones. The code should be designed to be easily understood and maintained by other de...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. ...
python_sharegpt_23k
18,584
Write a Python function to generate a 500x20 matrix where each element is the sum of the two elements directly above it and to the left, and then find the maximum value in the bottom row multiplied by the sum of the values in the top row divided by 2. Optimize the code for faster execution using memoization. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def optimized_matrix_calculation(matrix_size: int, row_length: int) -> float: """ Generates a matrix of size matrix_size x row_length where each element is the sum of the two elements directly above it a...
python_sharegpt_23k
18,585
Write a Python function to determine whether each number in a given list of integers is prime or composite. The function should return a list of tuples, where each tuple contains a number and a string indicating whether the number is "Prime" or "Composite". 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, Tuple import math def is_prime(num: int) -> bool: """ Check if a number is prime. Args: num (int): The number to check. Returns: bool: True if the number is prime, False otherw...
python_sharegpt_23k
18,588
Write a Python function to sort a dataset of fruits by their sweetness values in descending order and group them by their origin countries. Additionally, implement a function to calculate the average sweetness of fruits for each country. The dataset is represented as a dictionary where each key is a fruit name and the ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def sort_and_group_fruits(fruits: Dict[str, Dict[str, str]]) -> Dict[str, List[Tuple[str, int]]]: """ Sort the fruits by their sweetness values in descending order and group them by their or...
python_sharegpt_23k
18,589
Write a Python function to find the longest common subsequence (LCS) of two given strings. The function should take two strings as input and return the longest common subsequence as a string. The time complexity of the algorithm should not exceed O(mn), where m and n are the lengths of the input strings. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python def longest_common_subsequence(str1: str, str2: str) -> str: """ Finds the longest common subsequence (LCS) of two given strings. Args: str1 (str): The first input string. str2 (str): The second input string...
python_sharegpt_23k
18,595
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
18,599
Write a Python function to convert a fraction into its decimal equivalent. The function should take two positive integer inputs, the numerator and the denominator, and return the decimal equivalent as a float. The function should be able to handle any positive integer values for the numerator and denominator. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python def fraction_to_decimal(numerator: int, denominator: int) -> float: """ Converts a fraction into its decimal equivalent. Args: numerator (int): The numerator of the fraction. Must be a positive integer. deno...
python_sharegpt_23k
18,601
Write a Python function to count the number of 5-digit numbers in a given dataset that start with the digit '4'. The dataset is a list of strings, where each string represents a 5-digit number. The function should use a regular expression to filter out the numbers that do not start with '4' and return the count of the ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def count_5_digit_numbers_starting_with_4(dataset: List[str]) -> int: """ Counts the number of 5-digit numbers in the given dataset that start with the digit '4'. Args: dataset (Li...
python_sharegpt_23k
18,606
Write a Python function to calculate the sum of a list of numbers with added error handling. The function should raise appropriate exceptions for the following scenarios: 1. If the input is not a list, raise a `TypeError` with the message "Input must be a list". 2. If the input list is empty, raise a `ValueError` with ...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_sum(lst): """ Calculate the sum of a list of numbers with added error handling. Args: lst (list): The list of numbers to sum. Returns: float or int: The sum of the list. Raises: ...
python_sharegpt_23k
18,608
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 include a comment section with some fascinating yet less popular facts or e...
Here is the Python code to solve the given problem in the markdown block: ```python import datetime def time_difference_to_moon_landing() -> float: """ 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. ...
python_sharegpt_23k
18,609
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...