source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
python_sharegpt_23k | 19,477 | 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 | 19,481 | Write a Python function to generate a haiku with a specific theme or subject. The haiku should consist of three lines with syllable counts of 5, 7, and 5 respectively. The function should take a theme as input and return the haiku as a string. The code should start with:
```python
from typing import List
def generate_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_haiku(theme: str) -> str:
"""
Generates a haiku with a specific theme. The haiku consists of three lines with syllable counts of 5, 7, and 5 respectively.
Args:
th... |
python_sharegpt_23k | 19,482 | 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 return a dictionary containing the length of the string, the time taken to print it, and the formatted string. The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import time
def measure_print_time(string: str, font_size: int = 12, color: str = 'black') -> Dict[str, any]:
"""
Measures the time it takes to print a string and returns the formatted string along with ... |
python_sharegpt_23k | 19,484 | 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 | 19,494 | 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:
"""
Splits the input string into individual words and concatenates them using underscores.
Args:
text (str): The input string to be processed.
Returns:
... |
python_sharegpt_23k | 19,496 | Write a Python function to remove all occurrences of a specific word or phrase from a given text, irrespective of its case sensitivity or presence of special characters. The function should return the modified text after removing the specified word or phrase.
The code should start with:
```python
import re
def remove... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def remove_word_from_text(text: str, word: str) -> str:
"""
Removes all occurrences of a specific word or phrase from a given text, irrespective of its case sensitivity or presence of special characters.
Args:
... |
python_sharegpt_23k | 19,503 | Write a Python function that calculates the sum and average of three given numbers, and prints the factors of each number up to 20. The function should return the sum and average of the numbers. Additionally, provide a brief explanation of the significance of these three numbers in the context of their respective histo... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_sum_avg_factors(num1: int, num2: int, num3: int) -> tuple:
"""
Calculate the sum and average of three given numbers, print the factors of each number up to 20,
and return the sum and average.
Args:
... |
python_sharegpt_23k | 19,504 | 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 | 19,508 | 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 parameters representing the lengths of the legs and return the length of the hypotenuse. The code should start with:
```python
import math
def calculate_... | 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 | 19,509 | 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 | 19,512 | Write a Python function to rewrite a given sentence while preserving its original meaning. The function should replace specific phrases in the sentence with semantically equivalent phrases. The code should start with:
```python
def rewrite_sentence(sentence: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def rewrite_sentence(sentence: str) -> str:
"""
Rewrites a given sentence by replacing specific phrases with semantically equivalent phrases.
Args:
sentence (str): The original sentence to be rewritten.
Returns... |
python_sharegpt_23k | 19,516 | 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. The code should start with:
```python
from typing import List
def select_romantic_constellation(const... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def select_romantic_constellation(constellations: List[str]) -> str:
"""
Selects a random constellation from a list of constellations associated with love, beauty, and eternity.
Args:
... |
python_sharegpt_23k | 19,517 | 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.
Onl... |
python_sharegpt_23k | 19,522 | 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 | 19,523 | 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. The list should include at least 10 jokes involving various historical figures. The code should start with:
```python
from typing import List
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() -> str:
"""
Generates a random historical figure joke from a predefined list of jokes.
Returns:
str: A randomly selected joke involving a histo... |
python_sharegpt_23k | 19,529 | Write a Python function to efficiently calculate the Euclidean distance between two points in an n-dimensional space using list comprehension. The function should take two tuples as input, each representing the coordinates of a point, and return a float representing the distance between these points. The function shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
import math
def euclidean_distance(point1: Tuple[float], point2: Tuple[float]) -> float:
"""
Calculate the Euclidean distance between two points in an n-dimensional space.
Args:
point1 (Tup... |
python_sharegpt_23k | 19,533 | Write a Python function to convert a temperature from Fahrenheit to Celsius. The function should take a single argument representing the temperature in Fahrenheit and return the temperature in Celsius. The code should start with:
```python
def fahrenheit_to_celsius(fahrenheit: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def fahrenheit_to_celsius(fahrenheit: float) -> float:
"""
Convert a temperature from Fahrenheit to Celsius.
Args:
fahrenheit (float): The temperature in Fahrenheit.
Returns:
float: The temperature in C... |
python_sharegpt_23k | 19,536 | Write a Python function to generate a random numerical sequence of eight digits where each digit follows a Gaussian distribution with a specified mean and standard deviation. The function should ensure that each digit in the sequence is an integer between 0 and 9.
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
import numpy as np
def generate_gaussian_sequence(mean: float, std_dev: float) -> str:
"""
Generates a random numerical sequence of eight digits where each digit follows a Gaussian distribution.
Arg... |
python_sharegpt_23k | 19,538 | 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 sum_... | 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 | 19,540 | 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 | 19,541 | 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 based on the given pattern.
The sequence follows the pattern where each number is derived by multiplying
the previo... |
python_sharegpt_23k | 19,542 | Write a Python function to reverse a given list of integers. The function should return a new list that is the reverse of the input list, without modifying the original list. The code should start with:
```python
from typing import List
def reverse_list(input_list: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def reverse_list(input_list: List[int]) -> List[int]:
"""
Returns a new list that is the reverse of the input list without modifying the original list.
Args:
input_list (List[int]): The li... |
python_sharegpt_23k | 19,545 | 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 | 19,548 | 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 | 19,562 | Write a Python function to determine the affordable items for multiple budgets from multiple lists of prices. The function should return a dictionary where each key is a budget and each value is a list of prices that are less than or equal to that budget. If a price exceeds a budget, it should be ignored.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def find_affordable_items(budgets: List[int], price_lists: List[List[int]]) -> Dict[int, List[int]]:
"""
Determine the affordable items for multiple budgets from multiple lists of prices.
Args... |
python_sharegpt_23k | 19,564 | Write a Python function to sort a given list of words in ascending order based on their ASCII values and return both the sorted list and the reverse sorted list. The function should handle any list of strings and return two lists: one sorted in ascending order and the other in descending order.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_words_by_ascii(words: List[str]) -> Tuple[List[str], List[str]]:
"""
Sorts a given list of words in ascending order based on their ASCII values and returns both the sorted list and the re... |
python_sharegpt_23k | 19,578 | 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 | 19,585 | Write a Python function to determine if a given string is a palindrome, ignoring spaces, punctuation marks, and case sensitivity. The function should return `True` if the string is a palindrome and `False` otherwise. The code should start with:
```python
import string
def is_palindrome(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import string
def is_palindrome(s: str) -> bool:
"""
Determine if a given string is a palindrome, ignoring spaces, punctuation marks, and case sensitivity.
Args:
s (str): The input string to check.
Returns:
... |
python_sharegpt_23k | 19,588 | Write a Python function to convert a decimal number to its binary representation without using the built-in `bin()` function. The function should handle positive integers only. The code should start with:
```python
def decimal_to_binary(decimal_num: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def decimal_to_binary(decimal_num: int) -> str:
"""
Converts a decimal number to its binary representation without using the built-in `bin()` function.
Args:
decimal_num (int): A positive integer to be converted to ... |
python_sharegpt_23k | 19,590 | Write a Python function to find and return a list of rare words from a given list of words. A rare word is defined as a word that appears exactly once in the list. Additionally, the function should exclude words that start with the letters 'a' or 'b' (case insensitive), and capitalize the first letter of each remaining... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_rare_words(word_list: List[str]) -> List[str]:
"""
Finds and returns a list of rare words from the given list of words.
A rare word is defined as a word that appears exactly once in the list... |
python_sharegpt_23k | 19,591 | Write a Python function to remove all alphabetic characters from a given alphanumeric string and return the resulting numeric string. The function should handle strings of varying lengths and ensure that only numeric characters are retained in the output.
The code should start with:
```python
def remove_alphabets(s: s... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_alphabets(s: str) -> str:
"""
Removes all alphabetic characters from the given alphanumeric string and returns the resulting numeric string.
Args:
s (str): The alphanumeric string from which alphabetic ch... |
python_sharegpt_23k | 19,592 | Write a Python function to find the maximum and minimum values for each data type (floats and strings) in a list, including nested lists. The function should return a dictionary where each key is a data type ('float' or 'str') and the value is another dictionary with 'max' and 'min' keys. If the list contains nested li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union, Dict
def find_max_min(data: Union[List[Union[float, str, List]], float, str]) -> Dict[str, Dict[str, Union[float, str]]]:
"""
Find the maximum and minimum values for each data type (floats and st... |
python_sharegpt_23k | 19,594 | Write a Python function to categorize non-conventional manufacturing processes based on their primary material removal mechanism. The function should take a list of process names and return a dictionary where the keys are the primary material removal mechanisms and the values are lists of processes that use those mecha... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def categorize_processes(processes: List[str]) -> Dict[str, List[str]]:
"""
Categorizes non-conventional manufacturing processes based on their primary material removal mechanism.
Args:
... |
python_sharegpt_23k | 19,597 | Write a Python function to classify a list of data points based on the given classification rule and return a dictionary containing the count of data points classified as "A" and "B". Each data point is a tuple consisting of two values: a numerical value `x` and a binary value `y`. The classification rule is as follows... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def classify_data_points(data_points: List[Tuple[int, int]]) -> Dict[str, int]:
"""
Classify a list of data points based on the given rule and return the count of each classification.
A... |
python_sharegpt_23k | 19,599 | Write a Python function to generate all possible chords of three notes from a given musical scale. The scale is represented as a list of notes. Each chord should be a combination of three unique notes from the scale. The function should return a list of lists, where each inner list represents a chord.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import itertools
def generate_chords(scale: List[str]) -> List[List[str]]:
"""
Generate all possible chords of three notes from a given musical scale.
Args:
scale (List[str]): A list of stri... |
python_sharegpt_23k | 19,601 | Write a Python function to generate a random string of 50 alphanumeric characters, convert it into a binary string, count the frequency of each unique character in the binary string, and return a sorted dictionary of these frequencies in descending order based on the count of each character.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import random
import string
from collections import Counter
def generate_and_analyze_binary_string() -> Dict[str, int]:
"""
Generates a random string of 50 alphanumeric characters, converts it to a binar... |
python_sharegpt_23k | 19,614 | 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 = 1, color: str = 'default') -> float:
"""
Measures the time it takes to print a string and applies formatting options such as font size and color.
... |
python_sharegpt_23k | 19,632 | Write a Python function to calculate the total profit for a store given the total revenue, cost of goods sold, operating expenses, and taxes. The function should return the calculated profit. Additionally, provide a detailed explanation of the factors that contribute to the final profit value.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_profit(total_revenue: float, cost_of_goods_sold: float, operating_expenses: float, taxes: float) -> float:
"""
Calculate the total profit for a store given the total revenue, cost of goods sold, operating expenses,... |
python_sharegpt_23k | 19,640 | Write a Python function to calculate the sum of the squares of all even numbers in a given list. The function should iterate over the list, check if each number is even, and if so, add its square to a running total. The code should start with:
```python
from typing import List
def sum_of_squares_of_evens(numbers: List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_squares_of_evens(numbers: List[int]) -> int:
"""
Calculate the sum of the squares of all even numbers in the given list.
Args:
numbers (List[int]): A list of integers.
Return... |
python_sharegpt_23k | 19,647 | Write a Python function to divide two numbers using multiple steps, such as declaring variables, defining functions, and applying conditional statements. The function should be robust enough to handle various inputs and outputs, and it should consider the potential errors and exceptions, such as division by zero and no... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_divide(num1, num2):
"""
Safely divides two numbers and returns the result or an error message.
Args:
num1 (int or float): The numerator.
num2 (int or float): The denominator.
Returns:
f... |
python_sharegpt_23k | 19,658 | Write a Python function to add two positive integers within a specific range (1 to 100). The function should validate the inputs and return an informative error message if the inputs are not valid. The code should start with:
```python
def add_positive_integers_in_range(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def add_positive_integers_in_range(x: int, y: int) -> int:
"""
Adds two positive integers within the range of 1 to 100.
Args:
x (int): The first integer to be added.
y (int): The second integer to be added.
... |
python_sharegpt_23k | 19,673 | Write a Python function to filter a list of integers and return a new list containing only the elements that are divisible by both 3 and 5, but not by 2. The function should use list comprehension and lambda functions. The code should start with:
```python
from typing import List
def filter_divisible_numbers(numbers: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_divisible_numbers(numbers: List[int]) -> List[int]:
"""
Filters a list of integers and returns a new list containing only the elements
that are divisible by both 3 and 5, but not by 2.
... |
python_sharegpt_23k | 19,693 | Write a Python function to extract unique values from a list of tuples based on the second element of each tuple, but only for tuples where the first element starts with a vowel. The extracted unique values should then be sorted alphabetically. The function should start with:
```python
from typing import List, Tuple
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def extract_and_sort_unique_values(tuples_list: List[Tuple[str, int]]) -> List[int]:
"""
Extracts unique values from a list of tuples based on the second element of each tuple,
but only for tu... |
python_sharegpt_23k | 19,696 | Write a Python function to generate a random color in RGB format and provide a clue based on the dominant color component (red, green, or blue) to help solve a riddle. The riddle is: "I am vast and constantly shifting, my magnificence is limitless, I display serene nature yet fierce intensity, and I am teeming with lif... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_color_clue() -> tuple:
"""
Generates a random color in RGB format and provides a clue based on the dominant color component to help solve a riddle.
The riddle is: "I am vast and constantly shifti... |
python_sharegpt_23k | 19,706 | Write a Python function to calculate the sum of all even numbers in a given list, while filtering out any non-integer elements. The function should handle lists with mixed data types and only consider integers for the sum.
The code should start with:
```python
from typing import List, Union
def sum_even_numbers(numbe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def sum_even_numbers(numbers: List[Union[int, float, str, bool]]) -> int:
"""
Calculate the sum of all even numbers in a given list, filtering out non-integer elements.
Args:
numbers ... |
python_sharegpt_23k | 19,718 | Write a Python function to enhance a given sentence by adding an HTML tag with a specified class to a specific word in the sentence. The function should replace the specified word with an HTML-tagged version of the word.
The code should start with:
```python
def enhance_sentence_with_tag(sentence: str, word: str, tag:... | Here is the Python code to solve the given problem in the markdown block:
```python
def enhance_sentence_with_tag(sentence: str, word: str, tag: str) -> str:
"""
Enhances a given sentence by adding an HTML tag with a specified class to a specific word.
Args:
sentence (str): The original sentence to... |
python_sharegpt_23k | 19,737 | Write a Python function to generate a random code that consists of four characters: two uppercase letters followed by two numbers. The letters should represent the initials of a program name, the first number should represent the number of trees in an outdoor classroom, and the second number should represent the total ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
import random
import string
def generate_outdoor_classroom_code() -> str:
"""
Generates a random code consisting of four characters: two uppercase letters followed by two numbers.
The letters repres... |
python_sharegpt_23k | 19,738 | 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() -> float:
"""
Generates a 500x20 matrix where each element is the sum of the two elements directly above it and to the left,
and then finds the maximum value in the... |
python_sharegpt_23k | 19,745 | 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 | 19,746 | Write a Python function to compute the nth Fibonacci number using memoization to optimize performance. The function should cache previously computed Fibonacci numbers to avoid redundant calculations, thus improving efficiency. The code should start with:
```python
def fibonacci_memoized(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci_memoized(n: int) -> int:
"""
Compute the nth Fibonacci number using memoization to optimize performance.
Args:
n (int): The position in the Fibonacci sequence to compute.
Returns:
int: The... |
python_sharegpt_23k | 19,752 | Write a Python function to determine the current date, time, and time zone, and calculate the number of seconds that have passed since the start of the day. The function should return a dictionary containing the current date, time, time zone, and the number of seconds since midnight.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import datetime
def get_current_time_info() -> Dict[str, str]:
"""
Determine the current date, time, time zone, and calculate the number of seconds since midnight.
Returns:
Dict[str, str]: A... |
python_sharegpt_23k | 19,764 | Write a Python function to calculate the sum of all even numbers up to a given integer `n`. The function should efficiently compute this sum with a time complexity of O(n/2), which simplifies to O(n).
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 up to a given integer n.
Args:
n (int): The upper limit of the range (inclusive) for which to calculate the sum of even numbers.
Re... |
python_sharegpt_23k | 19,766 | Write a Python function to find the minimum value in a list of numbers. The function should handle lists of integers and floats, and should return the smallest value in the list. The code should start with:
```python
from typing import List, Union
def find_minimum(numbers: List[Union[int, float]]) -> Union[int, float]... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Union
def find_minimum(numbers: List[Union[int, float]]) -> Union[int, float]:
"""
Find the minimum value in a list of numbers.
Args:
numbers (List[Union[int, float]]): A list of integers... |
python_sharegpt_23k | 19,778 | Write a Python function that takes two prime numbers as input and returns the product of these two numbers. Additionally, the function should print a table showing the first 10 multiples of the product. The function should include error handling to ensure that both inputs are indeed prime numbers. The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
def prime_product_with_multiples(num1: int, num2: int) -> int:
"""
Calculate the product of two prime numbers and print a table of the first 10 multiples of the product.
Args:
num1 (int): The first prime number.
... |
python_sharegpt_23k | 19,784 | Write a Python function to generate an undirected, weighted, fully connected graph with a given number of nodes. Each node should have a unique identifier between 1 and 1000 and contain two integers between 0 and 1000 representing X and Y coordinates. The edge weights should be the Euclidean distance between the nodes ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
import random
import math
def generate_graph(num_nodes: int) -> Dict[int, Dict[int, int]]:
"""
Generates an undirected, weighted, fully connected graph with the given number of nodes.
Each no... |
python_sharegpt_23k | 19,787 | Write a Python function to remove all occurrences of a specific word or phrase from a given text, irrespective of its case sensitivity or presence of special characters. The function should return the modified text after removing the specified word or phrase.
The code should start with:
```python
import re
def remove... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def remove_word_from_text(text: str, word: str) -> str:
"""
Removes all occurrences of a specific word or phrase from a given text, irrespective of its case sensitivity or presence of special characters.
Args:
... |
python_sharegpt_23k | 19,788 | Write a Python function to remove all duplicate characters from an input string, ignoring case sensitivity, and return a new string containing only unique characters sorted alphabetically. The function should handle strings of varying sizes and edge cases effectively.
The code should start with:
```python
def remove_d... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_duplicates_and_sort(input_string: str) -> str:
"""
Removes all duplicate characters from the input string, ignoring case sensitivity,
and returns a new string containing only unique characters sorted alphabeticall... |
python_sharegpt_23k | 19,795 | 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 by frequency. Additionally, the function should inc... | 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 | 19,814 | Write a Python function to print the values of columns A and B from a given input table, and also indicate whether the value in Column A is odd or even. The input table is represented as a list of tuples, where each tuple contains two elements: the value for Column A and the value for Column B. The function should iter... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def print_columns_with_parity(table: List[Tuple[int, str]]) -> None:
"""
Prints the values of columns A and B from a given input table, and indicates whether the value in Column A is odd or even.
... |
python_sharegpt_23k | 19,819 | 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. Additionally, write a function that takes a greeting message as input and prints it. The function should be designed to handle any string input for the gr... | Here is the Python code to solve the given problem in the markdown block:
```python
#!/usr/bin/python3
# Greeting python program
def print_greeting(message: str) -> None:
"""
Prints the given greeting message.
Args:
message (str): The greeting message to be printed.
Returns:
None
... |
python_sharegpt_23k | 19,821 | Write a Python function to simulate the time it takes for a car to slide on a frigid road given various factors such as temperature, speed, traction, visibility, road condition, and driver error. The function should calculate the time to slide based on a friction coefficient that is influenced by these factors. The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def simulate_car_slide(temp: float, speed: float, traction: str, visibility: str, road_condition: str, driver_error: str) -> float:
"""
Simulate the time it takes for a car to slide on a frigid road given various ... |
python_sharegpt_23k | 19,824 | Write a Python function to generate a limerick using a randomly selected word from a list of words that rhyme with "orange". The function should return the limerick as a string. The limerick structure should be as follows:
```
There once was a man from Blorenge
Whose hair was the color of [selected_word]
He searched h... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_limerick(rhyming_words: List[str]) -> str:
"""
Generates a limerick using a randomly selected word from a list of words that rhyme with "orange".
Args:
rhyming_wor... |
python_sharegpt_23k | 19,826 | Write a Python function to calculate the Euclidean distance between two points in a 2D plane. The function should validate the input types and handle the case where the two points are the same. If all required parameters are inputted correctly and the function is ready for execution, it should return a confirmation mes... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_distance(x1: float, y1: float, x2: float, y2: float) -> str:
"""
Calculate the Euclidean distance between two points (x1, y1) and (x2, y2) in a 2D plane.
If the input types are invalid or the points are the sam... |
python_sharegpt_23k | 19,827 | Write a Python function to find the first duplicate number within a given list of integers without using any additional memory. The function should modify the input list in place and return the first duplicate number found. If no duplicates are found, the function should return -1. The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_duplicate_in_place(nums: List[int]) -> int:
"""
Finds the first duplicate number within a given list of integers without using additional memory.
Args:
nums (List[int]): The list of... |
python_sharegpt_23k | 19,838 | Write a Python function to implement the Q-learning algorithm for an autonomous agent in a simple environment. The environment is represented by a reward matrix where each state has two possible actions, and the agent's goal is to learn the optimal policy to maximize cumulative rewards over time. The function should tr... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def q_learning_agent(reward_matrix: np.ndarray, n_episodes: int, learning_rate: float, discount_factor: float, epsilon: float) -> np.ndarray:
"""
Implements the Q-learning algorithm to train an autonomous age... |
python_sharegpt_23k | 19,840 | Write a Python function that replaces the word "astounding" in a given sentence with a randomly selected synonym from a predefined list of synonyms. Additionally, the function should return a table of these synonyms along with their definitions. The code should start with:
```python
from typing import List, Tuple
impor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import random
def replace_astounding_with_synonym(sentence: str) -> Tuple[str, List[Tuple[str, str]]]:
"""
Replaces the word "astounding" in the given sentence with a randomly selected synonym and... |
python_sharegpt_23k | 19,842 | Write a Python function to perform binary search on a sorted array of integers to find the index of a target value. If the target value is not found, return -1. The function should use the binary search algorithm, which involves repeatedly dividing the search interval in half. 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 binary_search(array: List[int], target: int) -> int:
"""
Perform binary search on a sorted array to find the index of the target value.
Args:
array (List[int]): A sorted list of integers... |
python_sharegpt_23k | 19,844 | Write a Python function to generate a distinctive and personalized birthday message for each friend in a provided list of friends. The message should not only contain their name but also reflect their individuality, interests, and traits. The function should start with:
```python
from typing import List
def generate_b... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_birthday_messages(friends: List[str]) -> List[str]:
"""
Generates a distinctive and personalized birthday message for each friend in the provided list.
Args:
friends (List[str])... |
python_sharegpt_23k | 19,845 | Write a Python function to generate a keto-friendly dinner recipe that meets the following criteria:
1. The total prep time should be 30 minutes or less.
2. Each serving should have less than 10 grams of carbs.
3. The function should return a dictionary containing the recipe's title, ingredients, instructions, and nutr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def generate_keto_recipe() -> Dict[str, Dict[str, List[str]]]:
"""
Generates a keto-friendly dinner recipe that meets the following criteria:
1. The total prep time is 30 minutes or less.
2... |
python_sharegpt_23k | 19,847 | Write a Python function to simulate the financial impact of choosing between a one-year lease and a two-year lease, given the current monthly expenses, the increase in monthly expenses, and the monthly rent for each lease option. The function should calculate the remaining budget for each lease option and the total cos... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def simulate_lease_options(current_rent: int, monthly_expenses: int, increase_expenses: int, one_year_lease: int, two_year_lease: int) -> Dict[str, Dict[str, int]]:
"""
Simulate the financial impact of c... |
python_sharegpt_23k | 19,851 | 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, remove any punctuation, white space, or special characters, and then concatenate the words using underscores to create a single string. 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 words from the input string using underscores, removing any punctuation, white space, or special characters.
Args:
text (str): The input string to... |
python_sharegpt_23k | 19,853 | 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 each row until the condition is met. 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
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 | 19,866 | Write a Python function to implement a stable sorting algorithm with a space complexity of O(1) that can handle duplicates in the input without affecting the time or space complexity. The algorithm should maintain the relative order of equal elements in the sorted output. The code should start with:
```python
from typi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def stable_sort_in_place(arr: List[int]) -> List[int]:
"""
Sorts the input list in place using the Cocktail Shaker Sort algorithm, which is stable and has O(1) space complexity.
Args:
arr (L... |
python_sharegpt_23k | 19,871 | 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
import re
def generate_unhealthy_relationship_signs() -> List[str]:
"""
Generates a comprehensive list of ten behavioral and emotional signs that indicate an unhealthy relationship.
Returns:
... |
python_sharegpt_23k | 19,875 | Write a Python function to generate a tryptic joke about a popular movie, utilizing wordplay, puns, and references to popular culture. The function should take a movie title, a hero, a villain, a weapon, and a team as input and return a list of three jokes. Each joke should be structured in a way that combines the inpu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import random
def generate_tryptic_joke(movie: str, hero: str, villain: str, weapon: str, team: str) -> List[Tuple[str, str]]:
"""
Generates a tryptic joke about a popular movie using wordplay, pu... |
python_sharegpt_23k | 19,907 | Write a Python function to generate a sequence of prime numbers up to a given integer input `n` using the Sieve of Eratosthenes algorithm. The function should return a list of all prime numbers less than or equal to `n`.
The code should start with:
```python
from typing import List
def generate_primes(n: int) -> List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_primes(n: int) -> List[int]:
"""
Generate a list of prime numbers up to a given integer n using the Sieve of Eratosthenes algorithm.
Args:
n (int): The upper limit up to which p... |
python_sharegpt_23k | 19,908 | Write a Python function to implement a binary search algorithm for a sorted array of integers. The function should return the index of the target element if it exists in the array, otherwise return -1. The function should be optimized to minimize the number of iterations and should handle edge cases such as an empty ar... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(arr: List[int], target: int) -> int:
"""
Perform a binary search on a sorted array to find the index of the target element.
Args:
arr (List[int]): A sorted list of integers... |
python_sharegpt_23k | 19,914 | Write a Python function called `remove_duplicates_advanced` that takes a list as input and returns a new list with all the duplicate elements removed. The function should only use nested loops to traverse the list and compare each element with all the previous elements. The function should not use any built-in Python f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_advanced(lst: List[int]) -> List[int]:
"""
Removes duplicate elements from a list using only nested loops and primitive data types.
Args:
lst (List[int]): The input lis... |
python_sharegpt_23k | 19,917 | Write a Python function to find the least common multiple (LCM) of three given integers and calculate the sum of all the prime factors of the LCM. The function should take three integers as input and return a tuple containing the LCM and the sum of its prime factors.
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 Tuple
import math
def lcm_and_prime_factors_sum(a: int, b: int, c: int) -> Tuple[int, int]:
"""
Calculate the least common multiple (LCM) of three integers and the sum of all the prime factors of the LCM.
... |
python_sharegpt_23k | 19,923 | Write a Python function to determine the usefulness of two algorithms, `Algorithm X` and `Algorithm Y`, based on their accuracy. The function should take two boolean values as input, representing the accuracy of `Algorithm X` and `Algorithm Y`. The function should print whether each algorithm is useful or not useful ba... | Here is the Python code to solve the given problem in the markdown block:
```python
def determine_usefulness(accuracy_algorithm_X: bool, accuracy_algorithm_Y: bool) -> None:
"""
Determines the usefulness of Algorithm X and Algorithm Y based on their accuracy.
Args:
accuracy_algorithm_X (bool): The ... |
python_sharegpt_23k | 19,928 | Write a Python function to normalize a given string by converting all characters to lowercase and removing any special characters or punctuation marks, while preserving the order of the remaining characters. The function should return the normalized string.
The code should start with:
```python
import re
def normaliz... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def normalize_string(input_string: str) -> str:
"""
Normalizes the given string by converting all characters to lowercase and removing any special characters or punctuation marks.
Args:
input_string (str)... |
python_sharegpt_23k | 19,937 | Write a Python function that takes an iterable (such as a list, tuple, or string) and returns a list of tuples where each tuple contains the index and the corresponding item from the iterable. The function should use the built-in `enumerate()` function to achieve this.
The code should start with:
```python
from typing... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Iterable
def indexed_items(iterable: Iterable) -> List[Tuple[int, any]]:
"""
Returns a list of tuples where each tuple contains the index and the corresponding item from the iterable.
Args:
... |
python_sharegpt_23k | 19,947 | Write a Python function to calculate the product of two integers using a recursive approach. The function should handle both positive and negative integers. The code should start with:
```python
def recursive_multiply(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def recursive_multiply(a: int, b: int) -> int:
"""
Calculate the product of two integers using a recursive approach.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
int... |
python_sharegpt_23k | 19,949 | Write a Python function to generate a detailed description of each type of Gallagher Access Control Hardware Module from a given list. The function should return a formatted string that includes the module type and its corresponding description.
The code should start with:
```python
from typing import List, Dict
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def describe_modules(modules: List[str], module_types: Dict[str, str]) -> str:
"""
Generates a detailed description of each type of Gallagher Access Control Hardware Module.
Args:
modu... |
python_sharegpt_23k | 19,951 | Write a Python function to reverse the order of characters in a given string. The function should take a string as input and return the reversed string. The code should start with:
```python
def reverse_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_string(s: str) -> str:
"""
Reverses the order of characters in a given string.
Args:
s (str): The input string to be reversed.
Returns:
str: The reversed string.
"""
# Use string s... |
python_sharegpt_23k | 19,957 | Write a Python function that takes an input list of integers and returns a dictionary where the keys are the original numbers and the values are their corresponding squares. Use the dictionary data type to store the results. The function should handle an empty list gracefully by returning an empty dictionary.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_square_dict(input_list: List[int]) -> Dict[int, int]:
"""
Creates a dictionary where the keys are the original numbers from the input list and the values are their squares.
Args:
... |
python_sharegpt_23k | 19,973 | Write a Python function to generate a table that lists the ASCII codes and hexadecimal codes of all uppercase letters in alphabetical order. The function should return a formatted string representing the table.
The code should start with:
```python
def generate_ascii_hex_table() -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def generate_ascii_hex_table() -> str:
"""
Generates a formatted table of ASCII and hexadecimal codes for all uppercase letters.
Returns:
str: A formatted string representing the table.
"""
# Initialize the ... |
python_sharegpt_23k | 19,976 | Write a Python function to find the smallest difference between any two distinct numbers in a given set of non-negative integers, ensuring that the resulting difference is greater than or equal to a specified minimum value. If there are less than two numbers in the set or if all numbers in the set are identical, the fu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def smallest_difference_with_min_value(nums: List[int], min_value: int) -> int:
"""
Find the smallest difference between any two distinct numbers in a given set of non-negative integers,
ensuring tha... |
python_sharegpt_23k | 19,984 | Write a Python function to extract route-map names and permit/deny statements from a given configuration string, and filter out any statements containing specific words provided by the user. The filtered words should be stored in a list. After filtering, only permit/deny statements that do not include the filtered word... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def filter_route_maps(config: str, filtered_words: List[str]) -> None:
"""
Extracts route-map names and permit/deny statements from a given configuration string,
and filters out any stateme... |
python_sharegpt_23k | 19,996 | Write a Python function to calculate the Levenshtein distance between two given strings. The Levenshtein distance is defined as the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one word into the other. The function should start with:
```python
def levenshtein_dis... | Here is the Python code to solve the given problem in the markdown block:
```python
def levenshtein_distance(s1: str, s2: str) -> int:
"""
Calculate the Levenshtein distance between two strings.
The Levenshtein distance is the minimum number of single-character edits
(insertions, deletions, or substitu... |
python_sharegpt_23k | 19,998 | Write a Python function to validate a string based on the following criteria:
1. The input must be a string.
2. The string must have a length of at least 3 characters.
3. The string must contain only alphabetic characters.
4. If the string meets all the criteria, it should be converted to title case and returned.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_string(string: str) -> bool | str:
"""
Validates a string based on the following criteria:
1. The input must be a string.
2. The string must have a length of at least 3 characters.
3. The string must con... |
python_sharegpt_23k | 20,008 | Write a Python function to sum the first five even elements of a given array and check if the sum is greater than 10 and less than 20. The array contains 10 elements, where the first 5 elements are even numbers and the next 5 elements are odd numbers. Additionally, count and print the number of even and odd elements se... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_and_count_elements(arr: List[int]) -> None:
"""
Sums the first five even elements of a given array and checks if the sum is greater than 10 and less than 20.
Additionally, counts and prints t... |
python_sharegpt_23k | 20,009 | 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 | 20,013 | Write a Python function to define a hierarchical network topology with three distinct IP addresses, each representing a different layer in the network. The function should return a dictionary containing the IP addresses, subnet masks, and network addresses for the gateway router, DNS server, and web server. Each device... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def define_network_topology() -> Dict[str, Dict[str, str]]:
"""
Define a hierarchical network topology with distinct IP addresses, subnet masks, and network addresses for a gateway router, DNS server, an... |
python_sharegpt_23k | 20,015 | Write a Python function to convert a given temperature in Celsius to Fahrenheit using the formula `(Celsius * 9/5) + 32`. The function should be able to handle both positive and negative temperatures. Additionally, create a function that generates a table of Fahrenheit equivalents for Celsius temperatures ranging from ... | Here is the Python code to solve the given problem in the markdown block:
```python
def celsius_to_fahrenheit(celsius: float) -> float:
"""
Convert a given temperature in Celsius to Fahrenheit.
Args:
celsius (float): The temperature in Celsius to be converted.
Returns:
float: The tempe... |
python_sharegpt_23k | 20,019 | Write a Python function to generate a random simile and a random metaphor from predefined lists and print 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_devices(... | 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.
Args:
... |
python_sharegpt_23k | 20,022 | Write a Python function to implement a merge sort algorithm that can handle sorting of integers, strings, and floating-point numbers, including possible duplicates. The sorting should be stable and should not cause any loss of precision for floating-point numbers. The function should start with:
```python
from typing i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def merge_sort(arr: List[Union[int, float, str]]) -> List[Union[int, float, str]]:
"""
Sorts a list containing integers, floating-point numbers, and strings using the merge sort algorithm.
Ar... |
python_sharegpt_23k | 20,031 | Write a Python function to create a dictionary where each key is a word from a given list of words, and the corresponding value is the length of the word. The function should handle an empty list gracefully by returning an empty dictionary.
The code should start with:
```python
from typing import List, Dict
def creat... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_word_length_dict(words: List[str]) -> Dict[str, int]:
"""
Creates a dictionary where each key is a word from the given list and the corresponding value is the length of the word.
Ar... |
python_sharegpt_23k | 20,035 | Write a Python function to print categories from a dictionary in a specific order. The first row should contain categories grouped by their size, with larger categories on the left and smaller categories on the right. The second row should contain the remaining categories arranged alphabetically. Each category should b... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def print_categories_by_size_and_alphabet(categories: Dict[str, List[str]]) -> None:
"""
Prints categories from a dictionary in a specific order. The first row contains categories grouped by their ... |
python_sharegpt_23k | 20,039 | Write a Python function to find all pairs of anagrams in a given list of strings. The function should return a list of tuples, where each tuple contains a pair of anagrams. The function should be efficient and able to handle large lists of strings with varying lengths. The code should start with:
```python
from typing ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
from collections import defaultdict
def find_anagram_pairs(strings: List[str]) -> List[Tuple[str, str]]:
"""
Finds all pairs of anagrams in a given list of strings.
Args:
strings (Lis... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.