source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 14,171 | Write a Python function to filter out prime numbers from a given list of integers. The function should return a new list containing only the prime numbers found in the input list. The function should handle edge cases such as an empty list or a list containing non-prime numbers.
The code should start with:
```python
f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_prime_numbers(numbers: List[int]) -> List[int]:
"""
Returns a new list containing only prime numbers from the input list.
Args:
numbers (List[int]): The input list containing integer... |
code_exercise_27k | 14,172 | Write a Python function to create a partial function that retrieves an element at a specific index in a list of nested lists. The function should be able to handle nested lists of arbitrary depth and should raise an `IndexError` if the provided indices are out of bounds.
The code should start with:
```python
from func... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
from typing import Any, List
def get_nested_element(nested_list: List[Any], indices: List[int]) -> Any:
"""
Get the element at a specific index in a list of nested lists.
Args:
nested_... |
code_exercise_27k | 14,176 | Write a Python function to find the longest string in a given list of strings. If there are multiple strings with the same maximum length, return the first one encountered. The function should raise a `ValueError` if the input list is empty.
The code should start with:
```python
from typing import List
def find_longe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_longest_string(strings: List[str]) -> str:
"""
Find and return the longest string from a given list of strings.
Args:
strings (List[str]): A list of strings to be evaluated.
Re... |
code_exercise_27k | 14,179 | Write a Python function to calculate the average value of a list of integers. The function should handle the following cases:
1. If the input is not a list, raise a `TypeError`.
2. If the input list is empty, raise a `ValueError`.
3. Otherwise, return the average value of the integers in the list as a float.
The code ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_average(numbers: List[int]) -> float:
"""
Calculates the average value of a list of integers.
Args:
numbers (List[int]): A list of integers.
Returns:
float: The av... |
code_exercise_27k | 14,181 | Write a Python function to create a partial function that calculates the area of an ellipse given the major axis and a fixed minor axis. The function should be able to handle cases where the major axis is negative or zero by raising a `ValueError`.
The code should start with:
```python
from functools import partial
im... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import partial
import math
def calculate_ellipse_area(a: float, b: float) -> float:
"""
Calculates the area of an ellipse given its major and minor axes.
Parameters:
a (float): Major axis of the ellipse.... |
code_exercise_27k | 14,182 | Write a Python function to convert a given string to uppercase, while also handling special cases such as strings containing non-alphabetic characters and empty strings. The function should return the converted string or an appropriate message if the input is invalid.
The code should start with:
```python
def convert_... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_uppercase(string: str) -> str:
"""
Convert a given string to uppercase.
This function takes a string as input and converts all alphabetic characters to uppercase.
If the input string is empty, it returns ... |
code_exercise_27k | 14,190 | 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 be efficient and handle various edge cases, such as an empty list or a list with no odd numbers. The code should start with:
```python
from typing import List
def get_odd_numbe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_odd_numbers(nums: List[int]) -> List[int]:
"""
Returns a new list containing only the odd numbers from the given list of integers.
Args:
nums (List[int]): A list of integers from whi... |
code_exercise_27k | 14,191 | Write a Python function to calculate the product of all numbers in a given list of integers. If the list is empty, the function should return 1. The function should handle both positive and negative integers, as well as zero. The code should start with:
```python
from typing import List
def calculate_product(nums: Lis... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def calculate_product(nums: List[int]) -> int:
"""
Calculate the product of all numbers in a given list of integers.
Args:
nums (List[int]): A list of integers.
Returns:
int: ... |
code_exercise_27k | 14,198 | Write a Python function to count the occurrences of each character in a given string and return the result as a dictionary. The function should handle both uppercase and lowercase characters as distinct and should not count spaces. The code should start with:
```python
def count_characters_no_spaces(string: str) -> dic... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_characters_no_spaces(string: str) -> dict:
"""
Count the occurrences of each character in a given string, ignoring spaces.
Parameters:
string (str): The input string to count characters for.
Returns:
... |
code_exercise_27k | 14,199 | Write a Python function to calculate the sum of all numbers in a given list. The function should handle lists containing integers and floating-point numbers. The function should raise a `TypeError` if the input is not a list or if any element in the list is not a number.
The code should start with:
```python
def calcu... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_sum(numbers: list) -> float:
"""
Calculates the sum of all numbers in the given list.
Args:
numbers (list): A list of numbers (integers or floating-point numbers).
Returns:
float: The sum ... |
code_exercise_27k | 14,201 | Write a Python function to remove all whitespace characters from a given string. The function should handle various types of whitespace characters, including spaces, tabs, and newlines. The code should start with:
```python
def remove_all_whitespace(string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def remove_all_whitespace(string: str) -> str:
"""
Removes all whitespace characters from a given string.
Parameters:
string (str): The input string from which all whitespace characters will be removed.
... |
code_exercise_27k | 14,204 | Write a Python function to filter out palindrome strings from a given list of strings. A palindrome is a string that reads the same backward as forward. The function should return a new list containing only the palindrome strings.
The code should start with:
```python
from typing import List
def filter_palindromes(st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_palindromes(strings: List[str]) -> List[str]:
"""
Filters out palindrome strings from a given list of strings.
Args:
strings (List[str]): A list of strings to be filtered.
Re... |
code_exercise_27k | 14,207 | Write a Python function to calculate the sum of the squares of the numbers in a given list. The function should return the sum of the squares of all the numbers in the list. The code should start with:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
"""
Calculate the sum of the squares of the numbers in the given list.
Args:
numbers (List[int]): A list of integers.
Returns:
int... |
code_exercise_27k | 14,208 | Write a Python function to replace all occurrences of a given substring with another substring in a string. The function should handle cases where the substring to be replaced is a part of a larger substring. The code should start with:
```python
def replace_substring(string: str, old_substring: str, new_substring: str... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_substring(string: str, old_substring: str, new_substring: str) -> str:
"""
Replace all occurrences of a given substring in a string with a new substring.
Args:
string (str): The original string.
... |
code_exercise_27k | 14,210 | Write a Python function to reverse a list of integers in place. The function should modify the original list and not return a new list. The code should start with:
```python
from typing import List
def reverse_list_in_place(nums: List[int]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def reverse_list_in_place(nums: List[int]) -> None:
"""
Reverses a list of integers in place.
Args:
nums (List[int]): The input list of integers to be reversed.
Returns:
None:... |
code_exercise_27k | 14,211 | Write a Python function to filter out prime numbers from a given list of integers. The function should return a new list containing only the prime numbers found in the input list. The code should start with:
```python
from typing import List
def filter_primes(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 filter_primes(numbers: List[int]) -> List[int]:
"""
Filters out prime numbers from a given list of integers.
Args:
numbers (List[int]): A list of integers to filter.
Returns:
... |
code_exercise_27k | 14,213 | Write a Python function to convert all strings in a given list to lowercase. The function should return a new list containing the lowercase versions of the original strings. The code should start with:
```python
from typing import List
def convert_to_lowercase(strings: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def convert_to_lowercase(strings: List[str]) -> List[str]:
"""
Convert all strings in a given list to lowercase.
Args:
strings (List[str]): A list of strings to be converted to lowercase.
... |
code_exercise_27k | 14,216 | Write a Python function to filter out positive numbers from a given list of numbers and return a new list containing only the positive numbers. The function should handle various edge cases, such as an empty list, a list with only negative numbers, and a list with mixed numbers. The code should start with:
```python
fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_positive_numbers(numbers: List[int]) -> List[int]:
"""
Filters out positive numbers from the given list and returns a new list.
Args:
numbers (List[int]): A list of integers.
Re... |
code_exercise_27k | 14,221 | Write a Python function to find and return the third largest number in a given list of integers. If the list contains fewer than three unique numbers, the function should raise a `ValueError`. The code should start with:
```python
from typing import List
def third_largest_number(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def third_largest_number(numbers: List[int]) -> int:
"""
Find and return the third largest number in a given list of integers.
Args:
numbers (List[int]): The list of integers.
Returns:
... |
code_exercise_27k | 14,222 | Write a Python function to filter a list of strings and return a new list containing only the strings that contain the letter 'a'. The function should be case-insensitive, meaning it should consider both 'a' and 'A' as valid matches. The code should start with:
```python
from typing import List
def filter_strings_with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_strings_with_a(strings: List[str]) -> List[str]:
"""
Filters a list of strings and returns a new list with only the strings that contain the letter 'a'.
Args:
strings (List[str]):... |
code_exercise_27k | 14,225 | Write a Python function to round each number in a given list to the nearest integer and return a new list with the rounded numbers. The function should handle both positive and negative numbers, and should not modify the original list.
The code should start with:
```python
from typing import List
def round_numbers(nu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def round_numbers(numbers: List[float]) -> List[int]:
"""
Rounds each number in the given list to the nearest integer and returns a new list with the rounded numbers.
Args:
numbers (List[flo... |
code_exercise_27k | 14,227 | Write a Python function to reverse each string in a given list of strings. The function should return a new list containing the reversed strings. The original list should remain unchanged. The code should start with:
```python
from typing import List
def reverse_strings(strings: List[str]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def reverse_strings(strings: List[str]) -> List[str]:
"""
Reverses each string in the given list of strings and returns a new list with the reversed strings.
Args:
strings (List[str]): A l... |
code_exercise_27k | 14,228 | Write a Python function to filter out numbers from a given list that are multiples of a specified divisor. The function should return a new list containing only the numbers that are multiples of the given divisor. The code should start with:
```python
from typing import List
def filter_multiples(numbers: List[int], di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_multiples(numbers: List[int], divisor: int) -> List[int]:
"""
Returns a new list with only the numbers that are multiples of the specified divisor.
Args:
numbers (List[int]): A li... |
code_exercise_27k | 14,230 | Write a Python function to calculate the median value of a given list of integers. The function should handle both even and odd lengths of the list and return the median as a float. The function should also raise a `ValueError` if the list is empty or contains non-integer values.
The code should start with:
```python
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_median(numbers: List[int]) -> float:
"""
Calculate the median value of a list of integers.
Parameters:
numbers (List[int]): A list of integers.
Returns:
float: The median ... |
code_exercise_27k | 14,233 | Write a Python function to sort a list of numbers in descending order using the merge sort algorithm. The function should return a new list with the numbers sorted in descending order. The merge sort algorithm should be implemented from scratch without using Python's built-in sorting functions.
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 merge_sort_desc(numbers: List[int]) -> List[int]:
"""
Sorts a list of numbers in descending order using the merge sort algorithm.
Args:
numbers (List[int]): A list of numbers to be sorte... |
code_exercise_27k | 14,234 | Write a Python function to validate a credit card number using the Luhn algorithm. The function should take a string as input and return a boolean indicating whether the credit card number is valid. The function should handle any non-digit characters in the input string and ensure the length of the cleaned number is be... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_credit_card_number(number: str) -> bool:
"""
Validates a credit card number using the Luhn algorithm.
Args:
number (str): The credit card number to be validated.
Returns:
bool: True if the ... |
code_exercise_27k | 14,238 | Write a Python function to validate if a given string is a valid IPv4 address. An IPv4 address consists of four decimal numbers, each ranging from 0 to 255, separated by dots (`.`). The function should return `True` if the input string is a valid IPv4 address and `False` otherwise.
The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_ipv4(ip_address: str) -> bool:
"""
Validates if the given string is a valid IPv4 address.
An IPv4 address consists of four decimal numbers, each ranging from 0 to 255,
separated by dots ('.').
Args:
... |
code_exercise_27k | 14,240 | Write a Python function to calculate the sum of the first 50 numbers in a given list of integers. If the list contains fewer than 50 numbers, the function should raise a `ValueError` with an appropriate message.
The code should start with:
```python
from typing import List
def sum_first_50_numbers(numbers: List[int])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_first_50_numbers(numbers: List[int]) -> int:
"""
Calculates the sum of the first 50 numbers in a given list of integers.
Args:
numbers (List[int]): A list of integers.
Returns:
... |
code_exercise_27k | 14,247 | Write a Python function to convert a list of integers into their corresponding Roman numerals. The function should handle integers from 1 to 3999. The code should start with:
```python
from typing import List
def convert_to_roman_numerals(nums: List[int]) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_to_roman_numerals(nums: List[int]) -> List[str]:
"""
Converts a list of integers to their corresponding Roman numerals.
Args:
nums (List[int]): The list of integers to be convert... |
code_exercise_27k | 14,251 | Write a Python function to validate if a given string is a valid IPv6 address. The function should adhere to the standard IPv6 format, which consists of 8 groups of 4 hexadecimal digits, separated by colons (:). Each group must contain only valid hexadecimal digits (0-9, a-f, or A-F), and leading zeros in a group can b... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_ipv6_address(address: str) -> bool:
"""
Check if the given string is a valid IPv6 address.
An IPv6 address is valid if it follows the standard IPv6 format:
- Consists of 8 groups of 4 hexadecimal digits, se... |
code_exercise_27k | 14,254 | Write a Python function to find the second largest prime number in a given list of integers. If there are fewer than two prime numbers in the list, raise a `ValueError`. The function should start with:
```python
from typing import List
def find_second_largest_prime(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_second_largest_prime(numbers: List[int]) -> int:
"""
Finds the second largest prime number in a list of integers.
Args:
numbers (List[int]): A list of integers to search for the sec... |
code_exercise_27k | 14,257 | Write a Python function to sort a list of numbers in ascending order, ignoring the sign of the numbers. The function should return a new list with the numbers sorted based on their absolute values. The code should start with:
```python
from typing import List
def sort_numbers_by_absolute_value(numbers: List[int]) -> L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_numbers_by_absolute_value(numbers: List[int]) -> List[int]:
"""
Sorts the numbers in ascending order based on their absolute values.
Args:
numbers (List[int]): A list of integers to... |
code_exercise_27k | 14,260 | Write a Python function to reverse each string in a given list of strings and return a new list with the reversed strings. The function should handle input validation to ensure that the input is a list. If the input is not a list, the function should raise a `TypeError`.
The code should start with:
```python
from typi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_strings(strings: List[str]) -> List[str]:
"""
Reverses each string in the given list and returns a new list with the reversed strings.
Args:
strings (List[str]): A list of string... |
code_exercise_27k | 14,265 | Write a Python function to convert a list of integers to their corresponding hexadecimal representations. The function should handle both positive and negative integers, and the hexadecimal values should be returned in a new list. The code should start with:
```python
from typing import List
def convert_to_hex(numbers... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def convert_to_hex(numbers: List[int]) -> List[str]:
"""
Converts a list of integers to their corresponding hexadecimal representations.
Args:
numbers (List[int]): A list of integers to be... |
code_exercise_27k | 14,266 | Write a Python function to calculate the sum of the squares of all the numbers in a given list of integers. The function should handle both positive and negative integers. The code should start with:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
"""
Calculate the sum of squares of all the numbers in a list.
Args:
numbers (List[int]): A list of integers.
Returns:
int: The su... |
code_exercise_27k | 14,268 | Write a Python function to encrypt a list of strings using a Caesar cipher. The Caesar cipher is a substitution cipher that shifts the letters of the alphabet by a certain number of positions. For example, if the shift is 1, the letter 'a' will be replaced by 'b', 'b' by 'c', and so on. The shift value can be positive ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def caesar_cipher(strings: List[str], shift: int) -> List[str]:
"""
Encrypts a list of strings using a Caesar cipher.
The Caesar cipher is a substitution cipher that shifts the letters of the al... |
code_exercise_27k | 14,272 | Write a Python function to count the occurrences of each unique character in a given string and return the result as a dictionary. The function should handle both uppercase and lowercase characters as distinct and should not count spaces. The code should start with:
```python
def count_unique_characters(string: str) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_unique_characters(string: str) -> dict:
"""
Count the occurrences of each unique character in a given string, ignoring spaces.
Args:
string (str): The input string to count unique characters in.
Retur... |
code_exercise_27k | 14,278 | Write a Python function to check if a given string represents a valid time in the format "HH:MM:SS". The function should ensure that the string is correctly formatted and that the hours, minutes, and seconds are within their respective valid ranges. The code should start with:
```python
def is_valid_time(time: str) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_time(time: str) -> bool:
"""
Check if a string represents a valid time in the format "HH:MM:SS".
Parameters:
time (str): A string representing a time in the format "HH:MM:SS".
Returns:
bool: True i... |
code_exercise_27k | 14,280 | Create a Python function that generates a closure to convert an input string to lowercase and prepend a prefix to it. The closure should be able to handle any input string and prefix provided during the closure creation. The function should start with:
```python
def create_string_modifier(prefix: str) -> callable:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def create_string_modifier(prefix: str) -> callable:
"""
Create a closure that converts an input string to lowercase and prepends a prefix to it.
Args:
prefix (str): The prefix to be added to the converted string.
... |
code_exercise_27k | 14,285 | Write a Python function to determine if a given string is a valid hex color code. A valid hex color code must start with a pound sign (`#`) and be followed by either 3 or 6 hexadecimal digits (0-9, a-f, A-F). The function should return `True` if the string is a valid hex color code and `False` otherwise.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_hex_color_code(color_code: str) -> bool:
"""
Determines if a given string is a valid hex color code.
A valid hex color code must start with a pound sign (#) and be followed by either
3 or 6 hexadecimal digi... |
code_exercise_27k | 14,304 | Write a Python function to calculate the sum of numbers at even indices in a given list of integers. The function should return 0 if the list is empty or contains less than two elements. The code should start with:
```python
from typing import List
def sum_even_indices(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_even_indices(numbers: List[int]) -> int:
"""
Calculates the sum of numbers at even indices in a given list.
Args:
numbers (List[int]): A list of integers.
Returns:
int: ... |
code_exercise_27k | 14,311 | Write a Python function to sort a list of strings based on the frequency of each character in the strings. The function should return a new list with the strings sorted in ascending order of character frequency. If two strings have the same character frequency, they should remain in the order they appeared in the origi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import Counter
def sort_by_char_frequency(strings: List[str]) -> List[str]:
"""
Sorts a list of strings based on the frequency of each character in the strings.
Args:
string... |
code_exercise_27k | 14,312 | Write a Python function to validate if a given string is a valid UUID (Universally Unique Identifier) according to the standard UUID format. The function should use regular expressions to check the format of the string.
The code should start with:
```python
import re
def is_valid_uuid(uuid: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_uuid(uuid: str) -> bool:
"""
Validates if a given string is a valid UUID (Universally Unique Identifier).
Args:
uuid (str): The string to check.
Returns:
bool: True if the string... |
code_exercise_27k | 14,315 | Write a Python function to find the number in a list of integers that is closest to the average value of the list. If there are multiple numbers with the same smallest difference to the average, return the smallest of those numbers.
The code should start with:
```python
from typing import List
def closest_to_average(... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def closest_to_average(lst: List[int]) -> int:
"""
Finds the number in the list that is closest to the average value of the list.
Args:
lst (List[int]): The list of integers.
Re... |
code_exercise_27k | 14,328 | Write a Python function to calculate the sum of the first and last numbers in a given list of integers. If the list is empty, raise a `ValueError` with a specific message. The function should start with:
```python
from typing import List
def sum_of_first_and_last(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_first_and_last(numbers: List[int]) -> int:
"""
Calculate the sum of the first and last numbers in a list.
Args:
numbers (List[int]): A list of integers.
Returns:
int:... |
code_exercise_27k | 14,329 | Write a Python function to validate a list of integers. The function should raise a `ValueError` with the message "Input list contains non-integer values" if any element in the list is not an integer. If all elements are integers, the function should return `True`.
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 validate_integer_list(lst: List[int]) -> bool:
"""
Validates that all elements in the input list are integers.
Args:
lst (List[int]): The list to be validated.
Raises:
Value... |
code_exercise_27k | 14,330 | Write a Python function to count the occurrences of each unique alphabetic character in a given string, ignoring case sensitivity. The function should return a dictionary where the keys are the unique alphabetic characters and the values are their corresponding counts.
The code should start with:
```python
def count_u... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_unique_characters(string: str) -> dict:
"""
Counts the occurrences of each unique alphabetic character in a given string, ignoring case sensitivity.
Args:
string (str): The input string for counting the oc... |
code_exercise_27k | 14,334 | Write a Python function that performs division of two numbers and raises a `TypeError` with the argument "Unsupported operand type" if either of the operands is not an integer. Additionally, the function should raise a `ZeroDivisionError` if the divisor is zero. The function should return the quotient of the division a... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_divide(a, b) -> float:
"""
Divides two integers and returns the result as a float.
Args:
a (int): The dividend.
b (int): The divisor.
Returns:
float: The quotient of the division.
... |
code_exercise_27k | 14,342 | Write a Python function to find the index of the first occurrence of the maximum value in a given list of integers. If the list is empty, the function should return `None`. The function should also handle type and value errors appropriately.
The code should start with:
```python
from typing import List, Optional
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_first_max_index(lst: List[int]) -> Optional[int]:
"""
Finds the index of the first occurrence of the maximum value in a given list of integers.
Args:
lst (List[int]): A li... |
code_exercise_27k | 14,344 | Write a Python function to count the occurrences of each unique alphanumeric character in a given string. The function should ignore any non-alphanumeric characters and return a dictionary where the keys are the unique alphanumeric characters and the values are their respective counts.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_alphanumeric_chars(string: str) -> dict:
"""
Count the occurrences of each unique alphanumeric character in a given string.
Args:
string (str): The input string to be analyzed.
Returns:
dict: ... |
code_exercise_27k | 14,347 | Write a Python function to find the string with the most distinct characters from a given list of strings. If there are multiple strings with the same number of distinct characters, return the first one encountered.
The code should start with:
```python
from typing import List
def find_string_with_most_distinct_chara... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_string_with_most_distinct_characters(strings: List[str]) -> str:
"""
Finds the string with the most distinct characters from a given list of strings.
Args:
strings (List[str]): A li... |
code_exercise_27k | 14,350 | Write a Python function to find the index of the first occurrence of the minimum value in a given list of integers. If the list is empty, raise a `ValueError`. The function should start with:
```python
from typing import List
def find_minimum_index(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_minimum_index(numbers: List[int]) -> int:
"""
Find the index of the first occurrence of the minimum value in a list of integers.
Args:
numbers (List[int]): A list of integers.
... |
code_exercise_27k | 14,356 | Write a Python function that performs division of two numbers and raises a `ZeroDivisionError` with the argument "Division by zero" if the denominator is zero. The function should return the result of the division if the denominator is non-zero. The code should start with:
```python
def safe_divide(numerator: float, de... | Here is the Python code to solve the given problem in the markdown block:
```python
def safe_divide(numerator: float, denominator: float) -> float:
"""
Safely divide two numbers, raising a ZeroDivisionError with the message "Division by zero" if the denominator is zero.
Args:
numerator (float): The... |
code_exercise_27k | 14,358 | Write a Python function to count the occurrences of each unique printable character in a given string. The function should return a dictionary where the keys are the unique printable characters and the values are their respective counts. The function should only consider characters that are printable, as determined by ... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_printable_chars(string: str) -> dict:
"""
Count the occurrences of each unique printable character in the given string.
Args:
string (str): The input string.
Returns:
dict: A dictionary with u... |
code_exercise_27k | 14,361 | Write a Python function to find the string with the most repeated characters in consecutive groups from a given list of strings. If multiple strings have the same maximum number of repeated characters, the function should return the first occurrence.
The code should start with:
```python
from typing import List
def m... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def most_repeated_string(strings: List[str]) -> str:
"""
Returns the string with the most repeated characters in consecutive groups from a list of strings.
Args:
strings (List[str]): A list ... |
code_exercise_27k | 14,369 | Write a Python function to calculate the difference between the maximum and minimum values in a given list of integers. If the list is empty, the function should raise a `ValueError`. The code should start with:
```python
from typing import List
def get_difference(nums: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_difference(nums: List[int]) -> int:
"""
Calculates the difference between the maximum and minimum values in a list of integers.
Args:
nums (List[int]): A list of integers.
Retur... |
code_exercise_27k | 14,371 | Write a Python function that creates a closure to calculate the exponentiation of a given base and exponent. The closure should take a base number and return an inner function that takes an exponent and returns the result of the base raised to that exponent. The code should start with:
```python
def create_exponentiati... | Here is the Python code to solve the given problem in the markdown block:
```python
def create_exponentiation_closure(base: int) -> callable:
"""
Creates a closure that calculates the exponentiation of a given base and exponent.
Args:
base (int): The base number for exponentiation.
Returns:
... |
code_exercise_27k | 14,382 | Write a Python function to determine if a given string is a valid HTML tag. An HTML tag is considered valid if it meets the following criteria:
1. The string starts with `<` and ends with `>`.
2. The string has at least 3 characters (including the `<` and `>`).
3. The second character is an alphabetic character (a-z, A... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_html_tag(tag: str) -> bool:
"""
Determines if a given string is a valid HTML tag.
Parameters:
tag (str): The input string to be checked.
Returns:
bool: True if the string is a valid HTML tag, False... |
code_exercise_27k | 14,383 | Write a Python function to sort a list of integers in descending order using the merge sort algorithm. The function should return a new list with the numbers sorted in descending order. The merge sort algorithm should be implemented from scratch without using Python's built-in `sorted` function or any other sorting fun... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort_descending(numbers: List[int]) -> List[int]:
"""
Sorts the given list of integers in descending order using the merge sort algorithm.
Args:
numbers (List[int]): A list of inte... |
code_exercise_27k | 14,394 | Write a Python function to check if a given string is a valid HTML attribute value. An HTML attribute value is considered valid if it meets the following criteria:
1. The value must be a non-empty string.
2. The value must not contain any of the following invalid characters: `<`, `>`, `&`, `"`, `'`.
3. The value must n... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_html_attribute_value(value: str) -> bool:
"""
Checks if a string is a valid HTML attribute value.
Parameters:
value (str): The string to be checked.
Returns:
bool: True if the string is a valid HTM... |
code_exercise_27k | 14,407 | Write a Python function to remove duplicates from a given list of integers while preserving the order of the first occurrence of each element. The function should return a new list with only unique numbers.
The code should start with:
```python
from typing import List
def remove_duplicates_preserve_order(input_list: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_preserve_order(input_list: List[int]) -> List[int]:
"""
Removes duplicate numbers from a list of integers while preserving the order of the first occurrence of each element.
Ar... |
code_exercise_27k | 14,410 | Write a Python function to count the occurrences of each unique word in a given string, considering only alphabetic characters and ignoring case sensitivity. The function should return a dictionary where the keys are the unique words (in lowercase) and the values are the corresponding counts of those words.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import re
from collections import defaultdict
def count_unique_words(string: str) -> Dict[str, int]:
"""
Count the occurrences of each unique word in a string, considering only alphabetic characters and ... |
code_exercise_27k | 14,426 | Write a Python function to filter out prime numbers from a given list of integers. The function should return a new list containing only the prime numbers from the input list. The code should start with:
```python
from typing import List
def filter_primes(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 filter_primes(numbers: List[int]) -> List[int]:
"""
Filters out prime numbers from a given list of integers.
Args:
numbers (List[int]): A list of integers from which to filter prime numb... |
code_exercise_27k | 14,443 | 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.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
int: The sum of the two integers.
""... |
code_exercise_27k | 14,448 | Write a Python function to count the number of words in a given string. The function should handle various edge cases, such as strings with multiple spaces, leading and trailing spaces, and empty strings. The code should start with:
```python
def count_words(string: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_words(string: str) -> int:
"""
Count the number of words in a given string.
This function handles strings with multiple spaces, leading and trailing spaces, and empty strings.
Args:
string (str): The ... |
code_exercise_27k | 14,449 | Write a Python function that performs division of two numbers and raises a `TypeError` if either of the inputs is not a number (i.e., not an `int` or `float`). The function should also raise a `ZeroDivisionError` if the divisor is zero. The function should start with:
```python
def safe_divide(a, b):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def safe_divide(a, b):
"""
Safely divides two numbers and raises appropriate errors if the inputs are invalid.
Args:
a (int or float): The dividend.
b (int or float): The divisor.
Returns:
float... |
code_exercise_27k | 14,451 | Write a Python function to calculate the sum of all the numbers in a given list of integers, but with a twist: the function should also handle a special case where if the list contains exactly one element, it should return the square of that element instead of the sum.
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 calculate_sum_with_special_case(numbers: List[int]) -> int:
"""
Calculate the sum of a list of integers, with a special case:
If the list contains exactly one element, return the square of that e... |
code_exercise_27k | 14,457 | Write a Python function to concatenate two strings with a specified delimiter. The function should take three parameters: the first string, the second string, and an optional delimiter. If the delimiter is not provided, it should default to a space. The function should return the concatenated string.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
def concatenate_with_delimiter(string1: str, string2: str, delimiter: str = " ") -> str:
"""
Concatenates two strings with a specified delimiter.
Parameters:
- string1 (str): The first string to be concatenated.
- s... |
code_exercise_27k | 14,459 | Write a Python function to determine if a given integer is a power of two. The function should return `True` if the integer is a power of two, and `False` otherwise. The code should start with:
```python
def is_power_of_two(n: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_power_of_two(n: int) -> bool:
"""
Determines if a given integer is a power of two.
Args:
n (int): The integer to be checked.
Returns:
bool: True if the integer is a power of two, False otherwise.... |
code_exercise_27k | 14,461 | Write a Python function to find the length of the longest string in a given list of strings. The function should efficiently determine the maximum length by iterating through the list once.
The code should start with:
```python
from typing import List
def longest_string_length(strings: List[str]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_string_length(strings: List[str]) -> int:
"""
Calculate the length of the longest string in a list of strings.
Args:
strings (List[str]): A list of strings.
Returns:
... |
code_exercise_27k | 14,463 | Write a Python function that raises a `ZeroDivisionError` with a custom error message when a division by zero is attempted. The function should take a single argument, which is the numerator, and attempt to divide it by zero. If a `ZeroDivisionError` is caught, the function should raise a new `ZeroDivisionError` with a... | Here is the Python code to solve the given problem in the markdown block:
```python
def custom_division_error(numerator: int) -> None:
"""
Attempts to divide the given numerator by zero and raises a custom ZeroDivisionError.
Args:
numerator (int): The numerator to be divided by zero.
Raises:
... |
code_exercise_27k | 14,470 | Write a Python function to count the number of key-value pairs in a given dictionary. The function should handle dictionaries with various types of keys and values. The code should start with:
```python
def count_key_value_pairs(dictionary: dict) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_key_value_pairs(dictionary: dict) -> int:
"""
Count the number of key-value pairs in a given dictionary.
Args:
dictionary (dict): The dictionary for which to count the key-value pairs.
Returns:
... |
code_exercise_27k | 14,480 | Write a Python function to count the number of vowels in a given string. The function should be case-insensitive, meaning both uppercase and lowercase vowels should be counted. 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 in a given string.
Args:
string (str): The input string in which to count the vowels.
Returns:
int: The number of vowels in the st... |
code_exercise_27k | 14,484 | Write a Python function to merge two sorted lists into a single sorted list. The function should efficiently merge the two lists in O(n + m) time complexity, where n and m are the lengths of the two lists. The function should handle cases where one or both lists are empty.
The code should start with:
```python
from ty... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Merges two sorted lists into a single sorted list.
Args:
list1 (List[int]): The first sorted list.
list2 ... |
code_exercise_27k | 14,487 | Write a Python function to calculate the square of a given number. The function should handle both integers and floating-point numbers. Additionally, the function should raise a `TypeError` if the input is not a number.
The code should start with:
```python
def square_number(num):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def square_number(num):
"""
Calculate the square of a given number.
Args:
num (int or float): The number to be squared.
Returns:
int or float: The square of the input number.
Raises:
TypeEr... |
code_exercise_27k | 14,489 | Write a Python function to calculate the lengths of strings in a given list and return a new list containing these lengths. The function should handle an empty list and strings of varying lengths efficiently.
The code should start with:
```python
from typing import List
def get_string_lengths(strings: List[str]) -> L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_string_lengths(strings: List[str]) -> List[int]:
"""
Returns a new list containing the lengths of the input strings.
Args:
strings (List[str]): A list of strings.
Returns:
... |
code_exercise_27k | 14,495 | Write a Python function to reverse a given string using a different approach than slicing. The function should use a loop to reverse the string. The code should start with:
```python
def reverse_string_loop(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_string_loop(input_string: str) -> str:
"""
Reverse the input string using a loop.
This function iterates over the input string from the end to the beginning,
appending each character to a new string, which... |
code_exercise_27k | 14,497 | Write a Python function to convert all strings in a given list to their uppercase versions and return a new list containing these uppercase strings. The function should handle an empty list by returning an empty list. The code should start with:
```python
from typing import List
def uppercase_strings(strings: List[str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def uppercase_strings(strings: List[str]) -> List[str]:
"""
Converts all the strings in a list to uppercase and returns a new list.
Args:
strings (List[str]): A list of strings to be convert... |
code_exercise_27k | 14,503 | Write a Python function to calculate the sum of the squared values of a given list of numbers. The function should return the sum of the squares of all elements in the list. The code should start with:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
"""
Calculate the sum of the squared values of a given list of numbers.
Args:
numbers (List[int]): A list of integers.
Returns:
... |
code_exercise_27k | 14,519 | Write a Python function to calculate the product of all the numbers in a given list of integers. If the list is empty, raise a `ValueError` with the message "List is empty". The function should start with:
```python
from typing import List
def calculate_product(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_product(numbers: List[int]) -> int:
"""
Calculates the product of all the numbers in a given list.
Args:
numbers (List[int]): A list of integers.
Returns:
int: The... |
code_exercise_27k | 14,521 | Write a Python function to merge two dictionaries. If there are common keys in both dictionaries, the values from the second dictionary should overwrite the values from the first dictionary. The function should handle any type of dictionary values, including nested dictionaries.
The code should start with:
```python
d... | Here is the Python code to solve the given problem in the markdown block:
```python
def merge_dicts(dict1: dict, dict2: dict) -> dict:
"""
Merge two dictionaries. If there are common keys, the values from dict2 will overwrite the values from dict1.
Args:
dict1 (dict): The first dictionary.
... |
code_exercise_27k | 14,522 | Write a Python function to determine if a given number is prime. The function should return `True` if the number is prime and `False` otherwise. The function should be efficient, especially for larger numbers, by leveraging mathematical properties of prime numbers.
The code should start with:
```python
def is_prime(nu... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(number: int) -> bool:
"""
Determine if a given number is prime.
Args:
number (int): The number to be checked for primality.
Returns:
bool: True if the number is prime, False otherwise.
... |
code_exercise_27k | 14,525 | Write a Python function that implements a closure. The closure should accept a function as an argument and return another closure. The returned closure should take a list as its argument and apply the specified function to each element of the list. The code should start with:
```python
from typing import Callable, List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Callable, List
def apply_function_to_list(func: Callable) -> Callable[[List], List]:
"""
Returns a closure that applies the specified function to each element of a given list.
Args:
func (Callabl... |
code_exercise_27k | 14,540 | Write a Python function to return a new list containing only the unique values from a given list of strings, while preserving the order of their first appearance. The function should handle an empty list gracefully and ensure that the returned list maintains the original order of unique elements.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_unique_values_in_order(string_list: List[str]) -> List[str]:
"""
Returns a new list with only the unique values from the given list of strings,
preserving the order of their first appearance.... |
code_exercise_27k | 14,544 | Write a Python function to determine if a given list of numbers is in strictly increasing order. The function should return `True` if the list is in strictly increasing order, and `False` otherwise. The function should handle lists of any length, including empty lists and lists with a single element.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_strictly_increasing(numbers: List[int]) -> bool:
"""
Determine if a list of numbers is in strictly increasing order.
Args:
numbers (List[int]): The list of numbers to be checked.
... |
code_exercise_27k | 14,551 | Write a Python function to find the maximum sum of any contiguous subarray (sublist) of a given list of integers. The function should efficiently handle cases with negative numbers and empty lists.
The code should start with:
```python
from typing import List
def max_subarray_sum(nums: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_subarray_sum(nums: List[int]) -> int:
"""
Finds the maximum sum of any contiguous subarray in a given list of integers.
Args:
nums (List[int]): A list of integers.
Returns:
... |
code_exercise_27k | 14,555 | Write a Python function to find the intersection of two sets, ensuring that the function handles cases where the input sets are not of type `set` by raising a `TypeError`. The function should return a new set containing the common elements between the two sets.
The code should start with:
```python
def set_intersectio... | Here is the Python code to solve the given problem in the markdown block:
```python
def set_intersection(set1, set2):
"""
Returns the intersection of two sets.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
set: A new set containing the common elements be... |
code_exercise_27k | 14,559 | Write a Python function to calculate the sum of an arbitrary number of integers. The function should accept a variable number of integer arguments and return their sum. The code should start with:
```python
from typing import List
def sum_integers(*args: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_integers(*args: int) -> int:
"""
Calculate the sum of an arbitrary number of integers.
Args:
*args (int): Variable number of integer arguments.
Returns:
int: The sum of ... |
code_exercise_27k | 14,564 | Create a Python function that uses a closure to count the occurrences of each word in a given string. The function should return a closure that, when called, returns a dictionary mapping each unique word to its count of occurrences.
The code should start with:
```python
def word_occurrences(string: str) -> callable:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
def word_occurrences(string: str) -> callable:
"""
A closure that returns the number of occurrences of each word in a given string.
Parameters:
- string (str): The input string to count word occurrences from.
Retur... |
code_exercise_27k | 14,568 | Write a Python function to calculate the average of a list of integers. The function should handle the following cases:
1. If the input is not a list, raise a `TypeError`.
2. If the input list is empty, raise a `ValueError`.
3. Otherwise, calculate and return the average of the integers in the list.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_average(numbers: List[int]) -> float:
"""
Calculates the average of a list of integers.
Args:
numbers (List[int]): A list of integers.
Returns:
float: The average ... |
code_exercise_27k | 14,577 | Write a Python function to check if a given string is a palindrome, considering only alphanumeric characters and ignoring case sensitivity. The function should return `True` if the string is a palindrome and `False` otherwise. The code should start with:
```python
def is_palindrome(text: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_palindrome(text: str) -> bool:
"""
Checks if a given string is a palindrome, considering only alphanumeric characters and ignoring case sensitivity.
Args:
text (str): The input string to check for ... |
code_exercise_27k | 14,583 | Write a Python function to multiply all the numbers in a given list and return the result. The function should handle edge cases such as an empty list or a list containing non-numeric values. The code should start with:
```python
from typing import List, Union
def multiply_list(numbers: List[Union[int, float]]) -> Uni... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def multiply_list(numbers: List[Union[int, float]]) -> Union[int, float]:
"""
Multiply all the numbers in a list and return the result.
Args:
numbers (List[Union[int, float]]): A list... |
code_exercise_27k | 14,586 | Write a Python function to sort a list of integers in ascending order using the merge sort algorithm. The merge sort algorithm is a divide-and-conquer algorithm that recursively divides the list into halves, sorts each half, and then merges the sorted halves back together. The code should start with:
```python
from typ... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def merge_sort(data: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order using the merge sort algorithm.
Args:
data (List[int]): A list of integers to be sorted.
... |
code_exercise_27k | 14,588 | Write a Python function to count the number of occurrences of a given element in a list. The function should be efficient and handle various types of elements, including integers, strings, and other data types. The code should start with:
```python
from typing import List, Any
def count_occurrences(lst: List[Any], ele... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def count_occurrences(lst: List[Any], element: Any) -> int:
"""
Counts the number of occurrences of a given element in a list.
Args:
lst (List[Any]): The list in which the occurrences a... |
code_exercise_27k | 14,592 | Write a Python function to check if a given number is a prime number. The function should return `True` if the number is prime and `False` otherwise. The function should handle edge cases such as negative numbers, 0, and 1, which are not prime numbers. The function should also be efficient by only checking for factors ... | 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.
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Args:
number (int): The... |
code_exercise_27k | 14,594 | Write a Python function that implements a closure to count the frequency of each character in a given string. The closure should return a function that, when called, returns a dictionary with the count of each character in the original string.
The code should start with:
```python
def char_frequency_counter(string: st... | Here is the Python code to solve the given problem in the markdown block:
```python
def char_frequency_counter(string: str) -> callable:
"""
A closure that counts the frequency of each character in a given string.
Args:
string (str): The input string to count the character frequency.
Returns:
... |
code_exercise_27k | 14,595 | Write a Python function to remove duplicates from a given list while preserving the order of elements. The function should return a new list containing only the unique elements from the original list in the order they first appear.
The code should start with:
```python
from typing import List
def remove_duplicates_pr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_preserve_order(lst: List[int]) -> List[int]:
"""
Removes duplicates from a list while preserving the order of elements.
Args:
lst (List[int]): The list from which dupli... |
code_exercise_27k | 14,615 | Write a Python function to determine if a given year is a leap year. The function should follow the rules for leap years:
1. A year is a leap year if it is divisible by 4.
2. However, if the year is also divisible by 100, it is not a leap year unless it is also divisible by 400.
The code should start with:
```python
d... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_leap_year(year: int) -> bool:
"""
Determine if a given year is a leap year.
Parameters:
year (int): The year to be checked.
Returns:
bool: True if the year is a leap year, False otherwise.
Leap year... |
code_exercise_27k | 14,634 | Write a Python function to count the number of vowels in a given string, considering both uppercase and lowercase vowels. The function should be case-insensitive and should return the total count of vowels in the string.
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 in a given string.
Args:
string (str): The input string in which to count the vowels.
Returns:
int: The total number of vowels in th... |
code_exercise_27k | 14,640 | 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, using all the original letters exactly once. The function should ignore case and non-alphabetic characters.
The code should start with:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(str1: str, str2: str) -> bool:
"""
Check if two strings are anagrams of each other.
An anagram is a word or phrase formed by rearranging the letters of a different word or phrase,
using all the original... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.