Checking String Start Character Using Lambda
Write a Python program that uses a lambda function to check if a given string starts with a specified character. The function should return True if the string starts with the specified character, and False otherwise.
Example 1:
Input: 'hello', 'h' Output: True
Example 2:
Input: 'world', 'x' Output: False
Use a lambda function to create an anonymous function that checks whether a string starts with a specified character.
# Define the lambda function check_start_char = lambda s, c: True if s[0].lower() == c.lower() else False # Test the function print(check_start_char('hello', 'h')) # Output: True print(check_start_char('world', 'x')) # Output: False
Unlock AI & Data Science treasures. Log in!