source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 9,413 | Write a Python function to extract all the hexadecimal numbers (starting with "0x") from a given string. The function should return a list of all such hexadecimal numbers found in the input string. The code should start with:
```python
from typing import List
import re
def extract_hex_numbers(text: str) -> List[str]:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def extract_hex_numbers(text: str) -> List[str]:
"""
Extracts all hexadecimal numbers starting with '0x' from a given string.
Args:
text (str): The input string to extract hexadeci... |
code_exercise_27k | 9,447 | Write a Python function to calculate the sum of all divisors of a given number. The function should take an integer as input and return the sum of all its divisors. The function should handle non-negative integers only.
The code should start with:
```python
def sum_of_divisors(number: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_divisors(number: int) -> int:
"""
Calculate the sum of all divisors of a given number.
Args:
number (int): The number for which to calculate the sum of divisors.
Returns:
int: The sum of all ... |
code_exercise_27k | 9,448 | Write a Python function to validate if a given string is a valid XML tag. An XML tag should start with an opening angle bracket `<`, followed by a valid tag name, and end with a closing angle bracket `>`. The tag name must start with a letter or an underscore, and can be followed by any combination of letters, digits, ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_xml_tag(tag: str) -> bool:
"""
Validates if a given string is a valid XML tag.
An XML tag should start with an opening angle bracket `<`, followed by a valid tag name,
and end with a closing angl... |
code_exercise_27k | 9,464 | Write a Python function to validate if a given string represents a valid time in the format "hh:mm:ss". The function should use regular expressions to ensure that the time string adheres to the 24-hour format, where "hh" ranges from 00 to 23, and "mm" and "ss" range from 00 to 59. The function should return `True` if t... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_time(time_string: str) -> bool:
"""
Validate if a given string represents a valid time in the format "hh:mm:ss".
Args:
time_string (str): The string to be validated.
Returns:
boo... |
code_exercise_27k | 9,490 | Write a Python function to replace all digits in a given string with the character "#". The function should iterate through each character in the string, check if it is a digit, and replace it with "#" if it is. If the character is not a digit, it should remain unchanged. The function should return the processed string... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_digits_with_hashtag(string: str) -> str:
"""
Replaces all digits in a given string with the character "#".
Args:
string (str): The input string to be processed.
Returns:
str: The processed s... |
code_exercise_27k | 9,502 | Write a Python function to remove extra spaces from a given string, ensuring that only single spaces separate words and that there are no leading or trailing spaces. The function should handle various edge cases, such as strings with multiple spaces between words, leading and trailing spaces, and strings with no spaces... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def clean_string(string: str) -> str:
"""
Removes extra spaces from a given string, ensuring that only single spaces separate words
and that there are no leading or trailing spaces.
Args:
string (str)... |
code_exercise_27k | 9,509 | Write a Python function to remove leading zeros from a given number represented as a string. The function should handle both positive and negative numbers, and should return the number with leading zeros removed. If the number consists entirely of zeros, the function should return '0'. The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def remove_leading_zeros(number: str) -> str:
"""
Remove leading zeros from a given number represented as a string.
Args:
number (str): The number from which leading zeros need to be removed.
Returns... |
code_exercise_27k | 9,514 | Write a Python function to remove consecutive duplicate characters from a given string. The function should return a new string where all consecutive duplicate characters are replaced with a single instance of that character. The code should start with:
```python
def remove_consecutive_duplicates(string: str) -> str:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_consecutive_duplicates(string: str) -> str:
"""
Remove consecutive duplicate characters from a given string.
Args:
string (str): The input string to remove consecutive duplicate characters from.
Retu... |
code_exercise_27k | 9,517 | Write a Python function to replace all occurrences of a specified character with another character in a given string, except when the character is within quotes. The function should handle single and double quotes.
The code should start with:
```python
def replace_char_except_quotes(string: str, char_to_replace: str, ... | Here is the Python code to solve the given problem in the markdown block:
```python
def replace_char_except_quotes(string: str, char_to_replace: str, replacement: str) -> str:
"""
Replaces all occurrences of a specified character with another character in a string, except within quotes.
Args:
strin... |
code_exercise_27k | 9,536 | Write a Python function to replace all occurrences of multiple consecutive whitespaces with a single space character in a given string using regular expressions. The function should handle various types of whitespace characters, including spaces, tabs, and newlines.
The code should start with:
```python
import re
def... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def replace_multiple_whitespaces(string: str) -> str:
"""
Replace all occurrences of multiple consecutive whitespaces with a single space character.
Args:
string (str): The input string in which to replac... |
code_exercise_27k | 9,549 | Write a Python function to replace all occurrences of a string followed by a number within parentheses with just the number. The function should use regular expressions to identify and replace the patterns. The code should start with:
```python
import re
def replace_string_with_number(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def replace_string_with_number(text: str) -> str:
"""
Replace all occurrences of a string followed by a number within parentheses with just the number.
Args:
text (str): The input text where replacements ... |
code_exercise_27k | 9,561 | Write a Python function to convert a hexadecimal string into the corresponding decimal number using regular expressions for validation. The function should raise a `ValueError` if the input string is not a valid hexadecimal number.
The code should start with:
```python
import re
def hex_to_decimal(hex_str: str) -> in... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def hex_to_decimal(hex_str: str) -> int:
"""
Converts a hexadecimal string to the corresponding decimal number.
Args:
hex_str (str): A string containing a hexadecimal number.
Returns:
int: Th... |
code_exercise_27k | 9,563 | Write a Python function to replace all occurrences of a specific word surrounded by whitespace with its uppercase version in a given text. The function should be case-insensitive and should only replace the word when it is surrounded by whitespace. The code should start with:
```python
def replace_word_with_uppercase(t... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def replace_word_with_uppercase(text: str, word: str) -> str:
"""
Replaces all occurrences of a specific word surrounded by whitespace with its uppercase version.
Args:
text (str): The text in which the r... |
code_exercise_27k | 9,573 | Write a Python function to replace all HTML `<img>` tags in a given HTML string with the path to the image specified in the `src` attribute. The function should use regular expressions to identify and replace the `<img>` tags. The code should start with:
```python
import re
def replace_img_tags_with_path(html: str) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def replace_img_tags_with_path(html: str) -> str:
"""
Replace all HTML img tags with the path to the image specified in the src attribute.
Args:
html (str): The HTML code to process.
Returns:
... |
code_exercise_27k | 9,578 | Write a Python function to replace all occurrences of a string surrounded by double braces (e.g., `{{hello}}`) with a random number between 1 and 1000. The function should handle multiple occurrences of the same placeholder and ensure that each replacement is unique within the same string.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
import random
from typing import Set
def replace_double_braces_with_random(string: str) -> str:
"""
Replaces all occurrences of a string surrounded by double braces with a unique random number between 1 and 1000.
... |
code_exercise_27k | 9,588 | Write a Python function to replace all occurrences of a string followed by a number within square brackets with just the number. The function should use regular expressions to identify and replace the patterns. The code should start with:
```python
import re
def replace_string_with_number(text: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def replace_string_with_number(text: str) -> str:
"""
Replaces all occurrences of a string followed by a number within square brackets with just the number.
Args:
text (str): The text to be processed.
... |
code_exercise_27k | 9,591 | Write a Python function to match both uppercase and lowercase characters in a given string using a regular expression pattern. The function should return a list of all matched characters. The code should start with:
```python
import re
from typing import List
def match_uppercase_lowercase(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 match_uppercase_lowercase(string: str) -> List[str]:
"""
Matches both uppercase and lowercase characters in a given string using a regular expression pattern.
Args:
string (str... |
code_exercise_27k | 9,594 | Write a Python function to match and return all uppercase characters in a given text using a regular expression. The function should return a list of all matched uppercase characters.
The code should start with:
```python
import re
from typing import List
def match_uppercase_chars(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 match_uppercase_chars(text: str) -> List[str]:
"""
Match and return all uppercase characters in the given text using a regular expression.
Args:
text (str): The text to be sear... |
code_exercise_27k | 9,598 | Write a Python function to check if a given string contains only lowercase characters using a regular expression. The function should return `True` if the string matches the pattern and `False` otherwise. The code should start with:
```python
import re
def is_lowercase_string(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_lowercase_string(string: str) -> bool:
"""
Checks if the given string contains only lowercase characters using a regular expression.
Args:
string (str): The input string to be checked.
Returns... |
code_exercise_27k | 9,617 | Write a Python function to match a specific character set using a regular expression pattern. The function should return a list of all matches found in the given string. The function should handle input validation to ensure that both the pattern and the string are of type `str`.
The code should start with:
```python
i... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def match_character_set(pattern: str, string: str) -> List[str]:
"""
Match a specific character set using a regular expression pattern and return all matches found in the string.
Args:
... |
code_exercise_27k | 9,618 | Write a Python function to validate if a given string starts with a specified prefix using regular expressions. The function should return `True` if the string starts with the prefix, otherwise `False`.
The code should start with:
```python
import re
def starts_with_prefix(string: str, prefix: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def starts_with_prefix(string: str, prefix: str) -> bool:
"""
Validates if the given string starts with the specified prefix using regular expressions.
Args:
string (str): The input string to be checked.
... |
code_exercise_27k | 9,639 | Write a Python function to validate if a given phone number matches a specific format using regular expressions. The phone number format should be as follows: `+<country code>-<area code>-<first part>-<second part>`, where:
- `<country code>` is 1 to 3 digits.
- `<area code>` is exactly 3 digits.
- `<first part>` is ex... | 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:
"""
Validate if a given phone number matches the specified format.
The phone number format should be: +<country code>-<area code>-<first part>-<second part>
... |
code_exercise_27k | 9,645 | Write a Python function to validate an email address using a regular expression pattern. The function should return `True` if the email address matches the pattern and `False` otherwise. The email address should follow the standard format of a username part followed by the domain part. The username part can include let... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_email(email: str) -> bool:
"""
Validates an email address using a regular expression pattern.
Args:
email (str): The email address to be validated.
Returns:
bool: True if the ema... |
code_exercise_27k | 9,653 | Write a Python function to validate if a given time string is in the format `hh:mm:ss` (24-hour clock). The function should use a regular expression to check the format and return `True` if the time string is valid, and `False` otherwise. The code should start with:
```python
import re
def validate_time_format(time_st... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_time_format(time_string: str) -> bool:
"""
Validate if a given time string is in the format hh:mm:ss (24-hour clock).
Args:
time_string (str): The time string to be validated.
Returns:
... |
code_exercise_27k | 9,656 | Write a Python function to validate a specific URL format using a regular expression. The URL should start with either `http://` or `https://`, optionally followed by `www.`, then a domain name consisting of alphanumeric characters and hyphens, followed by a dot (`.`) and a domain extension of at least two alphabetic c... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_url(url: str) -> bool:
"""
Validates if the given URL matches a specific format using a regular expression.
The URL should start with either 'http://' or 'https://', optionally followed by 'www.',
... |
code_exercise_27k | 9,660 | Write a Python function to find all words in a given text that have a specific number of characters using regular expressions. The function should return a list of all such words. The code should start with:
```python
import re
from typing import List
def find_words_with_length(word_length: int, 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 find_words_with_length(word_length: int, text: str) -> List[str]:
"""
Find all words in the given text that have exactly the specified number of characters.
Args:
word_length (... |
code_exercise_27k | 9,665 | Write a Python function to match a word containing a specific substring using regular expressions. The function should return the matched word if found, otherwise return `None`. The function should handle case-insensitive matching.
The code should start with:
```python
import re
def find_word_with_substring(text: str... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def find_word_with_substring(text: str, substring: str) -> str:
"""
Finds a word in the given text that contains the specified substring.
Args:
text (str): The text to search within.
substring (st... |
code_exercise_27k | 9,690 | Write a Python function to find the maximum of three numbers. The function should take three numbers as input and return the maximum of the three. The code should start with:
```python
def find_maximum_of_three(num1: int, num2: int, num3: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_maximum_of_three(num1: int, num2: int, num3: int) -> int:
"""
Finds the maximum of three numbers.
Parameters:
num1 (int or float): The first number.
num2 (int or float): The second number.
num3 (int or ... |
code_exercise_27k | 9,697 | Write a Python function to determine the largest number among three given numbers without using the built-in `max` function. The function should compare the numbers manually and return the largest one. The code should start with:
```python
def find_largest_manual(num1: int, num2: int, num3: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_largest_manual(num1: int, num2: int, num3: int) -> int:
"""
Determines the largest number among three given numbers without using the built-in max function.
Args:
num1 (int): The first number.
num2 ... |
code_exercise_27k | 9,700 | Write a Python function to validate if a given string is a valid email address according to a specific regular expression pattern. The function should return `True` if the email is valid and `False` otherwise. The code should start with:
```python
import re
def is_valid_email(email: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_email(email: str) -> bool:
"""
Validate if a given string is a valid email address.
Args:
email (str): The email address to be validated.
Returns:
bool: True if the email is vali... |
code_exercise_27k | 9,714 | Write a Python function to determine if a given string is a valid URL or not. The function should validate URLs that start with `http://` or `https://`, optionally include `www.`, have a domain name, and may include a port number and a path. The function should return `True` if the string is a valid URL, and `False` ot... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_url(url: str) -> bool:
"""
Determine if a given string is a valid URL or not.
Args:
url (str): The string to be checked.
Returns:
bool: True if the string is a valid URL, False o... |
code_exercise_27k | 9,739 | Write a Python function to generate a regular expression pattern that matches a specific word followed by a specific character set. The function should take two parameters: the word to match and the character set to match after the word. The function should return the constructed regular expression pattern as a string.... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def generate_regex_pattern(word: str, characters: str) -> str:
"""
Generates a regular expression pattern that matches a specific word followed by a specific character set.
Args:
word (str): The specific ... |
code_exercise_27k | 9,745 | Write a Python function to generate a regular expression pattern that matches a specific word followed by any character except a specific character. The function should take two arguments: the specific word and the specific character to avoid. The function should return the regular expression pattern as a string.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def generate_regex_pattern(word: str, char_to_avoid: str) -> str:
"""
Generates a regular expression pattern that matches a specific word followed by any character except a specific character.
Args:
word ... |
code_exercise_27k | 9,752 | Write a Python function to determine if a given number is a power of 2. The function should handle both positive and negative integers, as well as zero. The function should return `True` if the number is a power of 2, and `False` otherwise. The code should start with:
```python
def is_power_of_two(num: int) -> bool:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_power_of_two(num: int) -> bool:
"""
Determine if a given number is a power of 2.
Args:
num (int): The number to be checked.
Returns:
bool: True if the number is a power of 2, False otherwise.
... |
code_exercise_27k | 9,758 | Write a Python function to determine if a given string is an anagram of another string. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should handle strings with spaces and should be case-insensitive.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_anagram(string1: str, string2: str) -> bool:
"""
Determines if two strings are anagrams of each other.
Args:
string1 (str): The first string to compare.
string2 (str): The second string to compare.
... |
code_exercise_27k | 9,765 | Write a Python function to find all occurrences of a specific word followed by any non-digit character in a given text using regular expressions. The function should return a list of matched occurrences as strings.
The code should start with:
```python
import re
from typing import List
def find_word_followed_by_non_d... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def find_word_followed_by_non_digit(text: str, word: str) -> List[str]:
"""
Find all occurrences of a specific word followed by any non-digit character in a given text.
Args:
text ... |
code_exercise_27k | 9,773 | Write a Python function to determine if a given string is a palindrome when ignoring spaces, punctuation, and case sensitivity. The function should return `True` if the string is a palindrome and `False` otherwise. The code should start with:
```python
import string
def is_palindrome_ignore_case_and_punctuation(text: ... | Here is the Python code to solve the given problem in the markdown block:
```python
import string
def is_palindrome_ignore_case_and_punctuation(text: str) -> bool:
"""
Determines if a given string is a palindrome when ignoring spaces, punctuation, and case sensitivity.
Args:
text (str): The string... |
code_exercise_27k | 9,781 | Write a Python function to find a specific word followed by another specific word only at the beginning of a string using regular expressions. The function should return the matched string if found, otherwise `None`. The code should start with:
```python
import re
def find_specific_word_at_start(text: str, word1: str,... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def find_specific_word_at_start(text: str, word1: str, word2: str) -> str:
"""
Find a specific word followed by another specific word at the beginning of a string.
Args:
text (str): The input text string ... |
code_exercise_27k | 9,782 | Write a Python function to determine if a given email address is unique within a list of previously entered email addresses. The function should return `True` if the email address is unique (i.e., not present in the list), and `False` otherwise. The function should handle case-insensitive comparisons by converting all ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_unique_email(email: str, email_list: List[str]) -> bool:
"""
Determine if a given email address is unique within a list of previously entered email addresses.
This function converts all email... |
code_exercise_27k | 9,784 | Write a Python function to generate a regular expression pattern that matches a specific word followed by another specific word only at the end of a string. The function should return the compiled regular expression pattern.
The code should start with:
```python
import re
def match_word_at_end(word1: str, word2: str)... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_word_at_end(word1: str, word2: str) -> re.Pattern:
"""
Generates a regular expression pattern that matches a specific word followed by another specific word at the end of a string.
Args:
word1 (... |
code_exercise_27k | 9,804 | Write a Python function to determine if two given lists have any common elements. The function should return a boolean value indicating whether there is at least one common element between the two lists. The code should start with:
```python
from typing import List
def has_common_elements(list1: List[int], list2: List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def has_common_elements(list1: List[int], list2: List[int]) -> bool:
"""
Determines if two given lists have any common elements.
Args:
list1 (List[int]): The first list of integers.
... |
code_exercise_27k | 9,818 | Write a Python function to validate if a given string is a valid MAC address. A valid MAC address should follow the format of six groups of two hexadecimal digits, separated by either colons (`:`) or hyphens (`-`). The function should return `True` if the MAC address is valid, and `False` otherwise.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_mac_address(mac_address: str) -> bool:
"""
Validate if the given string is a valid MAC address.
A valid MAC address consists of six groups of two hexadecimal digits,
separated by either colons ('... |
code_exercise_27k | 9,829 | Write a Python function to generate a regular expression pattern that matches a specific word followed by another specific word, only at the beginning of a string, repeated a specific number of times. The function should ensure that the pattern is correctly formatted and handles edge cases such as zero repetitions.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def generate_regex_pattern(word1: str, word2: str, repetitions: int) -> str:
"""
Generates a regular expression pattern that matches a specific word followed by another specific word,
only at the beginning of a st... |
code_exercise_27k | 9,835 | Write a Python function to determine if two given strings are anagrams of each other, considering letter cases. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should ignore non-alphabetic characters and ... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(string1: str, string2: str) -> bool:
"""
Determines if two given strings are anagrams of each other, considering letter cases.
Args:
string1 (str): The first string.
string2 (str): The secon... |
code_exercise_27k | 9,855 | Write a Python function to determine if a given number is a Pronic number. A Pronic number, also known as an oblong number, is a number that is the product of two consecutive integers. For example, 6 is a Pronic number because it can be expressed as 2 * 3. The function should return `True` if the number is Pronic and `... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_pronic_number(num: int) -> bool:
"""
Determine if a given number is a Pronic number.
A Pronic number, also known as an oblong number, is a number that is the product
of two consecutive integers. For example, 6 is... |
code_exercise_27k | 9,859 | Write a Python function to determine if two given strings are anagrams of each other, ignoring letter cases and spaces. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
The code should start with:
```python
def are_an... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(s1: str, s2: str) -> bool:
"""
Determines if two given strings are anagrams of each other, ignoring letter cases and spaces.
Args:
s1 (str): The first string.
s2 (str): The second string.
... |
code_exercise_27k | 9,875 | Write a Python function to determine if a given string is a valid HTML tag. The function should check if the string starts with a `<` and ends with a `>`, and that all characters between these delimiters are alphanumeric or underscores. The function should return `True` if the string is a valid HTML tag, and `False` ot... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_html_tag(tag_str: str) -> bool:
"""
Determines if a given string is a valid HTML tag.
Args:
tag_str (str): The string to check.
Returns:
bool: True if the string is a valid HTML tag, False ... |
code_exercise_27k | 9,884 | Write a Python function to detect whether a specific word is followed by any character repeated one or more times in a given text using regular expressions. The function should return `True` if the pattern is found, otherwise `False`. The code should start with:
```python
import re
def matches_word_followed_by_any_cha... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def matches_word_followed_by_any_character(text: str, word: str) -> bool:
"""
Detects whether a specific word is followed by any character repeated one or more times in a given text.
Args:
text (str): The... |
code_exercise_27k | 9,893 | Write a Python function to determine if a given number is a Duck number. A Duck number is defined as a positive number that contains at least one zero and does not start with a zero. The function should return `True` if the number is a Duck number and `False` otherwise.
The code should start with:
```python
def is_duc... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_duck_number(number: int) -> bool:
"""
Determines if a given number is a Duck number.
A Duck number is a positive number that contains at least one zero and does not start with a zero.
Args:
number (int):... |
code_exercise_27k | 9,897 | Write a Python function to determine if a given string is a valid XML attribute name according to the XML specification. The function should use a regular expression to validate the attribute name. The code should start with:
```python
import re
def is_valid_xml_attribute(attribute: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_xml_attribute(attribute: str) -> bool:
"""
Determines if a given string is a valid XML attribute name according to the XML specification.
Parameters:
attribute (str): The string to be checked... |
code_exercise_27k | 9,910 | Write a Python function to determine if a given number is a Happy number. A number is considered Happy if the sum of the squares of its digits eventually equals 1. If the sequence of sums of squares of digits enters a cycle without reaching 1, the number is not a Happy number.
The code should start with:
```python
def... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_happy_number(n: int) -> bool:
"""
Determine if a given number is a Happy number.
A number is considered Happy if the sum of the squares of its digits eventually equals 1.
If the sequence of sums of squares of dig... |
code_exercise_27k | 9,915 | Write a Python function to determine if a given string is a valid HTML tag attribute name according to the HTML5 specification. The function should use a regular expression to validate the attribute name.
The code should start with:
```python
import re
def is_valid_html_attribute(attribute: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_html_attribute(attribute: str) -> bool:
"""
Determines if the given string is a valid HTML tag attribute name according to the HTML5 specification.
Args:
attribute (str): The attribute name t... |
code_exercise_27k | 9,920 | Write a Python function to find all occurrences of a specific word followed by a specific character repeated a minimum number of times in a given text. The function should return a list of all matches found.
The code should start with:
```python
import re
from typing import List
def find_word_followed_by_character(te... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def find_word_followed_by_character(text: str, word: str, character: str, min_occurrences: int) -> List[str]:
"""
Find all occurrences of a specific word followed by a specific character repeat... |
code_exercise_27k | 9,926 | Write a Python function to match a specific word followed by any whitespace character repeated a minimum number of times using regular expressions. The function should return a match object if the pattern is found, otherwise None.
The code should start with:
```python
import re
def match_word_with_whitespace(word: st... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_word_with_whitespace(word: str, min_whitespace_count: int, text: str) -> re.Match:
"""
Matches a specific word followed by any whitespace character repeated a minimum number of times.
Args:
word... |
code_exercise_27k | 9,947 | Write a Python function to determine if a given string is a valid XML tag attribute value. An XML attribute value must adhere to the following rules:
1. It cannot be empty or `None`.
2. It cannot start with the character `<`.
3. It cannot contain any control characters (ASCII values 0-8, 11-12, 14-31, 127).
4. It canno... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_xml_attribute_value(attribute_value: str) -> bool:
"""
Determines if a given string is a valid XML tag attribute value.
An XML attribute value must adhere to the following rules:
1. It cannot be ... |
code_exercise_27k | 9,948 | Write a Python function to check if a given string starts with a digit using a regular expression. The function should return `True` if the string starts with a digit and `False` otherwise. The code should start with:
```python
import re
def starts_with_digit(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def starts_with_digit(string: str) -> bool:
"""
Check if the given string starts with a digit using a regular expression.
Args:
string (str): The input string to check.
Returns:
bool: True if... |
code_exercise_27k | 9,954 | Write a Python function to determine if a given string is a valid HTML tag attribute value. The function should ensure that the string starts and ends with the same type of quote (either single or double), and the content between the quotes should not contain the same type of quote. The function should return `True` if... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_attribute_value(value: str) -> bool:
"""
Determines if a given string is a valid HTML tag attribute value.
A valid attribute value should meet the following conditions:
- It should start and end ... |
code_exercise_27k | 9,955 | Write a Python function to match the last character of a string if it is not a whitespace character using regular expressions. The function should return the matched character as a string if found, otherwise return an empty string.
The code should start with:
```python
import re
def match_last_non_space_char(string: ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_last_non_space_char(string: str) -> str:
"""
Matches the last character of a string if it is not a whitespace character.
Args:
string (str): The input string to match against.
Returns:
... |
code_exercise_27k | 9,959 | Write a Python function to validate a phone number in the format: `(XXX) XXX-XXXX`, where `X` is a digit. The function should use regular expressions to check if the input string matches this specific format. The function should return `True` if the phone number matches the format, and `False` otherwise.
The code shou... | 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:
"""
Validate if the given phone number matches the format: (XXX) XXX-XXXX.
Args:
phone_number (str): The phone number to be validated.
Returns:
... |
code_exercise_27k | 9,962 | Write a Python function to validate an email address using a regular expression. The email address must start with one or more alphanumeric characters, followed by an "@" symbol, then a domain name consisting of one or more alphanumeric characters, and finally ending with ".com". The function should return `True` if th... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_email(email: str) -> bool:
"""
Validate an email address using a regular expression.
The email address must start with one or more alphanumeric characters,
followed by an "@" symbol, then a d... |
code_exercise_27k | 9,966 | Write a Python function to match and extract HTML tags from a given string, excluding the root `<html>` and `</html>` tags. The function should use a regular expression to identify and return a list of all HTML tags found in the string.
The code should start with:
```python
import re
from typing import List
def extra... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def extract_html_tags(html_string: str) -> List[str]:
"""
Extracts all HTML tags from a given string, excluding the root <html> and </html> tags.
The regex pattern used here is:
`<(?!\... |
code_exercise_27k | 9,972 | Write a Python function to validate if a given date string is in the format "YYYY-MM-DD" and represents a valid date. The function should check for the correct format and also validate the date itself (e.g., February 30th should be invalid).
The code should start with:
```python
from typing import Optional
def valida... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Optional
import re
from datetime import datetime
def validate_date(date_str: str) -> Optional[str]:
"""
Validate if a given date string is in the format "YYYY-MM-DD" and represents a valid date.
Args:
... |
code_exercise_27k | 9,976 | Write a Python function to validate if a given string contains at least one uppercase letter, one digit, and one special character. The function should use regular expressions to perform this validation. 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 if the given string contains at least one uppercase letter, one digit, and one special character.
Args:
string (str): The input string to be validat... |
code_exercise_27k | 9,977 | Write a Python function to validate an email address using a regular expression. The function should return `True` if the email address is valid and `False` otherwise. The email validation should follow these rules:
1. The email address must start with one or more word characters (alphanumeric characters and underscore... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_email(address: str) -> bool:
"""
Validates an email address using a regular expression.
Args:
address (str): The email address to be validated.
Returns:
bool: True if the email a... |
code_exercise_27k | 9,981 | Write a Python function to validate if a given string is a valid URL using a regular expression. The function should return `True` if the URL is valid and `False` otherwise. The URL should match the following criteria:
- It can start with `http://`, `https://`, `ftp://`, or `ftps://`.
- It can include a domain name, wh... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_url(url: str) -> bool:
"""
Validate if a given string is a valid URL using a regular expression.
Args:
url (str): The URL to be validated.
Returns:
bool: True if the URL is valid... |
code_exercise_27k | 9,987 | Write a Python function to determine if a given string is a valid CSS class name according to the CSS specification. A valid CSS class name must start with a letter (a-z, A-Z), an underscore (_), or a backslash (\), and can be followed by any combination of letters, numbers, hyphens (-), underscores (_), or backslashes... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_css_class(class_name: str) -> bool:
"""
Determines if a given string is a valid CSS class name according to the CSS specification.
Args:
class_name (str): The string to check.
Returns:
... |
code_exercise_27k | 9,993 | Write a Python function to validate if a given string matches the format of a social security number (SSN) in the format `xxx-xx-xxxx`, where `x` is a digit. The function should return `True` if the string matches the format, and `False` otherwise. The code should start with:
```python
import re
def validate_ssn(ssn: ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_ssn(ssn: str) -> bool:
"""
Validate if a given string matches the format of a social security number (SSN) in the format xxx-xx-xxxx.
Args:
ssn (str): The string to validate as a social secur... |
code_exercise_27k | 9,997 | Write a Python function to check if a given word starts with a capital letter using a regular expression. The function should return `True` if the word starts with a capital letter and `False` otherwise. The code should start with:
```python
import re
def starts_with_capital(word: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def starts_with_capital(word: str) -> bool:
"""
Check if the given word starts with a capital letter using a regular expression.
Args:
word (str): The word to check.
Returns:
bool: True if th... |
code_exercise_27k | 10,003 | Write a Python function to determine if a given word contains both uppercase and lowercase letters using a regular expression. The function should return `True` if the word contains both uppercase and lowercase letters, and `False` otherwise.
The code should start with:
```python
import re
def contains_upper_and_lowe... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_upper_and_lower(word: str) -> bool:
"""
Determines if a given word contains both uppercase and lowercase letters.
Args:
word (str): The word to be checked.
Returns:
bool: True if... |
code_exercise_27k | 10,007 | Write a Python function to determine if a given sentence ends with a question mark. The function should use a regular expression to match the sentence pattern. The code should start with:
```python
import re
def ends_with_question_mark(sentence: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def ends_with_question_mark(sentence: str) -> bool:
"""
Determines if a given sentence ends with a question mark.
Args:
sentence (str): The sentence to check.
Returns:
bool: True if the sente... |
code_exercise_27k | 10,014 | Write a Python function to determine if a given string is a valid XML entity reference. An XML entity reference starts with an ampersand (`&`), followed by a name that starts with a letter and can contain letters and digits, and ends with a semicolon (`;`). The function should return `True` if the string is a valid XML... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_xml_entity_reference(string: str) -> bool:
"""
Determines if a given string is a valid XML entity reference.
An XML entity reference starts with an ampersand (&), followed by a name
that starts w... |
code_exercise_27k | 10,034 | Write a Python function to match a word that does not contain any vowels using regular expressions. The function should return `True` if the word does not contain any vowels, and `False` otherwise. The function should handle both uppercase and lowercase vowels.
The code should start with:
```python
import re
def matc... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_non_vowel_word(word: str) -> bool:
"""
Match a word that does not contain any vowels using regular expressions.
Args:
word (str): The word to be matched.
Returns:
bool: True if the ... |
code_exercise_27k | 10,038 | Write a Python function to determine if the sum of the digits of a given number, raised to the power of the number of digits, is equal to the original number. This is known as checking if the sum of digits is an Armstrong number. The function should return `True` if the sum of digits is an Armstrong number, and `False`... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_armstrong_digits_sum(number: int) -> bool:
"""
Determines if the sum of the digits of a given number, raised to the power of the number of digits, is equal to the original number.
Args:
number (int): The numb... |
code_exercise_27k | 10,040 | Write a Python function to determine if a given word contains an odd number of letters using a regular expression. The function should return `True` if the word has an odd number of letters, and `False` otherwise. The code should start with:
```python
import re
def is_odd_length_word(word: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_odd_length_word(word: str) -> bool:
"""
Determine if a given word contains an odd number of letters using a regular expression.
Args:
word (str): The word to be checked.
Returns:
bool:... |
code_exercise_27k | 10,042 | Write a Python function to validate if a given string consists of only lowercase letters using a regular expression. The function should return `True` if the string matches the criteria and `False` otherwise. The code should start with:
```python
import re
def is_lowercase_word(word: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_lowercase_word(word: str) -> bool:
"""
Validates if the given string consists of only lowercase letters.
Args:
word (str): The string to be checked.
Returns:
bool: True if the string c... |
code_exercise_27k | 10,044 | Write a Python function to determine if a given string is a valid XML processing instruction. An XML processing instruction should start with `<?xml` and end with `?>`, with optional attributes in between. The function should return `True` if the string is a valid XML processing instruction, and `False` otherwise.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_xml_processing_instruction(instruction: str) -> bool:
"""
Determines if a given string is a valid XML processing instruction.
Args:
instruction (str): The string to check.
Returns:
... |
code_exercise_27k | 10,055 | Write a Python function to determine if a given word contains at least two consecutive vowels followed by at least two consecutive consonants. The function should use regular expressions to perform this check.
The code should start with:
```python
import re
def has_consecutive_vowels_and_consonants(word: str) -> bool... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def has_consecutive_vowels_and_consonants(word: str) -> bool:
"""
Determines if a given word contains at least two consecutive vowels followed by at least two consecutive consonants.
Args:
word (str): The... |
code_exercise_27k | 10,069 | Write a Python function to determine if a given word contains at least one special character from the set `!@#$%^&*()`. The function should use regular expressions to perform this check.
The code should start with:
```python
import re
def contains_special_character(word: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_special_character(word: str) -> bool:
"""
Determines if the given word contains at least one special character from the set !@#$%^&*().
Args:
word (str): The word to check for special charact... |
code_exercise_27k | 10,085 | Write a Python function to find the sum of all the numbers in a given list, including handling cases where the list contains nested lists. The function should recursively sum all numbers, regardless of the nesting level.
The code should start with:
```python
from typing import List, Union
def recursive_sum(number_lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def recursive_sum(number_list: Union[List[Union[int, float]], List[List[Union[int, float]]]]) -> Union[int, float]:
"""
Computes the sum of all the numbers in the given list, including nested list... |
code_exercise_27k | 10,114 | Write a Python function to find a word in a list of words where the first letter is not the same as the last letter. The function should return the matched word if found, otherwise return `None`. The code should start with:
```python
from typing import List, Optional
def find_word_with_different_first_and_last_letters... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
import random
def find_word_with_different_first_and_last_letters(words: List[str]) -> Optional[str]:
"""
Find a word in a list of words where the first letter is not the same as the last lette... |
code_exercise_27k | 10,126 | Write a Python function to determine whether 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 div... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(num: int) -> bool:
"""
Determine whether a given number is a prime number.
Args:
num (int): The number to be checked.
Returns:
bool: True if the number is prime, False otherwise.
"""
... |
code_exercise_27k | 10,128 | Write a Python function to reverse a given string using a non-slicing method. The function should iterate through the string and build the reversed string character by character. The code should start with:
```python
def reverse_string_non_slicing(string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string_non_slicing(string: str) -> str:
"""
Reverse a given string using a non-slicing method.
Args:
string (str): The string to be reversed.
Returns:
str: The reversed string.
"""
#... |
code_exercise_27k | 10,136 | Write a Python function to sort a list of numbers 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 until each sublist contains a single element, then merges the sublists back together in sorted order.
The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sort(numbers: List[int]) -> List[int]:
"""
Sorts a list of numbers in ascending order using the merge sort algorithm.
Args:
numbers (List[int]): A list of numbers to be sorted.
... |
code_exercise_27k | 10,142 | Write a Python function to find the first sentence in a list that contains both the words "cat" and "dog". The function should use regular expressions to ensure that "cat" and "dog" are matched as whole words and not as substrings within other words. The function should return the first matching sentence or `None` if n... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
import re
def find_sentence_with_cat_and_dog(sentences: List[str]) -> Optional[str]:
"""
Find the first sentence in a list that contains both the words "cat" and "dog".
Args:
sente... |
code_exercise_27k | 10,147 | Write a Python function to find the greatest common divisor (GCD) of two numbers using the Euclidean algorithm. The function should handle edge cases such as both numbers being zero and should return the absolute value of the GCD.
The code should start with:
```python
def find_gcd(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_gcd(a: int, b: int) -> int:
"""
Returns the greatest common divisor (GCD) of two numbers using the Euclidean algorithm.
Args:
a (int): The first number.
b (int): The second number.
Returns:
... |
code_exercise_27k | 10,163 | Write a Python function to find the first n prime numbers efficiently. The function should return a list of the first n prime numbers. The code should start with:
```python
from typing import List
def find_first_n_primes(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_prime(num: int) -> bool:
"""
Check if a number is prime.
Args:
num (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise.
... |
code_exercise_27k | 10,168 | Write a Python function to count the number of words in a given string, considering various edge cases such as multiple spaces, leading and trailing spaces, and empty strings. The function should handle these cases gracefully and return the correct word count.
The code should start with:
```python
def count_words(stri... | 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 splits the input string by whitespace and returns the number of resulting words.
It handles cases with multiple spaces,... |
code_exercise_27k | 10,171 | Write a Python function to generate a random number between a given range, ensuring that the function handles invalid input ranges by raising a `ValueError`. The function should be able to generate a random number inclusively within the specified range.
The code should start with:
```python
import random
def generate... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_random_number(start: int, end: int) -> int:
"""
Generates a random number between the given range [start, end] (inclusive).
Args:
start (int): The lower bound of the range (inclusive).
... |
code_exercise_27k | 10,185 | Write a Python function to calculate the sum of natural numbers up to a given number using recursion. The function should be able to handle both positive and zero inputs. The code should start with:
```python
def sum_of_natural_numbers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_natural_numbers(n: int) -> int:
"""
Calculate the sum of natural numbers up to a given number using recursion.
Args:
n (int): The given number up to which the sum is to be calculated.
Returns:
... |
code_exercise_27k | 10,187 | Write a Python function to validate an email address using a regular expression. The function should return `True` if the email address is valid and `False` otherwise. The email validation should follow these rules:
1. The email must start with one or more letters, digits, dots, underscores, percent symbols, plus or mi... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_email(email: str) -> bool:
"""
Determine if the provided email address is valid.
Args:
email (str): The email address to validate.
Returns:
bool: True if the email address is val... |
code_exercise_27k | 10,190 | Write a Python function to determine if two given strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. The function should handle strings with spaces and should be case-insensitive.
The... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(str1: str, str2: str) -> bool:
"""
Determine if two strings are anagrams of each other.
Args:
str1 (str): The first string.
str2 (str): The second string.
Returns:
bool: True if... |
code_exercise_27k | 10,195 | Write a Python function to validate if a given string contains only alphanumeric characters and no other characters. The function should return `True` if the string is alphanumeric, and `False` otherwise. The code should start with:
```python
import re
def is_alphanumeric(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_alphanumeric(string: str) -> bool:
"""
Validate if the given string contains only alphanumeric characters.
Args:
string (str): The string to validate.
Returns:
bool: True if the string... |
code_exercise_27k | 10,197 | Write a Python function to validate if a given URL starts with either "http://" or "https://" using a regular expression. The function should return `True` if the URL matches the pattern and `False` otherwise. The code should start with:
```python
import re
def validate_url(url: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_url(url: str) -> bool:
"""
Validate if a given URL starts with either "http://" or "https://".
Args:
url (str): The URL to be validated.
Returns:
bool: True if the URL starts wit... |
code_exercise_27k | 10,202 | Write a Python function to convert a decimal number to its binary representation. The function should handle both positive and zero decimal numbers. The code should start with:
```python
def decimal_to_binary(decimal_num: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def decimal_to_binary(decimal_num: int) -> str:
"""
Convert a decimal number to its binary representation.
Args:
decimal_num (int): The decimal number to be converted.
Returns:
str: The binary represent... |
code_exercise_27k | 10,212 | Write a Python function to check if a given string is a palindrome using a regular expression to sanitize the input string. The function should remove all non-alphanumeric characters and convert the string to lowercase before checking if it reads the same forwards and backwards.
The code should start with:
```python
i... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_palindrome_with_regex(string: str) -> bool:
"""
Check if a given string is a palindrome after sanitizing it using a regular expression.
Args:
string (str): The input string to be checked.
Retu... |
code_exercise_27k | 10,215 | Write a Python function to determine if a given word is either entirely in uppercase or entirely in lowercase using regular expressions. The function should return `True` if the word matches the pattern, and `False` otherwise. The code should start with:
```python
import re
def is_all_uppercase_or_lowercase(word: str)... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_all_uppercase_or_lowercase(word: str) -> bool:
"""
Determines if a given word is either entirely in uppercase or entirely in lowercase.
Args:
word (str): The word to check.
Returns:
bo... |
code_exercise_27k | 10,226 | Write a Python function to compute the power of a given number using an iterative approach. The function should handle non-negative integer exponents and should not use Python's built-in exponentiation operator (`**`). Instead, it should use a loop to multiply the base by itself the number of times specified by the exp... | Here is the Python code to solve the given problem in the markdown block:
```python
def compute_power_iterative(base: int, exponent: int) -> int:
"""
Compute the power of a given number using an iterative approach.
Parameters:
base (int or float): The base number.
exponent (int): The exponent, must... |
code_exercise_27k | 10,230 | Write a Python function to validate a credit card number string in the format "xxxx-xxxx-xxxx-xxxx" using regular expressions. The function should return `True` if the input string matches the format, and `False` otherwise. The code should start with:
```python
import re
def validate_credit_card_number(card_number: st... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_credit_card_number(card_number: str) -> bool:
"""
Validate if a given string is a valid credit card number in the format "xxxx-xxxx-xxxx-xxxx".
Args:
card_number (str): The input string to be... |
code_exercise_27k | 10,234 | Write a Python function to determine if a given word is either composed entirely of digits or entirely of letters. The function should use a regular expression to perform this check. The code should start with:
```python
import re
def is_all_digits_or_all_letters(word: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_all_digits_or_all_letters(word: str) -> bool:
"""
Determine if a given word is composed entirely of digits or entirely of letters.
Args:
word (str): The word to be checked.
Returns:
bo... |
code_exercise_27k | 10,242 | Write a Python function to calculate the sum of all digits of a given number. The function should handle both positive and negative integers. The code should start with:
```python
def sum_of_digits(number: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_digits(number: int) -> int:
"""
Calculate the sum of all digits in a given number.
Args:
number (int): The number for which the sum of the digits needs to be calculated.
Returns:
int: The sum... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.