source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 8,906 | Write a Python function to convert a given tuple into a dictionary where each element of the tuple becomes a key, and its corresponding index in the tuple becomes the value. The function should handle tuples of any length, including empty tuples. The code should start with:
```python
from typing import Tuple, Dict
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict
def tuple_to_dict(t: Tuple) -> Dict:
"""
Convert a tuple into a dictionary where each element of the tuple becomes a key,
and its corresponding index in the tuple becomes the value.
Args:... |
code_exercise_27k | 8,910 | Write a Python function to check if a given string is a valid IPv4 address. An IPv4 address consists of four decimal numbers separated by dots, where each number ranges from 0 to 255. The function should handle edge cases such as leading zeros, non-numeric characters, and incorrect number of parts.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_ipv4_address(ip_address: str) -> bool:
"""
Check if a given string is a valid IPv4 address.
An IPv4 address consists of four decimal numbers separated by dots, where each number ranges from 0 to 255.
Args:... |
code_exercise_27k | 8,915 | Write a Python function to determine if a given number is both a prime number and a palindrome. The function should return `True` if the number meets both criteria, and `False` otherwise. The code should start with:
```python
def is_prime_palindrome(n: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime_palindrome(n: int) -> bool:
"""
Determine if a given number is both a prime number and a palindrome.
Args:
n (int): The number to check.
Returns:
bool: True if the number is both prime and ... |
code_exercise_27k | 8,916 | Write a Python function to choose a random item from a list without replacement. The function should remove the chosen item from the list to ensure it is not selected again. The code should start with:
```python
from typing import List, Any
import random
def choose_random_item_without_replacement(items: List[Any]) -> ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
import random
def choose_random_item_without_replacement(items: List[Any]) -> Any:
"""
Choose a random item from a list without replacement.
This function selects a random item from the given l... |
code_exercise_27k | 8,918 | Write a Python function to check if two tuples have the same elements in the same order. The function should return `True` if the tuples are identical in terms of both elements and their order, and `False` otherwise. The code should start with:
```python
def check_tuples_same_order(tuple1: tuple, tuple2: tuple) -> bool... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_tuples_same_order(tuple1: tuple, tuple2: tuple) -> bool:
"""
Check if two tuples have the same elements in the same order.
Args:
tuple1 (tuple): The first tuple to compare.
tuple2 (tuple): The seco... |
code_exercise_27k | 8,929 | Implement a binary search algorithm to find a specific element in a sorted list. The function should return the index of the target element if it exists in the list, otherwise, it should return -1. The function should also validate that the input list is sorted in ascending order, and raise a `ValueError` if it is not.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(arr: List[int], target: int) -> int:
"""
Binary search algorithm to find a specific element in a sorted list.
Args:
arr (List[int]): The sorted list to search on.
t... |
code_exercise_27k | 8,934 | Write a Python function to sort a tuple of integers in descending order. The function should accept a tuple of integers as input and return a new tuple with the integers sorted in descending order. The original tuple should not be modified.
The code should start with:
```python
from typing import Tuple
def sort_tuple... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def sort_tuple_descending(tuple_of_integers: Tuple[int, ...]) -> Tuple[int, ...]:
"""
Sorts a tuple of integers in descending order and returns a new tuple.
Args:
tuple_of_integers (Tuple[i... |
code_exercise_27k | 8,935 | Write a Python function to simulate a sliding window over a list of integers. The function should return a list of deques, each representing a window of a specified size as it slides over the input list. The sliding window should start from the beginning of the list and move one element at a time to the right.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from collections import deque
def sliding_window(input_list: List[int], window_size: int) -> List[deque]:
"""
Simulates a sliding window over a list of integers and returns a list of deques,
each rep... |
code_exercise_27k | 8,937 | Write a Python function to find the intersection of two given lists, ensuring that the function handles duplicate elements correctly and returns the intersection in the order they appear in the first list. The function should be efficient and avoid using sets directly for the intersection operation.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_intersection_ordered(list1: List[int], list2: List[int]) -> List[int]:
"""
Finds the intersection of two given lists, preserving the order of elements as they appear in the first list.
Args... |
code_exercise_27k | 8,938 | Write a Python function to check if all elements of a given tuple are positive. The function should return `True` if all elements are positive, and `False` otherwise. The code should start with:
```python
def check_all_positive(my_tuple: tuple) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def check_all_positive(my_tuple: tuple) -> bool:
"""
Check if all elements of a given tuple are positive.
Args:
my_tuple (tuple): The input tuple to check.
Returns:
bool: True if all elements are positi... |
code_exercise_27k | 8,942 | Write a Python function to reverse the order of elements in a given tuple and return a new tuple with the elements in reverse order. The function should handle tuples of any length, including empty tuples. The code should start with:
```python
def reverse_tuple(input_tuple: tuple) -> tuple:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_tuple(input_tuple: tuple) -> tuple:
"""
Reverses the order of elements in a given tuple and returns a new tuple with the elements in reverse order.
Args:
input_tuple (tuple): The input tuple to be revers... |
code_exercise_27k | 8,947 | Write a Python function to calculate the factorial of a given non-negative integer using recursion. The function should raise a `ValueError` if the input number is negative.
The code should start with:
```python
def factorial(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int:
"""
Calculate the factorial of a given non-negative integer using recursion.
Parameters:
n (int): The non-negative integer for which the factorial needs to be calculated.
Returns:
... |
code_exercise_27k | 8,949 | Write a Python function to shuffle the elements of a given tuple and return a new tuple with the elements in a random order. The function should ensure that the original tuple remains unchanged. The code should start with:
```python
from typing import Tuple
import random
def shuffle_tuple(input_tuple: Tuple) -> Tuple:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
import random
def shuffle_tuple(input_tuple: Tuple) -> Tuple:
"""
Returns a new tuple with elements of the input tuple in a random order.
Parameters:
-----------
input_tuple : tuple
... |
code_exercise_27k | 8,953 | Write a Python function to check if all elements of a given tuple are negative. The function should return `True` if all elements are negative, and `False` otherwise. The code should start with:
```python
from typing import Tuple
def are_all_elements_negative(t: Tuple[int, ...]) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def are_all_elements_negative(t: Tuple[int, ...]) -> bool:
"""
Check if all elements of a given tuple are negative.
Args:
t (Tuple[int, ...]): The tuple of integers to be checked.
Retu... |
code_exercise_27k | 8,962 | Write a Python function to count the number of occurrences for each month in a given list of datetime objects. The function should return a dictionary where the keys are month names (e.g., 'January') and the values are the counts of occurrences for each month.
The code should start with:
```python
from datetime import... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
from typing import List, Dict
def count_month_occurrences(date_list: List[datetime]) -> Dict[str, int]:
"""
Counts the number of occurrences for each month in a given list of datetime objects.
... |
code_exercise_27k | 8,964 | Write a Python function to check if a given tuple is a subset of another tuple. The function should return `True` if all elements of the first tuple are present in the second tuple, and `False` otherwise. The function should handle tuples with duplicate elements and should be efficient.
The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_subset(test_tuple: tuple, main_tuple: tuple) -> bool:
"""
Check if a tuple is a subset of another tuple.
Args:
test_tuple (tuple): The tuple to be checked.
main_tuple (tuple): The main tuple to check ... |
code_exercise_27k | 8,965 | Write a Python function to calculate the median of a 2D array using the `numpy` module. The function should handle the following:
1. Verify that the input is a valid 2D array.
2. Verify that the input array is not empty.
3. Calculate and return the median of the 2D array.
The code should start with:
```python
import n... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def calculate_median(arr: np.ndarray) -> float:
"""
Calculate the median of a 2D array.
Parameters:
arr (numpy.ndarray): The 2D array for which the median needs to be calculated.
Returns:
... |
code_exercise_27k | 8,968 | Write a Python function to return a new tuple containing the last half of the elements from a given tuple. If the length of the tuple is odd, the middle element should be included in the last half. The function should handle tuples of any length, including empty tuples. The code should start with:
```python
def get_las... | Here is the Python code to solve the given problem in the markdown block:
```python
def get_last_half_tuple(input_tuple: tuple) -> tuple:
"""
Returns a new tuple containing the last half of the elements from the given tuple.
Args:
input_tuple (tuple): The tuple from which the last half of the eleme... |
code_exercise_27k | 8,970 | Write a Python function to count the number of occurrences for each hour of the day from a given list of datetime objects. The function should return a dictionary where the keys represent the hour of the day (in 24-hour format) and the values represent the count of occurrences for each hour.
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 datetime import datetime
from collections import defaultdict
def count_hour_occurrences(datetime_list: List[datetime]) -> Dict[int, int]:
"""
Count the number of occurrences for each hour of t... |
code_exercise_27k | 8,971 | Write a Python function to check if a tuple is a superset of another tuple. A tuple is considered a superset of another tuple if it contains all the elements of the other tuple. The function should return `True` if the first tuple is a superset of the second tuple, and `False` otherwise.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_superset(tuple1: tuple, tuple2: tuple) -> bool:
"""
Check if tuple1 is a superset of tuple2.
A tuple is considered a superset of another tuple if it contains all the elements of the other tuple.
Parameters:
... |
code_exercise_27k | 8,974 | Write a Python function to shuffle the elements of a given tuple randomly and return a new tuple with the elements shuffled. The function should handle tuples of any length, including empty tuples. The code should start with:
```python
from typing import Tuple
import random
def shuffle_tuple(input_tuple: Tuple) -> Tup... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
import random
def shuffle_tuple(input_tuple: Tuple) -> Tuple:
"""
Shuffles the elements of a tuple randomly and returns a new shuffled tuple.
Args:
input_tuple (Tuple): The input tuple to b... |
code_exercise_27k | 8,978 | Write a Python function to calculate the natural logarithm of a given number using the `math` module. The function should handle both positive and negative numbers, returning the natural logarithm for positive numbers and `None` for non-positive numbers. The code should start with:
```python
import math
def calculate_... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def calculate_natural_logarithm(number: float) -> float:
"""
Calculates the natural logarithm of a given number.
Args:
number (float): The number whose natural logarithm is to be calculated.
Return... |
code_exercise_27k | 8,979 | Write a Python function to convert a given `datetime` object to a string in the "ordinal" date format (e.g., 1st, 2nd, 3rd, ...). The function should handle the special cases for the suffixes "st", "nd", "rd", and "th" appropriately. The code should start with:
```python
import datetime
def convert_to_ordinal_date(dat... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def convert_to_ordinal_date(date: datetime.datetime) -> str:
"""
Convert a datetime object to the "ordinal" date format (e.g., 1st, 2nd, 3rd, ...).
Parameters:
date (datetime.datetime): The datetime obj... |
code_exercise_27k | 8,987 | Implement a Python function to sort a given list using the bubble sort algorithm. The function should be able to handle lists of integers and return the sorted list. The code should start with:
```python
from typing import List
def bubble_sort(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(arr: List[int]) -> List[int]:
"""
Sorts a given list using the bubble sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
List[int... |
code_exercise_27k | 8,988 | Write a Python function to calculate the sum of squares of a given tuple of integers. The function should accept a tuple of integers and return the sum of their squares. The code should start with:
```python
from typing import Tuple
def sum_of_squares(nums: Tuple[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def sum_of_squares(nums: Tuple[int]) -> int:
"""
Calculate the sum of squares of a given tuple of integers.
Args:
nums (Tuple[int]): A tuple containing integers.
Returns:
int: ... |
code_exercise_27k | 8,990 | Write a Python function to calculate the number of days between two given dates, ensuring that the function handles cases where the start date is later than the end date by returning a negative number of days. The function should also handle cases where the dates are the same by returning 0. The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def days_between_dates(start_date: datetime.date, end_date: datetime.date) -> int:
"""
Calculate the number of days between two dates.
Args:
start_date (datetime.date): The first date.
end_d... |
code_exercise_27k | 8,991 | Implement a merge sort algorithm to sort a given list of integers. The function should be able to handle lists of any size, including empty lists and lists with duplicate elements. The code should start with:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the Merge Sort algorithm.
Args:
arr (List[int]): The unsorted list of integers.
Returns:
List[int... |
code_exercise_27k | 8,992 | Write a Python function to merge two dictionaries into a single dictionary, where each key-value pair is represented as a tuple. If a key exists in both dictionaries, the value from the second dictionary should overwrite the value from the first dictionary. The function should return a list of these tuple key-value pai... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def merge_dicts(dict1: Dict[str, int], dict2: Dict[str, int]) -> List[Tuple[str, int]]:
"""
Merge two dictionaries into a single dictionary where each key-value pair is represented as a tupl... |
code_exercise_27k | 8,993 | Write a Python function to group the elements of a given tuple by their parity (odd and even). The function should return a new tuple containing two sub-tuples: one for odd numbers and one for even numbers. The code should start with:
```python
from typing import Tuple
def group_by_parity(numbers: Tuple[int]) -> Tuple... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def group_by_parity(numbers: Tuple[int]) -> Tuple[Tuple[int], Tuple[int]]:
"""
Groups the elements of the given tuple by their parity (odd and even).
Args:
numbers (Tuple[int]): The input t... |
code_exercise_27k | 8,995 | Implement a Python function to sort a given list using the quicksort algorithm. The function should be able to handle lists of integers and return the sorted list. The code should start with:
```python
from typing import List
def quicksort(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def quicksort(arr: List[int]) -> List[int]:
"""
Sorts a given list of integers using the quicksort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
Returns:
... |
code_exercise_27k | 9,001 | Write a Python function to multiply all elements in a given tuple by a specified factor and return a new tuple with the multiplied elements. The function should handle tuples containing integers, floats, or a mix of both. The code should start with:
```python
from typing import Tuple, Union
def multiply_tuple_elements... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Union
def multiply_tuple_elements(tuple_data: Tuple[Union[int, float]], factor: Union[int, float]) -> Tuple[Union[int, float]]:
"""
Multiplies all elements in the input tuple by the given factor and re... |
code_exercise_27k | 9,002 | Write a Python function to add a specified number of days to a given date. The function should handle both positive and negative day increments. The code should start with:
```python
import datetime
def add_days_to_date(date: datetime.datetime, days: int) -> datetime.datetime:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def add_days_to_date(date: datetime.datetime, days: int) -> datetime.datetime:
"""
Adds a specified number of days to a given date.
Args:
date (datetime.datetime): The date to which days need to be ... |
code_exercise_27k | 9,005 | Write a Python function to count the number of occurrences of each unique element in a given tuple. The function should return a dictionary where the keys are the unique elements in the tuple and the values are the counts of their occurrences. The code should start with:
```python
from typing import Dict, Tuple
def co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def count_occurrences(t: Tuple) -> Dict[any, int]:
"""
Counts the number of occurrences of each unique element in a tuple.
Args:
t (Tuple): The input tuple.
Returns:
Dict... |
code_exercise_27k | 9,008 | Write a Python function to create a new tuple where each element is the product of the corresponding element in the input tuple and its index. The function should handle tuples of any length, including empty tuples. The code should start with:
```python
from typing import Tuple
def multiply_elements_by_indices(t: Tupl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def multiply_elements_by_indices(t: Tuple[int]) -> Tuple[int]:
"""
Creates a new tuple where each element is the product of the corresponding element
in the input tuple and its index.
Args:
... |
code_exercise_27k | 9,009 | Write a Python function to generate a list of unique random numbers within a specified range. The function should ensure that the generated numbers are unique and within the given range. The function should also handle cases where the number of requested unique numbers exceeds the possible unique numbers within the ran... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
from typing import List
def generate_unique_random_numbers(num_numbers: int, min_value: int, max_value: int) -> List[int]:
"""
Generates a list of unique random numbers within a specified range.
Args:
... |
code_exercise_27k | 9,013 | Write a Python function to find the difference between the largest and smallest elements in a tuple of numbers. The function should handle the following cases:
1. If the input is not a tuple, raise a `ValueError` with the message "Input should be a tuple."
2. If the input tuple is empty, raise a `ValueError` with the m... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_difference(numbers: tuple) -> int:
"""
Find the difference between the largest and smallest elements in a tuple of numbers.
Args:
numbers (tuple): A tuple of numbers.
Returns:
int: The differen... |
code_exercise_27k | 9,017 | Write a Python function to extract elements at odd indices from a given tuple and return a new tuple containing only those elements. The function should handle tuples of any length, including empty tuples. The code should start with:
```python
from typing import Tuple
def extract_odd_index_elements(input_tuple: Tuple)... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def extract_odd_index_elements(input_tuple: Tuple) -> Tuple:
"""
Extracts elements at odd indices from the given tuple and returns a new tuple containing only those elements.
Args:
input_tu... |
code_exercise_27k | 9,018 | Write a Python function to find the date that is N days from a specified date. The function should handle both positive and negative values of N, representing future and past dates respectively. The function should also handle edge cases such as adding zero days or providing a date that is already in the past.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def find_date_n_days_from(start_date: datetime.date, n: int) -> datetime.date:
"""
Calculate the date that is N days from a specified date.
Args:
start_date (datetime.date): The initial date.
... |
code_exercise_27k | 9,020 | Write a Python function to determine if a given number is a strong number. A strong number is defined as a number where the sum of the factorial of its digits equals the number itself. The function should take an integer as input and return a boolean indicating whether the number is a strong number.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_strong_number(num: int) -> bool:
"""
Determine if a given number is a strong number.
A strong number is a number where the sum of the factorial of its digits equals the number itself.
Args:
num (int): Th... |
code_exercise_27k | 9,021 | Write a Python function to check if a given tuple is a valid palindrome. A tuple is considered a valid palindrome if the elements are the same when read forwards and backwards. The function should return `True` if the tuple is a valid palindrome and `False` otherwise. The code should start with:
```python
from typing i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def is_valid_palindrome(tup: Tuple) -> bool:
"""
Check if a given tuple is a valid palindrome.
A tuple is considered a valid palindrome if the elements are the same when read forwards and backwards... |
code_exercise_27k | 9,022 | Write a Python function to calculate the number of weekdays (Monday to Friday) between two specified dates, inclusive of the start and end dates. The function should handle cases where the start date is later than the end date by swapping them. The code should start with:
```python
from datetime import date, timedelta
... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import date, timedelta
def count_weekdays(start_date: date, end_date: date) -> int:
"""
Calculates the number of weekdays (Monday to Friday) between two specified dates, inclusive.
Args:
start_date (d... |
code_exercise_27k | 9,023 | Write a Python function to determine if a given number is a Narcissistic number. A Narcissistic number (also known as a pluperfect number or 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. The function should take an integer as input and return... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_narcissistic(n: int) -> bool:
"""
Determine if a given number is a Narcissistic number.
A Narcissistic number is a number that is equal to the sum of its own digits,
each raised to the power of the number of digi... |
code_exercise_27k | 9,029 | Write a Python function to calculate the Greatest Common Divisor (GCD) of two given non-negative integers using the Euclidean algorithm. The function should handle the case where either of the input numbers is zero and should raise a `ValueError` if either of the input numbers is negative.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
def gcd(a: int, b: int) -> int:
"""
Calculate the Greatest Common Divisor (GCD) of two given non-negative integers.
Parameters:
a (int): First non-negative integer.
b (int): Second non-negative integer.
Returns... |
code_exercise_27k | 9,033 | Write a Python function to create a new tuple by alternately selecting elements from both ends of a given tuple. The function should start by picking an element from the beginning of the tuple, then an element from the end, and continue this pattern until all elements are selected. If the tuple has an odd number of ele... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def alternate_ends(input_tuple: Tuple) -> Tuple:
"""
Create a new tuple by alternately selecting elements from both ends of the given tuple.
Parameters:
input_tuple (Tuple): The input tuple fro... |
code_exercise_27k | 9,038 | Write a Python function to determine the number of leap years between two given years, inclusive. A leap year is defined as a year that is divisible by 4, except for years that are divisible by 100 but not by 400. The function should handle cases where the start year is greater than the end year by swapping them.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_leap_years(start_year: int, end_year: int) -> int:
"""
Calculates the number of leap years between two given years, inclusive.
Args:
start_year (int): The starting year.
end_year (int): The ending ... |
code_exercise_27k | 9,039 | Write a Python function to validate if a given string consists of exactly five lowercase vowels (a, e, i, o, u). The function should return `True` if the string matches the criteria, and `False` otherwise. The code should start with:
```python
import re
def is_five_vowels(input_string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_five_vowels(input_string: str) -> bool:
"""
Validate if the given string consists of exactly five lowercase vowels (a, e, i, o, u).
Args:
input_string (str): The string to be validated.
Return... |
code_exercise_27k | 9,040 | Write a Python function to repeat each element of a given list a specific number of times using the `itertools` module. The function should return a new list containing the repeated elements. The code should start with:
```python
from typing import List
import itertools
def repeat_elements(elements: List[any], times: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import itertools
def repeat_elements(elements: List[any], times: int) -> List[any]:
"""
Repeats each element of a given list a specific number of times using the itertools module.
Args:
elem... |
code_exercise_27k | 9,050 | Write a Python function to extract all time durations in the format `HH:MM:SS` from a given text document. The function should use regular expressions to identify and extract these time durations efficiently. The code should start with:
```python
import re
from typing import List
def extract_time_durations(text: str) ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def extract_time_durations(text: str) -> List[str]:
"""
Extracts all time durations in the format HH:MM:SS from a given text.
Args:
text (str): The input text to search for time du... |
code_exercise_27k | 9,053 | Write a Python function to validate if a given string consists of exactly five alphanumeric characters. The function should use a regular expression to perform the validation. The code should start with:
```python
import re
def is_valid_five_alphanumeric(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_five_alphanumeric(string: str) -> bool:
"""
Validate if a given string consists of exactly five alphanumeric characters.
Args:
string (str): The string to be validated.
Returns:
... |
code_exercise_27k | 9,061 | Write a Python function to check if a given string contains at least one word with more than two consecutive vowels. The function should use regular expressions to perform this check efficiently.
The code should start with:
```python
import re
def contains_consecutive_vowels(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_consecutive_vowels(s: str) -> bool:
"""
Check if a string contains at least one word with more than two consecutive vowels.
Args:
s (str): The input string to be checked.
Returns:
... |
code_exercise_27k | 9,065 | Write a Python function to extract all dates in the format `DD/MM/YYYY` from a given text document using regular expressions. The function should return a list of strings, where each string is a date in the specified format. The code should start with:
```python
import re
from typing import List
def extract_dates(text... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def extract_dates(text: str) -> List[str]:
"""
Extracts all dates in the format DD/MM/YYYY from a given text document.
Args:
text (str): The text document to search for dates.
... |
code_exercise_27k | 9,069 | Write a Python function to validate if a given string matches the pattern of exactly three digits followed by a hyphen and three uppercase letters. The function should return `True` if the string matches the pattern, and `False` otherwise. The code should start with:
```python
import re
def validate_string_pattern(str... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_string_pattern(string: str) -> bool:
"""
Validates if the given string matches the pattern of exactly three digits followed by a hyphen and three uppercase letters.
Args:
string (str): The st... |
code_exercise_27k | 9,078 | Write a Python function to add 'n' days to a given date. The function should take a date string in the format 'yyyy-mm-dd' and an integer 'n' representing the number of days to add. The function should return the resulting date in the same 'yyyy-mm-dd' format.
The code should start with:
```python
from datetime import... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime, timedelta
def add_days_to_date(date_str: str, n: int) -> str:
"""
Add 'n' days to a given date.
Args:
date_str (str): The initial date in the format 'yyyy-mm-dd'.
n (int): The... |
code_exercise_27k | 9,083 | Write a Python function to validate if a given string matches a specific pattern using regular expressions. The pattern should consist of exactly four letters (uppercase or lowercase), followed by exactly two digits, and ending with a special character (any character that is not a letter or digit).
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_string(string: str) -> bool:
"""
Validates if the given string matches the pattern:
- Exactly four letters (uppercase or lowercase)
- Followed by exactly two digits
- Ends with a special chara... |
code_exercise_27k | 9,089 | Write a Python function to convert a given number of seconds since the Unix epoch (January 1, 1970, 00:00:00 UTC) to a `datetime` object. The function should handle both positive and negative values of seconds. The code should start with:
```python
from datetime import datetime
def seconds_to_datetime(seconds: int) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def seconds_to_datetime(seconds: int) -> datetime:
"""
Convert a given number of seconds since the Unix epoch to a datetime object.
Args:
seconds (int): The number of seconds since the... |
code_exercise_27k | 9,092 | Write a Python function to find all the email addresses in a given string using regular expressions. The function should return a list of all valid email addresses found in the string. The code should start with:
```python
import re
from typing import List
def find_emails(string: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def find_emails(string: str) -> List[str]:
"""
Find all email addresses in a given string using regular expressions.
Args:
string (str): The string in which to find email addresses... |
code_exercise_27k | 9,093 | Write a Python function to calculate the time difference between two datetime objects in seconds. The function should handle datetime objects with different dates and times, and return the absolute value of the time difference in seconds. The code should start with:
```python
from datetime import datetime
def calculat... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def calculate_time_difference_in_seconds(start_time: datetime, end_time: datetime) -> int:
"""
Calculates the absolute time difference between two datetime objects in seconds.
Args:
st... |
code_exercise_27k | 9,101 | Write a Python function to find the nearest future date that is a Friday from a given date. The function should take a `datetime.date` object as input and return the nearest future `datetime.date` object that falls on a Friday.
The code should start with:
```python
import datetime
def get_nearest_future_friday(date: ... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def get_nearest_future_friday(date: datetime.date) -> datetime.date:
"""
Find the nearest future date that is a Friday from a given date.
Args:
date (datetime.date): The input date from which to fin... |
code_exercise_27k | 9,104 | Write a Python function to validate whether a given string matches the pattern of exactly two uppercase letters followed by two digits. The function should return `True` if the string matches the pattern, and `False` otherwise. The code should start with:
```python
import re
def validate_string(string: str) -> bool:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_string(string: str) -> bool:
"""
Validates whether a given string matches the pattern of exactly two uppercase letters followed by two digits.
Args:
string (str): The string to be validated.
... |
code_exercise_27k | 9,115 | Write a Python function to match a string that consists of exactly two lowercase vowels followed by two uppercase letters using regular expressions. The function should return `True` if the string matches the pattern and `False` otherwise. The code should start with:
```python
import re
def match_vowel_uppercase_patte... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_vowel_uppercase_pattern(string: str) -> bool:
"""
Match a string containing exactly two lowercase vowels followed by two uppercase letters.
Args:
string (str): The string to match the pattern ag... |
code_exercise_27k | 9,120 | Write a Python function to count the occurrences of each element in a given list using the `collections.Counter` class. The function should return a dictionary where the keys are the elements of the list and the values are their respective counts.
The code should start with:
```python
from collections import Counter
f... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import Counter
from typing import List, Dict
def count_elements(input_list: List[int]) -> Dict[int, int]:
"""
Count the occurrences of each element in a given list.
Args:
input_list (List[int]): Th... |
code_exercise_27k | 9,124 | Write a Python function to generate all possible combinations of a given list of elements. Each combination should be a tuple, and the function should return a list of all such tuples. The function should handle lists of varying lengths and ensure that all possible combinations are generated, including combinations of ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import itertools
def generate_all_combinations(input_list: List[int]) -> List[Tuple[int, ...]]:
"""
Generate all possible combinations of a given list of elements.
Args:
input_list (L... |
code_exercise_27k | 9,136 | Write a Python function to calculate the number of working days between two given dates, excluding weekends and a list of specified holidays. The function should handle both string and `datetime` object inputs for the dates. The code should start with:
```python
from typing import List, Union
from datetime import datet... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
from datetime import datetime, timedelta
def get_working_days_with_holidays(start_date: Union[str, datetime], end_date: Union[str, datetime], holidays: List[Union[str, datetime]]) -> int:
"""
Calc... |
code_exercise_27k | 9,139 | Write a Python function to validate if a given string matches a specific pattern: exactly three uppercase letters followed by two digits and a special character. The function should return `True` if the string matches the pattern, and `False` otherwise. The code should start with:
```python
import re
def validate_stri... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_string_pattern(string: str) -> bool:
"""
Validate if a given string matches the pattern: exactly three uppercase letters followed by two digits and a special character.
Args:
string (str): Th... |
code_exercise_27k | 9,146 | Write a Python function to find the date of the last Sunday that falls before a given date. The function should take a `datetime.date` object as input and return another `datetime.date` object representing the last Sunday before the given date. The code should start with:
```python
import datetime
def get_last_sunday(... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def get_last_sunday(date: datetime.date) -> datetime.date:
"""
Get the date of the last Sunday that falls before a given date.
Args:
date (datetime.date): The date to find the last Sunday before.
... |
code_exercise_27k | 9,149 | Write a Python function to find the first day of the next month from a given date. The function should take a `datetime.date` object as input and return a new `datetime.date` object representing the first day of the next month. The code should start with:
```python
import datetime
def get_first_day_of_next_month(date:... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def get_first_day_of_next_month(date: datetime.date) -> datetime.date:
"""
Calculate the first day of the next month from a given date.
Args:
date (datetime.date): The input date.
Returns:
... |
code_exercise_27k | 9,153 | Write a Python function to validate if a given string matches a specific pattern using regular expressions. The pattern should consist of exactly two lowercase vowels, followed by two uppercase letters, and end with a digit. The function should return `True` if the string matches the pattern, and `False` otherwise.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_string(string: str) -> bool:
"""
Validate if a given string matches the pattern: exactly two lowercase vowels, followed by two uppercase letters, and ends with a digit.
Args:
string (str): Th... |
code_exercise_27k | 9,183 | Write a Python function to find the sum of two numbers, ensuring that the function handles both integer and floating-point inputs. The function should be able to handle edge cases such as negative numbers, zero, and very large numbers. The code should start with:
```python
def find_sum(num1: int | float, num2: int | fl... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_sum(num1: int | float, num2: int | float) -> int | float:
"""
Calculate the sum of two numbers.
This function takes two numbers, which can be either integers or floating-point numbers,
and returns their sum. Th... |
code_exercise_27k | 9,187 | Write a Python function to calculate the sum of a list of numbers, ensuring that the input is a list and all elements in the list are 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
from typing import List,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def sum_of_list(numbers: List[Union[int, float]]) -> Union[int, float]:
"""
Calculates the sum of a list of numbers.
Args:
numbers (List[Union[int, float]]): A list of numbers.
R... |
code_exercise_27k | 9,202 | Write a Python function to find the sum of all prime numbers from 1 to a given integer `n`. The function should be efficient and should handle large values of `n` by using an optimized prime-checking algorithm.
The code should start with:
```python
def sum_of_primes(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(num: int) -> bool:
"""
Check if a number is prime.
Parameters:
num (int): The number to check.
Returns:
bool: True if the number is prime, False otherwise.
"""
if num < 2:
return Fa... |
code_exercise_27k | 9,212 | Write a Python function to calculate the sum of squares of the first n natural numbers. The function should handle input validation to ensure that n is a positive integer. The code should start with:
```python
def sum_of_squares(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_squares(n: int) -> int:
"""
Calculates the sum of squares of the first n natural numbers.
Args:
n (int): The number of natural numbers to consider.
Returns:
int: The sum of squares of the fir... |
code_exercise_27k | 9,217 | Write a Python function to calculate the sum of cubes of the first n natural numbers. The function should handle the case where n is less than 1 by raising a `ValueError`. The code should start with:
```python
def sum_of_cubes(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_cubes(n: int) -> int:
"""
Calculate the sum of the cubes of the first n natural numbers.
Args:
n (int): The number of natural numbers to consider.
Returns:
int: The sum of the cubes of the fi... |
code_exercise_27k | 9,218 | Write a Python function to validate if a given string matches a specific pattern using regular expressions. The pattern should consist of exactly two lowercase vowels, followed by two uppercase letters, and end with two digits. The function should return `True` if the string matches the pattern, and `False` otherwise.
... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_string(string: str) -> bool:
"""
Validates if the given string matches the pattern: exactly two lowercase vowels,
followed by two uppercase letters, and ends with two digits.
Args:
string... |
code_exercise_27k | 9,241 | Write a Python function to check if a given string contains only lowercase letters and no other characters. The function should return `True` if the string meets the criteria and `False` otherwise. The code should start with:
```python
import re
def is_lowercase_letters_only(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_lowercase_letters_only(string: str) -> bool:
"""
Check if the given string contains only lowercase letters and no other characters.
Args:
string (str): The input string to be checked.
Returns:... |
code_exercise_27k | 9,244 | Write a Python function to calculate the sum of all Fibonacci numbers less than a given integer `n`. The function should return the sum of all Fibonacci numbers that are less than `n` and are even. The code should start with:
```python
def sum_even_fibonacci_numbers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_even_fibonacci_numbers(n: int) -> int:
"""
Calculate the sum of all even Fibonacci numbers less than n.
Args:
n (int): The upper limit for the Fibonacci numbers.
Returns:
int: The sum of all eve... |
code_exercise_27k | 9,246 | Write a Python function to check if a given string contains at least one digit using regular expressions. The function should return `True` if the string contains at least one digit, and `False` otherwise. The code should start with:
```python
import re
def contains_digit(s: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_digit(s: str) -> bool:
"""
Check if a given string contains at least one digit using regular expressions.
Args:
s (str): The string to check for the presence of at least one digit.
Retur... |
code_exercise_27k | 9,247 | Write a Python function to check if a given string starts with a vowel (either uppercase or lowercase) and ends with a digit (0-9). The function should use regular expressions to perform this check. The code should start with:
```python
import re
def starts_with_vowel_ends_with_digit(text: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
import re
def starts_with_vowel_ends_with_digit(text: str) -> bool:
"""
Checks if the given string starts with a vowel (either uppercase or lowercase) and ends with a digit (0-9).
Args:
text (str): The input text... |
code_exercise_27k | 9,252 | Write a Python function to determine if a given string ends with a specific suffix, which is provided as an argument. The function should use regular expressions to perform the matching. The code should start with:
```python
import re
def match_string_with_suffix(string: str, suffix: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_string_with_suffix(string: str, suffix: str) -> bool:
"""
Determine if a given string ends with a specific suffix using regular expressions.
Args:
string (str): The input string to be checked.
... |
code_exercise_27k | 9,256 | Write a Python function to determine if a given string contains a digit followed by a letter, using regular expressions. The function should return `True` if the string matches the pattern, and `False` otherwise. The code should start with:
```python
import re
def contains_digit_followed_by_letter(string: str) -> bool... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_digit_followed_by_letter(string: str) -> bool:
"""
Determine if a given string contains a digit followed by a letter.
Args:
string (str): The input string to be checked.
Returns:
... |
code_exercise_27k | 9,257 | Write a Python function to find the sum of all negative numbers in a given list. The function should handle both integer and floating-point numbers. The code should start with:
```python
from typing import List, Union
def sum_negative_numbers(numbers: List[Union[int, float]]) -> Union[int, float]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def sum_negative_numbers(numbers: List[Union[int, float]]) -> Union[int, float]:
"""
Calculates the sum of all negative numbers in a list.
Args:
numbers (List[Union[int, float]]): A l... |
code_exercise_27k | 9,259 | Write a Python function to calculate the sum of all elements in a given matrix. The matrix is represented as a 2D list of integers. The function should handle matrices of any size, including empty matrices. The code should start with:
```python
from typing import List
def sum_matrix_elements(matrix: List[List[int]]) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_matrix_elements(matrix: List[List[int]]) -> int:
"""
Calculate the sum of all elements in a given matrix.
Args:
matrix (List[List[int]]): A 2D list representing the matrix.
Retu... |
code_exercise_27k | 9,262 | Write a Python function to check if a given string contains the word "cat" as a whole word. The function should return `True` if the word "cat" is found as a whole word in the string, and `False` otherwise. The function should use regular expressions to ensure that "cat" is matched as a whole word and not as part of an... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_cat_word(string: str) -> bool:
"""
Check if the given string contains the word 'cat' as a whole word.
Args:
string (str): The input string to be checked.
Returns:
bool: True if t... |
code_exercise_27k | 9,272 | Write a Python function to determine if a given string contains a repeating sequence of at least two characters. The function should use regular expressions to identify such patterns. The code should start with:
```python
import re
def contains_repeating_sequence(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_repeating_sequence(string: str) -> bool:
"""
Determine if the given string contains a repeating sequence of at least two characters.
Args:
string (str): The input string to be checked for rep... |
code_exercise_27k | 9,273 | Write a Python function to calculate the sum of all elements in each row of a given matrix. The function should return a list where each element is the sum of the corresponding row in the matrix. The code should start with:
```python
from typing import List
def row_sums(matrix: List[List[int]]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def row_sums(matrix: List[List[int]]) -> List[int]:
"""
Calculates the sum of all elements in each row of a given matrix.
Args:
matrix (List[List[int]]): A 2-dimensional list representing th... |
code_exercise_27k | 9,277 | Write a Python function to calculate the sum of all elements in each column of a given matrix. The matrix is represented as a list of lists, where each inner list represents a row of the matrix. The function should return a list containing the sum of each column. The code should start with:
```python
from typing import... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_columns(matrix: List[List[int]]) -> List[int]:
"""
Calculates the sum of all elements in each column of a given matrix.
Args:
matrix (List[List[int]]): The input matrix represente... |
code_exercise_27k | 9,292 | Write a Python function to extract all valid email addresses from a given string. The function should use a regular expression to identify and return a list of email addresses found in the input string. The code should start with:
```python
import re
from typing import List
def extract_emails(text: str) -> List[str]:
... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def extract_emails(text: str) -> List[str]:
"""
Extracts all valid email addresses from a given string.
Args:
text (str): The input string containing potential email addresses.
... |
code_exercise_27k | 9,301 | Write a Python function to replace all occurrences of a specified substring with another substring in a given text. The function should handle case sensitivity and multiple occurrences of the substring. The code should start with:
```python
def replace_substring(text: str, old_substring: str, new_substring: str) -> str... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_substring(text: str, old_substring: str, new_substring: str) -> str:
"""
Replaces all occurrences of a specified substring with another substring in the given text.
Args:
text (str): The input text in wh... |
code_exercise_27k | 9,305 | Write a Python function to replace all consecutive spaces with a single space in a given string. The function should handle strings with multiple consecutive spaces, leading and trailing spaces, and spaces within the text. The code should start with:
```python
def replace_consecutive_spaces(string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def replace_consecutive_spaces(string: str) -> str:
"""
Replace all consecutive spaces with a single space in the given string.
Args:
string (str): The input string to process.
Returns:
str: A new str... |
code_exercise_27k | 9,307 | Write a Python function to find the sum of two 2D arrays (lists of lists). The function should handle arrays of any size, but the dimensions of the two arrays must be the same. If the dimensions are not the same, the function should raise a `ValueError`. The function should return a new 2D array that is the element-wis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_2d_arrays(arr1: List[List[int]], arr2: List[List[int]]) -> List[List[int]]:
"""
Find the sum of two 2D arrays (lists of lists).
Args:
arr1 (List[List[int]]): The first 2D array.
... |
code_exercise_27k | 9,315 | Write a Python function to compute the sum of two 3D arrays (lists of lists of lists). The function should ensure that the dimensions of the input arrays match before performing the sum. If the dimensions do not match, the function should raise a `ValueError`. The code should start with:
```python
from typing import Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_3d_arrays(arr1: List[List[List[int]]], arr2: List[List[List[int]]]) -> List[List[List[int]]]:
"""
Compute the sum of two 3D arrays.
Args:
arr1 (List[List[List[int]]]): First 3D array... |
code_exercise_27k | 9,329 | Write a Python function to determine if a given text contains any word that has at least one uppercase letter and one lowercase letter. The function should return `True` if such a word is found, otherwise `False`. The code should start with:
```python
import re
def contains_mixed_case_word(text: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_mixed_case_word(text: str) -> bool:
"""
Determines if the given text contains any word with at least one uppercase letter and one lowercase letter.
Args:
text (str): The text to be searched.
... |
code_exercise_27k | 9,330 | Write a Python function to find the sum of two decimal numbers. The function should handle input validation to ensure that both inputs are decimal numbers (float). If either input is not a float, the function should raise a `TypeError`. The function should return the sum of the two decimal numbers.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
def add_decimal_numbers(a: float, b: float) -> float:
"""
Function to find the sum of two decimal numbers.
Args:
a (float): The first decimal number.
b (float): The second decimal number.
Returns:
... |
code_exercise_27k | 9,356 | Write a Python function to calculate the sum of two binary numbers represented as strings. The function should handle binary numbers of different lengths by padding the shorter one with leading zeros. The function should return the sum as a binary string. The code should start with:
```python
def binary_addition(binary... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_addition(binary1: str, binary2: str) -> str:
"""
Calculate the sum of two binary numbers represented as strings.
Args:
binary1 (str): The first binary number.
binary2 (str): The second binary numb... |
code_exercise_27k | 9,360 | Write a Python function to validate if a given string is a valid email address using a regular expression. The function should return `True` if the email is valid and `False` otherwise. The regular expression should be designed to match the common rules for email addresses, including the presence of a local part, an `@... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_email(email: str) -> bool:
"""
Validates if a given string is a valid email address using a regular expression.
Args:
email (str): The email address to be validated.
Returns:
boo... |
code_exercise_27k | 9,368 | Write a Python function to determine if a given string matches a specific pattern using regular expressions. The pattern should match strings that start with "Hello", contain any number of characters in between, and end with "World". The function should return `True` if the string matches the pattern, and `False` other... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_hello_world_pattern(s: str) -> bool:
"""
Determine if a given string matches the pattern "Hello...World".
The pattern matches strings that start with "Hello", contain any number of
characters in bet... |
code_exercise_27k | 9,374 | Write a Python function to validate if a given string matches a specific pattern: it must start with a capital letter followed by any number of lowercase letters. The function should return `True` if the string matches the pattern, and `False` otherwise. The code should start with:
```python
import re
def validate_str... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_string_pattern(string: str) -> bool:
"""
Validate if a given string starts with a capital letter followed by any number of lowercase letters.
Args:
string (str): The input string to validate.... |
code_exercise_27k | 9,379 | Write a Python function to validate if a given string is a valid phone number in the format `XXX-XXX-XXXX`, where `X` is a digit. The function should use regular expressions to perform the validation. The code should start with:
```python
import re
def validate_phone_number(phone_number: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_phone_number(phone_number: str) -> bool:
"""
Validates whether a given string is a valid phone number in the format XXX-XXX-XXXX.
Args:
phone_number (str): The phone number to be validated.
... |
code_exercise_27k | 9,392 | Write a Python function to extract all the dates in the format "dd-mm-yyyy" from a given string. The function should use a regular expression to identify and extract the dates. The code should start with:
```python
import re
from typing import List
def extract_dates(string: str) -> List[str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def extract_dates(string: str) -> List[str]:
"""
Extracts all the dates in the format "dd-mm-yyyy" from a given string.
Args:
string (str): The input string from which to extract d... |
code_exercise_27k | 9,406 | Write a Python function to validate if a given string is a valid IPv4 address. An IPv4 address consists of four decimal numbers separated by dots, where each number ranges from 0 to 255. The function should use a regular expression to perform the validation.
The code should start with:
```python
import re
def is_vali... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_ipv4_address(ip_address: str) -> bool:
"""
Validate if a given string is a valid IPv4 address.
Args:
ip_address (str): The string to check.
Returns:
bool: True if the string is a... |
code_exercise_27k | 9,409 | Write a Python function to determine if a given string contains at least one uppercase letter and at least one lowercase letter using regular expressions. The function should return `True` if the string meets the criteria, and `False` otherwise. The code should start with:
```python
import re
def contains_upper_and_lo... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_upper_and_lower(string: str) -> bool:
"""
Determines if a given string contains at least one uppercase letter and at least one lowercase letter.
Args:
string (str): The string to be checked.
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.