source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
python_sharegpt_23k | 20,043 | Write a Python function to generate a dataset of puns in the specified format. The function should randomly select puns from predefined categories and return a list of dictionaries, where each dictionary contains a pun and its category. The function should allow specifying the number of puns to generate.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
import random
def generate_puns(num_puns: int) -> List[Dict[str, str]]:
"""
Generates a dataset of puns in the specified format.
Args:
num_puns (int): The number of puns to generate.
... |
python_sharegpt_23k | 20,045 | Write a Python function to sort a list of movie dictionaries by their release year and display the title, budget, and country of origin for each movie. The function should only display movies with a budget of at least $5 million. The output should be formatted in a table with columns for the movie title, budget, and co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def display_movies_by_release_date(movies: List[Dict[str, any]]) -> None:
"""
Sorts a list of movie dictionaries by their release year and displays the title, budget, and country of origin for each... |
python_sharegpt_23k | 20,052 | Write a Python function to find all unique pairs of numbers in a given list that sum to zero. The function should handle both positive and negative numbers and ensure that no duplicate pairs are returned. The code should start with:
```python
from typing import List, Set, Tuple
def find_unique_pairs_sum_to_zero(arr: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Set, Tuple
def find_unique_pairs_sum_to_zero(arr: List[int]) -> Set[Tuple[int, int]]:
"""
Find all unique pairs of numbers in the given list that sum to zero.
Args:
arr (List[int]): The lis... |
python_sharegpt_23k | 20,060 | Write a Python function to remove duplicates from a sequence while preserving the original order of elements. The function should handle cases where the input sequence contains duplicate nested sequences (Seq[Seq[T]]), where duplicates are defined as two nested sequences having the same elements in the same order. The ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, List, Set
def remove_duplicates(seq: List[Any]) -> List[Any]:
"""
Removes duplicates from a sequence while preserving the original order.
Handles nested sequences by considering duplicates as two nes... |
python_sharegpt_23k | 20,064 | Write a Python function to compute the magnitude of a vector in Cartesian coordinates given its components (x, y, z). The function should use NumPy for efficient computation. The code should start with:
```python
import numpy as np
def compute_vector_magnitude(vector: np.ndarray) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def compute_vector_magnitude(vector: np.ndarray) -> float:
"""
Compute the magnitude of a vector in Cartesian coordinates given its components (x, y, z).
Args:
vector (np.ndarray): A NumPy array ... |
python_sharegpt_23k | 20,067 | Write a Python function to reverse a given string. The function should take a string as input and return the reversed version of the string. The code should start with:
```python
def reverse_string(string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_string(string: str) -> str:
"""
Reverses the given string.
Args:
string (str): The input string to be reversed.
Returns:
str: The reversed version of the input string.
"""
# Use sl... |
python_sharegpt_23k | 20,071 | Write a Python function to generate a formal invitation for a networking event using Markdown syntax. The function should accept event details such as event name, date, time, location, and RSVP email, and return a formatted Markdown string. The Markdown string should include sections for event details, purpose, and RSV... | 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, rsvp_email: str, purpose: str) -> str:
"""
Generates a formal invitation for a networking event using Markdown syntax.
Args:
event_name (st... |
python_sharegpt_23k | 20,073 | Write a Python function to calculate various statistical metrics from a list of integers. The function should return a dictionary containing the metrics `mean`, `median`, `mode`, `minimum`, `maximum`, and `standard deviation`. The `standard deviation` should be calculated using the formula `sqrt(1/(N-1) * sum((x - mean... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
from math import sqrt
from collections import Counter
def calculate_metrics(lst: List[int]) -> Dict[str, float]:
"""
Calculate various statistical metrics from a list of integers.
Args:
... |
python_sharegpt_23k | 20,077 | Write a Python function to group people by their age from a list of tuples. Each tuple contains a person's name and age. The function should return a dictionary where the keys are the unique ages and the values are lists of names of the people who have that age. The names within each age group should be sorted alphabet... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def group_people_by_age(people: List[Tuple[str, int]]) -> Dict[int, List[str]]:
"""
Groups people by their age from a list of tuples and returns a dictionary.
Args:
people (List... |
python_sharegpt_23k | 20,096 | Write a Python function to recommend matching accessories for a given t-shirt based on its color, size, and print design. The function should return a list of recommended accessories. If no matching accessories are found, the function should return an empty list.
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, Tuple, Dict
def recommend_accessories(color: str, size: str, print_design: str, accessories: Dict[Tuple[str, str, str], List[str]]) -> List[str]:
"""
Recommends matching accessories for a given t-shirt ... |
python_sharegpt_23k | 20,105 | Write a Python function to calculate the sum of all even numbers greater than 5 in a given list of numbers. The function should filter out the even numbers greater than 5, sum them, and return the total sum.
The code should start with:
```python
from typing import List
def sum_of_even_numbers_greater_than_5(nums: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_even_numbers_greater_than_5(nums: List[int]) -> int:
"""
Calculate the sum of all even numbers greater than 5 in the given list.
Args:
nums (List[int]): A list of integers from wh... |
python_sharegpt_23k | 20,111 | Write a Python function to evaluate the authenticity of a given sequence of parentheses, including different types of brackets such as square brackets, curly brackets, and angle brackets. The function should ensure that the brackets are balanced, properly nested, and not overlapping. The function should return `True` i... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_parentheses(s: str) -> bool:
"""
Evaluates the authenticity of a given sequence of parentheses, including different types of brackets.
Args:
s (str): The sequence of parentheses to evaluate.
Return... |
python_sharegpt_23k | 20,118 | Write a Python function to filter a dictionary and return a new dictionary containing only the key-value pairs where the value is greater than or equal to a specified threshold. The function should start with:
```python
from typing import Dict
def filter_dict_by_threshold(input_dict: Dict[str, int], threshold: int) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def filter_dict_by_threshold(input_dict: Dict[str, int], threshold: int) -> Dict[str, int]:
"""
Filters a dictionary to include only key-value pairs where the value is greater than or equal to a specifie... |
python_sharegpt_23k | 20,122 | Write a Python function to generate an HTML table that displays a list of fruits with their carbohydrate content sorted in descending order. The input is a list of dictionaries, where each dictionary contains the keys `"name"` and `"carbohydrates"`. The function should return a string containing the HTML table.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def generate_html_table(fruits: List[Dict[str, any]]) -> str:
"""
Generates an HTML table that displays a list of fruits with their carbohydrate content sorted in descending order.
Args:
... |
python_sharegpt_23k | 20,124 | Write a Python function to count the number of multi-line comments in a given Python source code string. The function should differentiate between multi-line comments enclosed in triple quotes (`"""` or `'''`) and single-line comments that are part of a multi-line comment block. The code should start with:
```python
de... | Here is the Python code to solve the given problem in the markdown block:
```python
import tokenize
from io import StringIO
def count_multi_line_comments(source_code: str) -> int:
"""
Count the number of multi-line comments in a given Python source code string.
Args:
source_code (str): The Python ... |
python_sharegpt_23k | 20,136 | Write a Python function to calculate the sum of the first `n` positive integers and another function to calculate the sum of the first `n` even positive integers. The functions should be efficient and avoid unnecessary computations.
The code should start with:
```python
def sum_of_first_n_integers(n: int) -> int:
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_first_n_integers(n: int) -> int:
"""
Calculate the sum of the first n positive integers.
Args:
n (int): The number of positive integers to sum.
Returns:
int: The sum of the first n positive i... |
python_sharegpt_23k | 20,139 | Write a Python function that applies a given function to each element of an iterable and returns a list of the results. The function should be designed to be more readable than using the built-in `map` function with a lambda function. The function should accept a function and an iterable as arguments and return a list ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Callable, Iterable, List
def apply_function_to_iterable(func: Callable, iterable: Iterable) -> List:
"""
Applies a given function to each element of an iterable and returns a list of the results.
Args:
... |
python_sharegpt_23k | 20,140 | Write a Python function to reverse a given string. The function should handle strings of varying lengths, including empty strings. The function should be efficient and should not use any built-in string reversal methods directly. Instead, it should use a loop to reverse the string manually.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(s: str) -> str:
"""
Reverses the given string.
Args:
s (str): The input string to be reversed.
Returns:
str: The reversed string.
"""
# Initialize an empty string to store the... |
python_sharegpt_23k | 20,142 | Write a Python function to generate a new list with unique elements from a given list of integers. The function should preserve the order of the first occurrence of each element. The code should start with:
```python
from typing import List
def unique_elements_ordered(lst: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def unique_elements_ordered(lst: List[int]) -> List[int]:
"""
Generate a new list with unique elements from the given list of integers, preserving the order of their first occurrence.
Args:
... |
python_sharegpt_23k | 20,144 | Write a Python function to find the three most frequently occurring words in a given sentence, ignoring punctuation and case sensitivity. The function should return a list of these three words in descending order of their frequency. If there are fewer than three unique words, the function should return as many as are a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import string
def most_frequent_words(sentence: str) -> List[str]:
"""
Find the three most frequently occurring words in a given sentence, ignoring punctuation and case sensitivity.
Args:
se... |
python_sharegpt_23k | 20,146 | Write a Python function to generate a list of numbers from 1 to 1000 (inclusive) following the "FizzBuzz" rules. The function should return a list where:
- If a number is divisible by 3, append "Fizz" to the list.
- If a number is divisible by 5, append "Buzz" to the list.
- If a number is divisible by both 3 and 5, ap... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fizzbuzz_list() -> List[str]:
"""
Generates a list of numbers from 1 to 1000 (inclusive) following the "FizzBuzz" rules.
Returns:
List[str]: A list where each element is either ... |
python_sharegpt_23k | 20,149 | Write a Python function to implement the selection sort algorithm to sort a given array of numbers in descending order. Additionally, provide a detailed analysis of the time complexity of the algorithm in Big-O notation, explaining the number of comparisons and swaps performed, considering the worst-case scenario where... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def selection_sort_descending(arr: List[int]) -> List[int]:
"""
Sorts the given array of numbers in descending order using the selection sort algorithm.
Args:
arr (List[int]): The array of n... |
python_sharegpt_23k | 20,150 | Write a Python function to convert a fraction into its decimal equivalent. The function should take two positive integer inputs, the numerator and the denominator, and return the decimal equivalent as a float. The function should be able to handle any positive integer values for the numerator and denominator. The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
def fraction_to_decimal(numerator: int, denominator: int) -> float:
"""
Converts a fraction into its decimal equivalent.
Args:
numerator (int): The numerator of the fraction. Must be a positive integer.
deno... |
python_sharegpt_23k | 20,154 | Write a Python function to generate a random story about a brave young girl and a villain. The function should create a plot and characters for the story, and then print the story in a structured format. The story should include a beginning, middle, and end, with plot points that describe the girl's journey and her int... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_story():
"""
Generates a random story about a brave young girl and a villain.
The story includes a beginning, middle, and end, with plot points that describe the girl's journey and her interactio... |
python_sharegpt_23k | 20,175 | Write a Python function to search for the occurrence of a specific number in an array of 10 integers, randomly generated between 20 to 30 inclusive. The function should return `True` if the number is found in the array, and `False` otherwise. The code should start with:
```python
from typing import List
import random
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def search_number_in_array(target: int) -> bool:
"""
Searches for the occurrence of a specific number in an array of 10 integers,
randomly generated between 20 to 30 inclusive.
Arg... |
python_sharegpt_23k | 20,176 | Write a Python function to generate the Fibonacci sequence up to the nth term using an iterative approach. Additionally, implement a vectorized version of the Fibonacci sequence generation using NumPy to compare the efficiency. The function should return a list of Fibonacci numbers up to the nth term.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import numpy as np
def fibonacci_iterative(n: int) -> List[int]:
"""
Generate the Fibonacci sequence up to the nth term using an iterative approach.
Args:
n (int): The number of terms in the... |
python_sharegpt_23k | 20,183 | Write a Python function to generate 10 alternative endings for a given story by randomly selecting different events to occur. The function should replace specific phrases in the original ending with randomly chosen alternatives. The code should start with:
```python
from typing import List
import random
def generate_a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_alternative_endings(original_ending: str) -> List[str]:
"""
Generates 10 alternative endings for a given story by randomly selecting different events to occur.
Args:
... |
python_sharegpt_23k | 20,193 | Write a Python function to generate a meal plan based on the delivery location and business concept. The function should take two parameters: `delivery_location` (a string representing the delivery location) and `business_concept` (an integer representing the index of the business concept within the delivery location's... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
# Define meal options for each business concept
vegan_meals = ['Vegan chili with cornbread', 'Tofu stir-fry with brown rice', 'Vegan lasagna', 'Vegan lentil soup', 'Vegan black bean burgers']
paleo... |
python_sharegpt_23k | 20,195 | Write a Python function to determine whether a given number is even or odd. The function should return a string indicating "Even" if the number is even and "Odd" if the number is odd.
The code should start with:
```python
def is_even_or_odd(number: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_even_or_odd(number: int) -> str:
"""
Determine whether the given number is even or odd.
Args:
number (int): The number to check.
Returns:
str: "Even" if the number is even, "Odd" if the number is... |
python_sharegpt_23k | 20,206 | Write a Python function to calculate the nth number of the Fibonacci sequence using an optimized approach that reduces time complexity. The function should use memoization to store previously computed Fibonacci numbers to avoid redundant calculations.
The code should start with:
```python
def fibonacci(n: int, memo: d... | Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci(n: int, memo: dict = {}) -> int:
"""
Calculate the nth number of the Fibonacci sequence using memoization to optimize time complexity.
Args:
n (int): The position in the Fibonacci sequence to calculate... |
python_sharegpt_23k | 20,208 | Write a Python function to remove all vowels from a given string using regular expressions. The function should handle both uppercase and lowercase vowels. The code should start with:
```python
import re
def remove_vowels(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
import re
def remove_vowels(text: str) -> str:
"""
Removes all vowels (both uppercase and lowercase) from the given string using regular expressions.
Args:
text (str): The input string from which vowels are to be... |
python_sharegpt_23k | 20,216 | Write a Python function to adjust the air quality reading based on the specifications of the air quality sensors on board the spaceship and the unpredictable weather conditions on a distant planet. The function should take an integer `reading` as input and return an adjusted integer `reading` that reflects the actual a... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def adjust_air_quality(reading: int) -> int:
"""
Adjusts the air quality reading based on the specifications of the air quality sensors
on board the spaceship and the unpredictable weather conditions on a dist... |
python_sharegpt_23k | 20,220 | Write a Python function to generate a sentence that includes the words 'mango', 'colossal', and 'section' in a specific order. The sentence should always start with 'A colossal mango', followed by 'section' in the middle, and end with 'was found in the'. The code should start with:
```python
def generate_sentence() -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_sentence() -> str:
"""
Generates a sentence that includes the words 'mango', 'colossal', and 'section' in a specific order.
The sentence structure is: "A colossal mango section was found in the".
Returns:
... |
python_sharegpt_23k | 20,228 | Write a Python function that multiplies each element of a given list by a specified scalar if a boolean flag is set to `True`. If the boolean flag is `False`, the function should return the original list unchanged. The function should handle lists of integers and ensure that the scalar is an integer.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_list_by_scalar(lst: List[int], scalar: int, should_multiply: bool) -> List[int]:
"""
Multiplies each element of a given list by a specified scalar if a boolean flag is True.
If the boole... |
python_sharegpt_23k | 20,229 | Write a Python function to correct common typos in a given text using regular expressions. The function should identify and correct common errors such as missing letters, transposed letters, and extra letters. The function should return the corrected text.
The code should start with:
```python
import re
def correct_t... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def correct_typos(text: str) -> str:
"""
Corrects common typos in a given text using regular expressions.
Args:
text (str): The input text containing typos.
Returns:
str: The corrected text w... |
python_sharegpt_23k | 20,232 | Write a Python function to filter out names from a given list that are palindromes (i.e., they read the same forward and backward). The function should not use Python's built-in palindrome function. The function should handle names with spaces and should be case-insensitive.
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 filter_palindrome_names(names: List[str]) -> List[str]:
"""
Filters out names from a given list that are palindromes.
Args:
names (List[str]): A list of names to be filtered.
Return... |
python_sharegpt_23k | 20,235 | Write a Python function to compute the total number of each product sold from a list of customer orders. Each order is represented as a tuple containing an order ID, a product name, and the quantity of the product sold. The function should return a dictionary where the keys are product names and the values are the tota... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Dict
def total_products_sold(orders: List[Tuple[int, str, int]]) -> Dict[str, int]:
"""
Computes the total number of each product sold from a list of customer orders.
Args:
orders (L... |
python_sharegpt_23k | 20,248 | Write a Python function to generate a table filled with random numbers, sort the table in ascending order, calculate the average of the numbers in the sorted table, and format the result in a readable manner. The function should take the number of rows, number of columns, and a seed value for the random number generato... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def process_table(num_rows: int, num_cols: int, seed: int) -> str:
"""
Generates a table filled with random numbers, sorts the table in ascending order,
calculates the average of the nu... |
python_sharegpt_23k | 20,252 | Write a Python function to retrieve the personal details of a specific person from a given dataset. The dataset is represented as a dictionary where each key is a person's name and the value is another dictionary containing their age, gender, and hometown. The function should accept a person's name as input and return ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Optional
def get_person_info(name: str, data: Dict[str, Dict[str, str]]) -> Optional[Dict[str, str]]:
"""
Retrieve the personal details of a specific person from a given dataset.
Args:
name... |
python_sharegpt_23k | 20,256 | Write a Python function to merge two dictionaries and concatenate two lists and two strings using the addition operation. The function should handle the merging of dictionaries by updating the first dictionary with the second one, and concatenate the lists and strings using the `+` operator. The function should return ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple, Union
def merge_and_concatenate(dict1: Dict[str, Union[str, int]], dict2: Dict[str, Union[str, int]],
list1: List[int], list2: List[int],
str1:... |
python_sharegpt_23k | 20,258 | Write a Python function to calculate the total amount after deducting the sales tax from a given subtotal. The function should take the subtotal and the tax rate as inputs and return the total amount after applying the tax deduction. The code should start with:
```python
def calculate_total_after_tax(subtotal: float, t... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_total_after_tax(subtotal: float, tax_rate: float) -> float:
"""
Calculate the total amount after deducting the sales tax from a given subtotal.
Args:
subtotal (float): The initial amount before tax ded... |
python_sharegpt_23k | 20,259 | Write a Python function that takes a string `input_str` as input and performs the following tasks:
1. Reverses the string.
2. Creates a table that displays the ASCII values of each character in the string and its binary equivalent.
3. Adds an error handling component that returns an error message if the input is not a ... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_hello(input_str: str) -> tuple:
"""
Reverses the input string 'hello' and creates a table displaying the ASCII values and binary equivalents of each character.
Args:
input_str (str): The input string to ... |
python_sharegpt_23k | 20,313 | Write a Python function to recommend a dish based on the given ingredients. The available dishes are stored in a dictionary where the key is the name of the dish and the value is the required ingredients with their respective quantities in a dictionary. The function should return the name of the dish that can be made w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Optional
def recommend_dish(available_dishes: Dict[str, Dict[str, int]], ingredients: Dict[str, int]) -> Optional[str]:
"""
Recommends a dish based on the given ingredients and returns the name of the d... |
python_sharegpt_23k | 20,314 | Write a Python function to classify a list of abstract concepts as positive, negative, or neutral based on predefined keywords. The function should take a list of concepts as input and return a list of tuples, where each tuple contains a concept and its corresponding category. If a concept does not match any predefined... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def classify_concepts(concepts: List[str]) -> List[Tuple[str, str]]:
"""
Classify a list of abstract concepts as positive, negative, neutral, or unknown based on predefined keywords.
Args:
... |
python_sharegpt_23k | 20,315 | Write a Python function that takes an array of integers and returns the sum of all the prime numbers within the array, the largest prime number, the smallest prime number, and the total count of prime numbers. The input array should be sorted in descending order before the function is applied. The function should handl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def prime_numbers_summary(arr: List[int]) -> Tuple[int, int, int, int]:
"""
Returns the sum of all prime numbers in the array, the largest prime number,
the smallest prime number, and the tota... |
python_sharegpt_23k | 20,317 | Write a Python function to calculate the average marks of a class given a list of marks. The function should handle cases where the list of marks is empty by returning `None`. The code should start with:
```python
from typing import List, Optional
def calculate_average_marks(marks: List[int]) -> Optional[float]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def calculate_average_marks(marks: List[int]) -> Optional[float]:
"""
Calculate the average marks of a class given a list of marks.
Args:
marks (List[int]): A list of integers repr... |
python_sharegpt_23k | 20,325 | Write a Python function to create a vector of numbers where each number in the vector appears 'm' times until the value of 'n' is reached. The resulting vector should be generated using NumPy and sorted in ascending order. The function should start with:
```python
import numpy as np
def create_sorted_vector(n: int, m:... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def create_sorted_vector(n: int, m: int) -> np.ndarray:
"""
Create a vector of numbers where each number appears 'm' times until the value of 'n' is reached.
The resulting vector is sorted in ascending or... |
python_sharegpt_23k | 20,332 | Write a Python function to perform matrix subtraction of two vectors `x` and `y`, producing a new vector `result`. The function should subtract each corresponding element of vector `y` from vector `x` and return the resultant vector. The function should handle vectors of different lengths by truncating the longer vecto... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def vector_subtraction(x: List[int], y: List[int]) -> List[int]:
"""
Perform matrix subtraction of two vectors x and y, producing a new vector result.
Args:
x (List[int]): The first vector.
... |
python_sharegpt_23k | 20,333 | Write a Python function to efficiently identify and extract prime numbers from a given list of integers. The function should handle large lists without causing significant delays and should only return prime numbers, ignoring non-prime ones. The code should be designed to be easily understood and maintained by other de... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise.
... |
python_sharegpt_23k | 20,336 | Write a Python function to calculate the number of times a piece of paper, initially 0.1 millimeters thick, needs to be folded to reach a specified thickness in meters. The function should take the target thickness in meters as an argument and return the number of folds required.
The code should start with:
```python
... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_folds_to_reach_thickness(target_thickness: float) -> int:
"""
Calculate the number of times a piece of paper, initially 0.1 millimeters thick,
needs to be folded to reach a specified thickness in meters.
A... |
python_sharegpt_23k | 20,338 | Write a Python function to categorize a list of ingredients into multiple categories, handling scenarios where an ingredient can belong to more than one category. Each ingredient should store a name and a quantity, and each category should store a name and a list of ingredients. The function should return a dictionary ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Union
def categorize_ingredients(ingredients: List[Dict[str, Union[str, int]]], categories: Dict[str, List[str]]) -> Dict[str, Dict[str, int]]:
"""
Categorizes a list of ingredients into multiple ... |
python_sharegpt_23k | 20,342 | Write a Python function to determine the status, location, priority, and estimated repair time of water pipes that need maintenance or repair. The function should take a list of pipes as input and return a list of dictionaries, each containing the status, location, priority, and estimated repair time of a pipe that nee... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def calculate_priority_and_repair_time(daily_water_requirement: float, historical_data: float) -> (float, float):
"""
Calculates the priority and estimated repair time of a pipe based on the daily ... |
python_sharegpt_23k | 20,345 | Write a Python function to generate a list of random integers between 1 and 100, sort the list in ascending order, and then calculate and return the average value of the sorted list. The function should handle lists of any length, including empty lists.
The code should start with:
```python
from typing import List, Un... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
import random
def sorted_list_average(length: int) -> Union[float, None]:
"""
Generates a list of random integers between 1 and 100, sorts the list in ascending order,
and then calculates and ... |
python_sharegpt_23k | 20,350 | Write a Python function to retrieve the personal details of a specific person from a given dataset. The dataset is represented as a dictionary where each key is a person's name and the value is another dictionary containing their personal details (age, gender, occupation, and hometown). The function should accept a per... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def get_person_info(data: Dict[str, Dict[str, str]], name: str) -> Dict[str, str]:
"""
Retrieves the personal details of a specific person from the given dataset.
Args:
data (Dict[str, Dict[... |
python_sharegpt_23k | 20,355 | Write a Python function to generate a string that emphasizes a given word or phrase using the "epizeuxis" rhetorical device, which involves repeating the word or phrase in quick succession. The function should allow customization of the number of repetitions and the punctuation used for emphasis.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
def emphasize_with_epizeuxis(phrase: str, repetitions: int = 3, punctuation: str = "!") -> str:
"""
Generates a string that emphasizes a given word or phrase using the "epizeuxis" rhetorical device.
Args:
phrase (st... |
python_sharegpt_23k | 20,360 | Write a Python function to compute and display the summation of even numbers present in a given list. The function should follow a two-step process:
1. Create a new list `even_nums` containing only the even numbers from the input list `data`.
2. Compute the summation of the `even_nums` list and print it alongside a tab... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_even_numbers(data: List[int]) -> None:
"""
Computes and displays the summation of even numbers present in the given list.
Args:
data (List[int]): The input list of integers.
... |
python_sharegpt_23k | 20,366 | Write a Python function to simulate the temperature maintenance of a cold beverage in an eco-friendly tumbler over a given time period. The function should take the initial temperature of the beverage, the time period in hours, and the heat transfer rate as inputs. The function should return the final temperature of th... | Here is the Python code to solve the given problem in the markdown block:
```python
def maintain_temperature(initial_temperature: float, time: float, heat_transfer_rate: float) -> float:
"""
Simulate the temperature maintenance of a cold beverage in an eco-friendly tumbler over a given time period.
Args:
... |
python_sharegpt_23k | 20,367 | Write a Python function to calculate the exact date that is a specified number of days after the current date. The function should take an integer `days` as input and return the future date as a `datetime.date` object. The code should start with:
```python
import datetime
def calculate_future_date(days: int) -> dateti... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def calculate_future_date(days: int) -> datetime.date:
"""
Calculate the exact date that is a specified number of days after the current date.
Args:
days (int): The number of days to add to the curr... |
python_sharegpt_23k | 20,380 | Write a Python function to create a dynamic onboarding process for an employee based on their department and job role. The function should be able to handle a more complex onboarding process with multiple steps and provide detailed information about each step, including its description, duration, and prerequisites. The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Any
def create_onboarding_process(employee_name: str, department: str, job_role: str) -> Dict[str, Any]:
"""
Create a dynamic onboarding process for an employee based on their department and job r... |
python_sharegpt_23k | 20,381 | Write a Python function to encrypt a given string using the ROT13 cipher and ensure that the output only contains uppercase letters. The ROT13 cipher is a substitution cipher that replaces each letter with the letter 13 places down the alphabet. Non-alphabetic characters should remain unchanged.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
def rot13_uppercase(input_string: str) -> str:
"""
Encrypts a given string using the ROT13 cipher and ensures the output is in uppercase.
Args:
input_string (str): The string to be encrypted.
Returns:
s... |
python_sharegpt_23k | 20,382 | Write a Python function to remove specific words from a dataset of course reviews. The function should handle variations in grammar and word order within the sentences and should also handle cases where the targeted word is part of a larger word. The function should use regular expressions to ensure that the words are ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def remove_targeted_words(dataset: List[str], words_to_remove: List[str]) -> List[str]:
"""
Removes specific words from a dataset of course reviews.
Args:
dataset (List[str]): A li... |
python_sharegpt_23k | 20,384 | Write a Python function to generate a list of random user records for testing purposes. Each record should include a unique ID, full name, email, phone number, address, city, state, ZIP code, and country. The function should accept an integer `num_records` as input, which specifies the number of records to generate. Th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
import random
def generate_test_data(num_records: int) -> List[Dict[str, str]]:
"""
Generates a list of random user records for testing purposes.
Args:
num_records (int): The number of... |
python_sharegpt_23k | 20,388 | Write a Python function to verify whether all circles in a given set of objects are blue. The set is represented as a list `Z` where each element `z_i` is a tuple `(a_i, b_i)`. The first element `a_i` represents the shape (1 for circle, 2 for triangle, 3 for square), and the second element `b_i` represents the color (1... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def verify_circles_color(Z: List[Tuple[int, int]]) -> bool:
"""
Verify whether all circles in the given set of objects are blue.
Args:
Z (List[Tuple[int, int]]): A list of tuples wher... |
python_sharegpt_23k | 20,389 | Write a Python function to determine if a given number is a prime number. The function should return `True` if the number is prime and `False` otherwise. The function should handle edge cases such as negative numbers, 0, and 1, which are not prime numbers. The code should start with:
```python
def is_prime(n: int) -> b... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(n: int) -> bool:
"""
Determine if a given number is a prime number.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise.
"""
... |
python_sharegpt_23k | 20,393 | Write a Python function to generate a random zodiac sign belonging to the fire element. The function should return the name of the randomly selected zodiac sign. The code should start with:
```python
from typing import List
import random
def get_random_fire_sign() -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def get_random_fire_sign() -> str:
"""
Generates a random zodiac sign belonging to the fire element.
Returns:
str: The name of the randomly selected fire element zodiac sign.
... |
python_sharegpt_23k | 20,397 | Write a Python function to calculate the average of a list of numbers, handling the scenario where the list is empty by returning `None`. The function should start with:
```python
from typing import List, Optional
def calculate_average(numbers: List[int]) -> Optional[float]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def calculate_average(numbers: List[int]) -> Optional[float]:
"""
Calculate the average of a list of numbers. If the list is empty, return None.
Args:
numbers (List[int]): The list... |
python_sharegpt_23k | 20,415 | Write a Python function to determine whether each number in a given list of integers is prime or composite. The function should return a list of tuples, where each tuple contains a number and its classification ("Prime" or "Composite").
The code should start with:
```python
from typing import List, Tuple
import math
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import math
def is_prime(num: int) -> bool:
"""
Check if a given number is prime.
Args:
num (int): The number to check.
Returns:
bool: True if the number is prime, False ... |
python_sharegpt_23k | 20,426 | Write a Python function that takes a list of dictionaries as input and returns a new list of dictionaries containing only the keys that appear in all dictionaries of the input list. If there are no common keys among the dictionaries, the function should return an empty list. The function should handle cases where the i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def common_keys_in_dicts(dicts: List[Dict[str, any]]) -> List[Dict[str, any]]:
"""
Returns a new list of dictionaries containing only the keys that appear in all dictionaries of the input list.
... |
python_sharegpt_23k | 20,436 | Write a Python function to find the second highest number in a given array of integers. The function should handle arrays with duplicate values and arrays with fewer than two elements. The code should start with:
```python
from typing import List
def find_second_highest(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_second_highest(arr: List[int]) -> int:
"""
Find the second highest number in a given array of integers.
Args:
arr (List[int]): The array of integers from which to find the second hi... |
python_sharegpt_23k | 20,438 | Write a Python function to categorize a list of places based on their continent and hemisphere. The function should take a dictionary where the keys are place names and the values are their respective continents. The function should return a dictionary with the following structure:
```python
{
'Asia': {'Northern He... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def categorize_places(places: Dict[str, str]) -> Dict[str, Dict[str, List[str]]]:
"""
Categorizes a list of places based on their continent and hemisphere.
Args:
places (Dict[str, str]... |
python_sharegpt_23k | 20,439 | 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 | 20,444 | Write a Python function to generate a personalized birthday wish message for animal lovers. The function should take the name of the person and their favorite animal as inputs and return a customized birthday message that includes an image of the favorite animal using HTML tags. If the favorite animal is not available ... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_birthday_wish(name: str, animal: str) -> str:
"""
Generates a personalized birthday wish message for an animal lover.
Args:
name (str): The name of the person.
animal (str): The favorite animal ... |
python_sharegpt_23k | 20,447 | Write a Python function to validate a list of email addresses using regular expressions. The function should return a list of boolean values indicating whether each email in the input list is valid or not. The code should start with:
```python
from typing import List
import re
def validate_emails(emails: List[str]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def validate_emails(emails: List[str]) -> List[bool]:
"""
Validates a list of email addresses using a regular expression pattern.
Args:
emails (List[str]): A list of email addresse... |
python_sharegpt_23k | 20,458 | Write a Python function that takes two integers as input and returns their sum. Additionally, the function should print the sum using the `print` statement. The function should be named `sum_two_numbers` and should start with:
```python
def sum_two_numbers(num1: int, num2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_two_numbers(num1: int, num2: int) -> int:
"""
Calculate the sum of two integers and print the result.
Args:
num1 (int): The first integer.
num2 (int): The second integer.
Returns:
int: T... |
python_sharegpt_23k | 20,460 | Write a Python function to initialize two integer variables `a` and `b` such that their sum is an odd number. Then, compute the product of these two variables, find the square root of the product, and round it to the nearest integer. Return the resulting value.
The code should start with:
```python
import math
def co... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def compute_final_value(a: int, b: int) -> int:
"""
Initialize two integer variables such that their sum is odd, compute their product,
find the square root of the product, and round it to the nearest integer.
... |
python_sharegpt_23k | 20,483 | Write a Python function to reverse an array of integers that includes both positive and negative integers. The function should take a list of integers as input and return the reversed list. The code should start with:
```python
from typing import List
def reverse_array(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_array(arr: List[int]) -> List[int]:
"""
Reverses an array of integers in-place.
Args:
arr (List[int]): The array of integers to be reversed.
Returns:
List[int]: The ... |
python_sharegpt_23k | 20,489 | Write a Python function to calculate the sum of two constants `a` and `b`, and then compute the error between the computed sum and the theoretical sum (which is 2). The function should also generate a table of 20 or more values of `a` and `b` (both ranging from 0 to 10) and compute the error for each pair. The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def calculate_sum_and_error(a: float, b: float) -> Tuple[float, float]:
"""
Calculate the sum of two constants `a` and `b`, and the error between the computed sum and the theoretical sum (2).
... |
python_sharegpt_23k | 20,491 | Write a Python function to extract the unique elements from a given list of integers. The function should return a list containing only the unique elements in the order they first appear in the input list.
The code should start with:
```python
from typing import List
def extract_unique_elements(input_list: List[int])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def extract_unique_elements(input_list: List[int]) -> List[int]:
"""
Extracts the unique elements from a given list of integers, maintaining the order of their first appearance.
Args:
input_... |
python_sharegpt_23k | 20,495 | Write a Python function to calculate the sum of all even numbers less than or equal to a given integer `n`. The function should iterate through all numbers from 1 to `n` and use a conditional statement to check if a number is even before adding it to the sum. The code should start with:
```python
def sum_even_numbers(n... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_even_numbers(n: int) -> int:
"""
Calculates the sum of all even numbers less than or equal to n.
Args:
n (int): The upper limit for the even numbers to be summed.
Returns:
int: The sum of all ev... |
python_sharegpt_23k | 20,498 | 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
import numpy as ... | Here is the Python code to solve the given problem in the markdown block:
```python
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.
Args:
mean (float):... |
python_sharegpt_23k | 20,507 | Write a Python function that applies a given complex mathematical formula to each element in a list of integers using the `map()` function. The function should return the transformed list. The mathematical formula to be applied is `num ** 2 + 2 * num + 1`.
The code should start with:
```python
from typing import List
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def apply_complex_formula(nums: List[int]) -> List[int]:
"""
Applies a complex mathematical formula to each element in the input list and returns the transformed list.
The formula applied to each el... |
python_sharegpt_23k | 20,509 | Write a Python function to find the first prime number greater than a given threshold from a list of numbers. The function should return the prime number if found, otherwise return `None`.
The code should start with:
```python
from typing import List, Optional
def find_first_prime_greater_than(numbers: List[int], thr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def is_prime(num: int) -> bool:
"""
Check if a given number is prime.
Args:
num (int): The number to check for primality.
Returns:
bool: True if the number is prime, F... |
python_sharegpt_23k | 20,510 | Write a Python function to generate a specified number of distinct LaTeX-formatted sentences describing a female's vocal performance, each showcasing a unique aspect of her performance such as tone, pitch, tempo, and style. The function should ensure that no two sentences are identical or similar to the examples given ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_vocal_performance_sentences(num_sentences: int) -> List[str]:
"""
Generates a specified number of distinct LaTeX-formatted sentences describing a female's vocal performance.
... |
python_sharegpt_23k | 20,518 | Write a Python function to calculate the sum of all odd numbers in a given list of integers while minimizing the memory footprint. The function should use generator expressions and built-in functions like `filter()` and `reduce()` to achieve this optimization.
The code should start with:
```python
from typing import L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from functools import reduce
def sum_of_odds(numbers: List[int]) -> int:
"""
Calculate the sum of all odd numbers in the given list of integers.
Args:
numbers (List[int]): The list of intege... |
python_sharegpt_23k | 20,524 | Write a Python function to calculate the Least Common Multiple (LCM) of numbers from 1 to n, considering the prime factors of each number and ensuring that the LCM only contains prime factors less than or equal to n. The function should be efficient and leverage number theory concepts.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_lcm_up_to_n(n: int) -> int:
"""
Calculate the Least Common Multiple (LCM) of numbers from 1 to n.
Args:
n (int): The upper limit of the range of numbers.
Returns:
int: The LCM of numbers f... |
python_sharegpt_23k | 20,550 | Write a Python function that takes a list of alphanumeric strings and returns the length of the longest word, defined as the sequence of characters delimited by whitespace, punctuation, or digits. The function should handle edge cases such as empty input lists, single-character words, and words with diacritical marks o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def longest_word_length(words: List[str]) -> int:
"""
Returns the length of the longest word in a list of alphanumeric strings,
where a word is defined as a sequence of characters delimited... |
python_sharegpt_23k | 20,551 | Write a Python function to add a suffix to a given word and return the new word. The function should handle cases where the suffix is an empty string or the word is an empty string. The code should start with:
```python
def add_suffix_to_word(word: str, suffix: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def add_suffix_to_word(word: str, suffix: str) -> str:
"""
Adds a suffix to a given word and returns the new word.
Args:
word (str): The base word to which the suffix will be added.
suffix (str): The suffix ... |
python_sharegpt_23k | 20,554 | Write a Python function to insert a specific element between two elements in a list, where the first element is less than a given value and the second element is greater than the given value, without increasing the list's size before the insertion. The function should update the indices of the following elements accord... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def insert_between_elements(my_list: List[float], insert_value: float, threshold: float) -> List[float]:
"""
Inserts a specific element between two elements in a list where the first element is less than... |
python_sharegpt_23k | 20,557 | Write a Python function to extract all instances of the term "machine learning engineer" from the job titles on an Indeed page for "Data Scientist". The function should parse the HTML content of the page and return a list of job titles that match the term "machine learning engineer". The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from bs4 import BeautifulSoup
import re
def extract_machine_learning_engineer_jobs(html_content: str) -> List[str]:
"""
Extracts all instances of the term "machine learning engineer" from job titles on a... |
python_sharegpt_23k | 20,562 | Write a Python function to generate a list of four distinct adjectives describing happiness. The function should ensure that each adjective is unique and not replicated. Use the `random` module to randomly select adjectives from a predefined list. The code should start with:
```python
from typing import List
import ran... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_distinct_happiness_adjectives() -> List[str]:
"""
Generates a list of four distinct adjectives describing happiness.
Returns:
List[str]: A list containing four uni... |
python_sharegpt_23k | 20,574 | Write a Python function to check if a given string contains a pair of double quotes and ensure that there are no consecutive double quotes (i.e., `""`). Additionally, the function should identify and return the indices of all single quotes in the string. The function should return a tuple containing a boolean indicatin... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_quotes(string: str) -> tuple[bool, list[int]]:
"""
Check if a given string contains a pair of double quotes and ensure there are no consecutive double quotes.
Additionally, identify and return the indices of all si... |
python_sharegpt_23k | 20,579 | Write a Python function to extract rows from a given NumPy matrix that contain prices denoted by a dollar sign. The matrix consists of item IDs and their corresponding prices, where some prices are represented with a dollar sign while others are not. The function should return a new NumPy array containing only the rows... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
import re
from typing import List
def extract_dollar_price_rows(matrix: np.ndarray) -> np.ndarray:
"""
Extracts rows from a given NumPy matrix that contain prices denoted by a dollar sign.
Args:
... |
python_sharegpt_23k | 20,580 | Write a Python function to calculate the average weight of each animal type from a given table. The table is represented as a list of lists, where each inner list contains the weights of the animals in the order: cats, dogs, rabbits, hamsters, and birds. The function should return a list of average weights correspondin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_average_weights(table: List[List[float]]) -> List[float]:
"""
Calculate the average weight of each animal type from a given table.
Args:
table (List[List[float]]): A list of li... |
python_sharegpt_23k | 20,611 | Write a Python function to filter out even numbers from a given list of integers. The function should return a new list containing only the even numbers from the input list. If the input list does not contain any even numbers, the function should return an empty list. The code should start with:
```python
from typing i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_even_numbers(lst: List[int]) -> List[int]:
"""
Filters out even numbers from a given list of integers and returns a new list containing only the even numbers.
Args:
lst (List[... |
python_sharegpt_23k | 20,614 | Write a Python function to determine the optimal placement of wind turbines based on multiple criteria including wind speed, direction, temperature, humidity, terrain, and surrounding environment. The function should return a boolean indicating whether the wind turbine can be placed at the given location or not. The co... | Here is the Python code to solve the given problem in the markdown block:
```python
def can_place_wind_turbine(wind_speed: float, wind_direction: int, temperature: int, humidity: int, terrain: str, environment: str) -> bool:
"""
Determines if a wind turbine can be placed at a given location based on multiple cr... |
python_sharegpt_23k | 20,616 | Write a Python function to simulate a murder mystery where each suspect has a soulmate, and the guilt of the murderer can be "Guilty", "Innocent", or "Unknown". The function should randomly assign soulmates to each suspect, generate a random victim and murderer, gather evidence, and determine the guilt of the murderer ... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
from typing import List, Dict
def simulate_murder_mystery(suspects: List[str]) -> Dict[str, str]:
"""
Simulate a murder mystery where each suspect has a soulmate, and the guilt of the murderer can be "Guilty", "In... |
python_sharegpt_23k | 20,618 | Write a Python function to find and return all occurrences of a specific pattern in a given text using regular expressions. The pattern should match any word character followed by an equals sign and then any digit character. The function should return a list of tuples, where each tuple contains the matched word charact... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List, Tuple
def find_word_equals_digit(text: str) -> List[Tuple[str, str]]:
"""
Find all occurrences of the pattern where a word character is followed by an equals sign and then a digit character.
... |
python_sharegpt_23k | 20,626 | Write a Python function to calculate the sum of a list of numbers with added error handling. The function should raise appropriate exceptions if the input is not a list, if the list contains non-numeric values, if the list is empty, or if the list length exceeds the maximum allowed length of \(10^6\).
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_sum(lst):
"""
Calculate the sum of a list of numbers with added error handling.
Args:
lst (list): The list of numbers to sum.
Returns:
float: The sum of the list.
Raises:
Type... |
python_sharegpt_23k | 20,627 | Write a Python function to multiply each element in a given list of integers by a specified factor. The function should return a new list with the modified elements. The input list and the factor should be provided as arguments to the function.
The code should start with:
```python
from typing import List
def multipl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_list_elements(input_list: List[int], factor: int) -> List[int]:
"""
Multiplies each element in the input list by the specified factor and returns a new list with the results.
Args:
... |
python_sharegpt_23k | 20,640 | 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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.