source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
code_exercise_27k
2,463
Write a Python function named `bitwise_is_bit_set_in_byte_fast` that takes two integers as input: a byte (8 bits) and a position. The function should return `True` if the bit at the specified position in the byte is set (1), and `False` otherwise. The function should use bitwise operations to perform the check. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python def bitwise_is_bit_set_in_byte_fast(byte: int, position: int) -> bool: """ Checks if the bit at the specified position in an 8-bit byte is set (1). Args: byte (int): The byte (8 bits) to check. position (int...
code_exercise_27k
2,465
Write a Python function named `bitwise_clear_bit_in_byte_fast` that takes two integers as input: a byte (8 bits) and a position. The function should return the byte with the bit at the specified position cleared (set to 0). The function should use bitwise operations to perform the clear operation efficiently. The funct...
Here is the Python code to solve the given problem in the markdown block: ```python def bitwise_clear_bit_in_byte_fast(byte: int, position: int) -> int: """ Clears the bit at the specified position in an 8-bit byte using bitwise operations. Args: byte (int): The 8-bit byte (0 to 255). posit...
code_exercise_27k
2,466
Write a Python function named `bitwise_toggle_bit_in_byte_fast` that takes two integers as input: a byte (8 bits) and a position. The function should return the byte with the bit at the specified position toggled (flipped). The function should use bitwise operations to perform the toggle operation efficiently. The func...
Here is the Python code to solve the given problem in the markdown block: ```python def bitwise_toggle_bit_in_byte_fast(byte: int, position: int) -> int: """ Toggles the bit at the specified position in an 8-bit byte using bitwise operations. Args: byte (int): The 8-bit byte (0 to 255) in which the...
code_exercise_27k
2,468
Write a Python function named `bitwise_reverse_byte_order_fast` that takes an integer representing a 32-bit value as input and returns the value with its byte order reversed. The function should use bitwise operations to perform the byte order reversal efficiently. The function should handle the input as a 32-bit unsig...
Here is the Python code to solve the given problem in the markdown block: ```python def bitwise_reverse_byte_order_fast(value: int) -> int: """ Reverses the byte order of a 32-bit integer using bitwise operations. Args: value (int): The 32-bit integer to reverse the byte order of. Returns: ...
code_exercise_27k
2,469
Write a Python function named `bitwise_extract_nibble_fast` that takes two integers as input: a byte (8 bits) and a nibble position. The function should return the nibble at the specified position in the byte. The function should use bitwise operations to perform the extraction. The nibble position is zero-indexed, mea...
Here is the Python code to solve the given problem in the markdown block: ```python def bitwise_extract_nibble_fast(byte: int, position: int) -> int: """ Extracts the nibble at the specified position in an 8-bit byte using bitwise operations. Args: byte (int): The 8-bit byte from which to extract t...
code_exercise_27k
2,470
Write a Python function named `bitwise_set_nibble_fast` that takes three integers as input: a byte (8 bits), a nibble position, and a value. The function should return the byte with the nibble at the specified position set to the specified value. The function should use bitwise operations to perform the set operation. ...
Here is the Python code to solve the given problem in the markdown block: ```python def bitwise_set_nibble_fast(byte: int, position: int, value: int) -> int: """ Sets the nibble at the specified position in an 8-bit byte to the specified value using bitwise operations. Args: byte (int): The 8-bit b...
code_exercise_27k
2,472
Write a Python function named `is_even` that takes an integer as input and returns `True` if the number is even, and `False` otherwise. The function should be designed to handle any integer input, including negative numbers and zero. The code should start with: ```python def is_even(num: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_even(num: int) -> bool: """ Check if a given integer is even. Parameters: num (int): The integer to be checked for evenness. Returns: bool: True if the integer is even, False otherwise. """ # Use...
code_exercise_27k
2,473
Write a Python function named `is_divisible_by_3` that takes an integer as input and returns `True` if the number is divisible by 3, and `False` otherwise. The function should be designed to handle both positive and negative integers. The code should start with: ```python def is_divisible_by_3(num: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_3(num: int) -> bool: """ Check if a given integer is divisible by 3. Args: num (int): The integer to be checked for divisibility by 3. Returns: bool: True if the number is divisible ...
code_exercise_27k
2,474
Write a Python function named `is_positive` that takes a number as input and returns `True` if the number is positive (greater than 0), and `False` otherwise. The function should handle both integers and floating-point numbers. The code should start with: ```python def is_positive(num: float) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive(num: float) -> bool: """ Check if a number is positive. Parameters: num (float): The number to be checked. Returns: bool: True if the number is positive (greater than 0), False otherwise. ""...
code_exercise_27k
2,476
Write a Python function to determine if a given integer is a prime number. The function should return `True` if the number is prime and `False` otherwise. The function should handle edge cases such as negative numbers, 0, and 1, which are not prime numbers. The code should start with: ```python import math def is_prim...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime(num: int) -> bool: """ Determine if a given integer is a prime number. Args: num (int): The number to be checked for primality. Returns: bool: True if the number is prime, Fals...
code_exercise_27k
2,477
Write a Python function to determine if a given integer is a power of two. The function should return `True` if the number is a power of two, and `False` otherwise. The function should handle both positive and negative integers, as well as zero. The code should start with: ```python def is_power_of_two(num: int) -> bo...
Here is the Python code to solve the given problem in the markdown block: ```python def is_power_of_two(num: int) -> bool: """ Determine if a given integer is a power of two. Args: num (int): The number to be checked. Returns: bool: True if the number is a power of two, False otherwise...
code_exercise_27k
2,479
Write a Python function named `is_vowel` that takes a single character (a string of length 1) as input and returns `True` if the character is a vowel (either uppercase or lowercase: 'a', 'e', 'i', 'o', 'u'), and `False` otherwise. The function should be case-insensitive. The code should start with: ```python def is_vo...
Here is the Python code to solve the given problem in the markdown block: ```python def is_vowel(char: str) -> bool: """ Check if a given character is a vowel. Parameters: char (str): The character to be checked. Must be a single character. Returns: bool: True if the character is a vowel (a, e...
code_exercise_27k
2,480
Write a Python function named `is_consonant` that takes a single character (string of length 1) as input and returns `True` if the character is a consonant (i.e., a letter that is not a vowel: a, e, i, o, u), and `False` otherwise. The function should be case-insensitive and should only consider alphabetic characters. ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_consonant(char: str) -> bool: """ Check if a character is a consonant. Parameters: char (str): The character to be checked. Must be a single character string. Returns: bool: True if the character is a co...
code_exercise_27k
2,481
Write a Python function named `is_positive_integer` that takes a number as input and returns `True` if the number is a positive integer, and `False` otherwise. The function should handle both integers and floating-point numbers. If the input is a floating-point number, it should be checked if it is equivalent to its in...
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive_integer(num) -> bool: """ Check if a number is a positive integer. Parameters: num (float or int): The number to be checked. Returns: bool: True if the number is a positive integer, False otherw...
code_exercise_27k
2,482
Write a Python function named `is_multiple_of` that takes two integers as input and returns `True` if the first number is a multiple of the second number, and `False` otherwise. The function should handle cases where the second number is zero by returning `False` to avoid division by zero errors. The code should start...
Here is the Python code to solve the given problem in the markdown block: ```python def is_multiple_of(num1: int, num2: int) -> bool: """ Check if the first number is a multiple of the second number. Parameters: num1 (int): The first number. num2 (int): The second number. Returns: bool: Tr...
code_exercise_27k
2,483
Write a Python function named `is_even_and_divisible_by_3` that takes an integer as input and returns `True` if the number is even and divisible by 3, and `False` otherwise. The function should be designed to handle any integer input, including negative numbers and zero. The code should start with: ```python def is_ev...
Here is the Python code to solve the given problem in the markdown block: ```python def is_even_and_divisible_by_3(num: int) -> bool: """ Check if a number is both even and divisible by 3. Parameters: num (int): The number to be checked. Returns: bool: True if the number is even and divisible ...
code_exercise_27k
2,484
Write a Python function named `is_positive_and_multiple_of_5` that takes a number as input and returns `True` if the number is positive and a multiple of 5, and `False` otherwise. The function should handle both integer and floating-point inputs. The code should start with: ```python def is_positive_and_multiple_of_5(...
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive_and_multiple_of_5(num: float) -> bool: """ Check if a number is positive and a multiple of 5. Parameters: num (float): The number to be checked. Returns: bool: True if the number is positive and...
code_exercise_27k
2,486
Write a Python function named `is_positive_and_divisible_by_2_or_3` that takes a number as input and returns `True` if the number is positive and divisible by either 2 or 3, and `False` otherwise. The function should handle both integer and floating-point inputs. The code should start with: ```python def is_positive_a...
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive_and_divisible_by_2_or_3(num: float) -> bool: """ Check if a number is positive and divisible by either 2 or 3. Parameters: num (float): The number to be checked. Returns: bool: True if the numbe...
code_exercise_27k
2,488
Write a Python function named `is_positive_and_multiple_of_8_or_9` that takes a number as input and returns `True` if the number is positive and a multiple of 8 or 9, and `False` otherwise. The function should handle both integer and floating-point inputs. The code should start with: ```python def is_positive_and_mult...
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive_and_multiple_of_8_or_9(num: float) -> bool: """ Check if a number is positive and a multiple of 8 or 9. Parameters: num (float): The number to be checked. Returns: bool: True if the number is po...
code_exercise_27k
2,489
Write a Python function named `is_divisible_by_5_and_6` that takes an integer as input and returns `True` if the number is divisible by both 5 and 6, and `False` otherwise. The function should handle any integer input, including negative numbers and zero. The code should start with: ```python def is_divisible_by_5_and...
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_5_and_6(num: int) -> bool: """ Check if a number is divisible by both 5 and 6. Args: num (int): The number to be checked for divisibility. Returns: bool: True if the number is divisi...
code_exercise_27k
2,490
Write a Python function named `is_positive_and_divisible_by_4_and_9` that takes a number as input and returns `True` if the number is positive and divisible by both 4 and 9, and `False` otherwise. The function should handle both integer and floating-point inputs. The code should start with: ```python def is_positive_a...
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive_and_divisible_by_4_and_9(num: float) -> bool: """ Check if a number is positive and divisible by both 4 and 9. Parameters: num (float): The number to be checked. Returns: bool: True if the numbe...
code_exercise_27k
2,491
Write a Python function to determine if a given integer is a multiple of both 3 and 5. The function should return `True` if the number is a multiple of both 3 and 5, and `False` otherwise. The function should handle both positive and negative integers. The code should start with: ```python def is_multiple_of_3_and_5(n...
Here is the Python code to solve the given problem in the markdown block: ```python def is_multiple_of_3_and_5(num: int) -> bool: """ Determine if a given integer is a multiple of both 3 and 5. Args: num (int): The integer to be checked. Returns: bool: True if the number is a multiple ...
code_exercise_27k
2,493
Write a Python function named `is_divisible_by_6_and_9` that takes an integer as input and returns `True` if the number is divisible by both 6 and 9, and `False` otherwise. The function should be efficient and straightforward, leveraging basic arithmetic operations. The code should start with: ```python def is_divisib...
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_6_and_9(num: int) -> bool: """ Check if a number is divisible by both 6 and 9. Parameters: num (int): The number to be checked. Returns: bool: True if the number is divisible by both 6 and 9...
code_exercise_27k
2,495
Write a Python function named `is_multiple_of_4_and_6` that takes an integer as input and returns `True` if the number is a multiple of both 4 and 6, and `False` otherwise. The function should be efficient and handle edge cases such as zero and negative numbers correctly. The code should start with: ```python def is_m...
Here is the Python code to solve the given problem in the markdown block: ```python def is_multiple_of_4_and_6(num: int) -> bool: """ Check if a number is a multiple of both 4 and 6. Parameters: num (int): The number to be checked. Returns: bool: True if the number is a multiple of both 4 and ...
code_exercise_27k
2,496
Write a Python function named `is_positive_and_multiple_of_3_and_4` that takes a number as input and returns `True` if the number is positive and a multiple of both 3 and 4, and `False` otherwise. The function should handle both integer and floating-point inputs. The code should start with: ```python def is_positive_a...
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive_and_multiple_of_3_and_4(num: float) -> bool: """ Check if a number is positive and a multiple of both 3 and 4. Parameters: num (float): The number to be checked. Returns: bool: True if the numbe...
code_exercise_27k
2,497
Write a Python function to determine if a given integer is divisible by both 8 and 10. The function should return `True` if the number is divisible by both 8 and 10, and `False` otherwise. The function should be named `is_divisible_by_8_and_10`. The code should start with: ```python def is_divisible_by_8_and_10(num: i...
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_8_and_10(num: int) -> bool: """ Check if a given integer is divisible by both 8 and 10. Parameters: num (int): The integer to be checked for divisibility by 8 and 10. Returns: bool: True if ...
code_exercise_27k
2,499
Write a Python function named `is_multiple_of_5_and_7` that takes an integer as input and returns `True` if the number is a multiple of both 5 and 7, and `False` otherwise. The function should handle both positive and negative integers. The code should start with: ```python def is_multiple_of_5_and_7(num: int) -> bool...
Here is the Python code to solve the given problem in the markdown block: ```python def is_multiple_of_5_and_7(num: int) -> bool: """ Check if a number is a multiple of both 5 and 7. Parameters: num (int): The number to be checked. Returns: bool: True if the number is a multiple of both 5 and ...
code_exercise_27k
2,500
Write a Python function named `is_positive_and_multiple_of_6_and_9` that takes a number as input and returns `True` if the number is positive and a multiple of both 6 and 9, and `False` otherwise. The function should handle both integer and floating-point inputs. The code should start with: ```python def is_positive_a...
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive_and_multiple_of_6_and_9(num: float) -> bool: """ Check if a number is positive and a multiple of both 6 and 9. Parameters: num (float): The number to be checked. Returns: bool: True if the numbe...
code_exercise_27k
2,501
Write a Python function named `is_divisible_by_3_and_4` that takes an integer as input and returns `True` if the number is divisible by both 3 and 4, and `False` otherwise. The function should be designed to handle any integer input, including negative numbers and zero. The code should start with: ```python def is_div...
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_3_and_4(num: int) -> bool: """ Check if a given integer is divisible by both 3 and 4. Args: num (int): The integer to be checked for divisibility. Returns: bool: True if the number i...
code_exercise_27k
2,503
Write a Python function to determine if a given integer is a multiple of both 6 and 8. The function should return `True` if the number is a multiple of both 6 and 8, and `False` otherwise. The code should start with: ```python def is_multiple_of_6_and_8(num: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_multiple_of_6_and_8(num: int) -> bool: """ Determine if a given integer is a multiple of both 6 and 8. Args: num (int): The integer to be checked. Returns: bool: True if the number is a multiple ...
code_exercise_27k
2,504
Write a Python function named `is_positive_and_multiple_of_4_and_7` that takes a number as input and returns `True` if the number is positive and a multiple of both 4 and 7, and `False` otherwise. The function should handle both integer and floating-point inputs. The code should start with: ```python def is_positive_a...
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive_and_multiple_of_4_and_7(num: float) -> bool: """ Check if a number is positive and a multiple of both 4 and 7. Parameters: num (float): The number to be checked. Returns: bool: True if the numbe...
code_exercise_27k
2,505
Write a Python function named `is_divisible_by_5_and_8` that takes an integer as input and returns `True` if the number is divisible by both 5 and 8, and `False` otherwise. The function should handle both positive and negative integers. The code should start with: ```python def is_divisible_by_5_and_8(num: int) -> boo...
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_5_and_8(num: int) -> bool: """ Check if a number is divisible by both 5 and 8. Args: num (int): The number to be checked. Returns: bool: True if the number is divisible by both 5 and...
code_exercise_27k
2,506
Write a Python function named `is_positive_and_divisible_by_6_and_7` that takes a number as input and returns `True` if the number is positive and divisible by both 6 and 7, and `False` otherwise. The function should handle both integer and floating-point inputs. The code should start with: ```python def is_positive_a...
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive_and_divisible_by_6_and_7(num: float) -> bool: """ Check if a number is positive and divisible by both 6 and 7. Args: num (float): The number to be checked. Returns: bool: True if the num...
code_exercise_27k
2,507
Write a Python function named `is_multiple_of_4_and_5` that takes an integer as input and returns `True` if the number is a multiple of both 4 and 5, and `False` otherwise. The function should handle both positive and negative integers. The code should start with: ```python def is_multiple_of_4_and_5(num: int) -> bool...
Here is the Python code to solve the given problem in the markdown block: ```python def is_multiple_of_4_and_5(num: int) -> bool: """ Check if a number is a multiple of both 4 and 5. Args: num (int): The number to be checked. Returns: bool: True if the number is a multiple of both 4 an...
code_exercise_27k
2,508
Write a Python function named `is_positive_and_multiple_of_5_and_6` that takes a number as input and returns `True` if the number is positive and a multiple of both 5 and 6, and `False` otherwise. The function should handle both integer and floating-point inputs. The code should start with: ```python def is_positive_a...
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive_and_multiple_of_5_and_6(num: float) -> bool: """ Check if a number is positive and a multiple of both 5 and 6. Parameters: num (float): The number to be checked. Returns: bool: True if the numbe...
code_exercise_27k
2,509
Write a Python function to determine if a given integer is divisible by both 6 and 8. The function should return `True` if the number is divisible by both 6 and 8, and `False` otherwise. The code should start with: ```python def is_divisible_by_6_and_8(num: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_6_and_8(num: int) -> bool: """ Check if a given integer is divisible by both 6 and 8. Parameters: num (int): The integer to be checked for divisibility by 6 and 8. Returns: bool: True if the...
code_exercise_27k
2,511
Write a Python function to determine if a given integer is a multiple of both 5 and 6. The function should return `True` if the number is a multiple of both 5 and 6, and `False` otherwise. The code should start with: ```python def is_multiple_of_5_and_6(num: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_multiple_of_5_and_6(num: int) -> bool: """ Determine if a given integer is a multiple of both 5 and 6. Args: num (int): The integer to be checked. Returns: bool: True if the number is a multiple ...
code_exercise_27k
2,512
Write a Python function named `is_positive_and_divisible_by_8_and_9` that takes a number as input and returns `True` if the number is positive and divisible by both 8 and 9, and `False` otherwise. The function should handle both integer and floating-point inputs. The code should start with: ```python def is_positive_a...
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive_and_divisible_by_8_and_9(num: float) -> bool: """ Check if a number is positive and divisible by both 8 and 9. Parameters: num (float): The number to be checked. Returns: bool: True if the numbe...
code_exercise_27k
2,513
Write a Python function named `is_divisible_by_4_and_5` that takes an integer as input and returns `True` if the number is divisible by both 4 and 5, and `False` otherwise. The function should handle both positive and negative integers. The code should start with: ```python def is_divisible_by_4_and_5(num: int) -> boo...
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_4_and_5(num: int) -> bool: """ Check if a number is divisible by both 4 and 5. Args: num (int): The number to be checked. Returns: bool: True if the number is divisible by both 4 and...
code_exercise_27k
2,514
Write a Python function named `is_positive_and_multiple_of_6_and_8` that takes a number as input and returns `True` if the number is positive and a multiple of both 6 and 8, and `False` otherwise. The function should handle both integer and floating-point inputs. The code should start with: ```python def is_positive_a...
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive_and_multiple_of_6_and_8(num: float) -> bool: """ Check if a number is positive and a multiple of both 6 and 8. Parameters: num (float): The number to be checked. Returns: bool: True if the numbe...
code_exercise_27k
2,516
Write a Python function named `is_positive_and_multiple_of_4_and_6` that takes a number as input and returns `True` if the number is positive and a multiple of both 4 and 6, and `False` otherwise. The function should handle both integer and floating-point inputs. The code should start with: ```python def is_positive_a...
Here is the Python code to solve the given problem in the markdown block: ```python def is_positive_and_multiple_of_4_and_6(num: float) -> bool: """ Check if a number is positive and a multiple of both 4 and 6. Parameters: num (float): The number to be checked. Returns: bool: True if the numbe...
code_exercise_27k
2,517
Write a Python function named `is_divisible_by_5_and_7` that takes an integer as input and returns `True` if the number is divisible by both 5 and 7, and `False` otherwise. The function should be designed to handle any integer input, including negative numbers and zero. The code should start with: ```python def is_div...
Here is the Python code to solve the given problem in the markdown block: ```python def is_divisible_by_5_and_7(num: int) -> bool: """ Check if a number is divisible by both 5 and 7. Args: num (int): The number to be checked. Returns: bool: True if the number is divisible by both 5 and...
code_exercise_27k
2,520
Write a Python function named `modify_string` that takes a string as an argument and returns a new string where every character is capitalized. 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 modify_string(string: str) -> str: """ Returns a new string where every character in the input string is capitalized. Args: string (str): The input string to be modified. Returns: str: A new string ...
code_exercise_27k
2,521
Write a Python function named `reverse_list` that takes a list as an argument and returns a new list with the elements in reverse order. The function should handle lists of any data type, including nested lists. The code should start with: ```python from typing import List, Any def reverse_list(lst: List[Any]) -> List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def reverse_list(lst: List[Any]) -> List[Any]: """ Returns a new list with the elements in reverse order. Args: lst (List[Any]): The list to be reversed. Returns: List[Any]...
code_exercise_27k
2,524
Write a Python function named `find_max` that takes a list of numbers as an argument and returns the maximum value in the list. The function should be implemented without using Python's built-in `max` function. Instead, use a loop to iterate through the list and keep track of the maximum value found. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_max(numbers: List[int]) -> Optional[int]: """ Find the maximum value in a list of integers. Args: numbers (List[int]): A list of integers from which to find the maximum va...
code_exercise_27k
2,526
Write a Python function named `is_palindrome` that takes a string as an argument and returns `True` if the string is a palindrome, and `False` otherwise. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, ignoring spaces, punctuation, and capitalization. T...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(string: str) -> bool: """ Determines if the given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, ignoring spac...
code_exercise_27k
2,527
Write a Python function named `find_common_elements` that takes two lists as arguments and returns a new list containing the common elements between the two lists. The function should handle lists with duplicate elements and return the common elements in the order they appear in the first list. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_common_elements(list1: List[int], list2: List[int]) -> List[int]: """ Finds the common elements between two lists and returns them in the order they appear in the first list. Args: ...
code_exercise_27k
2,528
Write a Python function named `is_prime` that takes an integer as an argument and returns `True` if the integer is a prime number, and `False` otherwise. A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers. The function should handle edge cases such as negative numbers...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime(num: int) -> bool: """ Determines if a given integer is a prime number. Args: num (int): The integer to check for primality. Returns: bool: True if the number is prime, False o...
code_exercise_27k
2,529
Write a Python function named `calculate_factorial` that takes an integer as an argument and returns the factorial of that number. The factorial of a non-negative integer `n`, denoted by `n!`, is the product of all positive integers less than or equal to `n`. If the input number is negative, the function should return ...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_factorial(num: int) -> int: """ Calculate the factorial of a non-negative integer. Args: num (int): The non-negative integer for which to calculate the factorial. Returns: int: The factori...
code_exercise_27k
2,530
Write a Python function named `remove_whitespace` that takes a string as an argument and returns a new string with all whitespace characters removed. The function should be able to handle various types of whitespace characters, including spaces, tabs, and newlines. The code should start with: ```python def remove_white...
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 the given string. Args: string (str): The input string from which whitespace characters are to be removed. Return...
code_exercise_27k
2,531
Write a Python function named `reverse_string` that takes a string as an argument and returns a new string with the characters 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 input string and returns the reversed string. Args: string (str): The input string to be reversed. Returns: str: The reversed string. If the inpu...
code_exercise_27k
2,533
Write a Python function named `capitalize_words` that takes a string as an argument and returns a new string where the first letter of each word is 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 ...
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 the given string. Args: string (str): The input string to be processed. Returns: str: A new string where the fi...
code_exercise_27k
2,534
Write a Python function named `count_occurrences` that takes a list and an element as arguments and returns the number of occurrences of the element in the list. The function should be implemented without using the built-in `count` method. The code should start with: ```python from typing import List, Any def count_oc...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def count_occurrences(lst: List[Any], element: Any) -> int: """ Counts the number of occurrences of a given element in a list. Args: lst (List[Any]): The list in which to count the occu...
code_exercise_27k
2,535
Write a Python function to determine if two given strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of another word or phrase, using all the original letters exactly once. The function should be case-insensitive and should ignore spaces. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python def is_anagram(str1: str, str2: str) -> bool: """ Determines if two given strings are anagrams of each other. Args: str1 (str): The first string to compare. str2 (str): The second string to compare. Ret...
code_exercise_27k
2,537
Write a Python function named `is_power_of_two` that takes an integer as an argument and returns `True` if the integer is a power of two, and `False` otherwise. A power of two is a number that can be expressed as \(2\) raised to some exponent. The function should handle both positive and negative integers, returning `F...
Here is the Python code to solve the given problem in the markdown block: ```python def is_power_of_two(num: int) -> bool: """ Determines if a given integer is a power of two. Args: num (int): The integer to check. Returns: bool: True if the integer is a power of two, False otherwise. ...
code_exercise_27k
2,538
Write a Python function named `find_unique_elements` that takes a list as an argument and returns a new list containing only the unique elements from the original list. The order of the elements should be preserved. The function should handle an empty list and lists with various data types. The code should start with: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_unique_elements(lst: List) -> List: """ Returns a list of unique elements from the input list, preserving the order of their first appearance. Args: lst (List): The input list from ...
code_exercise_27k
2,539
Write a Python function named `is_even` that takes an integer as an argument and returns `True` if the integer is even, and `False` otherwise. The function should handle both positive and negative integers. The code should start with: ```python def is_even(num: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_even(num: int) -> bool: """ Determines if a given integer is even. Args: num (int): The integer to check for evenness. Returns: bool: True if the integer is even, False otherwise. """ ret...
code_exercise_27k
2,541
Write a Python function named `is_subsequence` that takes two strings as arguments and returns `True` if the first string is a subsequence of the second string, and `False` otherwise. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_subsequence(str1: str, str2: str) -> bool: """ Determines if the first string is a subsequence of the second string. Args: str1 (str): The string to check if it is a subsequence. str2 (str): The strin...
code_exercise_27k
2,542
Write a Python function to find the missing number in a list of consecutive integers from 1 to n (inclusive) where one number is missing. The function should return the missing number. The code should start with: ```python from typing import List def find_missing_number(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def find_missing_number(numbers: List[int]) -> int: """ Find the missing number in a list of consecutive integers from 1 to n (inclusive) where one number is missing. Args: numbers (List[i...
code_exercise_27k
2,546
Write a Python function named `find_nth_largest` that takes a list of numbers and an integer `n` as arguments and returns the nth largest number in the list. Assume the list contains at least `n` distinct numbers. The function should be efficient and leverage the `heapq` module for optimal performance. The code should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import heapq def find_nth_largest(numbers: List[int], n: int) -> int: """ Find the nth largest number in a list of numbers. Args: numbers (List[int]): The list of numbers from which to find ...
code_exercise_27k
2,549
Write a Python function named `find_missing_numbers` that takes a list of integers from 1 to `n` (inclusive) with some missing numbers and returns a new list containing all the missing numbers in the given range. The function should be efficient and handle edge cases such as an empty list or a list with no missing numb...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_missing_numbers(numbers: List[int], n: int) -> List[int]: """ Finds and returns a list of missing numbers in the range from 1 to n (inclusive) that are not present in the given list of numbe...
code_exercise_27k
2,565
Write a Python function named `capitalize_words` that takes a string as input and returns a new string where the first letter of each word is 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...
Here is the Python code to solve the given problem in the markdown block: ```python def capitalize_words(input_string: str) -> str: """ Capitalizes the first letter of each word in the given string. Args: input_string (str): The input string to be processed. Returns: str: A new string ...
code_exercise_27k
2,566
Write a Python function named `find_max` that takes a list of numbers as input and returns the maximum value in the list. The function should be implemented without using Python's built-in `max` function. Instead, use a loop to iterate through the list and keep track of the maximum value found so far. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max(input_list: List[int]) -> int: """ Find the maximum value in a given list of integers. Args: input_list (List[int]): The list of integers from which to find the maximum value. ...
code_exercise_27k
2,567
Write a Python function named `remove_whitespace` that takes a string as input and returns a new string with all whitespace characters (spaces, tabs, and newlines) removed. The function should handle various types of whitespace characters efficiently. The code should start with: ```python def remove_whitespace(input_s...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_whitespace(input_string: str) -> str: """ Removes all whitespace characters (spaces, tabs, and newlines) from the input string. Args: input_string (str): The input string from which whitespace characters ...
code_exercise_27k
2,568
Write a Python function named `calculate_average` that takes a list of numbers as input and returns the average (mean) of the numbers. The function should handle an empty list by returning `None` instead of raising an error. The code should start with: ```python from typing import List, Optional def calculate_average(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def calculate_average(input_list: List[float]) -> Optional[float]: """ Calculate the average (mean) of a list of numbers. Args: input_list (List[float]): A list of numbers for whic...
code_exercise_27k
2,570
Write a Python function named `reverse_list` that takes a list as input and returns a new list with the elements reversed. The function should handle lists of any type of elements, including nested lists. The code should start with: ```python from typing import List, Any def reverse_list(input_list: List[Any]) -> List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def reverse_list(input_list: List[Any]) -> List[Any]: """ Reverses the elements of the input list and returns a new list with the elements in reverse order. Args: input_list (List[Any])...
code_exercise_27k
2,571
Write a Python function named `is_prime` that takes an integer as input and returns `True` if the number is prime, and `False` otherwise. The function should be efficient and handle edge cases such as negative numbers, 0, and 1. The code should start with: ```python def is_prime(number: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime(number: int) -> bool: """ Determines if a given integer is a prime number. Args: number (int): The integer to check for primality. Returns: bool: True if the number is prime, F...
code_exercise_27k
2,574
Write a Python function named `count_occurrences` that takes a list of elements and a target element as input, and returns the number of times the target element appears in the list. The function should be implemented without using the built-in `count` method. The code should start with: ```python from typing import L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def count_occurrences(input_list: List[Any], target_element: Any) -> int: """ Counts the number of times a target element appears in the input list. Args: input_list (List[Any]): The li...
code_exercise_27k
2,575
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: """ Determines if two strings are anagrams of each other. Args: string1 (str): The first string to compare. string2 (str): The second string to compare. ...
code_exercise_27k
2,577
Write a Python function named `remove_duplicates_case_sensitive` that takes a list of strings as input and returns a new list with duplicate strings removed, while considering the case of the strings. The function should preserve the order of the first occurrence of each 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 def remove_duplicates_case_sensitive(input_list: List[str]) -> List[str]: """ Removes duplicate strings from the input list while preserving the case sensitivity and the order of first occurrence. A...
code_exercise_27k
2,579
Write a Python function named `find_smallest_element` that takes a list of numbers as input and returns the smallest element in the list. The function should handle lists of integers and floating-point numbers. The code should start with: ```python from typing import List, Union def find_smallest_element(input_list: L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_smallest_element(input_list: List[Union[int, float]]) -> Union[int, float]: """ Find and return the smallest element in a given list of numbers. Args: input_list (List[Union[...
code_exercise_27k
2,580
Write a Python function named `is_power_of_two` that takes an integer as input and returns `True` if the number is a power of two, and `False` otherwise. The function should handle both positive and negative integers, as well as zero. The code should start with: ```python def is_power_of_two(number: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_power_of_two(number: int) -> bool: """ Determines if the given integer is a power of two. Args: number (int): The integer to check. Returns: bool: True if the number is a power of two, False othe...
code_exercise_27k
2,581
Write a Python function named `find_longest_common_prefix` that takes a list of strings as input and returns the longest common prefix among the strings. If there is no common prefix, return an empty string. The function should handle edge cases such as an empty list or a list containing empty strings. The code should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_longest_common_prefix(input_list: List[str]) -> str: """ Find the longest common prefix among a list of strings. Args: input_list (List[str]): A list of strings to find the common p...
code_exercise_27k
2,582
Write a Python function named `reverse_words` that takes a string as input and returns a new string with the words reversed (not the characters within each word). The function should handle various edge cases, such as empty strings, strings with multiple spaces, and strings with leading or trailing spaces. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_words(input_string: str) -> str: """ Reverses the order of words in a given string. Args: input_string (str): The input string containing words to be reversed. Returns: str: A new string wit...
code_exercise_27k
2,583
Write a Python function named `find_second_largest` that takes a list of numbers as input and returns the second largest number in the list. Assume the list has at least two distinct numbers. The function should handle the input list without modifying it. 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_largest(input_list: List[int]) -> int: """ Find the second largest number in a list of integers. Args: input_list (List[int]): A list of integers with at least two distinct n...
code_exercise_27k
2,584
Create a Python function named `is_perfect_square` that takes an integer as input and returns `True` if the number is a perfect square, and `False` otherwise. The function should handle both positive and negative integers, returning `False` for negative integers since they cannot be perfect squares. The code should st...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_perfect_square(number: int) -> bool: """ Determines if a given integer is a perfect square. Args: number (int): The integer to check. Returns: bool: True if the number is a perfect s...
code_exercise_27k
2,587
Write a Python function named `is_valid_palindrome` that takes a string as input and returns `True` if the string is a valid palindrome (reads the same forwards and backwards, ignoring non-alphanumeric characters), and `False` otherwise. The function should ignore case sensitivity and only consider alphanumeric charact...
Here is the Python code to solve the given problem in the markdown block: ```python def is_valid_palindrome(input_string: str) -> bool: """ Determines if the given string is a valid palindrome, ignoring non-alphanumeric characters and case sensitivity. Args: input_string (str): The string to check ...
code_exercise_27k
2,588
Write a Python function named `find_max_occurrence` that takes a string as input and returns the character that occurs the most number of times in the string. If there are multiple characters with the same maximum occurrence, return the one that appears first in the string. The function should handle an empty string by...
Here is the Python code to solve the given problem in the markdown block: ```python def find_max_occurrence(input_string: str) -> str: """ Finds the character that occurs the most number of times in the given string. If there are multiple characters with the same maximum occurrence, returns the one that app...
code_exercise_27k
2,589
Write a Python function named `is_anagram_case_insensitive` 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), ignoring the case of the characters. Return `False` otherwise. The function should handle empty strings and str...
Here is the Python code to solve the given problem in the markdown block: ```python def is_anagram_case_insensitive(string1: str, string2: str) -> bool: """ Determines if two strings are anagrams of each other, ignoring case and spaces. Args: string1 (str): The first string to compare. stri...
code_exercise_27k
2,595
Write a Python function named `find_max_length` that takes a list of strings as input and returns the length of the longest string in the list. The function should handle an empty list by returning 0. The code should start with: ```python from typing import List def find_max_length(input_list: List[str]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_length(input_list: List[str]) -> int: """ Find the length of the longest string in a given list of strings. Args: input_list (List[str]): A list of strings. Returns: ...
code_exercise_27k
2,596
Write a Python function named `find_common_elements_case_sensitive` that takes two lists of strings as input and returns a new list containing the common elements between the two input lists, considering the case of the strings. The function should be case-sensitive, meaning that "Hello" and "hello" are considered diff...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_common_elements_case_sensitive(list1: List[str], list2: List[str]) -> List[str]: """ Find and return the common elements between two lists of strings, considering the case sensitivity. Args...
code_exercise_27k
2,597
Write a Python function named `find_min_length` that takes a list of strings as input and returns the length of the shortest string in the list. The function should handle an empty list by returning 0. The code should start with: ```python from typing import List def find_min_length(input_list: List[str]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_min_length(input_list: List[str]) -> int: """ Find the length of the shortest string in the given list of strings. Args: input_list (List[str]): A list of strings. Returns: ...
code_exercise_27k
2,603
Write a Python function named `find_max_value` that takes a dictionary as input and returns the maximum value in the dictionary. The function should handle cases where the dictionary is empty by returning `None`. The code should start with: ```python from typing import Dict, Union def find_max_value(input_dict: Dict[s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Union def find_max_value(input_dict: Dict[str, int]) -> Union[int, None]: """ Find the maximum value in a given dictionary. Args: input_dict (Dict[str, int]): A dictionary where keys are st...
code_exercise_27k
2,614
Write a Python function named `is_in_list` that takes two parameters: a list called `my_list` and an element called `element`. The function should return `True` if the element is in the list, and `False` otherwise. The function should be efficient and handle various types of elements, including integers, strings, and o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def is_in_list(my_list: List[Any], element: Any) -> bool: """ Check if an element is in the given list. Args: my_list (List[Any]): The list to check. element (Any): The element ...
code_exercise_27k
2,615
Write a Python function named `count_occurrences` that takes two parameters: a list called `my_list` and an element called `element`. The function should return the number of occurrences of the element in the list. The function should be implemented without using the built-in `count` method. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def count_occurrences(my_list: List[Any], element: Any) -> int: """ Count the number of occurrences of an element in the given list. Args: my_list (List[Any]): The list to count occurre...
code_exercise_27k
2,616
Write a Python function named `is_subset` that takes two parameters: two lists called `list1` and `list2`. The function should return `True` if `list1` is a subset of `list2`, and `False` otherwise. A subset means that every element in `list1` must be present in `list2`. The function should handle lists with duplicate ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_subset(list1: List[int], list2: List[int]) -> bool: """ Check if list1 is a subset of list2. Parameters: list1 (List[int]): The first list. list2 (List[int]): The second list. Re...
code_exercise_27k
2,617
Write a Python function named `remove_duplicates` that takes a list called `my_list` as a parameter. The function should remove any duplicate elements from the list and return the updated list while preserving the order of the elements. The code should start with: ```python from typing import List def remove_duplicate...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates(my_list: List[int]) -> List[int]: """ Remove duplicate elements from the given list while preserving the order of elements. Args: my_list (List[int]): The list to remov...
code_exercise_27k
2,618
Write a Python function named `common_elements` that takes two parameters: two lists called `list1` and `list2`. The function should return a new list containing the common elements between `list1` and `list2`, ensuring that the order of elements in the result list is the same as they appear in `list1`. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def common_elements(list1: List[int], list2: List[int]) -> List[int]: """ Find the common elements between two lists and return them in the order they appear in the first list. Args: list1 (...
code_exercise_27k
2,621
Write a Python function named `is_anagram` that takes two parameters: two strings called `word1` and `word2`. The function should return `True` if `word1` is an anagram of `word2` (contains the same letters in a different order), and `False` otherwise. The function should handle case sensitivity and ignore spaces and p...
Here is the Python code to solve the given problem in the markdown block: ```python def is_anagram(word1: str, word2: str) -> bool: """ Check if word1 is an anagram of word2, ignoring case, spaces, and punctuation. Args: word1 (str): The first word. word2 (str): The second word. Return...
code_exercise_27k
2,625
Write a Python function named `is_subset_strict` that takes two parameters: two lists called `list1` and `list2`. The function should return `True` if `list1` is a strict subset of `list2` (all elements of `list1` are also present in `list2`, but `list2` may have additional elements), and `False` otherwise. The functio...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_subset_strict(list1: List[int], list2: List[int]) -> bool: """ Check if list1 is a strict subset of list2. Parameters: list1 (List[int]): The first list. list2 (List[int]): The second...
code_exercise_27k
2,627
Write a Python function to determine if one string is a subsequence of another string. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. The function should start with: ```python def is_subsequence(str1: str, str2...
Here is the Python code to solve the given problem in the markdown block: ```python def is_subsequence(str1: str, str2: str) -> bool: """ Determines if str1 is a subsequence of str2. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing t...
code_exercise_27k
2,629
Write a Python function named `is_sorted` that takes a list called `my_list` as a parameter. The function should return `True` if the elements in the list are sorted in non-decreasing order, and `False` otherwise. The function should handle lists of any length, including empty lists. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_sorted(my_list: List[int]) -> bool: """ Check if the elements in a list are sorted in non-decreasing order. Args: my_list (List[int]): The list to check. Returns: bool: T...
code_exercise_27k
2,630
Write a Python function named `find_missing_numbers` that takes two parameters: two lists called `list1` and `list2`. The function should return a new list containing the numbers that are present in `list1` but not in `list2`. The function should be efficient and handle edge cases such as empty lists and lists with dup...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_missing_numbers(list1: List[int], list2: List[int]) -> List[int]: """ Find the numbers that are present in list1 but not in list2. Args: list1 (List[int]): The first list of integer...
code_exercise_27k
2,632
Write a Python function named `find_common_elements` that takes two parameters: two lists called `list1` and `list2`. The function should return a new list containing the common elements between `list1` and `list2`, in the order they appear in `list1`. The function should be efficient and avoid unnecessary computations...
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 between two lists and return them in the order they appear in the first list. Args: li...
code_exercise_27k
2,633
Write a Python function named `is_unique_chars` that takes a string called `word` as a parameter. The function should return `True` if all characters in the word are unique (no duplicates), and `False` otherwise. The function should be efficient and avoid using additional data structures like sets or dictionaries for c...
Here is the Python code to solve the given problem in the markdown block: ```python def is_unique_chars(word: str) -> bool: """ Check if all characters in a word are unique. Parameters: word (str): The word to check. Returns: bool: True if all characters in the word are unique, False otherwise...
code_exercise_27k
2,635
Write a Python function named `is_balanced` that takes a string called `expression` as a parameter. 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 function should also handle other types ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_balanced(expression: str) -> bool: """ Check if the parentheses in an expression are balanced. Parameters: expression (str): The expression to check. Returns: bool: True if the parentheses are balanced, ...
code_exercise_27k
2,636
Write a Python function named `find_common_words` that takes two parameters: two lists called `list1` and `list2`. The function should return a new list containing the common words between `list1` and `list2`, sorted in alphabetical order. The function should handle cases where the lists may contain duplicate words and...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_common_words(list1: List[str], list2: List[str]) -> List[str]: """ Find the common words between two lists and return them in alphabetical order. Args: list1 (List[str]): The first ...
code_exercise_27k
2,637
Write a Python function named `is_anagram_strict` that takes two parameters: two strings called `str1` and `str2`. The function should return `True` if `str1` is a strict anagram of `str2` (contains the same characters with the same frequencies), and `False` otherwise. The function should handle case sensitivity and sh...
Here is the Python code to solve the given problem in the markdown block: ```python def is_anagram_strict(str1: str, str2: str) -> bool: """ Check if str1 is a strict anagram of str2. Parameters: str1 (str): The first string. str2 (str): The second string. Returns: bool: True if str1 is a ...
code_exercise_27k
2,643
Write a Python function named `is_subsequence` that takes two parameters: two strings called `str1` and `str2`. The function should return `True` if `str1` is a subsequence of `str2` (all characters in `str1` appear in `str2` in the same order), and `False` otherwise. The function should handle edge cases such as empty...
Here is the Python code to solve the given problem in the markdown block: ```python def is_subsequence(str1: str, str2: str) -> bool: """ Check if str1 is a subsequence of str2. Parameters: str1 (str): The first string to check if it is a subsequence. str2 (str): The second string to check against....
code_exercise_27k
2,644
Write a Python function named `find_unique_chars` that takes a string called `word` as a parameter. The function should return a new string containing the unique characters from the original word, in the order they first appear. The function should be efficient and avoid using additional data structures beyond what is ...
Here is the Python code to solve the given problem in the markdown block: ```python def find_unique_chars(word: str) -> str: """ Find the unique characters in a word while maintaining their order of first appearance. Args: word (str): The input string from which to extract unique characters. R...