source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
20,648
Write a Python function that takes a list of dictionaries and a key-value pair as input, and returns a new list of dictionaries that contain the specified key-value pair. The function should use dictionary comprehension to achieve this. The code should start with: ```python from typing import List, Dict def get_dicti...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def get_dictionaries_with_key_value_pair(dict_list: List[Dict[str, any]], key: str, value: any) -> List[Dict[str, any]]: """ Returns a new list of dictionaries that contain the specified key-value ...
python_sharegpt_23k
20,659
Write a Python function to sort a list of integers in descending order and remove any duplicates. The function should take a list of integers as input and return a new list with the integers sorted in descending order and duplicates removed. The code should start with: ```python from typing import List def sort_and_re...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_and_remove_duplicates(lst: List[int]) -> List[int]: """ Sorts a list of integers in descending order and removes any duplicates. Args: lst (List[int]): The list of integers to be pr...
python_sharegpt_23k
20,660
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, str]: """ Generates a classification puzzle for nocturnal mammals that live in underground burrows in the African sava...
python_sharegpt_23k
20,663
Write a Python function to calculate the sum of even numbers from 1 to a given positive integer `n`. The function should handle edge cases such as `n` being 0 or an odd number. The code should start with: ```python def sum_even_numbers(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_even_numbers(n: int) -> int: """ Calculate the sum of all even numbers from 1 to a given positive integer n. Args: n (int): The upper limit of the range (inclusive) for which to calculate the sum of even num...
python_sharegpt_23k
20,670
Write a Python function to calculate both the average temperature and the median temperature of a given set of temperature values. The function should handle both even and odd lengths of the input list. The code should start with: ```python from typing import List def calculate_temperatures(temperature: List[float]) -...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def calculate_temperatures(temperature: List[float]) -> Tuple[float, float]: """ Calculate the average and median temperatures from a given set of temperature values. Args: temperatur...
python_sharegpt_23k
20,671
Write a Python function to group students in a classroom based on their favorite subject among Math, Science, and English. The function should also sort the students within each subject group by their grade in ascending order. The function should return a dictionary where the keys are the subjects and the values are li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def group_and_sort_students_by_subject(students: List[Dict[str, any]]) -> Dict[str, List[Dict[str, any]]]: """ Groups students by their favorite subject and sorts them by their grade in ascending o...
python_sharegpt_23k
20,676
Write a Python function to calculate the quotient of two integers and ensure that the decimal number obtained is both precise up to a minimum of three decimal places and falls within a specified narrow range. The function should also check if the quotient is accurate based on the given range. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python def check_quotient_accuracy(dividend: int, divisor: int, min_range: float, max_range: float) -> str: """ Calculate the quotient of two integers and check if it falls within a specified range. Args: dividend (int): T...
python_sharegpt_23k
20,682
Write a Python function to calculate the sum of all even numbers in a given list of integers. The function should filter out the even numbers from the list, sum them up, and return the total sum. The code should start with: ```python from typing import List def sum_of_even_numbers(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def sum_of_even_numbers(numbers: List[int]) -> int: """ Calculate the sum of all even numbers in a given list of integers. Args: numbers (List[int]): A list of integers from which to find ...
python_sharegpt_23k
20,683
Write a Python function to perform a series of arithmetic operations on three variables `x`, `y`, and `z` and return the final value of `z`. The operations should include addition, multiplication, and subtraction. The function should start with: ```python def perform_operations(x: int, y: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def perform_operations(x: int, y: int) -> int: """ Perform a series of arithmetic operations on the variables x, y, and z, and return the final value of z. Args: x (int): The first integer value. y (int): Th...
python_sharegpt_23k
20,685
Write a Python function to categorize a list of fruits into two groups based on their pH values. The function should return two lists: one for acidic fruits (pH < 4.0) and one for non-acidic fruits (pH >= 4.0). The input is a dictionary where the keys are fruit names and the values are their pH values. The code should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def categorize_fruits(fruits: Dict[str, float]) -> (List[str], List[str]): """ Categorizes a list of fruits into acidic and non-acidic based on their pH values. Args: fruits (Dict[str,...
python_sharegpt_23k
20,691
Write a Python function to extract the essential words "celebrate", "victory", "parade", and "tomorrow" from a given sentence using a regular expression. The function should be robust enough to handle variations in word order, punctuation, and capitalization. The code should start with: ```python from typing import Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def extract_essential_words(sentence: str) -> List[str]: """ Extracts the essential words "celebrate", "victory", "parade", and "tomorrow" from a given sentence. Args: sentence (st...
python_sharegpt_23k
20,692
Write a Python function to find the top three most popular vegetables from a given list of vegetables and their respective popularity rankings. The input is a list of tuples, where each tuple contains the name of a vegetable and its popularity ranking. The function should return a list of the names of the top three mos...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_top_three_vegetables(vegetables: List[Tuple[str, int]]) -> List[str]: """ Finds the top three most popular vegetables from a given list of vegetables and their popularity rankings. A...
python_sharegpt_23k
20,700
Write a Python function to perform integer division and return both the quotient and the remainder. The function should take two parameters: the dividend and the divisor. The function should return a tuple containing the quotient and the remainder. The code should start with: ```python def integer_division(dividend: in...
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
20,705
Write a Python function to simulate a puzzle-solving scenario where `num_individuals` individuals work on a puzzle with `num_pieces` pieces. Each individual can move one piece at a time. The function should randomly assign each individual a piece to move and track how many times each piece has been moved. The function ...
Here is the Python code to solve the given problem in the markdown block: ```python import random from typing import List def simulate_puzzle(num_individuals: int, num_pieces: int, oligarchy: bool = False) -> int: """ Simulate a puzzle-solving scenario where num_individuals individuals work on a puzzle with nu...
python_sharegpt_23k
20,710
Write a Python function to classify a list of animals into mammals and non-mammals, and further classify the mammals into nocturnal and non-nocturnal creatures. The function should return a dictionary where the keys are the animal names and the values are tuples indicating whether the animal is a mammal and whether it ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple def classify_animals(animals: List[str]) -> Dict[str, Tuple[bool, bool]]: """ Classify a list of animals into mammals and non-mammals, and further classify the mammals into nocturnal and non...
python_sharegpt_23k
20,711
Write a Python function to calculate the sum of all odd numbers in a given list of integers. If the input list contains only even numbers, the function should return 0. The function should start with: ```python from typing import List def sum_of_odds(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_odds(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 sum of a...
python_sharegpt_23k
20,723
Write a Python function that takes a list of sublists and a function as input. The function should apply the given function to all elements of each sublist, except for the last two sublists. The result should be a nested list of tuples, where each tuple contains the original element and the result of applying the funct...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable, Any, Tuple def apply_function_to_sublists(sublists: List[List[Any]], func: Callable[[Any], Any]) -> List[List[Tuple[Any, Any]]]: """ Applies a given function to all elements of each sublist, e...
python_sharegpt_23k
20,724
Write a Python function to generate a random historical figure joke from a predefined list of jokes. The function should randomly select one joke from the list and return it as a string. The list should include at least 10 jokes involving various historical figures. The code should start with: ```python from typing imp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def get_random_historical_joke(jokes: List[str]) -> str: """ Generates a random historical figure joke from a given list of jokes. Args: jokes (List[str]): A list of strings wh...
python_sharegpt_23k
20,725
Write a Python function to calculate the center of mass of an array of three-dimensional points. Each point is represented as a list of three integers, and the mass of each point is assumed to be equal. The function should return the center of mass as a list of three floats. The code should start with: ```python from ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_center_of_mass(points: List[List[int]]) -> List[float]: """ Calculate the center of mass of an array of three-dimensional points. Args: points (List[List[int]]): A list of thre...
python_sharegpt_23k
20,731
Write a Python function to test for Schur's inequality of degree 4. Schur's inequality states that for non-negative real numbers \(a\), \(b\), \(c\), and \(d\), the following inequality holds: \[ a^4 + b^4 + c^4 + d^4 + 2abcd \geq a^2bc + ab^2c + abc^2 + abcd \] The function should take four non-negative real numbers a...
Here is the Python code to solve the given problem in the markdown block: ```python def schurs_inequality_degree_4(a: float, b: float, c: float, d: float) -> bool: """ Test for Schur's inequality of degree 4 for given non-negative real numbers a, b, c, and d. Schur's inequality of degree 4 states that: ...
python_sharegpt_23k
20,733
Write a Python function to perform a binary search on a sorted array that can handle multiple occurrences of a target key and return the range of indices where the target key is found. If the target key is not found, return -1. The code should start with: ```python from typing import List, Tuple def binary_search_mul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def binary_search_multi(arr: List[int], target: int) -> Tuple[int, int]: """ Perform a binary search on a sorted array to find the range of indices where the target key is found. Args: ...
python_sharegpt_23k
20,734
Write a Python function to perform a Caesar cipher encryption on a given string. The Caesar cipher shifts each letter in the string by a specified number of positions down the alphabet. The function should handle both uppercase and lowercase letters, preserving their case, and leave non-alphabetic characters unchanged....
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher_encrypt(text: str, shift: int) -> str: """ Encrypts the given text using a Caesar cipher with the specified shift. Args: text (str): The text to be encrypted. shift (int): The number of pos...
python_sharegpt_23k
20,741
Write a Python function to find the most recent date from a list of dates in the format "YYYY-MM-DD". The function should take a list of strings as input and return the most recent date as a string. The code should start with: ```python from typing import List def get_most_recent_date(dates: List[str]) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_most_recent_date(dates: List[str]) -> str: """ Find the most recent date from a list of dates in the format "YYYY-MM-DD". Args: dates (List[str]): A list of dates in the format "YYYY...
python_sharegpt_23k
20,744
Write a Python function to implement a merge sort algorithm that can handle arrays containing both positive and negative integers efficiently, with a time complexity of O(n log n). The function should be able to sort the array in ascending order. The code should start with: ```python from typing import List def merge...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers using the merge sort algorithm. Args: arr (List[int]): The array of integers to be sorted. Returns: L...
python_sharegpt_23k
20,750
Write a Python function to generate a complex math puzzle using specific symbols and operators, and then solve it to find the correct answer. The puzzle should involve multiple mathematical operations and use symbols that denote specific values. The function should return both the generated puzzle and its solution. Th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Dict import random def generate_and_solve_puzzle(difficulty: int) -> Tuple[str, int]: """ Generates a complex math puzzle using specific symbols and operators, and solves it to find the correct answer....
python_sharegpt_23k
20,756
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
20,768
Write a Python function to generate a table of outputs for a given range of values of `x` from 0 to `n` (inclusive), where `n` is a non-negative integer. The function should print different messages based on the value of `x` as follows: - If `x` is less than 5, print "x is less than 5". - If `x` is equal to 5, print "x...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_output_table(n: int) -> None: """ Generates a table of outputs for values of x from 0 to n (inclusive). Args: n (int): The upper limit of the range (inclusive). Returns: None: The function ...
python_sharegpt_23k
20,784
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
20,793
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
20,799
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, including empty lists. 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...
python_sharegpt_23k
20,807
Write a Python function to generate a list of all three-digit narcissistic numbers within a specified range. A narcissistic number is a non-negative integer of exactly three digits where the sum of the cubes of each digit is equal to the number itself. The function should not rely on any built-in libraries or functions...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_narcissistic_numbers(start: int, end: int) -> List[int]: """ Generate a list of all three-digit narcissistic numbers within the specified range. A narcissistic number is a non-negative inte...
python_sharegpt_23k
20,809
Write a Python function to calculate the sum of all even numbers in a given list of integers. The function should iterate through the list at least twice to ensure that the sum is calculated correctly. The code should start with: ```python from typing import List def sum_of_even_numbers(nums: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_even_numbers(nums: List[int]) -> int: """ Calculate the sum of all even numbers in a given list of integers. Args: nums (List[int]): A list of integers from which to calculate the...
python_sharegpt_23k
20,813
Implement a modified version of the bubble sort algorithm that terminates early if the array is already sorted. Additionally, the sorting algorithm should be optimized to have a time complexity of O(n) when the input array is already sorted in ascending order, where n is the length of the input array. The function shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def optimized_bubble_sort(arr: List[int]) -> List[int]: """ Sorts the input list using a modified bubble sort algorithm that terminates early if the array is already sorted. The algorithm is optimize...
python_sharegpt_23k
20,822
Write a Python function to clean a given serial number string by removing extra spaces and special characters (like hyphens and periods) while ensuring that valuable information is not accidentally deleted. The function should return the cleaned serial number string. The code should start with: ```python import re de...
Here is the Python code to solve the given problem in the markdown block: ```python import re def clean_serial_number(serial_num: str) -> str: """ Cleans a given serial number string by removing extra spaces and special characters. Args: serial_num (str): The serial number string to be cleaned. ...
python_sharegpt_23k
20,826
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
20,828
Write a Python function to classify a given list of plant names into either "Gymnosperm" or "Angiosperm" based on predefined characteristics. The function should return a dictionary where the keys are the plant names and the values are their classifications. 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, Dict def classify_plants(plant_names: List[str]) -> Dict[str, str]: """ Classify a list of plant names into either "Gymnosperm" or "Angiosperm" based on predefined characteristics. Args: pl...
python_sharegpt_23k
20,829
Write a Python function to find the intersection of two given lists. The intersection is defined as the set of elements that are present in both lists. The function should return a list containing these common elements, sorted in ascending order. The code should start with: ```python from typing import List def find_i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_intersection(list1: List[int], list2: List[int]) -> List[int]: """ Find the intersection of two lists and return the common elements sorted in ascending order. Args: list1 (List[int...
python_sharegpt_23k
20,831
Write a Python function to calculate the error between the computed sum of two units and the theoretical value of two, given a range of values for the constants `a` and `b`. The function should generate a table with twenty or more rows, each row containing the values of `a`, `b`, the computed sum `a + b`, the theoretic...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def calculate_error_table(a_values: List[float], b_values: List[float]) -> List[Tuple[float, float, float, float, float]]: """ Calculate the error between the computed sum of two units and the the...
python_sharegpt_23k
20,837
Write a Python function to compute the sum of even numbers in a given list and display a formatted table showing each element of the list along with its contribution to the sum if it is even. The function should return the total sum of even numbers. The code should start with: ```python from typing import List def su...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_even_numbers_and_display_table(data: List[int]) -> int: """ Computes the sum of even numbers in the given list and displays a formatted table. Args: data (List[int]): The list of int...
python_sharegpt_23k
20,838
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
20,841
Write a Python function to evaluate the self-confidence, self-awareness, and self-stability of a person based on their properties in a dictionary. The function should return a string describing the person's characteristics based on the given conditions. The code should start with: ```python def evaluate_person(person:...
Here is the Python code to solve the given problem in the markdown block: ```python def evaluate_person(person: dict) -> str: """ Evaluates the self-confidence, self-awareness, and self-stability of a person based on their properties. Args: person (dict): A dictionary containing the properties of t...
python_sharegpt_23k
20,848
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
20,860
Write a Python function to filter out specific words from permit/deny statements in route-maps and print only the statements that do not contain the filtered words. The function should handle multiple route-maps and ensure that it can filter out multiple words provided by the user. The code should start with: ```pytho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Set def filter_route_maps(route_maps: Dict[str, List[str]], filtered_words: Set[str]) -> None: """ Filters out permit/deny statements in route-maps that contain any of the specified filtered words...
python_sharegpt_23k
20,863
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 constructed using an f-string. The code should start with: ```python def generate_sentence(landm...
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
20,867
Write a Python function to return the absolute value of the larger input from two given numbers. The function should support both integers and floating-point numbers, handle negative numbers, and ensure that the inputs are valid numeric types. The code should start with: ```python def max_abs_value(num1: float, num2: f...
Here is the Python code to solve the given problem in the markdown block: ```python def max_abs_value(num1: float, num2: float) -> float: """ Returns the absolute value of the larger input from two given numbers. Args: num1 (float): The first number to compare. num2 (float): The second numb...
python_sharegpt_23k
20,872
Write a Python function to categorize a list of animals into those that live on land and those that live in water using a dictionary data structure. The function should accept a list of animal names and return a dictionary with two keys: 'Land Animals' and 'Water Animals'. The values for these keys should be lists of a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def categorize_animals(animals: List[str]) -> Dict[str, List[str]]: """ Categorizes a list of animals into those that live on land and those that live in water. Args: animals (List[str...
python_sharegpt_23k
20,874
Write a Python function to extract the original words from a sequence of transformed words, where each word has been prefixed with "drove" and suffixed with a pattern "verb-noun". The function should return the original words in the correct sequence. The code should start with: ```python def extract_original_words(tra...
Here is the Python code to solve the given problem in the markdown block: ```python def extract_original_words(transformed_words: str) -> str: """ Extracts the original words from a sequence of transformed words. Each transformed word has a fixed prefix "drove" and a suffix that follows the pattern "verb-n...
python_sharegpt_23k
20,881
Write a Python function to validate and print the IP addresses of a private network. The function should take three strings as input, each representing an IP address (gateway, DNS server, and web server). The function should validate that each IP address is in the correct format (four octets separated by dots, with eac...
Here is the Python code to solve the given problem in the markdown block: ```python import re def validate_and_print_ips(gateway_ip: str, dns_ip: str, web_server_ip: str) -> None: """ Validates and prints the IP addresses of a private network. Args: gateway_ip (str): The IP address of the gateway ...
python_sharegpt_23k
20,890
Write a Python function to calculate the shortest path between two points in a city using Dijkstra's algorithm, given a list of streets that can be used. The function should take a graph representation of the city, the starting point, the ending point, and a list of allowed streets. The function should return the short...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple import heapq def shortest_path_dijkstra(graph: Dict[str, List[Tuple[str, int]]], start: str, end: str, streets: List[Tuple[str, str]]) -> str: """ Calculate the shortest path between two poi...
python_sharegpt_23k
20,891
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
20,902
Write a Python function to generate a unique identifier for a new laptop model using the manufacturer name, screen size, and processor type. The identifier should be formatted as follows: - The manufacturer name should be truncated to the first 6 characters. - The screen size should be rounded to one decimal place. - T...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_laptop_identifier(manufacturer: str, screen_size: float, processor_type: str) -> str: """ Generates a unique identifier for a new laptop model using the manufacturer name, screen size, and processor type. Args:...
python_sharegpt_23k
20,919
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
20,924
Write a Python function to calculate the sum of all odd numbers in a given list of integers. The function should iterate through the list, check if each number is odd, and if so, add it to the total sum. The function should return the total sum of all odd numbers. 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 sum_of_odds(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 sum of a...
python_sharegpt_23k
20,941
Write a Python function to convert a list of books into a list of dictionaries. Each dictionary should contain specific information about a single book, including the book's title, author's name, genre, and publisher's name. The input to this function will be a list of lists, where each inner list represents a book wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def convert_books_to_dict(book_list: List[List[str]]) -> List[Dict[str, str]]: """ Converts a list of books into a list of dictionaries. Each book in the input list is represented as a list of...
python_sharegpt_23k
20,945
Write a Python function to calculate the hypotenuse of a right triangle given the lengths of its two legs using the Pythagorean theorem. The function should take two arguments representing the lengths of the legs and return the length of the hypotenuse. The code should start with: ```python import math def calculate_h...
Here is the Python code to solve the given problem in the markdown block: ```python import math def calculate_hypotenuse(leg1: float, leg2: float) -> float: """ Calculate the hypotenuse of a right triangle given the lengths of its two legs. The Pythagorean theorem is used to calculate the hypotenuse: c = ...
python_sharegpt_23k
20,948
Write a Python function to validate an IPv4 address and determine its class. 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 address should consist of fou...
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
20,958
Write a Python function to validate if a given email address follows the standard email format using regular expressions. The function should return `True` if the email is valid and `False` otherwise. The code should start with: ```python import re def validate_email(email: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python import re def validate_email(email: str) -> bool: """ Validates if the given email address follows the standard email format. Args: email (str): The email address to validate. Returns: bool: True if th...
python_sharegpt_23k
20,967
Write a Python function to generate a randomized alliteration using the word 'banana' that includes at least three adjectives and three nouns. The alliteration must have a clear theme related to tropical fruits and must also include at least two rhyming words. Additionally, provide a brief explanation of the cultural s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict import random def generate_alliteration_and_culture() -> Dict[str, str]: """ Generates a randomized alliteration using the word 'banana' that includes at least three adjectives and three nouns. The a...
python_sharegpt_23k
20,972
Write a Python function to integrate a new character into the "Guri and Gura" book series, update the plot of existing books to include the new character's contributions, and determine the number of themes in the book series that align with the new character's interests or strengths. The function should also suggest po...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def integrate_new_character(book_series: Dict, new_character: Dict) -> Dict: """ Integrates a new character into the "Guri and Gura" book series, updates the plot of existing books, determines ...
python_sharegpt_23k
20,973
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
20,981
Write a Python function to encrypt a given string using the ROT13 cipher. The function should ensure that the output only contains uppercase letters and that the input string must be at least 10 characters long. The ROT13 cipher is a substitution cipher that replaces each letter with the letter 13 places down the alpha...
Here is the Python code to solve the given problem in the markdown block: ```python def rot13_encrypt(text: str) -> str: """ Encrypts a given string using the ROT13 cipher. The output will only contain uppercase letters, and the input string must be at least 10 characters long. Non-alphabetic characters are...
python_sharegpt_23k
20,983
Write a Python function to find the first non-repeated character in a given string. The function should return the character if found, otherwise return `None`. The code should start with: ```python from collections import Counter def first_non_repeated_char(string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python from collections import Counter def first_non_repeated_char(string: str) -> str: """ Find the first non-repeated character in the given string. Args: string (str): The input string to search for the first non-repea...
python_sharegpt_23k
20,985
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
20,996
Write a Python function to cancel meetings scheduled for the current week when the assistant is activated by the activation word "Abuela". The function should consider the scenario where the system needs to check the current week's meetings using the current local time of the user, and only cancel meetings in that week...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime, timedelta def cancel_meetings(user_id: int, activation_word: str) -> str: """ Cancels meetings scheduled for the current week when the assistant is activated by the word "Abuela". Args: ...
python_sharegpt_23k
21,004
Write a Python function to generate a personalized letter of recommendation for an individual, 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 ...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_recommendation_letter(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: s...
python_sharegpt_23k
21,005
Write a Python function to randomly select and return a case study from a given list of data analysis case studies. The function should ensure that the case study is chosen randomly each time it is called. The code should start with: ```python from typing import List def get_random_case_study(case_studies: List[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_case_study(case_studies: List[str]) -> str: """ Randomly selects and returns a case study from the given list of data analysis case studies. Args: case_studies (...
python_sharegpt_23k
21,008
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
21,015
Write a Python function to generate the first `k` terms of a quadratic sequence represented by the polynomial equation `n^2 + n + 1`, starting from `n=0`. The function should return a list of these terms. The code should start with: ```python from typing import List def generate_quadratic_sequence(k: int) -> List[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_quadratic_sequence(k: int) -> List[int]: """ Generate the first k terms of a quadratic sequence represented by the polynomial equation n^2 + n + 1, starting from n=0. Args: k (i...
python_sharegpt_23k
21,026
Write a Python program that includes several functions to perform mathematical operations on a list of numbers. The functions should be: 1. `get_sum(numbers)`: Returns the sum of the input numbers. If the input list is empty, it should return 0. 2. `get_average(numbers)`: Returns the average of the input numbers. If th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def get_sum(numbers: List[Union[int, float]]) -> Union[int, float]: """ Returns the sum of a list of numbers. Args: numbers (List[Union[int, float]]): A list of numbers. Returns:...
python_sharegpt_23k
21,035
Write a Python function to generate an undirected, weighted, fully connected graph with a given number of nodes. Each node should contain two integers between 0 and 1000, representing X and Y coordinates. The edge weights should be the Euclidean distance between the nodes sharing that edge. Additionally, the graph shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import random import math def generate_graph(num_nodes: int) -> Tuple[List[List[int]], List[Tuple[int, int]]]: """ Generates an undirected, weighted, fully connected graph with the given number of...
python_sharegpt_23k
21,036
Write a Python function to calculate the mean of a list of integers provided in a table format, where each number has a corresponding descriptive tag. The function should accept a list of tuples, where each tuple contains a number and its descriptive tag, and return the mean of the numbers. 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 calculate_mean(data: List[Tuple[int, str]]) -> float: """ Calculate the mean of a list of integers with corresponding descriptive tags. Args: data (List[Tuple[int, str]]): A list ...
python_sharegpt_23k
21,041
Write a Python function to determine if a given string representation of a number is divisible by a specified divisor. The function should convert the string to an integer, check divisibility, and return a boolean indicating whether the number is divisible by the divisor. The code should start with: ```python def is_d...
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by(string_num: str, divisor: int) -> bool: """ Determines if a given string representation of a number is divisible by a specified divisor. Args: string_num (str): The string representation of the n...
python_sharegpt_23k
21,051
Write a Python function that takes a list of tuples as input, where each tuple contains a string and an integer. The function should return a dictionary where the keys are the strings from the tuples and the values are the squares of the integers from the tuples. Additionally, the function should include error handling...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def tuple_to_squared_dict(tuples: List[Tuple[str, int]]) -> Dict[str, int]: """ Converts a list of tuples into a dictionary where the keys are the strings from the tuples and the values ...
python_sharegpt_23k
21,052
Write a Python function to compute the quotient and remainder of a number divided by 5 for a given range of numbers. Additionally, identify and return the highest remainder among these divisions. The function should start with: ```python from typing import List, Tuple def analyze_divisions_by_five(numbers: List[int]) ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def analyze_divisions_by_five(numbers: List[int]) -> Tuple[List[Tuple[int, int, int]], int]: """ Analyzes the division of a list of numbers by 5, computing the quotient and remainder for each numb...
python_sharegpt_23k
21,054
Write a Python function to combine multiple regular expressions in a specific sequence to accurately match intricate patterns that have multiple nested conditions and eliminate ambiguity. The function should handle different types of inputs, including text, numerical data, and special characters, with varying lengths a...
Here is the Python code to solve the given problem in the markdown block: ```python import re from typing import List def combine_regex_patterns(input_string: str, patterns: List[str]) -> List[str]: """ Combines multiple regular expressions in a specific sequence to match intricate patterns in the input string...
python_sharegpt_23k
21,058
Write a Python function to calculate the average weight of all animals in a zoo for the month of August, ensuring data validation and access control measures. The function should handle a list of dictionaries, each representing an animal with keys `name`, `weight_august`, and `species`. The function should filter out n...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def calculate_average_weight(animals_list: List[Dict[str, any]], authorized_personnel: str) -> float: """ Calculate the average weight of all animals in the zoo for the month of August, ensuring da...
python_sharegpt_23k
21,071
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
21,075
Write a Python function to track and alert when a goat with a rare genetic mutation is stolen from a farm. Additionally, the function should count the number of goats that have been stolen. The function should start with: ```python from typing import List, Dict def track_stolen_goats(animals: List[Dict[str, any]], rar...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def track_stolen_goats(animals: List[Dict[str, any]], rare_mutation_color: str) -> int: """ Tracks and alerts when a goat with a rare genetic mutation is stolen from a farm. Additionally, count...
python_sharegpt_23k
21,094
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 items_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. Return...
python_sharegpt_23k
21,096
Write a Python function to check if the first three elements of a given list of strings match the sequence ["A", "B", "C"]. The function should be optimized for performance and readability while maintaining its functionality. The code should start with: ```python from typing import List def check_data(data: List[str])...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def check_data(data: List[str]) -> bool: """ Check if the first three elements of the given list match the sequence ["A", "B", "C"]. Args: data (List[str]): The list of strings to check. ...
python_sharegpt_23k
21,100
Write a Python function to generate the next number in a given sequence based on a mathematical pattern. The sequence provided is: 2, 6, 14, 30, 62. The function should identify the pattern and compute the next number in the sequence. The code should start with: ```python def next_number_in_sequence(previous_number: i...
Here is the Python code to solve the given problem in the markdown block: ```python def next_number_in_sequence(previous_number: int) -> int: """ Calculate the next number in the sequence 2, 6, 14, 30, 62, ... The sequence follows the pattern where each number is derived from the previous number by mul...
python_sharegpt_23k
21,103
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
21,106
Write a Python function to encrypt a given string using the ROT13 cipher. The ROT13 cipher is a substitution cipher that replaces each letter with the letter 13 places down the alphabet. Non-alphabetic characters should remain unchanged. The function should handle both uppercase and lowercase letters. The code should ...
Here is the Python code to solve the given problem in the markdown block: ```python def rot13_encrypt(message: str) -> str: """ Encrypts a given string using the ROT13 cipher. The ROT13 cipher replaces each letter with the letter 13 places down the alphabet. Non-alphabetic characters remain unchanged. ...
python_sharegpt_23k
21,109
Write a Python function to compute the nth Fibonacci number using a recursive approach with memoization to improve performance. The function should be able to handle large values of n efficiently by storing previously computed Fibonacci numbers in a dictionary to avoid redundant calculations. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci_memoized(n: int, memo: dict = None) -> int: """ Compute the nth Fibonacci number using a recursive approach with memoization. Args: n (int): The position in the Fibonacci sequence to compute. m...
python_sharegpt_23k
21,111
Write a Python function that demonstrates the difference in outcome when using the `re.match` method instead of the `re.findall` method to extract all digit characters from a given string. The function should return a list of all digit characters found in the string. The code should start with: ```python import re de...
Here is the Python code to solve the given problem in the markdown block: ```python import re def extract_digits(test: str) -> list: """ Extracts all digit characters from the given string using the re.match method. Args: test (str): The input string from which to extract digit characters. Re...
python_sharegpt_23k
21,112
Write a Python function to generate a military-style marching chant that includes words, numbers, and a consistent rhyming scheme. The function should take into consideration the user's desired chant length, tempo, and the number of syllables in each line of the chant. The output should be formatted as a table that sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict import random def generate_military_chant(chant_length: int, tempo: int, syllables_per_line: int) -> str: """ Generates a military-style marching chant with a consistent rhyming scheme. Args: ...
python_sharegpt_23k
21,119
Write a Python function to categorize a given word as an adverb based on common suffixes used to form adverbs in English. The function should check if the word ends with specific suffixes such as "ly", "ily", "ward", "wards", "wise", etc. If the word matches any of these suffixes, it should be classified as an adverb. ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_adverb(word: str) -> bool: """ Determines if a given word is an adverb based on common suffixes used to form adverbs in English. Args: word (str): The word to be categorized. Returns: bool: True ...
python_sharegpt_23k
21,120
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 and coefficients...
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
21,127
Write a Python function to transform a given string by converting all the vowels (both uppercase and lowercase) to uppercase. The function should handle both uppercase and lowercase vowels and should not modify any other characters in the string. The code should start with: ```python def uppercase_vowels(text: 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 (both uppercase and lowercase) in the given string to uppercase. Args: text (str): The input string to be transformed. Returns: str:...
python_sharegpt_23k
21,136
Write a Python function to scramble the letters of each word in a given phrase, while keeping the words in their original order. The function should return the scrambled phrase. The code should start with: ```python from typing import List import random def scramble_phrase(phrase: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def scramble_phrase(phrase: str) -> str: """ Scrambles the letters of each word in the given phrase while keeping the words in their original order. Args: phrase (str): The inp...
python_sharegpt_23k
21,144
Write a Python function that computes the sum of two numbers. The function should take two arguments, `x` and `y`, and an optional parameter `round_to`. The function should only return the sum of the two numbers if the values of `x` and `y` are greater than zero, otherwise, it should raise a `ValueError`. Additionally,...
Here is the Python code to solve the given problem in the markdown block: ```python def sum_two_numbers(x, y, round_to=None): """ Computes the sum of two numbers, x and y, with optional rounding. Args: x (int or float): The first number to be summed. y (int or float): The second number to b...
python_sharegpt_23k
21,145
Write a Python function to rearrange the words in a given text string in alphabetical order. The function should use the Python built-in function `sorted()` to achieve this. The function should start with: ```python def sort_words_alphabetically(text: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sort_words_alphabetically(text: str) -> str: """ Rearranges the words in a given text string in alphabetical order. Args: text (str): The input text string containing words to be sorted. Returns: st...
python_sharegpt_23k
21,147
Write a Python function to calculate the expression `10 + 2n` for a given range of values of `n` and determine whether each result is even or odd. The function should return a list of strings where each string contains the result followed by either "EVEN" or "ODD". The function should start with: ```python from typing ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_and_classify(start: int, end: int) -> List[str]: """ Calculate the expression 10 + 2n for each integer n in the range [start, end] and classify each result as even or odd. Args: ...
python_sharegpt_23k
21,154
Write a Python function that uses the `match` method from the `re` module to find all digit characters in a given input string. The function should return a string containing all the digit characters found in the input string. The code should start with: ```python import re def find_digits_with_match(test: str) -> str...
Here is the Python code to solve the given problem in the markdown block: ```python import re def find_digits_with_match(test: str) -> str: """ Finds all digit characters in the given input string using the `match` method from the `re` module. Args: test (str): The input string to search for digit...
python_sharegpt_23k
21,157
Write a Python function named `filter_even_numbers` that takes a list of integers and returns a new list containing only the even numbers from the input list. The function should also accept an optional boolean parameter `include_zero`. If `include_zero` is set to `True`, the function should include the number `0` in t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_even_numbers(numbers: List[int], include_zero: bool = False) -> List[int]: """ Filter the odd numbers from the list of numbers and return a new list containing only the even numbers. Args...
python_sharegpt_23k
21,158
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
21,159
Write a Python function to sort a list of high-toned individuals based on their art scores in descending order and return the sorted list. Each individual is represented as a tuple containing their name and art score. The function should start with: ```python from typing import List, Tuple def sort_high_toned_individu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def sort_high_toned_individuals(individuals: List[Tuple[str, int]]) -> List[Tuple[str, int]]: """ Sorts a list of high-toned individuals based on their art scores in descending order. Args: ...
python_sharegpt_23k
21,161
Write a Python function to identify all the prime factors of a given number using the trial division method. The function should handle edge cases such as negative numbers and non-integer inputs. If the input is a negative number, the function should return the prime factors of its absolute value. If the input is not a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def prime_factors(n: int) -> List[int]: """ Identify all the prime factors of a given number using the trial division method. Args: n (int): The number for which to find the prime factors. ...
python_sharegpt_23k
21,167
Write a Python function to verify if all circles in a given set of objects are blue. The set of objects is represented by a list `Z=[z_1,...,z_n]`, where each `z_i` is a pair of integers, i.e., each `z_i=(a_i, b_i)` where `a_i` and `b_i` are integers. These two integers represent the properties of `z_i`, with `a_i` rep...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def verify_all_circles_blue(Z: List[List[int]]) -> bool: """ Verifies if all circles in a given set of objects are blue. Args: Z (List[List[int]]): List of objects represented by pairs of in...
python_sharegpt_23k
21,188
Write a Python function to generate a haiku verse that includes a noun, adjective, and verb from specific categories. The haiku should adhere to the traditional structure of three lines with 5, 7, and 5 syllables respectively. The function should randomly select words from the provided lists of nouns, adjectives, and v...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_haiku(nouns: List[str], adjectives: List[str], verbs: List[str]) -> str: """ Generates a haiku verse using randomly selected words from the provided lists of nouns, adjectives,...