source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 13,757 | Write a Python function to calculate the cube of a given number. The function should be implemented using a lambda function and should return the cube of the input number. The code should start with:
```python
def cube(x: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def cube(x: int) -> int:
"""
Calculate the cube of a given number using a lambda function.
Args:
x (int): The number to be cubed.
Returns:
int: The cube of the input number.
"""
# Define the lam... |
code_exercise_27k | 13,758 | Write a Python function to check if a number is even. The function should be implemented using a lambda function and should return `True` if the number is even and `False` otherwise. The function should be named `is_even`.
The code should start with:
```python
is_even = lambda num: ...
```
| Here is the Python code to solve the given problem in the markdown block:
```python
is_even = lambda num: num % 2 == 0
"""
This lambda function takes a number 'num' as input and returns True if the number is even, and False otherwise.
Parameters:
- num: The number to be checked for evenness.
Returns:
- T... |
code_exercise_27k | 13,761 | Write a Python function to check if a given string starts with a vowel. The function should be implemented as a lambda function and should return `True` if the string starts with a vowel (either uppercase or lowercase), and `False` otherwise. The function should handle edge cases such as empty strings and strings with ... | Here is the Python code to solve the given problem in the markdown block:
```python
check_starts_with_vowel = lambda s: True if s and s[0].lower() in ['a', 'e', 'i', 'o', 'u'] else False
"""
This lambda function checks if a given string `s` starts with a vowel or not.
Parameters:
s (str): The input string to check.
... |
code_exercise_27k | 13,764 | Write a Python function to calculate the length of each string in a list of strings and return a list of these lengths. The function should handle an empty list by returning an empty list. The code should start with:
```python
from typing import List
def string_lengths(strings: List[str]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def string_lengths(strings: List[str]) -> List[int]:
"""
Calculate the length of each string in a list of strings and return a list of these lengths.
Args:
strings (List[str]): A list of s... |
code_exercise_27k | 13,766 | Write a Python function to calculate the product of two numbers using a lambda function. The function should be able to handle both integer and floating-point inputs. The code should start with:
```python
from typing import Union
def multiply_numbers(x: Union[int, float], y: Union[int, float]) -> Union[int, float]:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union
def multiply_numbers(x: Union[int, float], y: Union[int, float]) -> Union[int, float]:
"""
Calculate the product of two numbers using a lambda function.
Args:
x (Union[int, float]): The fir... |
code_exercise_27k | 13,770 | Write a Python function to concatenate multiple strings provided as a list of strings. The function should take a list of strings as input and return a single concatenated string. The code should start with:
```python
from typing import List
def concatenate_strings(strings: List[str]) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def concatenate_strings(strings: List[str]) -> str:
"""
Concatenates all strings in the given list into a single string.
Args:
strings (List[str]): A list of strings to be concatenated.
... |
code_exercise_27k | 13,771 | Write a Python function that takes a string as input and returns an iterator that generates one lowercase letter at a time from the given string. The function should use the `iter` and `next` methods to achieve this. The code should start with:
```python
def lowercase_iterator(string: str) -> iter:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def lowercase_iterator(string: str) -> iter:
"""
This function takes a string as input and returns an iterator
that generates one lowercase letter at a time from the given string.
Args:
string (str): The input s... |
code_exercise_27k | 13,772 | Write a Python function to find the largest number from a given list of integers. The function should be implemented using a lambda function and should return the largest number in the list. The code should start with:
```python
from typing import List
largest_number = lambda lst: ...
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
# Define the lambda function to find the largest number in a list
largest_number = lambda lst: max(lst)
"""
A lambda function that returns the largest number from a given list.
Parameters:
- lst: A list of num... |
code_exercise_27k | 13,774 | Write a Python function to calculate the average of a list of numbers. The function should handle empty lists by returning `None` instead of raising an error. The code 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.
Args:
numbers (List[int]): A list of integers.
Returns:
... |
code_exercise_27k | 13,783 | Write a Python function that performs a division operation between two numbers and raises a `ValueError` if the divisor is zero. Additionally, handle the `ValueError` gracefully by printing an error message. The function should also raise a `TypeError` if either of the arguments is not a number. The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_divide(a, b):
"""
Safely divide two numbers and return the result.
Args:
a (float or int): The dividend.
b (float or int): The divisor.
Returns:
float or int: The division result.
... |
code_exercise_27k | 13,790 | Write a Python function that safely divides a given dividend by a divisor, handling the case where the divisor is a string by raising a custom exception. The function should also handle the case where the divisor is zero by raising a `ZeroDivisionError`. The code should start with:
```python
def safe_divide(dividend, d... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_divide(dividend, divisor):
"""
Safely divides the dividend by the divisor, handling specific exceptions.
Args:
dividend (int or float): The numeric value to be divided.
divisor (int or float): The n... |
code_exercise_27k | 13,791 | Write a Python function to sum all the even numbers in a given list. The function should be implemented using a lambda function and should return the sum of all even numbers in the list. The code should start with:
```python
from typing import List
sum_even = lambda lst: ...
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
sum_even = lambda lst: sum(num for num in lst if num % 2 == 0)
"""
A lambda function to sum all the even numbers in a list.
Parameters:
- lst (list): A list of numbers.
Returns:
- int: The sum of all the ev... |
code_exercise_27k | 13,793 | Write a Python function to check if a list contains a specific element. The function should be implemented using a lambda function and should return a boolean value indicating whether the element is present in the list.
The code should start with:
```python
from typing import List, Any
contains_element = lambda lst: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
contains_element = lambda lst: lambda element: element in lst
"""
Check if a list contains a specific element.
Parameters:
- lst (list): The list to check.
- element: The specific element to check for in ... |
code_exercise_27k | 13,795 | Write a Python function to convert a list of strings to uppercase. The function should take a list of strings as input and return a new list where each string is converted to uppercase. The function should be implemented using a list comprehension for efficiency.
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 convert_to_uppercase(lst: List[str]) -> List[str]:
"""
Converts a list of strings to uppercase.
Args:
lst (List[str]): The list of strings to convert.
Returns:
List[str]: A ... |
code_exercise_27k | 13,797 | Write a Python function to find the minimum value from a given list of integers. The function should be implemented using a lambda function and should handle an empty list by returning `None`. The code should start with:
```python
from typing import List, Optional
find_min = lambda lst: ...
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Optional
find_min = lambda lst: min(lst) if lst else None
"""
A lambda function to find the minimum value from a list.
Parameters:
- lst (List[int]): The list from which to find the minimum value.
Returns:... |
code_exercise_27k | 13,811 | Write a Python function that processes a list of numbers and raises a `ValueError` if any of the numbers in the list are negative. The function should handle the exception and return a list of processed results for the positive numbers. The processed result for each positive number is twice its value.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def process_positive_numbers(numbers: List[int]) -> List[int]:
"""
Process a list of numbers, raising a ValueError if any number is negative.
For each positive number, return its processed result whi... |
code_exercise_27k | 13,824 | Write a Python function that iterates over a given string and returns one character at a time in reverse order using the `iter` and `next` methods. The function should handle empty strings by returning `None` immediately. The code should start with:
```python
def reverse_string_iterator(string: str):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string_iterator(string: str):
"""
Returns an iterator that yields one character at a time in reverse order from the given string.
Parameters:
string (str): The string to iterate over.
Yields:
char (... |
code_exercise_27k | 13,825 | Write a Python function to check if a given number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding the number itself). The function should return `True` if the number is perfect and `False` otherwise.
The code should start with:
```python
def is_pe... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_perfect_number(num: int) -> bool:
"""
Check if a given number is a perfect number.
Args:
num (int): The number to be checked for perfection.
Returns:
bool: True if the number is perfect, False ot... |
code_exercise_27k | 13,833 | Write a Python function to count the occurrences of each element in a given list. The function should return a dictionary where the keys are the unique elements from the list and the values are the counts of how many times each element appears in the list.
The code should start with:
```python
from typing import List,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_occurrences(lst: List[int]) -> Dict[int, int]:
"""
Count the occurrences of each element in a given list.
Args:
lst (List[int]): The input list to count occurrences from.
... |
code_exercise_27k | 13,835 | Write a Python function to create a partial function that multiplies a given number by a specified factor. The partial function should be created using the `functools.partial` function. The code should start with:
```python
from functools import partial
def create_multiplier(factor: int) -> callable:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def create_multiplier(factor: int) -> callable:
"""
Creates a partial function that multiplies a given number by the specified factor.
Args:
factor (int): The factor to multiply by.
... |
code_exercise_27k | 13,839 | Write a Python function to validate an RGB color value and handle any potential ValueError. The function should accept a tuple of three integers representing the RGB values (r, g, b). Each value must be within the range of 0 to 255. If any value is outside this range, the function should raise a ValueError with a descr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def validate_and_handle_rgb_color(rgb: Tuple[int, int, int]) -> str:
"""
Validate the given RGB color value and handle any potential ValueError.
Args:
rgb (Tuple[int, int, int]): A tuple of... |
code_exercise_27k | 13,840 | Write a Python function to create a partial function that multiplies a number by a given factor. The partial function should be able to handle both integers and floating-point numbers. If the input is not numeric, it should raise a `TypeError`.
The code should start with:
```python
from functools import partial
from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
from typing import Union
def multiply(factor: Union[int, float], x: Union[int, float]) -> Union[int, float]:
"""Multiplies a number by a given factor.
Args:
factor: The factor to multi... |
code_exercise_27k | 13,842 | Write a Python function to create a partial function that raises a number to the power of a given exponent. The partial function should be able to be called with a base number to compute the result.
The code should start with:
```python
import functools
def create_power_function(exponent: int):
"""
Create a p... | Here is the Python code to solve the given problem in the markdown block:
```python
import functools
def create_power_function(exponent: int):
"""
Create a partial function that raises a number to the given exponent.
Args:
exponent (int): The exponent to which the number will be raised.
Retur... |
code_exercise_27k | 13,846 | Write a Python function to create a partial function that subtracts a given number from 10. The partial function should be created using the `functools.partial` function. The code should start with:
```python
from functools import partial
def create_subtract_from_10_partial(x: float) -> partial:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def create_subtract_from_10_partial(x: float) -> partial:
"""
Create a partial function that subtracts a given number from 10.
Args:
x (float): The number to be subtracted from 10.
... |
code_exercise_27k | 13,852 | Write a Python function to create a partial function that concatenates a given prefix string to any input string. The partial function should be created using the `functools.partial` function. The code should start with:
```python
from functools import partial
def create_prefix_concatenator(prefix: str) -> callable:
`... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from functools import partial
def concatenate_with_prefix(prefix: str, input_str: str) -> str:
"""
Concatenates a prefix string with an input string.
Args:
prefix (str): The prefix string to be concatenated.
... |
code_exercise_27k | 13,855 | Write a Python function to create a partial function that swaps the positions of two numbers in a tuple. The partial function should be pre-set with specific indices for swapping. The code should start with:
```python
from functools import partial
def create_partial_swap(tup: tuple, index1: int, index2: int) -> partia... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
from typing import Tuple, Callable
def swap_numbers(tup: Tuple[int, ...], index1: int, index2: int) -> Tuple[int, ...]:
"""
Function to swap the positions of two numbers in a tuple.
Parameters... |
code_exercise_27k | 13,878 | Write a Python function to create a partial function that calculates the sum of two numbers, where one of the numbers is fixed. The partial function should be able to handle both integer and floating-point numbers. The code should start with:
```python
from functools import partial
def create_partial_sum(fixed_value: ... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from functools import partial
def create_partial_sum(fixed_value: int | float) -> callable:
"""
Create a partial function that calculates the sum of two numbers,
where one of the numbers is fixed to the given fixed_value.... |
code_exercise_27k | 13,883 | Write a Python function to create a partial function that finds the maximum element in a list, and then use this partial function to find the maximum element in a given list. The partial function should be created using the `functools.partial` function. The code should start with:
```python
from functools import partia... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
from typing import List, Union
def get_max_element(lst: List[Union[int, float]]) -> Union[int, float]:
"""
Return the maximum element in the given list.
Parameters:
lst (list): The inp... |
code_exercise_27k | 13,885 | Write a Python function to create a partial function that converts a list of integers to a string, with an optional separator that defaults to an empty string. The partial function should be created using the `functools.partial` function. The code should start with:
```python
from functools import partial
from typing i... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
from typing import List
def convert_to_string(int_list: List[int], separator: str = '') -> str:
"""
Convert a list of integers to a string with an optional separator.
Args:
int_list (L... |
code_exercise_27k | 13,889 | Write a Python function to create a partial function that checks if a string is a valid email address. The partial function should be created using the `functools.partial` function. The original function `is_valid_email` should use a regular expression to validate the email address. The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from functools import partial
def is_valid_email(email: str) -> bool:
"""
Check if a given string is a valid email address.
Args:
email (str): The string to be checked.
Returns:
bool: True if... |
code_exercise_27k | 13,895 | Write a Python function to find the length of a string without using the built-in `len()` function. The function should be able to handle any iterable (e.g., strings, lists, tuples) and return the count of elements in the iterable. The function should raise a `TypeError` if the input is not an iterable.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Iterable
def count_elements(iterable: Iterable) -> int:
"""
Counts the number of elements in an iterable without using the built-in len() function.
Args:
iterable (Iterable): The iterable to coun... |
code_exercise_27k | 13,905 | Write a Python function to create a partial function that reverses a string and applies it to a given list of strings. The partial function should be created using the `functools.partial` method. The function should return a list of reversed strings.
The code should start with:
```python
from typing import List
from f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from functools import partial
def reverse_string(s: str) -> str:
"""
Reverse the given string.
Args:
s (str): The string to be reversed.
Returns:
str: The reversed string.
"... |
code_exercise_27k | 13,908 | Write a Python function to remove duplicates from a given list while preserving the order of the elements. The function should use a partial function to achieve this. The code should start with:
```python
from typing import List
from functools import partial
def remove_duplicates_preserve_order(lst: List[int]) -> List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from functools import partial
def remove_duplicates_preserve_order(lst: List[int]) -> List[int]:
"""
Removes duplicates from a list while preserving the order of the elements.
Args:
lst (Lis... |
code_exercise_27k | 13,914 | Write a Python function to create a partial function that sorts a list of strings in alphabetical order, but with the option to reverse the order. The partial function should accept a boolean parameter `reverse` to determine the sorting order. The code should start with:
```python
from functools import partial
from typ... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
from typing import List
def sort_strings(strings: List[str], reverse: bool = False) -> List[str]:
"""
Sorts a list of strings in alphabetical order.
Args:
strings (list): The list of s... |
code_exercise_27k | 13,930 | Write a Python function to create a partial function that checks if a number is divisible by a given divisor. The partial function should be created using `functools.partial`. The original function should check if a number is divisible by a specified divisor. The code should start with:
```python
import functools
from ... | Here is the Python code to solve the given problem in the markdown block:
```python
import functools
from typing import Callable
def is_divisible(n: int, divisor: int) -> bool:
"""
Check whether a given number is divisible by a specified divisor.
Args:
n: The number to be checked.
divisor:... |
code_exercise_27k | 13,942 | Write a Python function to create a partial function that calculates the area of a triangle given the lengths of its sides. The partial function should be pre-configured with fixed side lengths. The code should start with:
```python
from functools import partial
from math import sqrt
def calculate_area(a: float, b: fl... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
from math import sqrt
def calculate_area(a: float, b: float, c: float) -> float:
"""
Calculate the area of a triangle given the lengths of its sides.
Parameters:
a (float): Length of side ... |
code_exercise_27k | 13,945 | Create a Python function that uses the `partial` function from the `functools` module to generate a specialized function for checking if a given string is a valid date in the format `dd-mm-yyyy`. The function should be able to handle leap years and invalid dates such as February 30th or April 31st.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def is_valid_date(date_str: str) -> bool:
"""
Check if the given string is a valid date in the format dd-mm-yyyy.
Args:
date_str (str): The string to be checked.
Returns:
... |
code_exercise_27k | 13,948 | Write a Python function to create a partial function that removes the nth element from a given list. The partial function should be created using the `functools.partial` function. The original function should handle the removal of the nth element and raise an `IndexError` if the index is out of range. The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from functools import partial
def remove_nth_element(n: int, lst: List[int]) -> List[int]:
"""
Remove the nth element from the given list.
Args:
n (int): The index of the element to be remov... |
code_exercise_27k | 13,952 | Write a Python function to create a partial function that converts a string to uppercase, but allows for an optional prefix to be added before the conversion. The partial function should be created using `functools.partial`. The original function should handle the conversion to uppercase and the addition of the prefix.... | Here is the Python code to solve the given problem in the markdown block:
```python
import functools
def convert_with_prefix(text: str, prefix: str = '') -> str:
"""
Converts the given string to uppercase and optionally adds a prefix.
Args:
text (str): The string to be converted.
prefix (s... |
code_exercise_27k | 13,962 | Write a Python function to remove punctuation marks from a given string using a partial function. The partial function should be created using the `functools.partial` module. The function should be able to handle various punctuation marks and return the modified string.
The code should start with:
```python
from typin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Callable
from functools import partial
import string
def remove_punctuation(text: str) -> str:
"""
Function to remove punctuation marks from a given string.
Parameters:
text (str): The string fro... |
code_exercise_27k | 13,964 | Create a Python function to check if a number is a perfect cube using a partial function. The partial function should be created using the `functools.partial` module. The function should be able to handle both positive and negative integers. The code should start with:
```python
from functools import partial
def is_pe... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def is_perfect_cube(n: int) -> bool:
"""
Check if a number is a perfect cube.
Args:
n (int): The number to be checked.
Returns:
bool: True if the number is a perfect cube,... |
code_exercise_27k | 13,966 | Write a Python function to create a partial function that calculates the Greatest Common Divisor (GCD) of two numbers, with the second argument fixed to a specified value. The partial function should be able to accept the first argument and compute the GCD accordingly.
The code should start with:
```python
from functo... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def gcd(a: int, b: int) -> int:
"""
Calculate the Greatest Common Divisor (GCD) of two numbers.
This function uses the Euclidean algorithm to calculate the GCD.
The Euclidean algorithm rep... |
code_exercise_27k | 13,969 | Write a Python function to create a partial function that removes leading and trailing whitespaces from a string. The partial function should be created using the `functools.partial` function. The original function `remove_whitespace` should be defined to remove the whitespaces from a given string. The partial function... | Here is the Python code to solve the given problem in the markdown block:
```python
import functools
def remove_whitespace(s: str) -> str:
"""
Remove leading and trailing whitespaces from a string.
Args:
s (str): The input string to be processed.
Returns:
str: The input string... |
code_exercise_27k | 13,972 | Write a Python function to check if a given number is an Armstrong number. An Armstrong number is a number that is equal to the sum of its own digits each raised to the power of the number of digits. For example, 153 is an Armstrong number because: 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_armstrong_number(n: int) -> bool:
"""
Check if a given number is an Armstrong number.
Parameters:
n (int): The number to be checked.
Returns:
bool: True if the number is an Armstrong number, False otherw... |
code_exercise_27k | 13,974 | Write a Python function to reverse a given string without using the built-in `reversed` function or any explicit loop structures. The function should return the reversed string. The code should start with:
```python
def reverse_string(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(input_string: str) -> str:
"""
Reverses the characters in a string without using the built-in reversed function and a loop structure.
Args:
input_string (str): The string to be reversed.
Retu... |
code_exercise_27k | 13,976 | Write a Python function to count the number of words in a given string using a partial function. The partial function should be created using the `functools.partial` module. The function should handle different types of strings, including strings with multiple spaces, empty strings, and strings with punctuation. The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def count_words(string: str) -> int:
"""
Count the number of words in a given string.
Args:
string (str): The input string.
Returns:
int: The number of words in the string... |
code_exercise_27k | 13,987 | Write a Python function to create a partial function that calculates the area of a circle given the radius. The partial function should be pre-configured with a fixed value for the radius. The code should start with:
```python
from functools import partial
import math
def create_partial_area_function(radius: float) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
import math
def create_partial_area_function(radius: float) -> partial:
"""
Creates a partial function that calculates the area of a circle with a fixed radius.
Args:
radius (float): T... |
code_exercise_27k | 13,990 | Write a Python function that safely divides two numbers and handles potential division by zero errors using a `try/finally` statement. The function should return the result of the division if successful, and `None` if a division by zero error occurs. Additionally, the function should print a message indicating that the... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_divide(a: float, b: float) -> float:
"""
Safely divides two numbers and handles potential division by zero errors.
Args:
a (float): The numerator.
b (float): The denominator.
Returns:
f... |
code_exercise_27k | 13,992 | Write a Python function to create a partial function that calculates a fixed percentage of a given number. The partial function should be created using the `functools.partial` function. The original function `calculate_percentage` should be used to calculate the percentage of a number. The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def calculate_percentage(number: float, percentage: float) -> float:
"""
Calculate the percentage of a given number.
Parameters:
number (float): The number to calculate the percentage of.
... |
code_exercise_27k | 13,998 | Write a Python function to find the Least Common Multiple (LCM) of two numbers using a partial function. The function should be able to handle any two positive integers and return their LCM. The code should start with:
```python
from functools import partial
def find_lcm(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def find_lcm(a: int, b: int) -> int:
"""
Returns the least common multiple (LCM) of two numbers.
Parameters:
a (int): First number.
b (int): Second number.
Returns:
int: The l... |
code_exercise_27k | 14,000 | Write a Python function to check if a given number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding the number itself). The function should be implemented using a partial function from the `functools` module to pre-configure the divisor sum calculati... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Callable
import functools
def is_perfect_number(num: int) -> bool:
"""
Check if a given number is a perfect number.
A perfect number is a positive integer that is equal to the sum of its proper divis... |
code_exercise_27k | 14,008 | Write a Python function to reverse the order of words in a given sentence using a partial function. The partial function should be created using the `functools.partial` module. The function should start with:
```python
from functools import partial
def reverse_sentence(sentence: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def reverse_sentence(sentence: str) -> str:
"""
Reverse the order of words in a given sentence.
Args:
sentence (str): The input sentence to reverse.
Returns:
str: The sent... |
code_exercise_27k | 14,010 | Write a Python function to create a partial function that converts a binary number to decimal. The partial function should be pre-configured to convert binary numbers to decimal without needing to pass the conversion function each time. The code should start with:
```python
import functools
def create_binary_to_decima... | Here is the Python code to solve the given problem in the markdown block:
```python
import functools
def binary_to_decimal(binary: str) -> int:
"""Converts a binary number to decimal.
Args:
binary (str): The binary number to be converted.
Returns:
int: The decimal equivalent of the binary... |
code_exercise_27k | 14,012 | Write a Python function to calculate the sum of all elements in a list. The function should handle lists containing integers or floats. The function should raise a `TypeError` if the input is not a list or if the list contains non-numeric values.
The code should start with:
```python
def calculate_sum(my_list):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_sum(my_list):
"""
Calculates the sum of all elements in a list.
Args:
my_list (list): A list of integers or floats.
Returns:
float or int: The sum of all elements in the list.
Raises:... |
code_exercise_27k | 14,016 | Write a Python function to check if a given number is a palindrome. Additionally, create a partial function using `functools.partial` that can be used to check if a number is a palindrome without needing to pass the function itself. The partial function should be named `check_palindrome`.
The code should start with:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def is_palindrome(number: int) -> bool:
"""
Check if a given number is a palindrome.
Args:
number (int): The number to be checked.
Returns:
bool: True if the number is a p... |
code_exercise_27k | 14,024 | Write a Python function to count the number of vowels in a given string. The function should be case-insensitive and should handle any non-string input by raising a `TypeError`. The code should start with:
```python
def count_vowels(string: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_vowels(string: str) -> int:
"""
Count the number of vowels in a given string.
Args:
string (str): The input string to count vowels from.
Returns:
int: The number of vowels found in the string.... |
code_exercise_27k | 14,029 | Write a Python function to reverse the order of a list using a while loop. The function should take a list as input and return the reversed list. The code should start with:
```python
from typing import List
def reverse_list_with_while_loop(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 reverse_list_with_while_loop(lst: List[int]) -> List[int]:
"""
Reverse the order of a list using a while loop.
Args:
lst (List[int]): The input list to be reversed.
Returns:
... |
code_exercise_27k | 14,034 | Write a Python function to remove duplicates from a given list using a set for efficiency. The function should return a new list containing only the unique elements from the original list, maintaining the order of their first appearance.
The code should start with:
```python
from typing import List
def remove_duplica... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_efficiently(nums: List[int]) -> List[int]:
"""
Removes duplicates from a list using a set for efficiency while maintaining the order of first appearance.
Args:
nums (Li... |
code_exercise_27k | 14,037 | Write a Python function to square each element of a given list and return a new list containing the squared elements. The function should handle lists of integers and floating-point numbers. The code should start with:
```python
from typing import List
def square_elements(input_list: List[float]) -> List[float]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def square_elements(input_list: List[float]) -> List[float]:
"""
Squares each element of the input list and returns a new list with the squared elements.
Args:
input_list (List[float]): Li... |
code_exercise_27k | 14,038 | Write a Python function to create a partial function that checks if a given string is a pangram. A pangram is a string that contains every letter of the alphabet at least once. The partial function should be pre-configured to check for pangrams in a specific language (e.g., English).
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Callable
import string
from functools import partial
def is_pangram(input_str: str, alphabet: set) -> bool:
"""
Check if a given string is a pangram based on the provided alphabet.
Args:
input_st... |
code_exercise_27k | 14,044 | Write a Python function to create a partial function that calculates the ASCII value of a character and then applies it to a list of characters to return a list of their corresponding ASCII values. The code should start with:
```python
from typing import List
from functools import partial
def ascii_values_of_character... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from functools import partial
def ascii_value(char: str) -> int:
"""
Returns the ASCII value of a character.
Parameters:
char (str): The character whose ASCII value needs to be calculated.
... |
code_exercise_27k | 14,045 | Write a Python function to count the number of occurrences of each character in a given string and return the results as a dictionary where the keys are the characters and the values are their respective counts. The function should handle any string input, including empty strings and strings with special characters.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_character_occurrences(string: str) -> Dict[str, int]:
"""
Count the number of occurrences of each character in a given string.
Args:
string (str): The string to be analyzed.
R... |
code_exercise_27k | 14,048 | Write a Python function to replace specific characters in a string with another character using a for loop. The function should handle multiple characters to be replaced and their corresponding replacements. The code should start with:
```python
def replace_multiple_chars(string: str, replacements: dict) -> str:
```
Wh... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_multiple_chars(string: str, replacements: dict) -> str:
"""
Replace multiple specific characters in a string with their corresponding replacements using a for loop.
Args:
string (str): The original strin... |
code_exercise_27k | 14,051 | Write a Python function to determine if a given number is a happy number using a partial function. A happy number is defined by the following process:
- Starting with any positive integer, replace the number by the sum of the squares of its digits.
- Repeat the process until the number equals 1 (where it will stay), or... | Here is the Python code to solve the given problem in the markdown block:
```python
import functools
def is_happy_number(n: int) -> bool:
"""
Check if a given number is a happy number using a partial function.
A happy number is defined by the following process:
- Starting with any positive integer, re... |
code_exercise_27k | 14,052 | Write a Python function to calculate the factorial of a given number using a recursive approach. The function should handle non-negative integers only. If the input is a negative integer, the function should return `None`.
The code should start with:
```python
def factorial_recursive(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def factorial_recursive(n: int) -> int:
"""
Calculate the factorial of a given number using a recursive approach.
Parameters:
n (int): The number for which the factorial needs to be calculated.
Returns:
int: Th... |
code_exercise_27k | 14,057 | Write a Python function to check if two lists have any common elements using a set for efficient comparison. The function should return `True` if there is at least one common element between the two lists, and `False` otherwise. The code should start with:
```python
from typing import List
def has_common_elements(list... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def has_common_elements(list1: List[int], list2: List[int]) -> bool:
"""
Check if two lists have any common elements using a set for efficient comparison.
Args:
list1 (List[int]): The first ... |
code_exercise_27k | 14,058 | Write a Python function that safely divides two numbers and handles potential division by zero errors using a `try/finally` statement. The function should return the quotient if the division is valid, and print a message indicating that the code has executed regardless of any errors. If the divisor is zero, an `Asserti... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_divide(a: float, b: float) -> float:
"""
Safely divides two numbers and returns the quotient. If the divisor is zero,
an AssertionError is raised, but the finally block ensures a message is printed.
Args:
... |
code_exercise_27k | 14,061 | Write a Python function to create a partial function that checks if a given string is an anagram of another predefined string. The partial function should be created using the `functools.partial` function. The original function `is_anagram` should be used to compare two strings and determine if they are anagrams. The p... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
from collections import Counter
def is_anagram(string1: str, string2: str) -> bool:
"""
Check if a given string is an anagram of another string.
Parameters:
string1 (str): The first string... |
code_exercise_27k | 14,062 | Write a Python function to remove all occurrences of a specific element from a given list using a list comprehension. The function should return the updated list with all occurrences of the specified element removed. The code should start with:
```python
from typing import List, Any
def remove_element_comprehension(my... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def remove_element_comprehension(my_list: List[Any], element: Any) -> List[Any]:
"""
Remove all occurrences of a specific element from a list using a list comprehension.
Args:
my_list (... |
code_exercise_27k | 14,064 | Write a Python function to filter out odd numbers from a given list and return a new list containing the squares of the remaining even numbers. The function should be efficient and should handle lists of varying sizes. The code should start with:
```python
from typing import List
def filter_and_square_even_numbers(num... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_and_square_even_numbers(numbers: List[int]) -> List[int]:
"""
Filters out odd numbers from the input list and returns a new list containing the squares of the remaining even numbers.
Args... |
code_exercise_27k | 14,066 | Write a Python function to calculate the number of trailing zeros in the factorial of a given number. The function should be efficient and should handle large numbers. The code should start with:
```python
def trailing_zeros_in_factorial(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def trailing_zeros_in_factorial(n: int) -> int:
"""
Calculate the number of trailing zeros in the factorial of a given number.
Args:
n (int): The input number.
Returns:
int: The number of trailing zeros... |
code_exercise_27k | 14,067 | Write a Python function to capitalize the first letter of each word in a given sentence using a list comprehension. The function should handle multiple spaces between words and leading/trailing spaces. The code should start with:
```python
def capitalize_sentence_with_list_comprehension(sentence: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def capitalize_sentence_with_list_comprehension(sentence: str) -> str:
"""
Capitalizes the first letter of each word in a sentence using a list comprehension.
Args:
sentence (str): The sentence to capitalize.
R... |
code_exercise_27k | 14,069 | Write a Python function to find the smallest and largest values in a given list of numbers using a for loop. The function should return a tuple containing the smallest and largest values. The code should start with:
```python
from typing import List, Tuple
def find_smallest_largest(numbers: List[int]) -> Tuple[int, in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_smallest_largest(numbers: List[int]) -> Tuple[int, int]:
"""
Finds the smallest and largest values in a list of numbers using a for loop.
Args:
numbers (List[int]): A list of... |
code_exercise_27k | 14,071 | Write a Python function to convert a given string into title case using a for loop. The function should capitalize the first letter of each word and convert the rest of the letters to lowercase. The code should start with:
```python
def convert_to_title_case(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_title_case(input_string: str) -> str:
"""
Convert a given string into title case using a for loop.
Parameters:
input_string (str): The input string to be converted into title case.
Returns:
str: ... |
code_exercise_27k | 14,073 | Write a Python function to sort a list of tuples based on the second element using a partial function. The partial function should be created using the `functools.partial` module. The code should start with:
```python
from typing import List, Tuple
from functools import partial
def sort_tuples_by_second(lst: List[Tupl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
from functools import partial
def sort_tuples_by_second(lst: List[Tuple[int, int]]) -> List[Tuple[int, int]]:
"""
Sorts a list of tuples based on the second element.
Args:
lst (li... |
code_exercise_27k | 14,075 | Write a Python function to multiply corresponding elements of two lists and store the result in a new list. The function should handle lists of equal length and raise a `ValueError` if the lengths of the input lists are not equal.
The code should start with:
```python
from typing import List
def multiply_lists(list1:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Multiplies corresponding elements of two lists and returns a new list.
Args:
list1 (List[int]): The first list of int... |
code_exercise_27k | 14,084 | Write a Python function to check if a given number is a T-prime number. A T-prime number is defined as the square of a prime number. The function should determine if the given number is the square of any prime number up to its square root. The code should start with:
```python
import math
def is_t_prime(n: int) -> boo... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def is_t_prime(n: int) -> bool:
"""
Check if the given number is a T-prime number.
A T-prime number is a square of a prime number. This function uses the Sieve of Eratosthenes
to find all prime numbers up t... |
code_exercise_27k | 14,093 | Write a Python function to create a partial function that calculates the XOR of a given binary number with a fixed binary number. The partial function should be created using the `functools.partial` function. The original function `binary_xor` should be used to perform the XOR operation between two binary numbers.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Callable
import functools
def binary_xor(a: str, b: str) -> str:
"""
Calculates the XOR of two binary numbers.
Parameters:
a (str): The first binary number.
b (str): The second binary number.
... |
code_exercise_27k | 14,096 | Write a Python function to check if a given number is a prime number using a for loop. 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... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(number: int) -> bool:
"""
Check if a given number is a prime number.
Args:
number (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise.
... |
code_exercise_27k | 14,100 | Write a Python function to count the occurrences of each element in a given list and return the result as a dictionary. The dictionary should have the elements as keys and their respective counts as values. The function should handle lists with any type of elements, including integers, strings, and other data types.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Any
def count_elements(list_to_count: List[Any]) -> Dict[Any, int]:
"""
Count the occurrences of each element in a given list and return the result as a dictionary.
Args:
list_to_coun... |
code_exercise_27k | 14,104 | Write a Python function to perform a binary search on a sorted list using a for loop instead of a while loop. The function should return the index of the target element if found, otherwise return -1. The code should start with:
```python
from typing import List, Any
def binary_search_for_loop(arr: List[Any], target: A... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
import math
def binary_search_for_loop(arr: List[Any], target: Any) -> int:
"""
Perform binary search on a sorted list using a for loop and return the index of the target element, if found.
Arg... |
code_exercise_27k | 14,105 | Write a Python function that uses a custom decorator to log the execution time of a function and ensure that the function's resources are properly cleaned up using a `try/finally` block. The function should be able to handle any exceptions raised during the execution of the function and log the exception details.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
import time
import functools
from typing import Any, Callable
def log_execution_time(function: Callable) -> Callable:
"""
A decorator that logs the execution time of a function and ensures proper resource cleanup.
Args:
... |
code_exercise_27k | 14,108 | Write a Python function to create a partial function that converts a decimal number to its binary representation, with a fixed base number. The partial function should be able to convert any given number to binary using the fixed base number as a reference.
The code should start with:
```python
from functools import p... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def decimal_to_binary(num: int) -> str:
"""Converts a decimal number to its binary representation.
Args:
num (int): The decimal number to convert.
Returns:
str: The binary rep... |
code_exercise_27k | 14,113 | Write a Python function to remove all special characters from a given string using a list comprehension. The function should be efficient and handle various edge cases, such as an empty string or a string with no special characters. The code should start with:
```python
def remove_special_characters(string: str) -> str... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_special_characters(string: str) -> str:
"""
Removes all special characters from a given string using a list comprehension.
Parameters:
string (str): The string from which special characters are to be removed.... |
code_exercise_27k | 14,114 | Write a Python function to check if a given string is a pangram without using string methods. A pangram is a sentence that contains every letter of the alphabet at least once. The function should be implemented using a partial function from the `functools` module. The code should start with:
```python
from functools im... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def is_pangram(alphabet: str, sentence: str) -> bool:
"""
Check if a given string is a pangram.
A pangram is a sentence that contains every letter of the alphabet at least once.
A... |
code_exercise_27k | 14,118 | Write a Python function to create a partial function that sorts a list of dictionaries based on a specific key. The partial function should be pre-configured to sort by a given key, so that it can be used directly on any list of dictionaries without needing to specify the key each time.
The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
from functools import partial
def sort_list_of_dicts_by_key(input_list: List[Dict], key: str) -> List[Dict]:
"""
Sorts a list of dictionaries based on the specified key.
Args:
input_li... |
code_exercise_27k | 14,129 | Write a Python function to create a partial function that calculates the number of days between a fixed start date and a variable end date. The function should be able to handle date strings in the format 'YYYY-MM-DD'.
The code should start with:
```python
from functools import partial
from datetime import datetime
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
from datetime import datetime
def days_between_dates(start_date: str, end_date: str) -> int:
"""
Calculate the number of days between two given dates.
Args:
start_date (str): A string ... |
code_exercise_27k | 14,130 | Write a Python function to merge two dictionaries such that if a key exists in both dictionaries, the value from the second dictionary should overwrite the value from the first dictionary. The function should handle cases where the input dictionaries may be empty or contain nested dictionaries. The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def merge_dictionaries(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Merge two dictionaries such that if a key exists in both dictionaries, the value from the second dictionar... |
code_exercise_27k | 14,140 | Write a Python function to calculate the sum of two integers and return the result. The function should handle both positive and negative integers, as well as zero. The code should start with:
```python
def calculate_sum(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_sum(a: int, b: int) -> int:
"""
Calculates the sum of two integers.
Parameters:
a (int): The first integer.
b (int): The second integer.
Returns:
int: The sum of the two integers.
"""
... |
code_exercise_27k | 14,142 | Write a Python function to find the maximum value in a given list of integers. The function should handle the case where the input list is empty by raising a `ValueError`. The code should start with:
```python
from typing import List
def find_max_value(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_max_value(numbers: List[int]) -> int:
"""
Finds and returns the maximum value in a given list of integers.
Args:
numbers (List[int]): A list of integers.
Returns:
int: ... |
code_exercise_27k | 14,144 | Write a Python function to count the number of words in a given string. The function should handle various edge cases such as empty strings, strings with multiple spaces, and strings with punctuation. The code should start with:
```python
def count_words(input_string: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def count_words(input_string: str) -> int:
"""
Counts the number of words in a given string.
This function handles various edge cases such as empty strings, strings with multiple spaces,
and strings with punctuation.
... |
code_exercise_27k | 14,153 | Write a Python function to determine if two given strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should ignore spaces and be case-insensitive.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(s1: str, s2: str) -> bool:
"""
Determine if two strings are anagrams of each other.
Parameters:
s1 (str): The first string to compare.
s2 (str): The second string to compare.
Returns:
bool:... |
code_exercise_27k | 14,156 | Write a Python function to filter out and return a new list containing only the odd numbers from a given list of integers. The function should handle an empty list and return an empty list in that case. The code should start with:
```python
from typing import List
def get_odd_numbers(numbers: List[int]) -> List[int]:
... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def get_odd_numbers(numbers: List[int]) -> List[int]:
"""
Returns a new list containing only the odd numbers from the original list.
Args:
numbers (List[int]): A list of integers.
Ret... |
code_exercise_27k | 14,157 | Write a Python function to check if a given binary number is divisible by a specified divisor. The function should be flexible enough to handle different divisors. The code should start with:
```python
from functools import partial
def check_binary_divisible_by(binary_number: str, divisor: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def check_binary_divisible_by(binary_number: str, divisor: int) -> bool:
"""
Check if a given binary number is divisible by a specified divisor.
Args:
binary_number (str): The binary n... |
code_exercise_27k | 14,159 | Write a Python function to reverse the order of words in a given sentence. The function should handle multiple spaces between words and leading/trailing spaces. The code should start with:
```python
def reverse_words_in_sentence(sentence: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_words_in_sentence(sentence: str) -> str:
"""
Reverse the order of words in a given sentence.
Args:
sentence (str): The sentence whose words are to be reversed.
Returns:
str: The sentence w... |
code_exercise_27k | 14,161 | Write a Python function to concatenate a list of strings into a single string with a specified delimiter. The function should allow the user to specify the delimiter, which can be any string. If no delimiter is provided, the function should use an empty string as the default delimiter.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def concatenate_strings_with_delimiter(string_list: List[str], delimiter: Optional[str] = None) -> str:
"""
Concatenates a list of strings into a single string with a specified delimiter.
... |
code_exercise_27k | 14,164 | Write a Python function to calculate the sum of all numbers greater than a given threshold in a list of integers. The function should take two parameters: a list of integers and an integer threshold. The function should return the sum of all numbers in the list that are greater than the threshold.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_numbers_greater_than_threshold(numbers: List[int], threshold: int) -> int:
"""
Calculate the sum of all numbers greater than a given threshold in a list of integers.
Args:
numbers (L... |
code_exercise_27k | 14,165 | Write a Python function to create a partial function that calculates the number of possible combinations given `n` and `r`, where `n` is fixed to a specific value. The partial function should be able to handle different values of `r` efficiently.
The code should start with:
```python
from typing import Callable
from f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Callable
from functools import partial
import math
def create_combinations_partial(n: int) -> Callable[[int], int]:
"""
Create a partial function that calculates the number of possible combinations given n an... |
code_exercise_27k | 14,166 | Write a Python function to count the number of vowels (both lowercase and uppercase) in a given string. The function should handle strings of any length, including empty strings. The code should start with:
```python
def count_vowels(string: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_vowels(string: str) -> int:
"""
Counts the number of vowels (a, e, i, o, u, A, E, I, O, U) in a given string.
Args:
string (str): The input string in which to count the vowels.
Returns:
int: T... |
code_exercise_27k | 14,168 | Write a Python function to check if a given string is an isogram using a partial function. An isogram is a word or phrase without a repeating letter. The function should be case-insensitive. The code should start with:
```python
from functools import partial
def is_isogram(word: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
def is_isogram(word: str) -> bool:
"""
Check if a given string is an isogram.
An isogram is a word or phrase without a repeating letter.
This function takes a string as input and retur... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.