How to Check if an Item in a List Contains a Letter in Python?

Estimated read time 1 min read

To check if an item in a list contains a letter in Python, you can use a loop with the in keyword to check each item in the list for the presence of the letter. Here’s an example:

my_list = ["apple", "banana", "cherry", "orange"]

for item in my_list:
    if "a" in item:
        print(item)

This code will loop through each item in my_list and check if the letter “a” is present in the item. If it is, the item will be printed to the console. You can replace the letter “a” with any other letter or combination of letters that you want to check for.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply