source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
python_sharegpt_23k | 15,732 | 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 sorted list of unique integers in descending order. The code should start with:
```python
from typing import List
def sort_and_remove_duplicates(lst: List[... | 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 | 15,734 | Write a Python function to sort a list of ice cream flavors by their prices in increasing order, while excluding flavors that contain certain dietary restrictions. The input list should contain at least 7 elements, where each element is a tuple consisting of a string representing the ice cream flavor, a float represent... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_ice_cream_flavors(ice_creams: List[Tuple[str, float, List[str]]], exclude_dietary: List[str]) -> List[Tuple[str, float, List[str]]]:
"""
Sorts a list of ice cream flavors by their prices ... |
python_sharegpt_23k | 15,743 | Write a Python function to calculate the total distance traveled by birds over a given number of days. The function should take a list of distances traveled each day and return the total distance. The code should start with:
```python
from typing import List
def calculate_total_distance(distances: List[int]) -> int:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_total_distance(distances: List[int]) -> int:
"""
Calculate the total distance traveled by birds over a given number of days.
Args:
distances (List[int]): A list of integers whe... |
python_sharegpt_23k | 15,746 | Write a Python function to find the highest and lowest values for each attribute in a given dataset. The dataset is represented as a 2D NumPy array where each row corresponds to a record and each column corresponds to an attribute. The function should return two lists: one for the highest values and one for the lowest ... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List
def find_attribute_extremes(dataset: np.ndarray) -> (List[float], List[float]):
"""
Find the highest and lowest values for each attribute in a given dataset.
Args:
dataset... |
python_sharegpt_23k | 15,751 | Write a Python function to generate a random word from a predefined list of English words that have the same meaning as the German word "Verantwortung". The function should then use this random word in a sentence. The list of words should include "Responsibility", "Accountability", "Duty", "Obligation", and "Liability"... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_sentence_with_random_word(words: List[str]) -> str:
"""
Generates a sentence using a random word from the provided list of English words.
Args:
words (List[str]): ... |
python_sharegpt_23k | 15,753 | 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 | 15,756 | Write a Python function to classify a list of data points based on the given classification rule and return 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: if `x` is greater than... | 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 data points based on the given rule and return the count of data points classified as "A" and "B"... |
python_sharegpt_23k | 15,757 | 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 separated by whitespace.
Returns:... |
python_sharegpt_23k | 15,760 | Write a Python function to check if a given string contains any substring that is a palindrome of a specified minimum length. The function should return `True` if such a substring exists, otherwise `False`. The function should be efficient and avoid unnecessary computations.
The code should start with:
```python
def c... | Here is the Python code to solve the given problem in the markdown block:
```python
def contains_palindrome(s: str, min_length: int) -> bool:
"""
Check if the given string contains any substring that is a palindrome of the specified minimum length.
Args:
s (str): The input string to check for palin... |
python_sharegpt_23k | 15,766 | Write a Python function to sort a list of words in alphabetical order and concatenate them into a sentence. The function should handle lists of varying lengths and ensure that the resulting sentence is grammatically correct by placing the words in the correct order.
The code should start with:
```python
from typing im... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_and_form_sentence(words: List[str]) -> str:
"""
Sorts a list of words in alphabetical order and concatenates them into a sentence.
Args:
words (List[str]): A list of words to be sor... |
python_sharegpt_23k | 15,768 | 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 sli... |
python_sharegpt_23k | 15,770 | Write a Python function to sort a list of chemical elements based on their atomic numbers. Each element is represented as a dictionary with keys `'name'` and `'atomic_number'`. The function should return a list of elements sorted in increasing order of atomic numbers.
The code should start with:
```python
from typing ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def sort_elements_by_atomic_number(elements: List[Dict[str, any]]) -> List[Dict[str, any]]:
"""
Sorts a list of chemical elements based on their atomic numbers.
Args:
elements (List[Di... |
python_sharegpt_23k | 15,777 | Write a Python function to generate all possible chords of a given scale, where each chord consists of three notes. The scale is provided as a list of notes. The function should return a list of lists, where each inner list represents a chord.
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 itertools
def generate_chords(scale: List[str]) -> List[List[str]]:
"""
Generate all possible chords of a given scale, where each chord consists of three notes.
Args:
scale (List[str]... |
python_sharegpt_23k | 15,784 | 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 | 15,786 | 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 | 15,789 | 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 randomly ... |
python_sharegpt_23k | 15,795 | Write a Python function to find the most recent date from a list of dates in the format "YYYY-MM-DD". The function should handle any valid date strings in the specified format and return the most recent date.
The code should start with:
```python
from typing import List
def get_most_recent_date(dates: List[str]) -> s... | 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:
"""
Finds the most recent date from a list of dates in the format "YYYY-MM-DD".
Args:
dates (List[str]): A list of date strings in the form... |
python_sharegpt_23k | 15,800 | Write a Python function to generate a list of five positive physical traits randomly selected from a predefined list of traits. The function should return the list of selected traits. The predefined list of traits includes:
- Bright eyes
- Thick hair
- Rosy cheeks
- Long legs
- Straight teeth
- Clear skin
- Broad shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_random_traits() -> List[str]:
"""
Generates a list of five positive physical traits randomly selected from a predefined list.
Returns:
List[str]: A list containing... |
python_sharegpt_23k | 15,802 | 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 to remove alp... |
python_sharegpt_23k | 15,810 | 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 | 15,815 | Write a Python function to measure the time it takes to print a string of varying lengths and to explore different formatting options such as font size and color. The function should also discuss potential memory constraints and optimization techniques for the string printing process. The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
import time
def measure_print_time_and_format(string: str, font_size: int = 12, color: str = 'black') -> float:
"""
Measures the time it takes to print a string and formats it with the specified font size and color.
Args:
... |
python_sharegpt_23k | 15,817 | 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 | 15,827 | 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 | 15,829 | 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 use regular expressions to ensure that the word or phrase is matched correctly, regardless of surrounding characters or case.
The... | 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 | 15,837 | 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 | 15,838 | 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 for divisibility, and return a boolean indicating whether the number is divisible by the divisor.
The code should start with:
```python
def ... | 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 | 15,850 | Write a Python function to select a random constellation from a predefined list of constellations that are associated with love, beauty, and eternity. The function should return the selected constellation as a string. Additionally, provide a function to generate a chorus line for a love song using the selected constell... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def select_constellation(constellations: List[str]) -> str:
"""
Selects a random constellation from a list of constellations associated with love, beauty, and eternity.
Args:
c... |
python_sharegpt_23k | 15,856 | 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 | 15,863 | 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 | 15,870 | 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 | 15,872 | 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 | 15,874 | 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 | 15,875 | 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 term is derived from the previous term
by m... |
python_sharegpt_23k | 15,876 | 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 | 15,879 | Write a Python function to extract the original words from a sequence of transformed words. Each transformed word has a common prefix "drove" and a unique suffix that follows the pattern "verb-noun". The function should return the original words in the correct sequence.
The code should start with:
```python
def extrac... | 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 common prefix "drove" and a unique suffix that follows the pattern... |
python_sharegpt_23k | 15,882 | 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 | 15,884 | Write a Python function to generate a 150-word detailed description of a room. The description should include information about the type of flooring, ceiling height, wall color, and any unique architectural features such as crown molding or decorative pillars. Consider the lighting sources in the room and how they affe... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_room_description() -> str:
"""
Generates a 150-word detailed description of a room.
The description includes information about the type of flooring, ceiling height, wall color,
architectural ... |
python_sharegpt_23k | 15,896 | 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 | 15,904 | Write a Python function to filter out European countries with a population greater than or equal to 5 million from a given list of tuples. Each tuple contains the name of a country and its population. The function should return a list of tuples containing only the countries that meet the criteria.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def filter_european_countries(countries: List[Tuple[str, int]]) -> List[Tuple[str, int]]:
"""
Filters out European countries with a population greater than or equal to 5 million.
Args:
... |
python_sharegpt_23k | 15,912 | 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 | 15,922 | 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 | 15,925 | 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 should be efficient in terms of both time and space complexity.
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 | 15,926 | 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 | 15,931 | 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 data points based on the given rule and return the count of each classification.
Args:
... |
python_sharegpt_23k | 15,933 | 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 | 15,935 | 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.
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 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 | 15,948 | 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(string: str) -> float:
"""
Measures the time it takes to print a given string and explores different formatting options.
Args:
string (str): The string to be printed.
Returns... |
python_sharegpt_23k | 15,957 | Write a Python function to determine the outcome of a card game between two players. Each player starts with 20 cards and 1000 prestige points. The game continues until one of the players runs out of cards or their prestige points drop to zero or below. The function should return a string indicating the winner or if th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def determine_game_outcome(player1_cards: List[int], player2_cards: List[int], player1_prestige: int, player2_prestige: int) -> str:
"""
Determine the outcome of a card game between two players.
The... |
python_sharegpt_23k | 15,966 | 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 | 15,974 | 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 | 15,981 | 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, handling division by zero and non-numeric inputs.
Args:
num1 (int or float): The numerator.
num2 (int or float): The denominator.
Returns:
... |
python_sharegpt_23k | 15,988 | Write a Python function to generate a personalized nutrition plan based on user's DNA analysis and dietary preferences. The function should take a dictionary of nutrient recommendations derived from DNA analysis and a list of dietary preferences as inputs, and return a list of meals for the user to consume over a given... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
import random
def generate_meal_plan(nutrient_recommendations: Dict[str, float], dietary_preferences: List[str]) -> List[str]:
"""
Generates a meal plan based on nutrient recommendations and dietar... |
python_sharegpt_23k | 15,992 | 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 | 16,006 | Write a Python function to evaluate the eligibility of a patient for surgery based on physical examination items. The function should examine specific physical examination items and print relevant messages if certain conditions are met. The function should also check the patient's temperature and blood pressure to dete... | Here is the Python code to solve the given problem in the markdown block:
```python
def evaluate_patient_eligibility(temperature: float, blood_pressure: str, hernia: str, costovertebral_angle_tenderness: str, rebounding_pain: str) -> None:
"""
Evaluate the eligibility of a patient for surgery based on physical ... |
python_sharegpt_23k | 16,027 | 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 | 16,041 | Write a Python function to calculate the sum of all even numbers in a given list, while filtering out non-integer elements. The function should handle lists with mixed data types and return the sum of all even integers.
The code should start with:
```python
from typing import List, Union
def sum_even_numbers(numbers:... | 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 integers in a given list, filtering out non-integer elements.
Args:
numbers... |
python_sharegpt_23k | 16,053 | Write a Python function to improve a given sentence by adding a descriptive HTML tag to a specified word. The function should replace the specified word in the sentence with an HTML-tagged version of the word. The HTML tag should include a class attribute that corresponds to the provided tag name.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
def add_html_tag(sentence: str, word: str, tag: str) -> str:
"""
Improve a given sentence by adding a descriptive HTML tag to a specified word.
Args:
sentence (str): The original sentence in which the word will be t... |
python_sharegpt_23k | 16,059 | Write a Python function to calculate the area of a circle given its radius. The function should handle both positive and zero radius values. The code should start with:
```python
import math
def calculate_circle_area(radius: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_circle_area(radius: float) -> float:
"""
Calculate the area of a circle given its radius.
Args:
radius (float): The radius of the circle.
Returns:
float: The area of the circl... |
python_sharegpt_23k | 16,071 | Write a Python function to calculate the average salary for each gender categorized by department from a given table of employee details. The table is represented as a list of dictionaries, where each dictionary contains the keys "Name", "Age", "Gender", "Salary", and "Department". The function should return a dictiona... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def average_salary_by_gender_and_department(table: List[Dict[str, any]]) -> Dict[tuple, float]:
"""
Calculate the average salary for each gender categorized by department from a given table of empl... |
python_sharegpt_23k | 16,080 | 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 | 16,081 | 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 | 16,087 | 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 these details.
The code should start with:
```python
from typing import Dict
import datetime
def get_current_t... | 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_details() -> Dict[str, str]:
"""
Determine the current date, time, time zone, and calculate the number of seconds since the start of the day.
Returns:
Di... |
python_sharegpt_23k | 16,090 | Write a Python function to efficiently remove items at specific positions from a given list without modifying the original list or creating a new list. The function should return a generator that yields the elements of the list that are not at the specified positions.
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, Set, Generator
def remove_items_at_positions(original_list: List[int], positions_to_remove: Set[int]) -> Generator[int, None, None]:
"""
Yields elements from the original list that are not at the specif... |
python_sharegpt_23k | 16,099 | 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 | 16,101 | Write a Python function to find the minimum value in a list of numbers. The function should handle lists of integers and floats. 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 | 16,112 | Write a Python function to calculate the revenue generated from selling apples, given the total quantity of apples sold and the selling price per apple. Additionally, calculate the number of carts needed to transport the apples, given the maximum capacity of each cart. The function should also account for the number of... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_revenue_and_carts(initial_quantity: int, selling_price_per_apple: float, max_capacity_of_cart: int, number_of_apples_eaten_by_son: int) -> tuple:
"""
Calculate the revenue generated from selling apples... |
python_sharegpt_23k | 16,113 | 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_multiples(num1: int, num2: int) -> int:
"""
Multiplies two prime numbers and prints a table of the first 10 multiples of their product.
Args:
num1 (int): The first prime number.
num2 (int): The sec... |
python_sharegpt_23k | 16,119 | 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 each node should contain two integers between 0 and 1000 representing X and Y coordinates. The edge weights should be the Euclidean distance ... | 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 | 16,130 | 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 frequency of each word in the input list and returns the result in ... |
python_sharegpt_23k | 16,149 | 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 | 16,162 | 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 | 16,164 | Write a Python function to dynamically adjust a probability based on various factors such as weather and user input, and then use this adjusted probability to determine whether to execute a block of code. The function should return a boolean indicating whether the block of code should be executed.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def should_execute_block(weather: str, user_input: str, default_probability: float = 0.5) -> bool:
"""
Dynamically adjusts a probability based on weather and user input, and determines whether to execute a block o... |
python_sharegpt_23k | 16,177 | 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 a target value.
Args:
array (List[int]): A sorted list of integers.
... |
python_sharegpt_23k | 16,179 | 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 | 16,180 | 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 name, ingredients, instructions, and nutri... | 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:
- Total prep time is 30 minutes or less.
- Each... |
python_sharegpt_23k | 16,186 | 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 | 16,188 | 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 adjusting the row elements if necessary. The code should start with:
```python
from typing import List
import random
def generate_pri... | 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 number is prime.
Args:
n (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
... |
python_sharegpt_23k | 16,201 | 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(arr: List[int]) -> List[int]:
"""
Sorts the input list in ascending order using the Cocktail Shaker Sort algorithm,
which is a stable sorting algorithm with O(1) space complexity.
... |
python_sharegpt_23k | 16,204 | Write a Python function to find all strings in a list that contain either 'cat' or 'dog' using regular expressions. The function should return a list of all such strings.
The code should start with:
```python
from typing import List
import re
def find_strings_with_cat_or_dog(strings: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
import re
def find_strings_with_cat_or_dog(strings: List[str]) -> List[str]:
"""
Find all strings in a list that contain either 'cat' or 'dog' using regular expressions.
Args:
strings (Lis... |
python_sharegpt_23k | 16,206 | Write a Python function to generate a comprehensive list of ten behavioral and emotional signs that indicate an unhealthy relationship. The function should include specific manifestations of controlling behavior, possessiveness, jealousy, and emotional abuse. The function should utilize a combination of string manipula... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_unhealthy_relationship_signs() -> List[str]:
"""
Generates a comprehensive list of ten behavioral and emotional signs that indicate an unhealthy relationship.
Returns:
List[str]... |
python_sharegpt_23k | 16,209 | Write a Python function to calculate the mean annual income and the average number of customers for prepaid companies and T-Money over the previous three years. The function should return the results as a dictionary with keys "Prepaid" and "T-Money" for both metrics. The revenue should be expressed in billions and roun... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def calculate_metrics(prepaids: Dict[str, Dict[str, int]], t_moneys: Dict[str, Dict[str, int]]) -> Dict[str, Dict[str, float]]:
"""
Calculate the mean annual income and the average number of customers fo... |
python_sharegpt_23k | 16,210 | Write a Python function to generate a tryptic joke about a popular movie, utilizing wordplay, puns, and references to popular culture. The function should take a movie title, a hero, a villain, a weapon, and a team as inputs and return a list of three jokes. Each joke should be structured in a way that it can be easily... | 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, ...]]:
"""
Generates a tryptic joke about a popular movie, utilizing wordpla... |
python_sharegpt_23k | 16,243 | 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 for generatin... |
python_sharegpt_23k | 16,244 | 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 | 16,249 | Write a Python function to find the next word in each sentence after the phrase "The family decided to". The function should take a list of sentences as input and return a list of the next words for each sentence. If the phrase "The family decided to" is not found in a sentence, the function should append `None` to the... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_next_words(sentences: List[str]) -> List[str]:
"""
Finds the next word in each sentence after the phrase "The family decided to".
Args:
sentences (List[str]): A list of sentences to... |
python_sharegpt_23k | 16,250 | 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 | 16,255 | Write a Python function to calculate the average heart rate (HR) and blood pressure (BP) from given data. The function should take two lists as input: one for heart rate data and one for blood pressure data. Each list contains numerical values representing the measurements taken at different times. The function should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Optional
def calculate_average_hr_bp(hr_data: List[float], bp_data: List[float]) -> Optional[Tuple[float, float]]:
"""
Calculate the average heart rate (HR) and blood pressure (BP) from given dat... |
python_sharegpt_23k | 16,259 | 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`, respectively. The function should print whether each algorithm is useful or... | 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 | 16,273 | 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 | 16,283 | 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 | 16,285 | Write a Python function to generate a detailed description of each type of Gallagher Access Control Hardware Module from a predefined 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
... | 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 | 16,293 | 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. The function should handle an empty list gracefully and ensure that the dictionary is correctly populated with the squares of the input numbers.
... | 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 | 16,312 | 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 | 16,320 | 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 | 16,332 | 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 | 16,334 | 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.
The function shou... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_string(string: str) -> str | bool:
"""
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 | 16,335 | Write a Python function to sort a list of movie titles by their release date and display the genres of each movie. Additionally, create a table that lists the runtime of each movie, and only display movies with a runtime of at least 90 minutes. 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 sort_and_display_movies(movies: List[Tuple[str, int, str, int]]) -> None:
"""
Sorts a list of movies by their release date and displays the genres and runtime of each movie.
Only movies wi... |
python_sharegpt_23k | 16,344 | 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 will contain 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 element... | 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:
"""
Sum the first five even elements of the given array and check if the sum is greater than 10 and less than 20.
Additionally, count and print the... |
python_sharegpt_23k | 16,349 | 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 IP add... | Here is the Python code to solve the given problem in the markdown block:
```python
def define_network_topology() -> dict:
"""
Defines a hierarchical network topology with distinct IP addresses, subnet masks, and network addresses
for the gateway router, DNS server, and web server.
Returns:
dic... |
python_sharegpt_23k | 16,351 | 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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.