source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
code_exercise_27k
773
Write a Python function named `compare_equal_ignore_case` that takes two strings as input and returns `True` if the strings are equal (ignoring case), and `False` otherwise. The function should handle edge cases such as empty strings and strings with different lengths. The code should start with: ```python def compare...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_equal_ignore_case(str1: str, str2: str) -> bool: """ Compare if the two strings are equal (ignoring case) and return True if they are, and False otherwise. Parameters: str1 (str): The first string. str2 ...
code_exercise_27k
775
Write a Python function named `compare_isalnum` that takes a string as input and returns `True` if all characters in the string are alphanumeric (i.e., either a letter or a number), and `False` otherwise. The function should handle empty strings by returning `False`. The code should start with: ```python def compare_i...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_isalnum(string: str) -> bool: """ Check if all characters in the given string are alphanumeric. Args: string (str): The string to be checked. Returns: bool: True if all characters in the str...
code_exercise_27k
776
Write a Python function named `compare_isalpha` that takes a string as input and returns `True` if all characters in the string are alphabetic (i.e., they are letters from the alphabet), and `False` otherwise. The function should handle edge cases such as empty strings and strings with spaces or special characters. Th...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_isalpha(string: str) -> bool: """ Check if all characters in the given string are alphabetic. This function returns True if all characters in the string are alphabetic (i.e., they are letters from the alphabet),...
code_exercise_27k
777
Write a Python function named `compare_isdigit` that takes a string as input and returns `True` if all characters in the string are digits, and `False` otherwise. The function should handle edge cases such as empty strings and strings with spaces or special characters. The code should start with: ```python def compare...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_isdigit(string: str) -> bool: """ Check if all characters in the given string are digits and return True if they are, and False otherwise. Args: string (str): The string to be checked. Returns: ...
code_exercise_27k
778
Write a Python function named `compare_islower` that takes a string as input and returns `True` if all characters in the string are lowercase, and `False` otherwise. The function should handle an empty string by returning `True` since an empty string has no characters that are not lowercase. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_islower(string: str) -> bool: """ Check if all characters in the given string are lowercase. Args: string (str): The string to be checked. Returns: bool: True if all characters in the string...
code_exercise_27k
779
Write a Python function named `compare_isupper` that takes a string as input and returns `True` if all characters in the string are uppercase, and `False` otherwise. The function should handle an empty string by returning `False`. The code should start with: ```python def compare_isupper(string: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def compare_isupper(string: str) -> bool: """ Check if all characters in the given string are uppercase. Args: string (str): The string to be checked. Returns: bool: True if all characters in the string...
code_exercise_27k
780
Write a Python function named `compare_isspace` that takes a string as input and returns `True` if all characters in the string are whitespace characters, and `False` otherwise. The function should be case-sensitive and should consider all whitespace characters defined in the Python `string.whitespace` constant. The c...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_isspace(string: str) -> bool: """ Check if all characters in the given string are whitespace characters. This function uses the `string.isspace()` method to determine if all characters in the input string ar...
code_exercise_27k
781
Write a Python function named `compare_swapcase` that takes a string as input and returns a new string with the case of each character swapped. The function should handle both uppercase and lowercase letters, and any non-alphabetic characters should remain unchanged. The code should start with: ```python def compare_sw...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_swapcase(string: str) -> str: """ Swap the case of each character in the input string and return a new string. Parameters: string (str): The input string whose characters' cases are to be swapped. Retur...
code_exercise_27k
782
Write a Python function named `compare_strip` that takes a string as input and returns a new string with leading and trailing whitespace removed. Additionally, the function should handle cases where the input string is `None` by returning an empty string. The code should start with: ```python def compare_strip(string:...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_strip(string: str) -> str: """ Remove leading and trailing whitespace from the string and return a new string. If the input string is None, return an empty string. Args: string (str): The string to b...
code_exercise_27k
784
Write a Python function named `compare_rstrip` that takes a string as input and returns a new string with trailing whitespace removed. The function should also compare the original string and the stripped string to determine if any changes were made. If the original string had trailing whitespace, the function should r...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_rstrip(string: str) -> str: """ Remove trailing whitespace from the string and return a new string. If trailing whitespace was removed, return the stripped string with a message. If no trailing whitespace was...
code_exercise_27k
785
Write a Python function named `compare_title` that takes a string as input and returns a new string with the first character of each word capitalized and the rest of the characters lowercase. The function should handle various edge cases, such as strings with multiple spaces, punctuation, and mixed case characters. Th...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_title(string: str) -> str: """ Capitalize the first character of each word in the string and return a new string. Parameters: string (str): The string to be modified. Returns: str: A new string with...
code_exercise_27k
786
Write a Python function named `compare_replace` that takes three strings as input: the original string, the string to be replaced, and the replacement string. The function should return a new string with all occurrences of the second string replaced by the third string. The function should handle cases where the string...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_replace(original: str, to_replace: str, replacement: str) -> str: """ Replace all occurrences of the second string with the third string in the original string and return a new string. Parameters: original (...
code_exercise_27k
787
Write a Python function named `concatenate_with_separator` that takes a list of strings and a separator string as input. The function should return a new string that is the concatenation of all the strings in the list, with the specified separator string between each string. If the list is empty, the function should re...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def concatenate_with_separator(string_list: List[str], separator: str) -> str: """ Concatenate all the strings in the list with the specified separator between each string and return a new string. A...
code_exercise_27k
788
Write a Python function named `compare_split` that takes a string as input and returns a list of strings, splitting the input string by whitespace characters. The function should handle various edge cases, such as empty strings, strings with multiple consecutive whitespace characters, and strings with leading or traili...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_split(string: str) -> list: """ Split the input string by whitespace characters and return a list of strings. Args: string (str): The string to be split. If None, an empty list is returned. Returns:...
code_exercise_27k
789
Write a Python function named `compare_split_custom` that takes two strings as input: the original string and the delimiter string. The function should return a list of strings, splitting the original string by the delimiter string. The function should handle cases where the delimiter is an empty string or where the de...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def compare_split_custom(string: str, delimiter: str) -> List[str]: """ Split the original string by the delimiter string and return a list of strings. Args: string (str): The original strin...
code_exercise_27k
790
Write a Python function named `compare_upper` that takes a string as input and returns a new string with all characters converted to uppercase. Additionally, the function should handle the following edge cases: - If the input string is `None`, the function should return an empty string. - If the input string is an empt...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_upper(string: str) -> str: """ Convert all characters in the string to uppercase and return a new string. Parameters: string (str): The string to be converted. If None, an empty string is returned. Retu...
code_exercise_27k
791
Write a Python function named `compare_lower` that takes a string as input and returns a new string with all characters converted to lowercase. Additionally, the function should handle special cases such as an empty string and non-string inputs by returning an empty string. The code should start with: ```python def co...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_lower(string: str) -> str: """ Convert all characters in the input string to lowercase and return a new string. If the input is not a string or is an empty string, return an empty string. Args: strin...
code_exercise_27k
792
Write a Python function named `compare_reverse` that takes a string as input and returns a new string with the characters in reverse order. The function should handle empty strings and strings with special characters, spaces, and numbers. The code should start with: ```python def compare_reverse(string: str) -> str: ``...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_reverse(string: str) -> str: """ Reverse the order of characters in the string and return a new string. Args: string (str): The string to be reversed. Returns: str: A new string with the cha...
code_exercise_27k
793
Write a Python function named `compare_isnumeric` that takes a string as input and returns `True` if all characters in the string are numeric (i.e., digits), and `False` otherwise. The function should handle edge cases such as empty strings and strings with non-numeric characters. The code should start with: ```python...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_isnumeric(string: str) -> bool: """ Check if all characters in the given string are numeric. Args: string (str): The string to be checked. Returns: bool: True if all characters in the string...
code_exercise_27k
796
Write a Python function named `compare_zfill` that takes two inputs: a string and a width. The function should return a new string with the original string padded with zeros on the left to reach the specified width. If the original string's length is greater than or equal to the specified width, the function should ret...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_zfill(string: str, width: int) -> str: """ Pad the original string with zeros on the left to reach the specified width and return a new string. Parameters: string (str): The original string. width (int):...
code_exercise_27k
797
Write a Python function named `compare_capitalize` that takes a string as input and returns a new string with the first character capitalized and the rest of the characters in lowercase. If the input string is empty, the function should return an empty string. The function should handle strings with special characters ...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_capitalize(string: str) -> str: """ Capitalize the first character of the string and convert the rest of the characters to lowercase, then return a new string. Args: string (str): The string to be capita...
code_exercise_27k
798
Write a Python function named `count_substring_occurrences` that takes two strings as input: the original string and the substring to be counted. The function should return the number of non-overlapping occurrences of the substring in the original string. The function should handle edge cases such as empty strings and ...
Here is the Python code to solve the given problem in the markdown block: ```python def count_substring_occurrences(original: str, substring: str) -> int: """ Count the number of non-overlapping occurrences of the substring in the original string. Args: original (str): The original string in which ...
code_exercise_27k
799
Write a Python function named `compare_find` that takes two strings as input: the original string and the substring to be searched. The function should return the index of the first occurrence of the substring in the original string, or -1 if the substring is not found. The function should be implemented without using ...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_find(original: str, substring: str) -> int: """ Find the index of the first occurrence of the substring in the original string and return the index. If the substring is not found, return -1. Args: origin...
code_exercise_27k
800
Write a Python function named `find_substring_index` that takes two strings as input: the original string and the substring to be searched. The function should return the index of the first occurrence of the substring in the original string. If the substring is not found, the function should raise a `ValueError`. The ...
Here is the Python code to solve the given problem in the markdown block: ```python def find_substring_index(original: str, substring: str) -> int: """ Find the index of the first occurrence of the substring in the original string and return the index. If the substring is not found, raise a ValueError. ...
code_exercise_27k
802
Write a Python function named `compare_rindex` that takes two strings as input: the original string and the substring to be searched. The function should return the index of the last occurrence of the substring in the original string. If the substring is not found, the function should raise a `ValueError`. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_rindex(original: str, substring: str) -> int: """ Find the index of the last occurrence of the substring in the original string and return the index. If the substring is not found, raise a ValueError. Args: ...
code_exercise_27k
803
Write a Python function named `compare_swap` that takes three strings as input: the original string, the first substring, and the second substring. The function should return a new string with all occurrences of the first substring replaced by the second substring. The function should handle cases where the substrings ...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_swap(original: str, substring1: str, substring2: str) -> str: """ Replace all occurrences of the first substring with the second substring in the original string and return a new string. Args: original (...
code_exercise_27k
804
Write a Python function named `compare_isprintable` that takes a string as input and returns `True` if all characters in the string are printable, and `False` otherwise. A printable character is defined as a character that is not a control character (e.g., newline, tab, etc.). The function should use the `str.isprintab...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_isprintable(string: str) -> bool: """ Determines if all characters in the given string are printable. Parameters: string (str): The string to be checked for printable characters. Returns: bool: True...
code_exercise_27k
805
Write a Python function named `compare_center` that takes two inputs: a string and a width. The function should return a new string that is centered within the specified width, with any extra space filled with a specified fill character. If the length of the string is greater than the specified width, the function shou...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_center(string: str, width: int, fillchar: str = ' ') -> str: """ Center the string within the specified width and return a new string. Any extra space is filled with the specified fill character. If the length of...
code_exercise_27k
807
Write a Python function named `compare_rjust` that takes three inputs: a string, a width, and an optional fill character. The function should return a new string that is right-justified within the specified width, with any extra space filled with the specified fill character. If the fill character is not provided, it s...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_rjust(string: str, width: int, fillchar: str = ' ') -> str: """ Right-justify the string within the specified width and return a new string. Any extra space is filled with the specified fill character. Args: ...
code_exercise_27k
811
Write a Python function named `compare_isascii` that takes a string as input and returns `True` if all characters in the string are ASCII characters, and `False` otherwise. An ASCII character is defined as a character whose Unicode code point is less than 128. The code should start with: ```python def compare_isascii(...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_isascii(string: str) -> bool: """ Check if all characters in the given string are ASCII characters. An ASCII character is defined as a character whose Unicode code point is less than 128. Args: stri...
code_exercise_27k
812
Write a Python function named `compare_encode` that takes two inputs: a string and an encoding. The function should return a new string encoded using the specified encoding. The function should handle different encodings such as 'utf-8', 'ascii', 'latin-1', etc. The code should start with: ```python def compare_encode(...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_encode(string: str, encoding: str) -> str: """ Encode the string using the specified encoding and return a new string. Args: string (str): The string to be encoded. encoding (str): The encoding t...
code_exercise_27k
813
Write a Python function named `compare_decode` that takes two inputs: a bytes object and an encoding string. The function should decode the bytes object using the specified encoding and return the resulting string. The function should handle cases where the encoding is not supported or the bytes object is not valid for...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_decode(byte_string: bytes, encoding: str) -> str: """ Decode the byte string from the specified encoding and return the resulting string. Args: byte_string (bytes): The byte string to be decoded. ...
code_exercise_27k
816
Write a Python function named `compare_ispunctuation` that takes a string as input and returns `True` if all characters in the string are punctuation characters, and `False` otherwise. The function should use the `string` module to check for punctuation characters. The code should start with: ```python import string ...
Here is the Python code to solve the given problem in the markdown block: ```python import string def compare_ispunctuation(input_string: str) -> bool: """ Check if all characters in the input string are punctuation characters. Args: input_string (str): The string to be checked. Returns: ...
code_exercise_27k
817
Write a Python function named `compare_iswhitespace` that takes a string as input and returns `True` if all characters in the string are whitespace characters, and `False` otherwise. The function should be case-sensitive and consider all Unicode whitespace characters. The code should start with: ```python def compare_...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_iswhitespace(string: str) -> bool: """ Check if all characters in the given string are whitespace characters. Parameters: string (str): The string to be checked. Returns: bool: True if all character...
code_exercise_27k
818
Write a Python function named `compare_title` that takes a string as input and returns a new string with the first character of each word capitalized and the rest of the characters in lowercase. The function should handle various edge cases, such as strings with multiple spaces, punctuation, and mixed case characters. ...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_title(string: str) -> str: """ Capitalize the first character of each word in the string and return a new string. Parameters: string (str): The string to be modified. Returns: str: A new string with...
code_exercise_27k
819
Write a Python function to count the number of words in a given string. The function should handle various edge cases, such as strings with multiple spaces, leading and trailing spaces, and empty strings. The code should start with: ```python def count_words(string: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def count_words(string: str) -> int: """ Counts the number of words in a given string. Args: string (str): The input string to count words from. Returns: int: The number of words in the string. ""...
code_exercise_27k
821
Write a Python function to count the number of lowercase letters in a given string. The function should handle various edge cases, such as an empty string, a string with no lowercase letters, and a string with only lowercase letters. The function should be efficient and easy to understand. The code should start with: ...
Here is the Python code to solve the given problem in the markdown block: ```python def count_lowercase_letters(string: str) -> int: """ Counts the number of lowercase letters in the given string. Args: string (str): The input string to count lowercase letters from. Returns: int: The n...
code_exercise_27k
822
Write a Python function to count the number of digits in a given string. The function should handle various edge cases, such as an empty string, a string with no digits, and a string with only digits. The function should also be able to handle non-digit characters effectively. The code should start with: ```python def...
Here is the Python code to solve the given problem in the markdown block: ```python def count_digits_in_string(string: str) -> int: """ Counts the number of digits in the given string. Args: string (str): The input string to count digits from. Returns: int: The number of digits in the ...
code_exercise_27k
824
Write a Python function to convert all uppercase letters in a given string to lowercase. The function should handle various edge cases, such as an empty string, a string with no uppercase letters, and a string with mixed case letters. The function should also handle non-alphabetic characters without any changes. The c...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_uppercase_to_lowercase(string: str) -> str: """ Converts all uppercase letters in the given string to lowercase. Args: string (str): The input string to be converted. Returns: str: The strin...
code_exercise_27k
825
Write a Python function to convert all lowercase letters in a given string to uppercase. The function should handle strings with mixed case, numbers, and special characters, converting only the lowercase letters to uppercase while leaving other characters unchanged. The code should start with: ```python def convert_low...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_lowercase_to_uppercase(string: str) -> str: """ Converts all lowercase letters in the given string to uppercase. Args: string (str): The input string to be processed. Returns: str: The strin...
code_exercise_27k
827
Write a Python function to reverse the order of words in a given string. The function should handle strings with multiple spaces between words and leading/trailing spaces. The code should start with: ```python def reverse_words_in_string(string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_words_in_string(string: str) -> str: """ Reverses the order of words in the given string. Args: string (str): The input string to reverse the words in. Returns: str: The string with the word...
code_exercise_27k
828
Write a Python function to reverse the order of words in a given string while keeping the characters within each word in their original order. The function should handle strings with multiple spaces and leading/trailing spaces. The code should start with: ```python def reverse_words(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def reverse_words(s: str) -> str: """ Reverses the order of words in the given string while keeping the characters within each word unchanged. Args: s (str): The input string containing words to be reversed. ...
code_exercise_27k
829
Write a Python function to remove all occurrences of a specified character from a given string. The function should handle both uppercase and lowercase characters. The code should start with: ```python def remove_character(string: str, char: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def remove_character(string: str, char: str) -> str: """ Removes all occurrences of the specified character from the given string. Args: string (str): The input string from which the character is to be removed. ...
code_exercise_27k
830
Write a Python function to remove all leading and trailing whitespace characters from a given string. The function should handle various types of whitespace characters, including spaces, tabs, and newlines. The code should start with: ```python def remove_whitespace(string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def remove_whitespace(string: str) -> str: """ Removes all leading and trailing whitespace characters from the given string. Args: string (str): The input string from which to remove whitespace. Returns: ...
code_exercise_27k
832
Write a Python function to sort the words in a given string in alphabetical order. The function should handle an empty string by returning an empty string. The function should also handle strings with multiple spaces between words by treating multiple spaces as a single space. The code should start with: ```python def ...
Here is the Python code to solve the given problem in the markdown block: ```python def sort_words_alphabetically(string: str) -> str: """ Sorts the words in the given string in alphabetical order. Args: string (str): The input string containing words to be sorted. Returns: str: The st...
code_exercise_27k
838
Write a Python function to convert each word in a given string to its uppercase version. The function should handle various edge cases, such as empty strings, strings with only one word, and strings with multiple spaces between words. The code should start with: ```python def uppercase_words(string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def uppercase_words(string: str) -> str: """ Converts each word in the given string to its uppercase version. Args: string (str): The input string to be processed. Returns: str: The string with each wor...
code_exercise_27k
839
Write a Python function to convert each word in a given string to its lowercase version. The function should handle strings with multiple spaces between words and should not modify the spaces between words. The code should start with: ```python def lowercase_words(string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def lowercase_words(string: str) -> str: """ Converts each word in the given string to its lowercase version while preserving the spaces between words. Args: string (str): The input string containing words to be con...
code_exercise_27k
840
Write a Python function to convert each word in a given string to its title case version. The function should handle various edge cases, such as empty strings, strings with only one word, and strings with multiple spaces between words. The code should start with: ```python def titlecase_words(string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def titlecase_words(string: str) -> str: """ Converts each word in the given string to its title case version. Args: string (str): The input string to be processed. Returns: str: The string with each wo...
code_exercise_27k
844
Write a Python function to replace each word in a given string with its ROT13 version. ROT13 is a simple substitution cipher that replaces a letter with the 13th letter after it in the alphabet. The function should handle both uppercase and lowercase letters and leave non-alphabetic characters unchanged. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python def rot13_words(string: str) -> str: """ Replaces each word in the given string with its ROT13 version. ROT13 is a simple substitution cipher that replaces a letter with the 13th letter after it in the alphabet. Non-alp...
code_exercise_27k
860
Write a Python function to encode each word in a given string using Salesforce encoding. Salesforce encoding replaces each character in a word with its corresponding HTML entity, which is represented as `&#<ASCII value>;`. For example, the character 'A' would be encoded as `&#65;`. The function should split the input s...
Here is the Python code to solve the given problem in the markdown block: ```python def salesforce_encode_words(string: str) -> str: """ Encodes each word in the given string using Salesforce encoding. Salesforce encoding replaces each character in a word with its corresponding HTML entity, represented...
code_exercise_27k
880
Write a Python function named `normalize_whitespace` that takes a string as input and returns the string with all consecutive whitespace characters replaced by a single space. The function should handle various types of whitespace characters, including spaces, tabs, and newlines. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python import re def normalize_whitespace(string: str) -> str: """ Normalizes the whitespace in a string by replacing consecutive whitespace characters with a single space. Args: string (str): The input string to norm...
code_exercise_27k
881
Write a Python function named `remove_punctuation` that takes a string as input and returns the string with all punctuation characters removed. The function should handle various types of punctuation and should not modify the case of the characters in the string. The code should start with: ```python import string def...
Here is the Python code to solve the given problem in the markdown block: ```python import string def remove_punctuation(input_string: str) -> str: """ Removes all punctuation characters from the given input string. Args: input_string (str): The input string from which punctuation characters are t...
code_exercise_27k
882
Write a Python function named `capitalize_first_letter` that takes a string as input and returns the string with the first letter of each word capitalized. The function should handle various edge cases, such as empty strings, strings with only one word, and strings with multiple spaces between words. The code should st...
Here is the Python code to solve the given problem in the markdown block: ```python def capitalize_first_letter(string: str) -> str: """ Capitalizes the first letter of each word in a given string. Args: string (str): The input string to capitalize. Returns: str: The string with the fi...
code_exercise_27k
883
Write a Python function named `reverse_string` that takes a string as input and returns the string in reverse order. The function should handle empty strings and strings with special characters and spaces correctly. The code should start with: ```python def reverse_string(string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(string: str) -> str: """ Reverses the order of characters in a string. Args: string (str): The input string to reverse. Returns: str: The string with characters in reverse order. ...
code_exercise_27k
884
Write a Python function named `remove_duplicates` that takes a string as input and returns the string with consecutive duplicate characters removed. The function should iterate through the string and build a new string by adding characters only if they are not the same as the previous character. The function should han...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_duplicates(string: str) -> str: """ Removes consecutive duplicate characters from a string. Args: string (str): The input string to remove duplicates from. Returns: str: The string with conse...
code_exercise_27k
888
Write a Python function named `split_string` that takes two string inputs: `string` and `delimiter`. The function should split the `string` into a list of substrings based on the `delimiter` and return the resulting list. The function should handle cases where the delimiter is not found in the string, and it should als...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def split_string(string: str, delimiter: str) -> List[str]: """ Splits a string into a list of substrings based on a delimiter. Args: string (str): The input string to split. delimit...
code_exercise_27k
889
Write a Python function named `remove_whitespace` that takes a string as input and returns the string with all whitespace characters removed. The function should handle various types of whitespace characters, including spaces, tabs, newlines, and carriage returns. The code should start with: ```python def remove_whites...
Here is the Python code to solve the given problem in the markdown block: ```python import re def remove_whitespace(string: str) -> str: """ Removes all whitespace characters from a given string. Args: string (str): The input string to remove whitespace from. Returns: str: The string ...
code_exercise_27k
892
Write a Python function named `is_anagram` that takes two strings as input and returns `True` if the two strings are anagrams of each other (contain the same characters in a different order), and `False` otherwise. The function should be case-insensitive and should ignore spaces and punctuation. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python def is_anagram(string1: str, string2: str) -> bool: """ Checks if two strings are anagrams of each other, ignoring case, spaces, and punctuation. Args: string1 (str): The first input string. string2 (str): T...
code_exercise_27k
893
Write a Python function named `capitalize_words` that takes a string as input and returns the string with the first letter of each word capitalized. The function should handle various edge cases, such as empty strings, strings with only one word, and strings with multiple spaces between words. The function should also ...
Here is the Python code to solve the given problem in the markdown block: ```python def capitalize_words(string: str) -> str: """ Capitalizes the first letter of each word in a string. Args: string (str): The input string to capitalize. Returns: str: The string with the first letter of...
code_exercise_27k
894
Write a Python function named `reverse_words` that takes a string as input and returns the string with the order of words reversed. The function should handle various edge cases, such as empty strings, strings with only one word, and strings with multiple spaces between words. The code should start with: ```python def ...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_words(string: str) -> str: """ Reverses the order of words in a given string. Args: string (str): The input string to reverse the words of. If None, it is treated as an empty string. Returns: ...
code_exercise_27k
895
Write a Python function named `remove_non_alphabetic` that takes a string as input and returns the string with all non-alphabetic characters removed. The function should preserve the order of the alphabetic characters in the string. The code should start with: ```python def remove_non_alphabetic(string: str) -> str: ``...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_non_alphabetic(string: str) -> str: """ Removes all non-alphabetic characters from a string. Args: string (str): The input string to remove non-alphabetic characters from. Returns: str: The s...
code_exercise_27k
898
Write a Python function named `is_valid_email` that takes a string as input and returns `True` if the string is a valid email address format, and `False` otherwise. The function should adhere to the following rules for a valid email address: 1. The local part (before the `@` symbol) should consist of alphanumeric chara...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_email(email: str) -> bool: """ Checks if a string is a valid email address format. Args: email (str): The input string to check. Returns: bool: True if the string is a valid emai...
code_exercise_27k
901
Write a Python function named `remove_extra_spaces` that takes a string as input and returns the string with extra spaces removed. Extra spaces are defined as consecutive whitespace characters (spaces, tabs, or newlines) that occur more than once. The function should handle various types of whitespace characters and en...
Here is the Python code to solve the given problem in the markdown block: ```python import re def remove_extra_spaces(string: str) -> str: """ Removes extra spaces from a string by replacing consecutive whitespace characters with a single space. Args: string (str): The input string to remove extra...
code_exercise_27k
902
Write a Python function named `is_valid_username` that takes a string as input and returns `True` if the string is a valid username format, and `False` otherwise. Assume that a valid username must meet the following criteria: - Contains only alphanumeric characters (letters and digits) - Starts with a letter - Has a le...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_username(string: str) -> bool: """ Checks if a string is a valid username format. Args: string (str): The input string to check. Returns: bool: True if the string is a valid user...
code_exercise_27k
903
Write a Python function named `remove_special_characters` that takes a string as input and returns the string with all special characters (non-alphanumeric characters) removed. The function should handle various edge cases, such as empty strings, strings with only special characters, and strings with no special charact...
Here is the Python code to solve the given problem in the markdown block: ```python import re def remove_special_characters(string: str) -> str: """ Removes all special characters (non-alphanumeric characters) from a string. Args: string (str): The input string to remove special characters from. ...
code_exercise_27k
905
Write a Python function named `is_valid_date` that takes a string as input and returns `True` if the string is a valid date format in the format "YYYY-MM-DD", and `False` otherwise. The function should ensure that the date string meets the following criteria: - Consists of four digits for the year, followed by a hyphen...
Here is the Python code to solve the given problem in the markdown block: ```python import re from datetime import datetime def is_valid_date(date_string: str) -> bool: """ Checks if a string is a valid date format in the format "YYYY-MM-DD". Args: date_string (str): The input string to check. ...
code_exercise_27k
907
Write a Python function named `is_valid_ipv4` that takes a string as input and returns `True` if the string is a valid IPv4 address format, and `False` otherwise. Assume that a valid IPv4 address must meet the following criteria: - Consists of four decimal numbers separated by periods (e.g., "192.168.0.1") - Each decim...
Here is the Python code to solve the given problem in the markdown block: ```python def is_valid_ipv4(ip_address: str) -> bool: """ Checks if a string is a valid IPv4 address format. Args: ip_address (str): The input string to check. Returns: bool: True if the string is a valid IPv4 ad...
code_exercise_27k
909
Write a Python function named `is_valid_hex_color` that takes a string as input and returns `True` if the string is a valid hexadecimal color code format, and `False` otherwise. A valid hexadecimal color code must meet the following criteria: - Starts with a hash symbol `#` - Followed by exactly six hexadecimal digits ...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_hex_color(string: str) -> bool: """ Checks if a string is a valid hexadecimal color code format. Args: string (str): The input string to check. Returns: bool: True if the string ...
code_exercise_27k
910
Create a Python function named `is_valid_time` that takes a string as input and returns `True` if the string is a valid time format in the format "HH:MM:SS", and `False` otherwise. Assume that a valid time must meet the following criteria: - Consists of two digits for the hour, followed by a colon (":"), followed by tw...
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: """ Checks if a string is a valid time format in the format "HH:MM:SS". Args: time_string (str): The input string to check. Returns: bool: True if...
code_exercise_27k
911
Write a Python function named `is_valid_domain` that takes a string as input and returns `True` if the string is a valid domain name format, and `False` otherwise. Assume that a valid domain name must meet the following criteria: - Consists of alphanumeric characters (letters and digits) and hyphens ("-") - Must start ...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_domain(string: str) -> bool: """ Checks if a string is a valid domain name format. Args: string (str): The input string to check. Returns: bool: True if the string is a valid dom...
code_exercise_27k
912
Write a Python function named `is_valid_file_extension` that takes a string as input and returns `True` if the string is a valid file extension format, and `False` otherwise. Assume that a valid file extension must meet the following criteria: - Starts with a period (".") - Contains only alphanumeric characters (letter...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_file_extension(string: str) -> bool: """ Checks if a string is a valid file extension format. Args: string (str): The input string to check. Returns: bool: True if the string is ...
code_exercise_27k
913
Create a Python function named `is_valid_credit_card_expiration` that takes a string as input and returns `True` if the string is a valid credit card expiration date format, and `False` otherwise. Assume that a valid credit card expiration date must meet the following criteria: - Consists of two digits for the month, f...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_credit_card_expiration(string: str) -> bool: """ Checks if a string is a valid credit card expiration date format. Args: string (str): The input string to check. Returns: ...
code_exercise_27k
914
Create a Python function named `is_valid_social_security_number` that takes a string as input and returns `True` if the string is a valid social security number format, and `False` otherwise. Assume that a valid social security number must meet the following criteria: - Consists of nine digits. - May contain hyphens (`...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_social_security_number(string: str) -> bool: """ Checks if a string is a valid social security number format. Args: string (str): The input string to check. Returns: bool: True i...
code_exercise_27k
915
Write a Python function named `is_valid_email_domain` that takes a string as input and returns `True` if the string is a valid email domain format, and `False` otherwise. Assume that a valid email domain must meet the following criteria: - Consists of alphanumeric characters (letters and digits) and hyphens ("-") - Mus...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_email_domain(string: str) -> bool: """ Checks if a string is a valid email domain format. Args: string (str): The input string to check. Returns: bool: True if the string is a va...
code_exercise_27k
916
Write a Python function named `is_valid_mac_address` that takes a string as input and returns `True` if the string is a valid MAC address format, and `False` otherwise. A valid MAC address must meet the following criteria: - Consists of six groups of two hexadecimal digits separated by colons (e.g., "00:1A:2B:3C:4D:5E"...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_mac_address(string: str) -> bool: """ Checks if a string is a valid MAC address format. Args: string (str): The input string to check. Returns: bool: True if the string is a vali...
code_exercise_27k
917
Write a Python function named `is_valid_postal_code` that takes a string as input and returns `True` if the string is a valid postal code format, and `False` otherwise. Assume that a valid postal code must meet the following criteria: - Consists of exactly five digits. - May optionally contain a hyphen (`-`) after the ...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_valid_postal_code(postal_code: str) -> bool: """ Checks if a string is a valid postal code format. Args: postal_code (str): The input string to check. Returns: bool: True if the string...
code_exercise_27k
918
Write a Python function named `count_pattern_occurrences` that takes in two parameters: a string `text` and a string `pattern`. The function should return the number of times the `pattern` appears in the `text`, considering case insensitivity. The function should handle edge cases such as empty strings and patterns lon...
Here is the Python code to solve the given problem in the markdown block: ```python def count_pattern_occurrences(text: str, pattern: str) -> int: """ Counts the number of times a given pattern appears in the text, considering case insensitivity. Args: text (str): The input text string. pat...
code_exercise_27k
921
Write a Python function to reverse a given string. The function should handle strings of varying lengths, including empty strings. The function should be efficient and should not use any built-in string reversal functions or methods. The code should start with: ```python def reverse_string(text: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(text: str) -> str: """ Reverses the given string. Args: text (str): The input text string to be reversed. Returns: str: The reversed version of the input string. """ # Initial...
code_exercise_27k
927
Write a Python function named `remove_whitespace` that takes in a parameter `text` and returns a string with all whitespace characters removed. The function should handle various types of whitespace characters, including spaces, tabs, and newlines. The code should start with: ```python def remove_whitespace(text: str)...
Here is the Python code to solve the given problem in the markdown block: ```python import re def remove_whitespace(text: str) -> str: """ Removes all whitespace characters from the given text string. Parameters: text (str): The input text string from which whitespace characters are to be removed. ...
code_exercise_27k
928
Write a Python function to count the number of words in a given text string, considering words separated by any whitespace (spaces, tabs, newlines). The function should handle various edge cases, such as empty strings, strings with multiple spaces, and strings with punctuation. The code should start with: ```python de...
Here is the Python code to solve the given problem in the markdown block: ```python def count_words(text: str) -> int: """ Counts the number of words in a given text string. This function splits the input text by any whitespace (spaces, tabs, newlines) and returns the number of resulting words. It hand...
code_exercise_27k
930
Write a Python function named `find_common_characters` that takes in two parameters `text1` and `text2` and returns a string containing all the common characters between the two strings, without duplicates. The order of the characters in the output string should match the order of their first occurrence in `text1`. Th...
Here is the Python code to solve the given problem in the markdown block: ```python def find_common_characters(text1: str, text2: str) -> str: """ Finds and returns a string containing all the common characters between two input strings, without duplicates. The order of the characters in the output string m...
code_exercise_27k
933
Write a Python function named `remove_punctuation` that takes in a parameter `text` and returns a string with all punctuation characters removed. The function should use the `string.punctuation` constant to identify and remove punctuation characters. The code should start with: ```python import string def remove_punct...
Here is the Python code to solve the given problem in the markdown block: ```python import string def remove_punctuation(text: str) -> str: """ Removes all punctuation characters from the given text. Args: text (str): The input text string from which punctuation characters are to be removed. ...
code_exercise_27k
939
Write a Python function named `reverse_words` that takes in a parameter `text` and returns a string with the words reversed. The function should handle multiple spaces between words and leading/trailing spaces correctly. The code should start with: ```python def reverse_words(text: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_words(text: str) -> str: """ Reverses the order of words in the given text string. This function splits the input text into words, reverses the order of the words, and then joins them back into a single stri...
code_exercise_27k
941
Write a Python function named `is_balanced_parentheses` that takes in a parameter `expression` which is a string containing parentheses. The function should return `True` if the parentheses in the expression are balanced (every opening parenthesis has a corresponding closing parenthesis), and `False` otherwise. The fun...
Here is the Python code to solve the given problem in the markdown block: ```python def is_balanced_parentheses(expression: str) -> bool: """ Check if the parentheses in the given expression are balanced. Parameters: expression (str): The input string containing parentheses. Returns: bool: Tru...
code_exercise_27k
942
Write a Python function named `find_common_elements` that takes in two parameters `list1` and `list2`, which are lists of integers. The function should return a list containing the common elements between the two lists, without duplicates. The order of elements in the output list should match the order of their first o...
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]: """ Finds the common elements between two lists of integers without duplicates, maintaining the order of their first occurr...
code_exercise_27k
943
Write a Python function named `remove_duplicates_sorted` that takes in a parameter `numbers` which is a sorted list of integers. The function should return a new list with all duplicate elements removed, while maintaining the original order of elements. The function should be efficient and should handle edge cases such...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_sorted(numbers: List[int]) -> List[int]: """ Removes duplicates from a sorted list of integers while maintaining the original order. Args: numbers (List[int]): A sorted...
code_exercise_27k
945
Write a Python function named `count_substring_occurrences` that takes in two parameters `text` and `substring` and returns the number of times the `substring` appears in the `text`, considering case insensitivity. The function should handle edge cases such as empty strings and substrings longer than the text. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python def count_substring_occurrences(text: str, substring: str) -> int: """ Counts the number of times a substring appears in a text, considering case insensitivity. Args: text (str): The input text string. subst...
code_exercise_27k
948
Write a Python function named `find_common_elements_sorted` that takes in two parameters `list1` and `list2`, which are sorted lists of integers. The function should return a list containing the common elements between the two lists, without duplicates. The order of elements in the output list should match the order of...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_common_elements_sorted(list1: List[int], list2: List[int]) -> List[int]: """ Finds the common elements between two sorted lists of integers without duplicates. The order of elements in the o...
code_exercise_27k
949
Write a Python function named `find_missing_numbers` that takes in two parameters `numbers1` and `numbers2`, which are lists of integers. The function should return a list containing the numbers that are present in `numbers1` but not in `numbers2`. The output list should be sorted in ascending order. The function shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_missing_numbers(numbers1: List[int], numbers2: List[int]) -> List[int]: """ Find the numbers that are present in 'numbers1' but not in 'numbers2' and return them sorted in ascending order. ...
code_exercise_27k
951
Write a Python function named `find_missing_elements` that takes in two parameters `list1` and `list2`, which are lists of integers. The function should return a list containing the elements that are present in `list1` but not in `list2`. The output list should be sorted in ascending order. The function should be effic...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_missing_elements(list1: List[int], list2: List[int]) -> List[int]: """ Returns a list of elements that are present in 'list1' but not in 'list2'. The output list is sorted in ascending order...
code_exercise_27k
952
Write a Python function named `find_common_elements_case_insensitive` that takes in two parameters `list1` and `list2`, which are lists of strings. The function should return a list containing the common elements between the two lists, without duplicates. The comparison should be case-insensitive. The order of elements...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_common_elements_case_insensitive(list1: List[str], list2: List[str]) -> List[str]: """ Finds the common elements between two lists of strings, without duplicates, in a case-insensitive manner. ...
code_exercise_27k
953
Write a Python function named `find_missing_elements_sorted` that takes in two parameters `list1` and `list2` which are sorted lists of integers. The function should return a list containing the elements that are present in `list1` but not in `list2`. The output list should be sorted in ascending order. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_missing_elements_sorted(list1: List[int], list2: List[int]) -> List[int]: """ Find the elements that are present in 'list1' but not in 'list2' from two sorted lists of integers. Args: ...
code_exercise_27k
954
Write a Python function named `find_common_elements_case_insensitive_sorted` that takes in two parameters `list1` and `list2`, which are sorted lists of strings. The function should return a list containing the common elements between the two lists, without duplicates. The comparison should be case-insensitive. The ord...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_common_elements_case_insensitive_sorted(list1: List[str], list2: List[str]) -> List[str]: """ Find common elements between two sorted lists of strings, without duplicates, in a case-insensitive ...
code_exercise_27k
957
Write a Python function named `compress_string` that takes a string as input and compresses it by replacing consecutive repeated characters with the character followed by the count of repetitions. For example, the string "aaabbbccc" should be compressed to "a3b3c3". If the input string is empty, the function should ret...
Here is the Python code to solve the given problem in the markdown block: ```python def compress_string(string: str) -> str: """ Compresses a string by replacing consecutive repeated characters with the character followed by the count of repetitions. Args: string (str): The input string to be compr...
code_exercise_27k
959
Write a Python function named `compress_string_easy` that takes a string as input and compresses it using a simple approach that replaces consecutive repeated characters with the character followed by the count of repetitions. This function should be categorized as "easy" difficulty level. The function should handle em...
Here is the Python code to solve the given problem in the markdown block: ```python def compress_string_easy(string: str) -> str: """ Compresses a string by replacing consecutive repeated characters with the character followed by the count of repetitions. Args: string (str): The input string to be ...
code_exercise_27k
960
Write a Python function named `compress_string_medium` that takes a string as input and compresses it using a medium-level approach. In this approach, instead of using the count of repetitions, we will use a marker character followed by the repeated character. For example, "aaabbbccc" should be compressed to "a3b3c3". ...
Here is the Python code to solve the given problem in the markdown block: ```python def compress_string_medium(string: str) -> str: """ Compresses the input string using a medium-level approach. Instead of using the count of repetitions, it uses a marker character followed by the repeated character. Ar...
code_exercise_27k
961
Write a Python function named `compress_string_hard` that takes a string as input and compresses it using a hard-level approach. In this approach, instead of using the count of repetitions or a marker character, we will use a combination of marker characters and numbers to represent the repeated characters. For example...
Here is the Python code to solve the given problem in the markdown block: ```python def compress_string_hard(string: str) -> str: """ Compresses the input string using a hard-level approach where repeated characters are represented by the character followed by the number of repetitions. Args: s...
code_exercise_27k
964
Create a Python function named `caesar_cipher` that takes two parameters: a string `message` and an integer `shift`. The function should encrypt the message using the Caesar cipher algorithm by shifting each letter in the message by the specified shift amount. The function should handle both uppercase and lowercase let...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher(message: str, shift: int) -> str: """ Encrypts the given message using the Caesar cipher algorithm. Args: message (str): The message to be encrypted. shift (int): The number of positions to...
code_exercise_27k
970
Create a Python function named `reverse_cipher` that takes a string `message` as a parameter. The function should encrypt the message by reversing the order of the characters. Return the encrypted message. The function should handle empty strings and strings with special characters and spaces correctly. The code should...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_cipher(message: str) -> str: """ Encrypts the given message by reversing the order of the characters. Args: message (str): The message to be encrypted. Returns: str: The encrypted message wi...
code_exercise_27k
973
Create a Python function named `rot13_cipher` that takes a string `message` as a parameter. The function should encrypt the message using the ROT13 cipher algorithm by shifting each letter in the message by 13 positions. Non-alphabet characters should remain unchanged. Return the encrypted message. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python def rot13_cipher(message: str) -> str: """ Encrypts the given message using the ROT13 cipher algorithm. The ROT13 cipher shifts each letter in the message by 13 positions in the alphabet. Non-alphabet characters remain ...