source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
python_sharegpt_23k | 17,492 | Write a Python function that uses the `match` method from the `re` module to find all digit characters in a given input string. The function should return a string containing all the digit characters found in the input string. The code should start with:
```python
import re
def find_digits_with_match(test: str) -> str... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def find_digits_with_match(test: str) -> str:
"""
Finds all digit characters in the given input string using the `match` method from the `re` module.
Args:
test (str): The input string to search for digit... |
python_sharegpt_23k | 17,495 | Write a Python function named `filter_even_numbers` that takes a list of integers and returns a new list containing only the even numbers. The function should have an optional boolean parameter `include_zero`. If `include_zero` is set to `True`, the function should include the number `0` in the output list if it is pre... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_even_numbers(numbers: List[int], include_zero: bool = False) -> List[int]:
"""
Filter the odd numbers from the list of numbers and return a new list containing only the even numbers.
Args... |
python_sharegpt_23k | 17,496 | Write a Python function to create a new list with the same elements but in reverse order, excluding non-integer elements from the input list. The function must have a time complexity of O(n/2) and should return an empty list if there are no valid integers in the input list. Additionally, optimize the code for larger da... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_int_list(lst: List[int]) -> List[int]:
"""
Create a new list with the same integer elements but in reverse order, excluding non-integer elements.
Args:
lst (List[int]): The input... |
python_sharegpt_23k | 17,499 | Write a Python function to identify all the prime factors of a given number using the trial division method. The function should handle edge cases such as negative numbers and non-integer inputs. If the input is a negative number, the function should return the prime factors of its absolute value. If the input is not a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def prime_factors(n: int) -> List[int]:
"""
Identify all the prime factors of a given number using the trial division method.
Args:
n (int): The number for which to find the prime factors.
... |
python_sharegpt_23k | 17,503 | Write a Python function to rank a list of cities based on their population in descending order. The function should take two lists as input: one containing the names of the cities and the other containing their corresponding populations. The function should return a list of city names sorted by their populations in des... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def rank_cities_by_population(cities: List[str], populations: List[int]) -> List[str]:
"""
Rank a list of cities based on their populations in descending order.
Args:
cities (List[str]): A l... |
python_sharegpt_23k | 17,505 | Write a Python function to verify if all circles in a given set of objects are blue. The set of objects is represented by a list `Z=[z_1,...,z_n]`, where each `z_i` is a pair of integers, i.e., each `z_i=(a_i, b_i)` where `a_i` and `b_i` are integers. These two integers represent the properties of `z_i`, with `a_i` rep... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def verify_all_circles_blue(Z: List[Tuple[int, int]]) -> bool:
"""
Verifies if all circles in a given set of objects are blue.
Args:
Z (List[Tuple[int, int]]): List of objects represe... |
python_sharegpt_23k | 17,526 | Write a Python function to generate a haiku verse that includes a noun, adjective, and verb from specific categories. The function should ensure that the generated verse adheres to the structure of a haiku, which typically consists of three lines with syllable counts of 5, 7, and 5, respectively. The categories and cor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import random
def generate_haiku(nouns: List[str], adjectives: List[str], verbs: List[str]) -> Tuple[str, str, str]:
"""
Generates a haiku verse that includes a noun, adjective, and verb from spec... |
python_sharegpt_23k | 17,536 | Write a Python function to generate a list of `n` random activities to do during self-isolation. The list should include both indoor and outdoor activities, and should not include any activities that involve social gatherings. The function should ensure that the list contains exactly `n` activities, with an equal numbe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_random_activities(n: int) -> List[str]:
"""
Generates a list of `n` random activities to do during self-isolation.
The list includes both indoor and outdoor activities, wit... |
python_sharegpt_23k | 17,539 | Write a Python function to calculate the sum of the squares of all the odd numbers between 1 and a given positive integer `n`, inclusive. The function should also generate a table with three columns: the first column should contain the odd numbers, the second column should contain their squares, and the third column sh... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_squares_of_odds(n: int) -> int:
"""
Calculate the sum of the squares of all the odd numbers between 1 and n, inclusive.
Additionally, generate a table with three columns: the odd numbers, their squares, and the ru... |
python_sharegpt_23k | 17,554 | Write a Python function to evaluate the performance and accuracy of the `sigmoid` function under various conditions and input distributions. The function should generate random inputs within specified ranges, apply the `sigmoid` function to these inputs, and then analyze the outputs to ensure they fall within the expec... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
import numpy as np
from typing import List, Tuple
def sigmoid(x: float) -> float:
"""
Compute the sigmoid function for a given input.
Args:
x (float): The input value.
Returns:
float: The... |
python_sharegpt_23k | 17,563 | Write a Python function to calculate the sum of the first `n` natural numbers using a while loop. The function should return the result rounded to two decimal points. The code should start with:
```python
def sum_of_first_n_numbers(n: int) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_first_n_numbers(n: int) -> float:
"""
Calculate the sum of the first n natural numbers using a while loop and return the result rounded to two decimal points.
Args:
n (int): The number of natural numbers ... |
python_sharegpt_23k | 17,564 | Write a Python function to calculate the percentage of completed goals from a given list of goals. Each goal in the list is represented by a boolean value (`True` for completed and `False` for not completed). The function should return the percentage of completed goals as a floating-point number.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def completed_goals_percentage(goals: List[bool]) -> float:
"""
Calculate the percentage of completed goals from a list of boolean values.
Args:
goals (List[bool]): A list of boolean values ... |
python_sharegpt_23k | 17,596 | Write a Python function to perform integer division and calculate the remainder of the division. The function should take two integers as input and return a tuple containing the quotient (result of integer division) and the remainder. Additionally, the function should print a message describing the division and the rem... | Here is the Python code to solve the given problem in the markdown block:
```python
def integer_division_with_remainder(num1: int, num2: int) -> tuple:
"""
Perform integer division and calculate the remainder of the division.
Args:
num1 (int): The dividend.
num2 (int): The divisor.
Ret... |
python_sharegpt_23k | 17,599 | Write a Python function to find the maximum number in a list of integers and count the frequency of each letter in a given string. The function should return a tuple containing the maximum number and a dictionary with the frequency count of each letter.
The code should start with:
```python
from typing import List, Di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
def analyze_data(numbers: List[int], word: str) -> Tuple[int, Dict[str, int]]:
"""
Analyzes a list of integers to find the maximum number and a string to count the frequency of each letter.
... |
python_sharegpt_23k | 17,606 | Write a Python function to generate a random sequence of 10 characters according to the following rules:
1. The first character is always an uppercase letter.
2. The next three characters are digits between 0 and 9.
3. The next four characters are lowercase letters.
4. The last two characters are either the special cha... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
import string
def generate_random_sequence() -> str:
"""
Generates a random sequence of 10 characters according to the following rules:
1. The first character is always an uppercase letter.
2. The next thr... |
python_sharegpt_23k | 17,607 | Write a Python function to group a given list of strings into 3-element sub-lists based on their similarity, while filtering out strings that are shorter than a specified minimum length. The function should handle different types of input lists, such as numerical data and mixed-type data, and ensure that the output sub... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def group_strings(strings: List[Union[str, int, float]], min_length: int) -> List[List[Union[str, int, float]]]:
"""
Groups a list of strings, integers, or floats into 3-element sub-lists based on... |
python_sharegpt_23k | 17,608 | Write a Python function to calculate the average release year of movies from a given dataset. The dataset is a list of dictionaries, where each dictionary represents a movie and contains keys for the movie title, director, and release year. The function should handle cases where the dataset might be empty.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def average_release_year(movies: List[Dict[str, any]]) -> float:
"""
Calculate the average release year of movies from a given dataset.
Args:
movies (List[Dict[str, any]]): A list of d... |
python_sharegpt_23k | 17,624 | Write a Python function to calculate the total revenue given the number of units sold and the price per unit. The function should be able to handle both integer and float inputs for the number of units and the price per unit. The code should start with:
```python
def calculate_revenue(num_units: float, price_per_unit: ... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_revenue(num_units: float, price_per_unit: float) -> float:
"""
Calculate the total revenue given the number of units sold and the price per unit.
Args:
num_units (float): The number of units sold. Can ... |
python_sharegpt_23k | 17,647 | Write a Python function to calculate the age of a person when they completed a specific work, given their birth year and the year they completed the work. The function should return the age as an integer.
The code should start with:
```python
def calculate_age_at_completion(birth_year: int, completion_year: int) -> in... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_age_at_completion(birth_year: int, completion_year: int) -> int:
"""
Calculate the age of a person when they completed a specific work.
Args:
birth_year (int): The birth year of the person.
com... |
python_sharegpt_23k | 17,652 | Write a Python function to calculate the sum of all integers between two given integers, inclusive. The function should handle cases where the first integer is greater than the second integer by iterating through the range in the correct order. The function should also include a docstring explaining its purpose, parame... | Here is the Python code to solve the given problem in the markdown block:
```python
def sum_between_numbers(m: int, n: int) -> int:
"""
Calculate the sum of all integers between two given integers, inclusive.
Args:
m (int): The first integer.
n (int): The second integer.
Returns:
... |
python_sharegpt_23k | 17,654 | Write a Python function to evaluate a list of mathematical expressions consisting of numbers and the operators `+`, `-`, `*`, `/`, and parentheses. The function should return a list of integers representing the results of evaluating each expression. The code should start with:
```python
from typing import List
def eva... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def evaluate_expressions(expressions: List[str]) -> List[int]:
"""
Evaluates a list of mathematical expressions and returns a list of their results.
Args:
expressions (List[str]): A list of ... |
python_sharegpt_23k | 17,657 | Write a Python function to randomly generate a list of five rare items, one from each category. The categories and their corresponding items are predefined. The function should ensure that each item is unique and belongs to a different category. The code should start with:
```python
from typing import List
import rando... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_rare_items() -> List[str]:
"""
Generates a list of five rare items, one from each predefined category.
Returns:
List[str]: A list containing five unique rare items... |
python_sharegpt_23k | 17,658 | Write a Python function to find the highest and lowest values for each attribute in a given dataset. The dataset is a 2D NumPy array where each row represents a record and each column represents a numerical attribute. The function should return two lists: one for the highest values and one for the lowest values of each... | 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_extremes(dataset: np.ndarray) -> (List[float], List[float]):
"""
Find the highest and lowest values for each attribute in a given dataset.
Args:
dataset (np.ndarr... |
python_sharegpt_23k | 17,661 | Write a Python function to identify the three numbers in a given list of integers that have the largest sum, excluding any negative numbers. The function should have a time complexity of O(n log n) or better.
The code should start with:
```python
from typing import List
def find_largest_sum_of_three(numbers: List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_largest_sum_of_three(numbers: List[int]) -> List[int]:
"""
Identifies the three numbers in a given list of integers that have the largest sum, excluding any negative numbers.
Args:
... |
python_sharegpt_23k | 17,667 | Write a Python function to calculate the Euclidean distance between two points in a 2D plane, ensuring that the result is accurate up to two decimal places. The function should handle any floating-point coordinates and return the distance rounded to two decimal places.
The code should start with:
```python
import math... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def euclidean_distance(x1: float, y1: float, x2: float, y2: float) -> float:
"""
Calculate the Euclidean distance between two points (x1, y1) and (x2, y2) in a 2D plane,
ensuring the result is accurate up to two... |
python_sharegpt_23k | 17,672 | Write a Python function to generate the nth number in the Fibonacci sequence using a tail-recursive approach. The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, starting from 0 and 1. The function should handle the base cases where n is less than or equal to 1 by retur... | Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci_tail_recursive(n: int) -> int:
"""
Generate the nth number in the Fibonacci sequence using a tail-recursive approach.
The Fibonacci sequence is a series of numbers where each number is the sum of the two prece... |
python_sharegpt_23k | 17,685 | Write a Python function to calculate the sum of even numbers in a given list of integers. The function should handle edge cases such as empty lists, non-integer values, and negative numbers. The function should complete the task in linear time and space complexity.
The code should start with:
```python
from typing imp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_even_numbers(numbers: List[int]) -> int:
"""
Calculate the sum of even numbers in a given list of integers.
Args:
numbers (List[int]): A list of integers that may contain non-inte... |
python_sharegpt_23k | 17,693 | Write a Python function to calculate the nth Fibonacci number using dynamic programming with memoization. The function should efficiently handle large values of n by storing previously computed results to avoid redundant calculations. Additionally, create a table that compares and contrasts the time and space complexit... | Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci_memo(n: int) -> int:
"""
Calculate the nth Fibonacci number using dynamic programming with memoization.
Args:
n (int): The position in the Fibonacci sequence to calculate.
Returns:
int: Th... |
python_sharegpt_23k | 17,694 | Write a Python function to generate a list of prime numbers up to a given limit `n`. The function should correctly identify prime numbers and 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[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def is_prime(n: int) -> bool:
"""
Check if a given number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, Fal... |
python_sharegpt_23k | 17,704 | Write a Python function to determine if a given number is a prime number. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The function should return `True` if the number is prime and `False` otherwise. The code should start with:
```python
def is_prime_number(n: ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime_number(n: int) -> bool:
"""
Determines 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 | 17,705 | Write a Python function to find the second smallest number in a list of integers without using any built-in functions or libraries. The function should handle duplicates and return the second smallest number. The code should start with:
```python
from typing import List
def find_second_smallest(numbers: List[int]) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_second_smallest(numbers: List[int]) -> int:
"""
Find the second smallest number in a list of integers without using any built-in functions or libraries.
Args:
numbers (List[int]): T... |
python_sharegpt_23k | 17,713 | Write a Python function to calculate the total bill for a group of N people ordering from a restaurant, including the discount applied based on the number of people in the group. The discount rules are as follows:
- For a group of 2-3 people, they get a 5% discount.
- For a group of 4-6 people, they get a 10% discount.... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_total_bill_with_discount(num_people: int, total_bill: float) -> float:
"""
Calculate the total bill for a group of N people ordering from a restaurant, including the discount applied.
Args:
num_people ... |
python_sharegpt_23k | 17,719 | Write a Python function to find the sum of all even numbers from 1 to `n` and output the even numbers used in the calculation. Additionally, the program should only execute in O(log n) time complexity using a binary search algorithm. The output should also include the total number of even integers used in the calculati... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def binary_search(arr: List[int], x: int) -> int:
"""
Perform a binary search to find the index of the largest number in arr that is less than or equal to x.
Args:
arr (List[int]): Th... |
python_sharegpt_23k | 17,722 | Write a Python function to compute the summation of the first `n` natural numbers. The function should take an integer `n` as input and return the sum of the first `n` natural numbers. The code should start with:
```python
def sum_of_first_n_numbers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_first_n_numbers(n: int) -> int:
"""
Compute the summation of the first n natural numbers.
Args:
n (int): The number of natural numbers to sum.
Returns:
int: The sum of the first n natural num... |
python_sharegpt_23k | 17,725 | Write a Python function to implement a sorting algorithm that has a space complexity of O(1) and can handle duplicates in the input without affecting the time or space complexity. The sorting algorithm should maintain the same requirements as the previous prompt.
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
def cycle_sort(array: List[int]) -> List[int]:
"""
Sorts the input array using Cycle Sort with a space complexity of O(1) and handles duplicates.
Args:
array (List[int]): The array to be sor... |
python_sharegpt_23k | 17,729 | Write a Python function to convert a given weight between kilograms and pounds, and another function to convert the weight of an object on Earth to its weight on the moon. The functions should be able to handle both directions of conversion (kilograms to pounds and pounds to kilograms) and provide the weight on the moo... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_weight(weight: float, from_unit: str, to_unit: str) -> float:
"""
Converts a given weight between kilograms and pounds.
Args:
weight (float): The weight to be converted.
from_unit (str): The unit... |
python_sharegpt_23k | 17,731 | Write a Python function to generate a random list of adjectives to describe different aspects of spring. The function should take an integer `n` as input, which represents the number of adjectives to generate. The function should return a list of `n` randomly selected adjectives from a predefined list of adjectives rel... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_spring_adjectives(n: int) -> List[str]:
"""
Generates a random list of adjectives to describe different aspects of spring.
Args:
n (int): The number of adjectives ... |
python_sharegpt_23k | 17,736 | Write a Python function to generate a random number between 1 and 100 that is not divisible by 5. The function should ensure that the generated number meets this criterion.
The code should start with:
```python
import random
def generate_random_number() -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_random_number() -> int:
"""
Generates a random number between 1 and 100 that is not divisible by 5.
Returns:
int: A random number between 1 and 100 that is not divisible by 5.
"""
... |
python_sharegpt_23k | 17,740 | Write a Python function to generate all Narcissistic numbers within a given range `[start, end]`. A Narcissistic number (also known as a pluperfect number or Armstrong number) is a number that is the sum of its own digits each raised to the power of the number of digits.
The function 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 find_narcissistic_numbers(start: int, end: int) -> List[int]:
"""
Generate all Narcissistic numbers within the given range [start, end].
A Narcissistic number is a number that is the sum of its ... |
python_sharegpt_23k | 17,742 | Write a Python function to analyze a list of orders for a furniture shop and identify which products have the highest profit margin. The profit margin for each product is defined as the difference between the selling price and the production cost, divided by the selling price. Only products with a profit margin greater... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def analyze_orders(orders: List[Dict]) -> List[Dict]:
"""
Analyzes a list of orders to identify high-profit products and returns details of orders containing such products.
Args:
order... |
python_sharegpt_23k | 17,746 | Create a Python function that generates a dictionary with five key-value pairs, where the values are all prime numbers. The keys must follow specific criteria:
1. The first key must be a palindrome and represent a type of animal often associated with intelligence.
2. The second key must be a combination of the chemical... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_prime_dictionary() -> dict:
"""
Generates a dictionary with five key-value pairs where the values are prime numbers.
The keys follow specific criteria:
1. The first key is a palindrome representing an intell... |
python_sharegpt_23k | 17,751 | Write a Python function to calculate the total number of human legs on three distinct boats, each containing different numbers of pirates and sailors. The function should accept three dictionaries, each representing a boat with keys 'pirates' and 'sailors', and return a human-readable string summarizing the total numbe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def calculate_total_legs(boat1: Dict[str, int], boat2: Dict[str, int], boat3: Dict[str, int]) -> str:
"""
Calculate the total number of human legs on three distinct boats.
Args:
boat1 (Dict[... |
python_sharegpt_23k | 17,783 | Write a Python function to sort a dictionary of entities by their respective ID numbers in ascending order. The function should return a new dictionary with the sorted entities. The dictionary should contain the following entities and their respective ID numbers:
- Alma WWTP: 55207
- Augusta SD: 57093
- Brinkley Water:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_entities_by_id(entities: Dict[str, int]) -> Dict[str, int]:
"""
Sorts a dictionary of entities by their respective ID numbers in ascending order.
Args:
entities (Dict[str, int]): A ... |
python_sharegpt_23k | 17,796 | Write a Python function to generate a randomized order of songs in a playlist. The function should take a list of song names as input and return a new list with the songs in a randomized order. The code should start with:
```python
from typing import List
def shuffle_playlist(songs: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def shuffle_playlist(songs: List[str]) -> List[str]:
"""
Generates a randomized order of songs in a playlist.
Args:
songs (List[str]): A list of song names.
Returns:
... |
python_sharegpt_23k | 17,798 | 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 | 17,799 | Write a Python function to perform a binary search on a sorted array of integers to find the index of a target integer. If the target integer is not found in the array, the function should return -1. The function should be efficient and use the binary search algorithm.
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
def binary_search(arr: List[int], target: int) -> int:
"""
Perform a binary search on a sorted array to find the index of a target integer.
Args:
arr (List[int]): A sorted list of intege... |
python_sharegpt_23k | 17,800 | Write a Python function to calculate the sum of multiple numbers efficiently, especially for large datasets. The function should support both small and large datasets and should be optimized for performance. The code should start with:
```python
from typing import List
def efficient_sum(numbers: List[int]) -> int:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def efficient_sum(numbers: List[int]) -> int:
"""
Calculate the sum of multiple numbers efficiently, especially for large datasets.
Args:
numbers (List[int]): A list of integers to be summed... |
python_sharegpt_23k | 17,804 | Write a Python function to implement a Mini-Batch Gradient Descent (MBGD) optimization algorithm for training a linear regression model. The function should update the model parameters using mini-batches of data, which combines the benefits of both Stochastic Gradient Descent (SGD) and Batch Gradient Descent (BGD). The... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def mini_batch_gradient_descent(X: np.ndarray, y: np.ndarray, alpha: float, epochs: int, batch_size: int) -> np.ndarray:
"""
Implements Mini-Batch Gradient Descent (MBGD) to train a linear regression model.
... |
python_sharegpt_23k | 17,814 | Write a Python function to sort a dataset of fruits by their sweetness values in descending order and group them by their origin countries. Additionally, implement a function to calculate the average sweetness of fruits for each country. The dataset is represented as a dictionary where each key is a fruit name and the ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def sort_and_group_fruits(fruits: Dict[str, Dict[str, str]]) -> Dict[str, List[Tuple[str, int]]]:
"""
Sort the fruits by their sweetness values in descending order and group them by their or... |
python_sharegpt_23k | 17,826 | Write a Python function to verify if all the circles in a given set of objects are blue. The set of objects is represented by a list `Z` where each element `z_i` is a tuple of two integers `(a_i, b_i)`. The first integer `a_i` represents the shape, and the second integer `b_i` represents the color. The shape 'circle' i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def is_all_blue(Z: List[Tuple[int, int]]) -> bool:
"""
Verifies if all the circles in a given set of objects are blue.
Args:
Z (List[Tuple[int, int]]): A list of tuples where each tup... |
python_sharegpt_23k | 17,830 | Write a Python function to reverse the words in a given string while maintaining the order of the words. For example, if the input string is "Hello world", the output should be "world Hello". The function should handle strings with multiple spaces between words and leading/trailing spaces.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_words_in_string(s: str) -> str:
"""
Reverses the words in a given string while maintaining the order of the words.
Args:
s (str): The input string containing words to be reversed.
Returns:
s... |
python_sharegpt_23k | 17,832 | Write a Python function to identify and generate the formula for an arithmetic sequence given a list of integers. The function should also be able to handle sequences of any length, with any starting number and common difference. Additionally, provide a detailed explanation of the mathematical concept behind the formul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def arithmetic_sequence_formula(sequence: List[int]) -> str:
"""
Identifies and generates the formula for an arithmetic sequence given a list of integers.
Args:
sequence (List[int]): A list ... |
python_sharegpt_23k | 17,840 | Write a Python function to find the sunrise time for a specific date from a list of sunrise times and fill in the missing word in a sentence. The sunrise times are provided as a list of strings in the format `'YYYY-MM-DD HH:MM:SS'`. The function should return the complete sentence with the missing word filled in.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import datetime
def fill_missing_word(sunrise_times: List[str], target_date: str) -> str:
"""
Finds the sunrise time for a specific date from a list of sunrise times and fills in the missing word in a se... |
python_sharegpt_23k | 17,846 | Write a Python function to extract phone numbers from a given text input using a regular expression. The function should be able to identify and extract phone numbers with varying formats, including different delimiters (such as dashes, periods, or spaces), country codes, and local numbers. The function should ignore a... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def extract_phone_numbers(text: str) -> List[str]:
"""
Extracts phone numbers from a given text input using a regular expression.
The function identifies and extracts phone numbers with va... |
python_sharegpt_23k | 17,849 | Write a Python function to reverse the characters in a given string and return the reversed string. The function should only use built-in Python functions and cannot use any third-party libraries or packages. The code should start with:
```python
def reverse_string(word: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_string(word: str) -> str:
"""
Reverses the characters in the given string and returns the reversed string.
Args:
word (str): The input string to be reversed.
Returns:
str: The reversed str... |
python_sharegpt_23k | 17,850 | Write a Python function that converts all lowercase letters in a given string to uppercase using the ASCII table. The function should handle strings containing both lowercase and uppercase letters, as well as other characters (such as punctuation and spaces). The function should return the modified string with all lett... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_uppercase(s: str) -> str:
"""
Converts all lowercase letters in the given string to uppercase using the ASCII table.
Args:
s (str): The input string containing lowercase and uppercase letters, and pos... |
python_sharegpt_23k | 17,851 | 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(dataset: List[int], min_range: int, max_range: int) -> Tuple[int, List[int], int]:
"""
Perform non-deterministic decision-making on a given dataset.
... |
python_sharegpt_23k | 17,859 | Write a Python function to initialize and display a 5x5 board game that combines elements of Chess and Tic-Tac-Toe. The board should have different pieces for each player, and the initial positions of the pieces should be set according to the given code snippet. The function should display the board in a readable forma... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def initialize_and_display_board() -> None:
"""
Initializes and displays a 5x5 board game with specific initial positions for each player's pieces.
The board combines elements of Chess and Tic-Tac-T... |
python_sharegpt_23k | 17,861 | Write a Python function to multiply two numbers, handling non-integer inputs by printing an error message and returning `None`. The function should accept integers and floats as valid inputs.
The code should start with:
```python
def multiply(a, b):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def multiply(a, b):
"""
Multiplies two numbers. If either input is not an integer or float, prints an error message and returns None.
Args:
a (int or float): The first number to multiply.
b (int or float): T... |
python_sharegpt_23k | 17,873 | Modify the given Python code to introduce a new weapon, "Phoenix Feather", that Harry Potter can use to defeat his enemies. Additionally, introduce a new enemy, "Acromantula", to the list that Harry Potter must fight against. Ensure that Harry Potter does not defeat an enemy using the same weapon twice. Finally, make i... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def harry_potter_adventure():
"""
Simulate Harry Potter's adventure where he fights against various enemies using different weapons.
Harry must defeat a specific number of enemies before the ring is destroyed.... |
python_sharegpt_23k | 17,884 | Write a Python function that takes two arguments: an integer `x` and a list of integers `y`, and returns a list of integers that are the result of multiplying `x` with each element in `y`. Additionally, write a function to calculate the sum of the resulting list. The code should start with:
```python
from typing import... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_elements(x: int, y: List[int]) -> List[int]:
"""
Multiplies each element in the list `y` by the integer `x`.
Args:
x (int): The integer to multiply each element in the list by.
... |
python_sharegpt_23k | 17,886 | Write a Python function named `drastically_gradually` that takes a list of numbers as input and gradually increases each number by 5, then drastically decreases them by 10. The function should return the final list.
The code should start with:
```python
from typing import List
def drastically_gradually(lst: List[int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def drastically_gradually(lst: List[int]) -> List[int]:
"""
Transforms a list of numbers by gradually increasing each number by 5 and then drastically decreasing them by 10.
Args:
lst (List[... |
python_sharegpt_23k | 17,888 | Write a Python function to compute the sum of the first n natural numbers. The function should be efficient and handle edge cases such as when n is 0 or negative. The code should start with:
```python
def sum_of_natural_numbers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_natural_numbers(n: int) -> int:
"""
Compute the sum of the first n natural numbers.
Args:
n (int): The number of natural numbers to sum.
Returns:
int: The sum of the first n natural numbers.
... |
python_sharegpt_23k | 17,899 | Write a Python function to convert a comma-separated string of integers into a NumPy array efficiently. The function should handle any valid comma-separated integer string, including those with spaces between the commas and integers.
The code should start with:
```python
import numpy as np
from typing import List
def... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List
def string_to_numpy_array(int_string: str) -> np.ndarray:
"""
Converts a comma-separated string of integers into a NumPy array.
Args:
int_string (str): A string containing... |
python_sharegpt_23k | 17,901 | Write a Python function to generate an HTML string that displays a sentence containing the words "blue", "apple", and "school". The word "apple" should be displayed in blue font color, while the words "blue" and "school" should be displayed in black font color. The function should accept three strings as input paramete... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_html_sentence(word1: str, word2: str, word3: str) -> str:
"""
Generates an HTML string that displays a sentence with specific words colored differently.
Args:
word1 (str): The first word to be displayed... |
python_sharegpt_23k | 17,903 | Write a Python function to reverse the order of words in a given sentence. The function should handle sentences with varying lengths and word counts, including sentences with punctuation. The code should start with:
```python
def reverse_sentence(sentence: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_sentence(sentence: str) -> str:
"""
Reverses the order of words in a given sentence.
Args:
sentence (str): The input sentence to be reversed.
Returns:
str: The sentence with the order of w... |
python_sharegpt_23k | 17,904 | Write a Python function to find and print all unique words that can be formed by rearranging the letters of one or more words in a given list. The function should handle duplicates and ignore case. The output should indicate which words are anagrams of each other.
The code should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_anagrams(words: List[str]) -> None:
"""
Finds and prints all unique words that can be formed by rearranging the letters of one or more words in the given list.
Args:
words (List[str... |
python_sharegpt_23k | 17,920 | Write a Python function to sort a list of fruit names based on the cumulative count of vowels in each fruit name, ensuring that the cumulative count increases progressively. The function should handle cases where the input list is empty or contains non-string elements by returning an empty list. The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_fruits_by_cumulative_vowels(fruit_list: List[str]) -> List[str]:
"""
Sorts a list of fruit names based on the cumulative count of vowels in each fruit name.
Args:
fruit_list (List[s... |
python_sharegpt_23k | 17,940 | Write a Python function to filter a list of retreat centers based on specific attributes such as location, budget, and duration. The function should return a list of retreat centers that match all the specified criteria. The code should start with:
```python
from typing import List, Dict
def filter_retreats(retreats_l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def filter_retreats(retreats_list: List[Dict], location: str, budget: int, duration: int) -> List[Dict]:
"""
Filters a list of retreat centers based on specific attributes such as location, budget,... |
python_sharegpt_23k | 17,945 | Write a Python function to sort a table based on multiple columns simultaneously. The function should accept a list of column names and sort the table based on those columns in ascending order. Additionally, it should provide an option to sort the 'Integer Column' in descending order while keeping the other columns in ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def sort_table(table: List[Dict[str, str]], columns: List[str], sort_integer_descending: bool = False) -> List[Dict[str, str]]:
"""
Sorts a table based on the given column names in ascending order.... |
python_sharegpt_23k | 17,953 | Write a Python function to calculate and display the average yearly revenue of prepaid companies and T-Money for the past three years separately. Additionally, ensure that the revenue is displayed in billions and rounded off to two decimal places. Also, provide the code to retrieve the total number of customers for pre... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def analyze_financial_data(revenue_data: List[List[float]], customer_data: List[List[int]]) -> None:
"""
Analyze and display the average yearly revenue and average number of customers for prepaid compani... |
python_sharegpt_23k | 17,955 | Write a Python function to categorize a list of words into adjectives and adverbs based on their suffix. Adjectives are words that do not end with "ly", while adverbs are words that end with "ly". The function should return a tuple containing two lists: the first list for adjectives and the second list for adverbs.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def categorize_words(words: List[str]) -> Tuple[List[str], List[str]]:
"""
Categorizes a list of words into adjectives and adverbs based on their suffix.
Args:
words (List[str]): A li... |
python_sharegpt_23k | 17,966 | Write a Python function to perform an algorithm with polynomial time complexity of O(n^2), where n is the length of the input list. The algorithm should sort a list of integers using the **Bubble Sort** method. The code should start with:
```python
from typing import List
def bubble_sort(numbers: List[int]) -> List[in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(numbers: List[int]) -> List[int]:
"""
Sorts a list of integers using the Bubble Sort algorithm.
Bubble Sort is a simple sorting algorithm that repeatedly steps through the list,
... |
python_sharegpt_23k | 17,968 | Write a Python function to calculate the total sum of income of employees who meet the following criteria:
1. The employee is male.
2. The employee has a college degree.
3. The employee is aged between 25 and 30 (inclusive).
4. The employee works more than 40 hours a week.
5. The employee has been with the company for ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def calculate_total_income(employees: List[Dict]) -> int:
"""
Calculate the total sum of income of employees who meet the specified criteria.
Args:
employees (List[Dict]): A list of di... |
python_sharegpt_23k | 17,974 | Write a Python function to extract the expiration date and security code from a given credit card string. The credit card string is in the format "XXXX-XXXX-XXXX-XXXX MM/YY CVV", where "X" represents a digit, "MM/YY" is the expiration date in the format of a two-digit month and two-digit year, and "CVV" is a three-digi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
import re
def extract_card_info(credit_card_string: str) -> Tuple[str, str]:
"""
Extracts the expiration date and security code from a given credit card string.
Args:
credit_card_string (st... |
python_sharegpt_23k | 17,977 | Write a Python function to recommend the most effective treatment for individuals based on their occupation and BMI. The function should take in the following parameters:
- A dictionary where the keys are medical conditions and the values are lists of treatments (e.g., `{"Diabetes": ["Insulin", "Metformin"], "High bloo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Callable
def recommend_treatment(conditions: Dict[str, List[str]], individuals: List[Dict], calculate_bmi: Callable[[float, float], float]) -> Dict[str, str]:
"""
Recommends the most effective tre... |
python_sharegpt_23k | 17,978 | Write a Python function to determine and print "Output 2" if the value of `x` is greater than the value of `y`, otherwise print "Output 1". The function should take two integers as input and return the appropriate output string.
The code should start with:
```python
def determine_output(x: int, y: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def determine_output(x: int, y: int) -> str:
"""
Determines the output string based on the comparison of two integers.
Args:
x (int): The first integer to compare.
y (int): The second integer to compare.
... |
python_sharegpt_23k | 17,985 | Write a Python function to sort a list of numbers using the merge sort algorithm. The function should recursively divide the list into halves until each sublist contains only one element, and then merge the sublists back together in sorted order. The code should start with:
```python
from typing import List
def merge_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(nums: List[int]) -> List[int]:
"""
Sorts a list of integers using the merge sort algorithm.
Args:
nums (List[int]): The list of integers to be sorted.
Returns:
Li... |
python_sharegpt_23k | 17,989 | Write a Python function to retrieve numbers with even or odd values from a specified range of indices in a list. The function should accept a list, a start index, an end index, and a boolean flag indicating whether to retrieve even or odd numbers. The function should return a list of the selected numbers.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_numbers_in_range(lst: List[int], start: int, end: int, even: bool) -> List[int]:
"""
Retrieves numbers with even or odd values from a specified range of indices in a list.
Args:
lst ... |
python_sharegpt_23k | 17,995 | Write a Python function to determine the color of a fruit based on a predefined dictionary of fruit names and their corresponding colors. The function should be case-insensitive and return "unknown" if the fruit name is not found in the dictionary. The code should start with:
```python
def determine_fruit_color(fruit_n... | Here is the Python code to solve the given problem in the markdown block:
```python
def determine_fruit_color(fruit_name: str) -> str:
"""
Determines the color of a fruit based on a predefined dictionary of fruit names and their corresponding colors.
Args:
fruit_name (str): The name of the fruit wh... |
python_sharegpt_23k | 17,997 | Write a Python function to extract all bigrams (consecutive pairs of words) from a given text. The function should return a list of tuples where each tuple contains a pair of words. The code should start with:
```python
from typing import List, Tuple
def extract_bigrams(text: str) -> List[Tuple[str, str]]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Tuple
def extract_bigrams(text: str) -> List[Tuple[str, str]]:
"""
Extracts all bigrams (consecutive pairs of words) from the given text.
Args:
text (str): The input text from which to ex... |
python_sharegpt_23k | 18,001 | Write a Python function to determine whether a given sentence is a pangram. A pangram is a sentence that contains every letter of the alphabet at least once. The function should take a string as input and return a boolean value indicating whether the string is a pangram or not.
The code should start with:
```python
de... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_pangram(sentence: str) -> bool:
"""
Determines whether a given sentence is a pangram.
A pangram is a sentence that contains every letter of the alphabet at least once.
Args:
sentence (str): The sentence ... |
python_sharegpt_23k | 18,003 | Write a Python function to determine which students in a given list are not considered intelligent. Each student is represented by a dictionary with keys "name" and "intelligence", where "intelligence" is a boolean value. The function should return a list of names of students who are not intelligent.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def find_not_intelligent_students(students: List[Dict[str, any]]) -> List[str]:
"""
Determine which students in a given list are not considered intelligent.
Args:
students (List[Dict[s... |
python_sharegpt_23k | 18,005 | Write a Python function to generate a 30-minute high-intensity interval training (HIIT) workout plan that incorporates running and cycling. The workout should consist of 5 cycles, each with a duration of 6 minutes. In each cycle, the client should alternate between running and cycling for 30 seconds each, with a 30-sec... | Here is the Python code to solve the given problem in the markdown block:
```python
def generate_hiit_workout():
"""
Generates a 30-minute high-intensity interval training (HIIT) workout plan.
The workout consists of 5 cycles, each lasting 6 minutes. In each cycle, the client
alternates between running... |
python_sharegpt_23k | 18,008 | Write a Python function to convert a traditional Italian tiramisu recipe into a vegan version by modifying the ingredient list. The function should replace non-vegan ingredients with their vegan alternatives while maintaining the classic taste of the dish. 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 convert_to_vegan_tiramisu(ingredients: List[str]) -> List[str]:
"""
Converts a traditional Italian tiramisu recipe into a vegan version by replacing non-vegan ingredients with vegan alternatives.
... |
python_sharegpt_23k | 18,011 | Write a Python function to calculate the total distance traveled by birds over a given number of days. The function should take a list of integers representing the distances traveled each day and return the total distance. The code should start with:
```python
from typing import List
def calculate_total_distance(dista... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_total_distance(distances: List[int]) -> int:
"""
Calculate the total distance traveled by birds over a given number of days.
Args:
distances (List[int]): A list of integers rep... |
python_sharegpt_23k | 18,021 | Write a Python function to filter a list of car dictionaries and return a list of cars that meet specific criteria. The criteria are: the car must be of the brand 'Toyota', the year must be greater than 2010, and the color must be 'red'. The function should be optimized to iterate through the list only once.
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def filter_red_toyotas(cars: List[Dict[str, str]]) -> List[Dict[str, str]]:
"""
Filters a list of car dictionaries and returns a list of cars that meet the following criteria:
- The car's brand... |
python_sharegpt_23k | 18,028 | Write a Python function to filter activities based on their intensity level and duration. The function should take a list of activities and an intensity level as input and return a list of activities that match the given intensity level and have a duration less than 30 minutes. The intensity levels are categorized as "... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def filter_activities(activity_list: List[str], intensity_level: str) -> List[str]:
"""
Filters activities based on the given intensity level and duration less than 30 minutes.
Args:
a... |
python_sharegpt_23k | 18,032 | Write a Python function to identify all prime numbers greater than a given threshold from a list of integers. The function should return a list of these prime numbers.
The code should start with:
```python
from typing import List
def find_primes_greater_than(numbers: List[int], threshold: int) -> List[int]:
```
| 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.
Returns:
bool: True if the number is prime, False otherwise.
"""
if n <... |
python_sharegpt_23k | 18,033 | Write a Python function to isolate the last 5 characters of each string in a list, but only for strings that contain only numeric characters. If a string contains any non-numeric characters, it should be ignored. The function should return a list of the isolated characters.
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 re
def isolate_last_five_numeric(data: List[str]) -> List[str]:
"""
Isolates the last 5 characters of each string in the input list that contains only numeric characters.
Args:
data (... |
python_sharegpt_23k | 18,036 | Write a Python function to determine if a certain element exists in a list and return its index if found. If the element is not found, return -1. The function should be efficient and handle edge cases such as an empty list or non-existent element.
The code should start with:
```python
from typing import List, Any
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def find_element_index(lst: List[Any], element: Any) -> int:
"""
Determine if a certain element exists in a list and return its index if found.
If the element is not found, return -1.
Args:... |
python_sharegpt_23k | 18,044 | Write a Python function to calculate the sum of all grades in a dictionary that contains information about students, including their names, ages, and grades. The dictionary is structured such that each student's name maps to another dictionary containing their age and grade. The function should iterate through the dict... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sum_grades(students: Dict[str, Dict[str, int]]) -> int:
"""
Calculate the sum of all grades in a dictionary of students.
Args:
students (Dict[str, Dict[str, int]]): A dictionary where ea... |
python_sharegpt_23k | 18,049 | Write a Python function to calculate the product of the sum of two lists and the difference of their sums. The function should take two lists of integers as input and return the calculated product. The code should start with:
```python
from typing import List
def product_of_sum_and_difference(list_a: List[int], list_b... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def product_of_sum_and_difference(list_a: List[int], list_b: List[int]) -> int:
"""
Calculate the product of the sum of two lists and the difference of their sums.
Args:
list_a (List[int]): ... |
python_sharegpt_23k | 18,059 | Write a Python function to extract the text "shadowToCatarin" from a given text input that includes the string "% shadowToCatarin: tp" and "%shadowToCatarin: tp". The function should use a regular expression to account for possible variations in the input format, such as spaces before or after the percentage sign and c... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def extract_shadow_to_catarin(text_input: str) -> List[str]:
"""
Extracts the text "shadowToCatarin" from the given text input using a regular expression.
Args:
text_input (str): T... |
python_sharegpt_23k | 18,091 | Write a Python function to generate a formatted table of expense items and their corresponding amounts, including a total row. The function should accept two lists: one for expense items and another for their amounts. The function should return a formatted string that represents the table.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_expense_table(expense_items: List[str], amounts: List[int]) -> str:
"""
Generates a formatted table of expense items and their corresponding amounts, including a total row.
Args:
... |
python_sharegpt_23k | 18,095 | Write a Python function that generates a LaTeX formula representing the sentence "She who enjoys jogging on the seashore" using a given subject. The function should also incorporate a table of synonyms for "run" and "beach" that it can utilize. The function should start with:
```python
from typing import Dict
def gene... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def generate_latex_formula(subject: str, synonyms: Dict[str, list]) -> str:
"""
Generates a LaTeX formula representing the sentence "She who enjoys jogging on the seashore" using a given subject and a ta... |
python_sharegpt_23k | 18,099 | Write a Python function to find the longest palindromic substring within a given string. The function should handle strings with both uppercase and lowercase letters, as well as special characters and spaces. The function should be efficient and effective for even the longest and most complex strings. The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
def longest_palindromic_substring(s: str) -> str:
"""
Find the longest palindromic substring within a given string.
Args:
s (str): The input string to search for the longest palindromic substring.
Returns:
... |
python_sharegpt_23k | 18,105 | Write a Python function to calculate the sum of all integers in a given list. The function should handle lists of any length, including empty lists. The function should return the sum of the integers in the list.
The code should start with:
```python
from typing import List
def calculate_sum(numbers: List[int]) -> in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_sum(numbers: List[int]) -> int:
"""
Calculate the sum of all integers in the given list.
Args:
numbers (List[int]): A list of integers.
Returns:
int: The sum of al... |
python_sharegpt_23k | 18,113 | Write a Python function to count the number of occurrences of a given character in a string. The function should be optimized for performance and should handle edge cases such as an empty string or a character that does not appear in the string. The code should start with:
```python
def count_occurrences(string: str, c... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_occurrences(string: str, char: str) -> int:
"""
Counts the number of occurrences of a given character in a string.
Args:
string (str): The string in which to count the occurrences.
char (str): The ... |
python_sharegpt_23k | 18,125 | Write a Python function to print a message "Hello World" a specified number of times, with the nth iteration appending the number n to the message. Additionally, the function should print a table with two columns: one for the iteration number and the other for the corresponding message.
The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_hello_world_with_table(n: int):
"""
Prints "Hello World" n times, with the nth iteration appending the number n to the message.
Additionally, prints a table with two columns: one for the iteration number and the ot... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.