source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 10,892 | Write a Python function to determine if a given number is a Mersenne prime. A Mersenne prime is a prime number that can be expressed in the form \(2^p - 1\), where \(p\) is also a prime number. The function should take an integer as input and return a boolean indicating whether the number is a Mersenne prime.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_mersenne_prime(n: int) -> bool:
"""
Determine if a given number is a Mersenne prime.
A Mersenne prime is a prime number that can be expressed in the form 2^p - 1,
where p is also a prime number.
Args:
... |
code_exercise_27k | 10,903 | Write a Python function to match strings that start and end with the same character, excluding digits. The function should return `True` if the string matches the pattern and `False` otherwise. The code should start with:
```python
import re
def match_start_end_same_character(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_start_end_same_character(string: str) -> bool:
"""
Matches strings that start and end with the same character, excluding digits.
Args:
string (str): The input string to match.
Returns:
... |
code_exercise_27k | 10,908 | Write a Python function to determine if a given string starts with a vowel (either uppercase or lowercase) and does not contain any digits. The function should use regular expressions to perform this check.
The code should start with:
```python
import re
def starts_with_vowel_no_digits(text: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def starts_with_vowel_no_digits(text: str) -> bool:
"""
Determines if the given string starts with a vowel and does not contain any digits.
Args:
text (str): The input string to check.
Returns:
... |
code_exercise_27k | 10,911 | Write a Python function to determine if a given string contains at least one non-word character followed by a whitespace character or special character. The function should use a regular expression to perform this check.
The code should start with:
```python
import re
def contains_non_word_followed_by_special(string:... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_non_word_followed_by_special(string: str) -> bool:
"""
Determine if the given string contains at least one non-word character followed by a whitespace character or special character.
Args:
st... |
code_exercise_27k | 10,932 | Write a Python function to determine if a given sentence is a pangram. A pangram is a sentence that contains every letter of the alphabet at least once. The function should ignore case and non-alphabetic characters.
The code should start with:
```python
def is_pangram(sentence: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_pangram(sentence: str) -> bool:
"""
Determine if a given sentence is a pangram.
A pangram is a sentence that contains every letter of the alphabet at least once.
This function ignores case and non-alphabetic char... |
code_exercise_27k | 10,934 | Write a Python function to determine if a given string contains at least one uppercase letter followed by a digit or special character. The function should use regular expressions to perform this check.
The code should start with:
```python
import re
def contains_uppercase_followed_by_digit_or_special(string: str) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_uppercase_followed_by_digit_or_special(string: str) -> bool:
"""
Determines if the given string contains at least one uppercase letter followed by a digit or special character.
Args:
string (... |
code_exercise_27k | 10,936 | Write a Python function to determine if a given string starts with a vowel (either uppercase or lowercase) and contains at least one uppercase letter. The function should use regular expressions to perform this check. The code should start with:
```python
import re
def starts_with_vowel_and_has_uppercase(string: str) ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def starts_with_vowel_and_has_uppercase(string: str) -> bool:
"""
Determines if a given string starts with a vowel (either uppercase or lowercase)
and contains at least one uppercase letter.
Args:
str... |
code_exercise_27k | 10,939 | Write a Python function to check if a given list is sorted in either ascending or descending order. The function should return `True` if the list is sorted in either order, and `False` otherwise. The code should start with:
```python
from typing import List
def is_sorted_any_order(lst: List[int]) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_sorted_any_order(lst: List[int]) -> bool:
"""
Check if a given list is sorted in either ascending or descending order.
Args:
lst (List[int]): The input list to be checked.
Return... |
code_exercise_27k | 10,960 | Write a Python function to match strings that contain at least one word character followed by a hyphen and then another word character, excluding vowels and the letter 'a'. The function should return `True` if the input text matches the pattern, and `False` otherwise. The code should start with:
```python
import re
de... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_word_hyphen_word(text: str) -> bool:
"""
Matches strings that contain at least one word character, followed by a hyphen, and then another word character,
excluding vowels and the letter 'a'.
Args:
... |
code_exercise_27k | 10,972 | Write a Python function to check if a given string starts with a lowercase letter and ends with a digit 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 starts_with_lowercase_ends_with_digit(input_s... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def starts_with_lowercase_ends_with_digit(input_string: str) -> bool:
"""
Check if a string starts with a lowercase letter and ends with a digit.
Args:
input_string (str): The input string to be checked.
... |
code_exercise_27k | 10,975 | Write a Python function to determine if a given string contains exactly three digits. The function should use regular expressions to perform this check. The code should start with:
```python
import re
def contains_exactly_three_digits(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_exactly_three_digits(string: str) -> bool:
"""
Determine if the given string contains exactly three digits.
Args:
string (str): The input string to be checked.
Returns:
bool: Tru... |
code_exercise_27k | 10,979 | Write a Python function to validate if a given string matches a specific pattern using regular expressions. The pattern should be:
- Starts with exactly two lowercase letters.
- Followed by exactly three uppercase letters.
- Ends with exactly one digit.
The function should return `True` if the string matches the patte... | 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 a given string matches the pattern:
- Starts with exactly two lowercase letters,
- Followed by exactly three uppercase letters,
- Ends wit... |
code_exercise_27k | 10,982 | Write a Python function to validate if a given string matches a specific pattern: the string must start with one or more digits followed by one or more 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_strin... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def validate_string_pattern(s: str) -> bool:
"""
Validate if a given string matches the pattern of starting with one or more digits followed by one or more letters.
Args:
s (str): The string to be validat... |
code_exercise_27k | 10,983 | Write a Python function to validate if a given string contains only lowercase letters using a regular expression. 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_only(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_lowercase_only(string: str) -> bool:
"""
Validate if the given string contains only lowercase letters.
Args:
string (str): The string to be checked.
Returns:
bool: True if the string c... |
code_exercise_27k | 10,986 | Write a Python function to check if a given string is a substring of another string. The function should return the starting index of the first occurrence of the substring if it exists, otherwise return -1. The function should handle edge cases such as empty strings and substrings longer than the string.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_substring_index(substring: str, string: str) -> int:
"""
Finds the starting index of the first occurrence of a substring within a string.
Args:
substring (str): The substring to search for.
string (... |
code_exercise_27k | 10,997 | Write a Python function to validate if a given string contains exactly five lowercase letters using regular expressions. 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_lowercase_letters(string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_five_lowercase_letters(string: str) -> bool:
"""
Validates if the given string contains exactly five lowercase letters.
Args:
string (str): The string to be validated.
Returns:
bool: T... |
code_exercise_27k | 11,004 | Write a Python function to check if a given string contains exactly a specified number of digits. The function should return `True` if the string contains exactly the specified number of digits, and `False` otherwise. The function should use regular expressions to perform the check.
The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_exact_digits(string: str, num_digits: int) -> bool:
"""
Check if the given string contains exactly the specified number of digits.
Args:
string (str): The string to be checked.
num_di... |
code_exercise_27k | 11,005 | Write a Python function to check if a given string is a valid Python identifier. A valid identifier must follow these rules:
1. It must start with a letter (a-z, A-Z) or an underscore (_).
2. The rest of the characters can be letters, digits (0-9), or underscores.
3. It cannot be a reserved keyword in Python.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from keyword import iskeyword
def is_valid_python_identifier(string: str) -> bool:
"""
Checks if a given string is a valid Python identifier.
A valid Python identifier must:
1. Start with a letter (a-z, A-Z) or an unde... |
code_exercise_27k | 11,011 | Write a Python function to determine if a given string contains both digits and letters using regular expressions. The function should return `True` if the string contains at least one digit and at least one letter, and `False` otherwise. The code should start with:
```python
import re
def contains_digits_and_letters(... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_digits_and_letters(text: str) -> bool:
"""
Determines if the given string contains both digits and letters.
Args:
text (str): The input string to be checked.
Returns:
bool: True ... |
code_exercise_27k | 11,012 | Write a Python function to determine if a given number is a perfect cube. The function should return `True` if the number is a perfect cube, and `False` otherwise. The function should handle both positive and negative integers.
The code should start with:
```python
def is_perfect_cube(number: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_perfect_cube(number: int) -> bool:
"""
Determine if a given number is a perfect cube.
Args:
number (int): The number to check for being a perfect cube.
Returns:
bool: True if the number is a perf... |
code_exercise_27k | 11,015 | Write a Python function to determine if a given string contains any of the specified special characters. The function should accept a string and a list of special characters as input and return a boolean indicating whether any of the special characters are present in the string.
The code should start with:
```python
f... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def contains_special_characters(string: str, special_characters: List[str]) -> bool:
"""
Determine if a given string contains any of the specified special characters.
Args:
string ... |
code_exercise_27k | 11,026 | Write a Python function to determine if a given number is an abundant number. An abundant number is defined as a number for which the sum of its proper divisors (excluding the number itself) is greater than the number. The function should return `True` if the number is abundant and `False` otherwise. The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_abundant_number(n: int) -> bool:
"""
Determine if a given number is an abundant number.
An abundant number is a number for which the sum of its proper divisors
(excluding the number itself) is greater than the nu... |
code_exercise_27k | 11,027 | Write a Python function to check if a given string contains at least one whitespace character using a regular expression. The function should return `True` if the string contains at least one whitespace character, and `False` otherwise. The code should start with:
```python
import re
def contains_whitespace(string: st... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_whitespace(string: str) -> bool:
"""
Check if the given string contains at least one whitespace character.
Args:
string (str): The input string to check for whitespace characters.
Return... |
code_exercise_27k | 11,029 | Write a Python function to determine if a given number is a narcissistic number. A narcissistic number, also known as an Armstrong number, is a number that is the sum of its own digits each raised to the power of the number of digits. The function should take an integer as input and return a boolean indicating whether ... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_narcissistic_number(num: int) -> bool:
"""
Determine if a given number is a narcissistic number.
A narcissistic number is a number that is the sum of its own digits each raised to the power of the number of digits.
... |
code_exercise_27k | 11,034 | Write a Python function to check if a given string starts with a specific word using regular expressions. The function should return `True` if the string starts with the specified word, and `False` otherwise. The code should start with:
```python
import re
def starts_with_word(word: str, string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def starts_with_word(word: str, string: str) -> bool:
"""
Check if the given string starts with the specified word using regular expressions.
Args:
word (str): The specific word to match at the beginning ... |
code_exercise_27k | 11,038 | Write a Python function to determine if a specific word is surrounded by any characters in a given string. The function should return `True` if the word is found surrounded by any characters, and `False` otherwise. The function should be case-insensitive.
The code should start with:
```python
import re
def is_word_su... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_word_surrounded_by_any_characters(string: str, word: str) -> bool:
"""
Determine if a specific word is surrounded by any characters in a given string.
Args:
string (str): The input string to search... |
code_exercise_27k | 11,042 | Write a Python function to match a string that contains a specific word, followed by a specific number of digits, using regular expressions. The function should return the matched string if found, otherwise return `None`. The code should start with:
```python
import re
def match_specific_word_with_digits(word: str, nu... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_specific_word_with_digits(word: str, num_digits: int, string: str) -> str:
"""
Matches a string containing a specific word, followed by a specific number of digits.
Args:
word (str): The specifi... |
code_exercise_27k | 11,051 | Write a Python function to check if a given string contains a specific word followed by exactly one or more whitespace characters. The function should return `True` if such a pattern is found, and `False` otherwise. The code should start with:
```python
import re
def match_word_with_spaces(word: str, text: str) -> boo... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_word_with_spaces(word: str, text: str) -> bool:
"""
Checks if the given text contains the specified word followed by exactly one or more whitespace characters.
Args:
word (str): The specific wor... |
code_exercise_27k | 11,056 | Write a Python function to check if a given matrix is upper triangular or not. An upper triangular matrix is a square matrix in which all the elements below the main diagonal are zero. The function should return `True` if the matrix is upper triangular, and `False` otherwise.
The code should start with:
```python
from... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_upper_triangular(matrix: List[List[int]]) -> bool:
"""
Check if a given matrix is upper triangular or not.
An upper triangular matrix is a square matrix in which all the elements below the ma... |
code_exercise_27k | 11,060 | Write a Python function to determine if a given number is a vampire number. A vampire number is a composite natural number with an even number of digits, that can be factored into two smaller natural numbers (called "fangs") each having exactly half the number of digits of the vampire number. The fangs, when concatenat... | Here is the Python code to solve the given problem in the markdown block:
```python
import math
def is_vampire_number(n: int) -> bool:
"""
Determine if a given number is a vampire number.
A vampire number is a composite natural number with an even number of digits,
that can be factored into two smalle... |
code_exercise_27k | 11,061 | Write a Python function to check if a given string contains a specific word followed by any number of special characters. The function should use regular expressions to perform this check. The code should start with:
```python
import re
def contains_word_with_special_chars(word: str, string: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_word_with_special_chars(word: str, string: str) -> bool:
"""
Checks if the given string contains the specified word followed by any number of special characters.
Args:
word (str): The specifi... |
code_exercise_27k | 11,074 | Write a Python function to determine if a given string contains two specific words, in any order, using regular expressions. The function should return `True` if both words are present in the string, and `False` otherwise. The code should start with:
```python
import re
def contains_words(text: str, word1: str, word2:... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_words(text: str, word1: str, word2: str) -> bool:
"""
Determine if a given string contains two specific words, in any order.
Args:
text (str): The input string to check.
word1 (str): ... |
code_exercise_27k | 11,082 | Write a Python function to determine if a given string contains two specific words separated by a specific character, with the option to ignore case sensitivity. The function should return `True` if the pattern is found, and `False` otherwise.
The code should start with:
```python
import re
def match_words_with_separ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_words_with_separator(string: str, word1: str, word2: str, separator: str, ignore_case: bool = False) -> bool:
"""
Determines if a given string contains two specific words separated by a specific character.
... |
code_exercise_27k | 11,086 | Write a Python function to check if a given matrix is a symmetric matrix. A symmetric matrix is a square matrix that is equal to its transpose. The function should return `True` if the matrix is symmetric and `False` otherwise. The code should start with:
```python
from typing import List
def is_symmetric_matrix(matri... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_symmetric_matrix(matrix: List[List[int]]) -> bool:
"""
Check if a given matrix is a symmetric matrix.
Args:
matrix (List[List[int]]): A square matrix (2D list) to be checked.
Ret... |
code_exercise_27k | 11,102 | Write a Python function to check if a given string is a valid XML tag. An XML tag must start with a letter or an underscore and can contain letters, numbers, hyphens, underscores, and periods. The function should return `True` if the string is a valid XML tag and `False` otherwise.
The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
import string
def is_valid_xml_tag(tag: str) -> bool:
"""
Check if a given string is a valid XML tag.
Args:
tag (str): The string to check.
Returns:
bool: True if the string is a valid XML tag, False o... |
code_exercise_27k | 11,115 | Write a Python function to match a string that contains a specific word, followed by a specific number of uppercase letters and a specific number of digits. The function should return `True` if the string matches the criteria, and `False` otherwise. The function should be robust and handle edge cases such as empty stri... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_word_uppercase_digits(string: str, word: str, uppercase_count: int, digit_count: int) -> bool:
"""
Matches a string containing a specific word, followed by a specific number of uppercase letters
and a sp... |
code_exercise_27k | 11,116 | Write a Python function to check if a given string is a valid XML attribute value. The function should adhere to the following rules for a valid XML attribute value:
1. The string should not be empty.
2. The string should not start with a digit.
3. The string should not contain any of the special characters: `<`, `>`, ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_xml_attribute_value(value: str) -> bool:
"""
Check if a given string is a valid XML attribute value.
Args:
value (str): The string to be checked.
Returns:
bool: True if the strin... |
code_exercise_27k | 11,118 | Write a Python function to match a string that contains a specific word, followed by a specific number of digits, with any number of characters in between. The function should return a boolean indicating whether such a match is found.
The code should start with:
```python
import re
def contains_word_and_digits(word: ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def contains_word_and_digits(word: str, num_of_digits: int, string_to_check: str) -> bool:
"""
Checks if a string contains a specific word followed by a specific number of digits,
with any number of characters in ... |
code_exercise_27k | 11,127 | Write a Python function to determine if a given word is an isogram. An isogram is a word or phrase without any repeating letters, regardless of case sensitivity. The function should ignore non-alphabetic characters and only consider alphabetic characters for determining if the word is an isogram.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_isogram(word: str) -> bool:
"""
Determine if a given word is an isogram.
An isogram is a word or phrase without any repeating letters, regardless of case sensitivity.
Non-alphabetic characters are ignored.
A... |
code_exercise_27k | 11,134 | Write a Python function to check if a given matrix is a zero matrix. A zero matrix is a matrix where all elements are zero. The function should return `True` if the matrix is a zero matrix, and `False` otherwise. The code should start with:
```python
from typing import List
def is_zero_matrix(matrix: List[List[int]]) ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_zero_matrix(matrix: List[List[int]]) -> bool:
"""
Check if a given matrix is a zero matrix.
Args:
matrix (List[List[int]]): The matrix to be checked.
Returns:
bool: True ... |
code_exercise_27k | 11,138 | Write a Python function to match a string that contains a specific word, followed by a specific number of digits, with any number of special characters in between. The function should return `True` if the string matches the pattern, and `False` otherwise. The code should start with:
```python
import re
def match_word_... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_word_and_digits_with_special_chars(word: str, num_digits: int, string: str) -> bool:
"""
Match a string that contains a specific word, followed by a specific number of digits,
with any number of special ... |
code_exercise_27k | 11,152 | Write a Python function to match a string that contains either of two specific words, followed by a specific number of digits and a specific number of uppercase letters. The function should return `True` if the string matches the specified pattern, and `False` otherwise. The code should start with:
```python
import re
... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_specific_pattern(string: str) -> bool:
"""
Match a string that contains either of two specific words, followed by exactly three digits
and exactly two uppercase letters.
Args:
string (str): ... |
code_exercise_27k | 11,162 | Write a Python function to check if a given string matches a specific pattern using regular expressions. The pattern requires the string to contain either of two specific words, followed by exactly 4 digits and exactly 3 lowercase letters. The function should return `True` if the string matches the pattern, and `False`... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_string(input_string: str) -> bool:
"""
Checks if the input string matches a specific pattern using regular expressions.
The pattern requires the string to contain either of two specific words,
follo... |
code_exercise_27k | 11,174 | Write a Python function to check if a given string is a valid CSS color code. The function should support the following CSS color formats:
1. Hexadecimal color codes (e.g., `#FFFFFF`, `#abc`).
2. RGB color codes (e.g., `rgb(255, 255, 255)`).
3. HSL color codes (e.g., `hsl(0, 100%, 50%)`).
The function should return `T... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_css_color(color_code: str) -> bool:
"""
Check if a given string is a valid CSS color code.
Parameters:
color_code (str): The string to be checked as a CSS color code.
Returns:
bo... |
code_exercise_27k | 11,176 | Write a Python function to check if a given string contains either of two specific words, followed by exactly four digits, with any number of special characters in between. The function should return `True` if the string matches the pattern, and `False` otherwise. The code should start with:
```python
import re
def ma... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_string_with_digits(string: str) -> bool:
"""
Checks if a given string contains either "word1" or "word2", followed by exactly four digits,
with any number of special characters in between.
Args:
... |
code_exercise_27k | 11,192 | Write a Python function to match a string that contains a specific word, followed by a specific number of lowercase letters, with any number of special characters in between. The function should return a boolean indicating whether the string matches the pattern.
The code should start with:
```python
import re
def mat... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_string_with_word_and_lowercase_letters(word: str, lowercase_letters_count: int) -> bool:
"""
Matches a string containing a specific word, followed by a specific number of lowercase letters,
with any numb... |
code_exercise_27k | 11,198 | Write a Python function to determine if a given matrix is a singular matrix. A singular matrix is a square matrix that does not have a multiplicative inverse. The function should check if the matrix is square and then use the determinant to determine if the matrix is singular. The code should start with:
```python
impo... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def is_singular_matrix(matrix: np.ndarray) -> bool:
"""
Determine if a given matrix is a singular matrix.
A singular matrix is a square matrix that does not have a multiplicative inverse.
This functi... |
code_exercise_27k | 11,201 | Write a Python function to check if a given string is a valid CSS class name according to the CSS specification. The function should validate the length of the string, the starting character, and the allowed characters. The code should start with:
```python
import re
def is_valid_css_class(class_name: str) -> bool:
``... | 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:
"""
Check if a given string is a valid CSS class name according to the CSS specification.
Parameters:
class_name (str): The string to check.
Returns:
... |
code_exercise_27k | 11,203 | Write a Python function to match a string that contains either of two specific words, followed by a specific number of digits and a specific number of words, with any number of special characters in between. The function should return `True` if the string matches the pattern, and `False` otherwise. The function should ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_string_with_words_digits_special_chars(word1: str, word2: str, num_digits: int, num_words: int, input_string: str) -> bool:
"""
Match a string that contains either of two specific words, followed by a specif... |
code_exercise_27k | 11,218 | Write a Python function to generate a regular expression that matches a string containing either of two specific words, followed by a specific number of lowercase letters and a specific number of digits. The function should validate the input parameters and return a compiled regular expression object.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def generate_regex(words: List[str], num_lower: int, num_digits: int) -> re.Pattern:
"""
Generate a regular expression that matches a string containing either of two specific words,
followe... |
code_exercise_27k | 11,229 | Write a Python function to check if a given string is a valid C variable name. A valid C variable name must start with a letter (either uppercase or lowercase) or an underscore, followed by any number of letters, digits, or underscores. The function should return `True` if the string is a valid C variable name, and `Fa... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def is_valid_c_variable_name(variable_name: str) -> bool:
"""
Check if a given string is a valid C variable name.
A valid C variable name must start with a letter (either uppercase or lowercase)
or an undersc... |
code_exercise_27k | 11,233 | Write a Python function to determine if a given number is a perfect Hamming number. A perfect Hamming number is defined as a number that can be expressed as a product of the prime factors 2, 3, and 5 only. The function should return `True` if the number is a perfect Hamming number and `False` otherwise.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_perfect_hamming_number(n: int) -> bool:
"""
Determine if a given number is a perfect Hamming number.
A perfect Hamming number is a number that can be expressed as a product of the prime factors 2, 3, and 5 only.
... |
code_exercise_27k | 11,236 | Write a Python function to match a string that contains a specific word, followed by a specific number of digits, with any number of lowercase letters in between. The function should return `True` if the string matches the specified pattern, and `False` otherwise. The code should start with:
```python
import re
def ma... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_specific_word_with_digits(word: str, num_digits: int, string: str) -> bool:
"""
Match a string that contains a specific word, followed by a specific number of digits,
with any number of lowercase letters... |
code_exercise_27k | 11,242 | Write a Python function to match a string that contains either of two specific words, followed by a specific number of lowercase letters, with any number of digits in between. The function should return a boolean indicating whether the string matches the pattern.
The code should start with:
```python
import re
def ma... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def match_string(word1: str, word2: str, letter_count: int, input_string: str) -> bool:
"""
Determines if the input string matches the pattern of containing either of two specific words,
followed by any number of ... |
code_exercise_27k | 11,248 | Write a Python function to determine if a given matrix is a Hilbert matrix. A Hilbert matrix is a square matrix where each element is defined by the formula `1 / (i + j + 1)`, where `i` and `j` are the row and column indices, starting from 0. The function should return `True` if the matrix is a Hilbert matrix, and `Fal... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_hilbert_matrix(matrix: List[List[float]]) -> bool:
"""
Determine if a given matrix is a Hilbert matrix.
A Hilbert matrix is a square matrix where each element is defined by the formula:
1... |
code_exercise_27k | 11,282 | Write a Python function to calculate the factorial of a given non-negative integer using a while loop. The function should handle the case where the input number is negative by raising a `ValueError`. The code should start with:
```python
def factorial_while_loop(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def factorial_while_loop(n: int) -> int:
"""
Calculate the factorial of a non-negative integer using a while loop.
Parameters:
n (int): The non-negative integer to calculate the factorial of.
Returns:
int: The ... |
code_exercise_27k | 11,288 | Write a Python function to calculate the average of a list of numbers using a while loop. The function should handle an empty list by returning `None`. The code should start with:
```python
from typing import List, Optional
def calculate_average_while_loop(numbers: List[int]) -> Optional[float]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Optional
def calculate_average_while_loop(numbers: List[int]) -> Optional[float]:
"""
Calculates the average of a list of numbers using a while loop.
Args:
numbers (List[int]): A list... |
code_exercise_27k | 11,294 | Write a Python function to find the largest number among three given numbers using a while loop. The function should take three integers as input and return the largest of the three. The function should use a while loop to repeatedly compare the numbers and update the largest number found so far. The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_largest_num(num1: int, num2: int, num3: int) -> int:
"""
Find the largest number among three given numbers using a while loop.
Parameters:
num1 (int): First number
num2 (int): Second number
num3 (int): ... |
code_exercise_27k | 11,301 | Write a Python function to find the common elements in two sorted lists using a while loop. The function should efficiently compare the elements of both lists and return a list of common elements. The code should start with:
```python
from typing import List
def find_common_elements(list1: List[int], list2: List[int])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_common_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Find the common elements in two sorted lists using a while loop.
Args:
list1 (List[int]): The first sorted list... |
code_exercise_27k | 11,303 | Write a Python function to count the number of digits in a given number using a while loop. The function should handle both positive and negative integers, as well as the special case of zero. The code should start with:
```python
def count_digits(number: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_digits(number: int) -> int:
"""
Counts the number of digits in a given number using a while loop.
Args:
number (int): The number for which the digits need to be counted.
Returns:
int: The numb... |
code_exercise_27k | 11,311 | Write a Python function to generate the Fibonacci series up to a given limit using a while loop. The function should return a list containing the Fibonacci series up to the given limit. The code should start with:
```python
from typing import List
def generate_fibonacci_series(limit: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci_series(limit: int) -> List[int]:
"""
Generates the Fibonacci series up to a given limit using a while loop.
Args:
limit (int): The upper limit for the Fibonacci series... |
code_exercise_27k | 11,322 | Write a Python function to calculate the cube of a number. The function should raise a `ValueError` if the input is not an integer or a float. The code should start with:
```python
def calculate_cube(x):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_cube(x):
"""
Calculates the cube of a number.
Args:
x (int or float): The number to calculate the cube of.
Returns:
int or float: The cube of the input number.
Raises:
ValueEr... |
code_exercise_27k | 11,324 | Write a Python function to check if two given strings are anagrams using a while loop. 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 case insensitivity.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(str1: str, str2: str) -> bool:
"""
Check if two given strings are anagrams.
An anagram is a word or phrase formed by rearranging the letters of a different word or phrase,
typically using all the origin... |
code_exercise_27k | 11,331 | Write a Python function to calculate the power of a number using a while loop. The function should handle both positive and negative exponents. The code should start with:
```python
def calculate_power(base: float, exponent: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_power(base: float, exponent: float) -> float:
"""
Calculate the power of a number using a while loop.
Args:
base (float): The base number.
exponent (float): The exponent.
Returns:
... |
code_exercise_27k | 11,346 | Write a Python function to sort a list of numbers in ascending order using a while loop. The function should perform an in-place sort, meaning it should modify the original list rather than creating a new one. The function should start with:
```python
from typing import List
def sort_numbers_in_place(numbers: List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_numbers_in_place(numbers: List[int]) -> None:
"""
Sorts a list of numbers in ascending order using a while loop.
The sorting is performed in-place, meaning the original list is modified.
... |
code_exercise_27k | 11,347 | Write a Python function to count the number of occurrences of a given element in a list using a for loop. The function should be efficient and handle various types of elements, including integers, strings, and other data types. The code should start with:
```python
from typing import List, Any
def count_occurrences_fo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def count_occurrences_for_loop(lst: List[Any], element: Any) -> int:
"""
Counts the number of occurrences of a given element in a list using a for loop.
Args:
lst (List[Any]): The list ... |
code_exercise_27k | 11,348 | Write a Python function to calculate the sum of squares of a given list of numbers. The function should take a list of integers as input and return the sum of the squares of each number in the list. The code should start with:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_squares(numbers: List[int]) -> int:
"""
Calculate the sum of squares of a given list of numbers.
Args:
numbers (List[int]): A list of integers.
Returns:
int: The sum ... |
code_exercise_27k | 11,352 | Write a Python function to perform a binary search on a sorted list to find the index of a target element. The function should use a while loop to repeatedly narrow down the search range until the target element is found or the search range is exhausted. If the target element is found, return its index; otherwise, retu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def binary_search(arr: List[Any], target: Any) -> int:
"""
Perform binary search on a sorted list to find the index of the target element.
Args:
arr (List[Any]): A sorted list of elemen... |
code_exercise_27k | 11,356 | Write a Python function to calculate the sum of all even numbers in a given list using list comprehension. The function should be efficient and concise. The code should start with:
```python
from typing import List
def sum_of_even_numbers(numbers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_even_numbers(numbers: List[int]) -> int:
"""
Calculates the sum of all even numbers in a given list using list comprehension.
Args:
numbers (List[int]): A list of integers.
R... |
code_exercise_27k | 11,358 | Write a Python function to reverse the order of words in a given sentence using a while loop. The function should handle sentences with varying lengths and should not use any built-in reverse functions or methods. The code should start with:
```python
def reverse_words_in_sentence(sentence: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_words_in_sentence(sentence: str) -> str:
"""
Reverses the order of words in a given sentence using a while loop.
Args:
sentence (str): The sentence to reverse.
Returns:
str: The reversed sen... |
code_exercise_27k | 11,359 | Write a Python function to reverse the order of elements in a given list of integers without using the built-in `reversed` function or slicing. The function should create a new list with the elements in reverse order and return it. The code should start with:
```python
from typing import List
def reverse_list(lst: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_list(lst: List[int]) -> List[int]:
"""
Reverse the order of elements in a list of integers without using built-in reversed or slicing.
Args:
lst (List[int]): A list of integers t... |
code_exercise_27k | 11,361 | Write a Python function to find the second smallest number in a given list of integers using a functional programming approach. The function should handle lists with at least two integers and raise a `ValueError` if the list contains fewer than two integers. The code should start with:
```python
from typing import List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_second_smallest(numbers: List[int]) -> int:
"""
Finds the second smallest number in a list of integers using a functional programming approach.
Args:
numbers (List[int]): A list of ... |
code_exercise_27k | 11,366 | Write a Python function to count the number of digits in a given number using a recursive approach. The function should handle both positive and negative integers. The code should start with:
```python
def count_digits(number: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def count_digits(number: int) -> int:
"""
Recursive function to count the number of digits in a given number.
Args:
number (int): The number to count the digits of.
Returns:
int: The number of digits ... |
code_exercise_27k | 11,367 | Write a Python function to print the numbers from 1 to n using a for loop. The function should take an integer `n` as input and print each number from 1 to `n` inclusive.
The code should start with:
```python
def print_numbers_up_to(n: int) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def print_numbers_up_to(n: int) -> None:
"""
Prints the numbers from 1 to n (inclusive) using a for loop.
Args:
n (int): The upper limit of the range of numbers to print.
Returns:
None: This function do... |
code_exercise_27k | 11,373 | Write a Python function to filter out non-prime numbers from a given list of integers using the `filter()` function. The function should return a new list containing only the prime numbers. The code should start with:
```python
from typing import List
def filter_prime_numbers(numbers: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_prime_numbers(numbers: List[int]) -> List[int]:
"""
Filter out non-prime numbers from the given list.
Parameters:
numbers (List[int]): A list of integers.
Returns:
List[int]:... |
code_exercise_27k | 11,376 | Write a Python function to check if a given string is an anagram of another string using functional programming concepts. The function should ignore case, spaces, and punctuation. The code should start with:
```python
def is_anagram(s1: str, s2: str) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_anagram(s1: str, s2: str) -> bool:
"""
Check if a given string is an anagram of another string, ignoring case, spaces, and punctuation.
Args:
s1 (str): The first string to compare.
s2 (str): The secon... |
code_exercise_27k | 11,382 | Write a Python function to concatenate all the strings in a given list with a specified separator using the `reduce()` function from the `functools` module. The function should handle an empty list by returning an empty string.
The code should start with:
```python
from functools import reduce
from typing import List
... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import reduce
from typing import List
def concatenate_with_separator(strings: List[str], separator: str) -> str:
"""
Concatenates all the strings in the given list with the specified separator using the reduce() ... |
code_exercise_27k | 11,385 | Write a Python function to check if a given number is prime. The function should return `True` if the number is prime and `False` otherwise. The function should handle special cases such as 0 and 1, which are not prime numbers. The function should also efficiently check for factors up to the square root of the number.
... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime(n: int) -> bool:
"""
Check if a given number is prime.
Args:
n (int): The number to be checked.
Returns:
bool: True if the number is prime, False otherwise.
"""
# Special case: 0 an... |
code_exercise_27k | 11,386 | Write a Python function to calculate the product of all elements in a given list using recursion. The function should handle lists of integers and floats, and it should raise appropriate exceptions for invalid inputs.
The code should start with:
```python
from typing import List, Union
def calculate_product_recursive... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def calculate_product_recursive(lst: List[Union[int, float]]) -> Union[int, float]:
"""
Calculates the product of all elements in a given list using recursion.
Args:
lst (List[Union[i... |
code_exercise_27k | 11,387 | Write a Python function to reverse a given string using a recursive approach. The function should handle strings of any length, including empty strings. The code should start with:
```python
def reverse_string_recursive(string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_string_recursive(string: str) -> str:
"""
Recursively reverses a given string.
Args:
string (str): The string to be reversed.
Returns:
str: The reversed string.
"""
# Base case: if... |
code_exercise_27k | 11,390 | Write a Python function to find all the numbers divisible by 5 from a given list of integers using the `map()` function. The function should return a list of these numbers. The code should start with:
```python
from typing import List
def find_divisible_by_5(numbers: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_divisible_by_5(numbers: List[int]) -> List[int]:
"""
Find all the numbers divisible by 5 in a given list of integers using the map() function.
Args:
numbers (List[int]): A list of i... |
code_exercise_27k | 11,391 | Write a Python function to count the number of odd and even numbers in a given list of integers. The function should return a tuple containing the count of odd numbers followed by the count of even numbers. The code should start with:
```python
from typing import List, Tuple
def count_odd_even_numbers(numbers: List[in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def count_odd_even_numbers(numbers: List[int]) -> Tuple[int, int]:
"""
Counts the number of odd and even numbers in a given list of integers.
Args:
numbers (List[int]): A list of inte... |
code_exercise_27k | 11,395 | Write a Python function to remove all duplicates from a given list using the `filter()` function. The function should return a new list containing only the unique elements from the original list, maintaining the order of their first appearance. The code should start with:
```python
from typing import List
def remove_d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates(lst: List[int]) -> List[int]:
"""
Removes all duplicates from a given list using the filter() function.
Args:
lst (List[int]): The list from which duplicates need to be... |
code_exercise_27k | 11,397 | Write a Python function to convert all strings in a given list to lowercase using the `map()` function. The function should take a list of strings as input and return a new list with all strings converted to lowercase. The code should start with:
```python
from typing import List
def convert_strings_to_lowercase(strin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_strings_to_lowercase(string_list: List[str]) -> List[str]:
"""
Converts all strings in the given list to lowercase using the map() function.
Args:
string_list (List[str]): A list... |
code_exercise_27k | 11,400 | Write a Python function to find the common elements between two lists using functional programming concepts. The function should be efficient and avoid modifying the input lists. The code should start with:
```python
from typing import List
def find_common_elements(list1: List[int], list2: List[int]) -> List[int]:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_common_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Returns a list of common elements between two input lists using functional programming concepts.
Args:
list1 (L... |
code_exercise_27k | 11,404 | Write a Python function to remove the nth index character from a given string. If the index is out of bounds, the function should return the original string without any changes. The function should handle both positive and negative indices.
The code should start with:
```python
def remove_nth_character(string: str, n:... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_nth_character(string: str, n: int) -> str:
"""
Remove the nth index character from a given string. If the index is out of bounds,
return the original string without any changes.
Args:
string (str): Th... |
code_exercise_27k | 11,405 | Write a Python function to find the length of the longest increasing subarray from a given list. The function should use a for loop to iterate through the list and determine the length of the longest increasing subarray. The function should handle edge cases such as an empty list and should return the correct length fo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_increasing_subarray_length(arr: List[int]) -> int:
"""
Find the length of the longest increasing subarray in a given list.
Args:
arr (List[int]): The list of integers from which ... |
code_exercise_27k | 11,406 | Write a Python function to calculate the average of all the numbers in a given list using functional programming concepts. The function should handle the following:
1. Ensure the input is a list.
2. Ensure the list is not empty.
3. Use the `reduce` function from the `functools` module to sum the elements of the list.
4... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from functools import reduce
def calculate_average(numbers: List[int]) -> float:
"""
Calculates the average of a list of integers using functional programming concepts.
Args:
numbers (List[i... |
code_exercise_27k | 11,408 | Write a Python function to calculate the sum of all prime numbers up to a given number `n`. The function should efficiently determine if a number is prime and then sum all prime numbers from 2 to `n`. 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(n: int) -> bool:
"""
Check if a number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwise.
"""
if n <= 1:
... |
code_exercise_27k | 11,410 | Write a Python function to sort a given list in ascending order using the selection sort algorithm. The function should use a nested loop to find the minimum element in the unsorted part of the list and swap it with the first element of the unsorted part. The code should start with:
```python
from typing import List
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def selection_sort(arr: List[int]) -> List[int]:
"""
Sorts a given list in ascending order using the selection sort algorithm.
Args:
arr (List[int]): The list to be sorted.
Returns:
... |
code_exercise_27k | 11,420 | Write a Python function to count the number of vowels in a given string using functional programming concepts. The function should be case-insensitive and should return the count of vowels (a, e, i, o, u) in the string.
The code should start with:
```python
def count_vowels(string: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def count_vowels(string: str) -> int:
"""
Count the number of vowels in a given string using functional programming concepts.
Args:
string (str): The input string to count the vowels from.
Returns:
int:... |
code_exercise_27k | 11,425 | Write a Python function to calculate the square of each number in a given list of integers using the `map()` function. The function should return a new list containing the squares of the input numbers, in the same order. The code should start with:
```python
from typing import List
def calculate_squares(numbers: List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_squares(numbers: List[int]) -> List[int]:
"""
Calculate the square of each number in the input list using the map() function.
Args:
numbers (List[int]): A list of integers.
... |
code_exercise_27k | 11,429 | Write a Python function to find the largest element in a given list using functional programming concepts. The function should leverage the `reduce` function from the `functools` module to achieve this. The code should start with:
```python
from functools import reduce
from typing import Any
def find_largest_element(e... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import reduce
from typing import Any
def find_largest_element(elements: list[Any]) -> Any:
"""
Finds the largest element in a given list using functional programming concepts.
Args:
elements (list): ... |
code_exercise_27k | 11,432 | Write a Python function to merge two sorted arrays into a single sorted array. The function should efficiently combine the elements from both arrays while maintaining the sorted order. The code should start with:
```python
from typing import List
def merge_sorted_arrays(arr1: List[int], arr2: 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_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Merge two sorted arrays into a single sorted array.
Args:
arr1 (List[int]): The first sorted array.
arr2 (... |
code_exercise_27k | 11,435 | Write a Python function to check if a given number is a prime number using recursion. The function should be efficient and should only check divisibility up to the square root of the number. The function should be named `is_prime_recursive` and should start with:
```python
def is_prime_recursive(n: int) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime_recursive(n: int) -> bool:
"""
Check if a given number is a prime number using recursion.
Args:
n (int): The number to be checked for prime.
Returns:
bool: True if 'n' is a prime number, Fa... |
code_exercise_27k | 11,442 | Write a Python function to generate the Fibonacci series up to a specified number of terms using nested loops. The function should validate the input to ensure it is a positive integer. If the input is invalid, the function should raise a `ValueError`. The code should start with:
```python
from typing import List
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci_series(n: int) -> List[int]:
"""
Generate a Fibonacci series up to the specified number of terms using nested loops.
Args:
n (int): The number of terms to generate in ... |
code_exercise_27k | 11,444 | Write a Python function to generate all possible combinations of a given list of numbers. Each combination should be a unique set of elements from the original list, including the empty combination and the combination containing all elements. The order of combinations does not matter, but the order of elements within e... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_combinations(nums: List[int]) -> List[List[int]]:
"""
Generate all possible combinations of a given list of numbers.
Args:
nums (List[int]): List of numbers from which to genera... |
code_exercise_27k | 11,445 | Write a Python function to convert a given string to title case using recursion. The function should capitalize the first letter of each word in the string while keeping the rest of the letters in lowercase. The function should handle multiple spaces between words and leading/trailing spaces.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_title_case_recursive(string: str) -> str:
"""
Recursively converts the given string to title case.
Args:
string (str): The input string to convert.
Returns:
str: The converted string in t... |
code_exercise_27k | 11,448 | Write a Python function to find the product of all numbers in a given list using the `reduce()` function from the `functools` module. The function should handle lists of integers and return the product of all elements. If the list is empty, the function should return 1. The code should start with:
```python
from functo... | Here is the Python code to solve the given problem in the markdown block:
```python
from functools import reduce
from typing import List
def find_product(numbers: List[int]) -> int:
"""
Calculate the product of all numbers in the given list using the reduce() function.
Args:
numbers (List[int]): A... |
code_exercise_27k | 11,449 | Write a Python function to perform binary search on a sorted list and return the index of the target element if found, otherwise return -1. The function should handle edge cases such as an empty list, a list with a single element, and a list where the target is not present. The code should start with:
```python
from ty... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_search(arr: List[int], target: int) -> int:
"""
Perform binary search on a sorted list to find the index of the target element.
Args:
arr (List[int]): A sorted list of integers.
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.