To check for the presence of 'abc' in any string in the list:

xs = ['abc-123', 'def-456', 'ghi-789', 'abc-456']

if any("abc" in s for s in xs):
    ...

To get all the items containing 'abc':

matching = [s for s in xs if "abc" in s]
Answer from Sven Marnach on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-find-string-in-list
Python Find String in List: Methods and Examples | DigitalOcean
1 month ago - A common point of confusion is that in on a list checks for an exact match, when you may just want to know whether any element contains a target substring. The following patterns solve this and let you choose the result you need: the matching elements, a True/False answer, or just the first match. Use a list comprehension with the in operator (which does check for substrings inside individual strings) to collect every element that contains the target text:
Discussions

Help!: Check if a Python list item contains a string inside another string but with conditions
Here's two possibilities. If the way you get it done isn't important, you could use a regex because writing string parsing code is always sorta annoying. The regex [aeiou]*[f][aeiou]* would work I think. It matches any number of vowels, then a single "f", and then any number of vowels again. There's also another option. You have two conditions. It seems you want a single "f", which can be checked via word.count("f") == 1 and that every letter (excluding the "f") be a vowel. Essentially, every letter should pass letter == "f" or letter in "aeiou". To check every letter, you can utilize the built-in Python functionall(...). Checking that both these conditions hold, you should get the desired result. More on reddit.com
🌐 r/learnpython
6
1
January 13, 2021
How to check if a string contains an element from a list in Python - Stack Overflow
I am wondering what would be the ... this in Python (without using the for loop)? I was thinking of something like this (like from C/C++), but it didn't work: Copyif ('.pdf' or '.doc' or '.xls') in url_string: print(url_string) Edit: I'm kinda forced to explain how this is different to the question below which is marked as potential duplicate (so it doesn't get closed I guess). The difference is, I wanted to check if a string is part of some list of strings ... More on stackoverflow.com
🌐 stackoverflow.com
Check contain string, and move the rest element to new list
I have a question related to a specific string being moved to new list. IF I have list like [“hello”, “world”, “====”,“my”, “name”,“is”,“XXX”], After “====”, the rest of the element will append to a new list so there are two new lists, listnew1 will store => ... More on discuss.python.org
🌐 discuss.python.org
11
0
February 2, 2023
How to check if a string contains a character in a list
Use a loop , iterate through the list, check for existence of the character . More on reddit.com
🌐 r/learnpython
7
2
February 19, 2022
🌐
Reddit
reddit.com › r/learnpython › how to check if any element in a list contains a substring
r/learnpython on Reddit: How to check if any element in a list contains a substring
October 28, 2019 -

Say I have a list of strings like: ["Hey dude", "Hey bro", "Sup dude", "Hey bud"]

How do I check if *any* of those strings in the list contain the word "Sup"?Alternatively, in my case, I could also check if *all* of the strings contain "Hey" , which I also don't know how to do.

(Sorry, I'm new to Python)

Edit: Thank you so much for all the help, guys <3

🌐
Delft Stack
delftstack.com › home › howto › python › python list contains string
How to Check if List Contains a String in Python | Delft Stack
February 2, 2024 - In the above code, list comprehension is used to search for strings having a in the list py_list. Note that writing the same code using other functions or loops would have taken more time, as more code is required for their implementation, but list comprehension solves that problem.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-test-if-string-contains-element-from-list
Python - Test if string contains element from list - GeeksforGeeks
July 11, 2025 - Testing if string contains an element from list is checking whether any of the individual items in a list appear within a given string. any() is the most efficient way to check if any element from the list is present in the list.
🌐
Stack Abuse
stackabuse.com › bytes › check-if-a-string-contains-an-element-from-a-list-in-python
Check if a String Contains an Element from a List in Python
October 6, 2023 - def check_string_for_list_elements(string, list): return any(str(i) in string for i in list) print(check_string_for_list_elements("I love Python programming and the number 3", [1, 2, 3])) This will return True as the number 3 is present in the string. It'll work since we first convert all items to string first using str(). Unlike JavaScript, Python won't do the conversion for you. In this Byte, we've explored three different methods to check if a string contains any element from a list in Python.
🌐
Flexiple
flexiple.com › python › python-list-contains
Python list contains: How to check if an item exists in list? - Flexiple
For checking if an element exists in a list, Python developers typically use the in operator , the count() method, or implement a loop to iterate through the list to check for the presence of an element.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › help!: check if a python list item contains a string inside another string but with conditions
r/learnpython on Reddit: Help!: Check if a Python list item contains a string inside another string but with conditions
January 13, 2021 -

I have two days learning python but I really need to do that code. I also posted this question in StackOverflow but it got downvoted the first second.

I want to make a function to print all the words that contain a specific consonant (only one) and any amount of vowels, but I don't know how to introduce the conditions here.

I made a list with 4 elements via the input method (I know I use a different way), and a method that prints all the words that include the letter "f", but as I said, it needs to be more specific (only one consonant, "f" in this case, and any amount of vowels):

list = []  
for x in range (4):     
    words = str(input("Type a word "))     
    list.append(words)  

#This method kinda works, but it needs to be more specific.   
matching = [s for s in list if "f" in s] 
print(matching) 

In my code, if I have words with the letter "f", I'll get a list with all the words containing any amount of "f" letters and any other consonant, but I just want one consonant "f" and vowels, not the other consonants.

My desired result is like

list = [fox, alfa, fa, real, fou]

#['fa', 'fou']

🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-find-the-string-in-a-list
Python program to find String in a List - GeeksforGeeks
July 23, 2025 - a = ['Learn', 'Python', 'With', 'GFG'] found = False for item in a: if item == 'Python': found = True break if found: print("String found!") else: print("String not found!") ... String found! The for loop iterates through the list and checks each element against the target string. While slower than the in operator, it gives us a greater control over the process. List comprehensions allow us to create a new list containing matching elements.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-check-if-string-contains-element-from-list
Check if a String contains an Element from a List in Python | bobbyhadz
Copied!my_list = ['BOBBY', 'HADZ', 'COM'] substring = 'z' result = any(substring.lower() in word.lower() for word in my_list) print(result) # 👉️ True if any(substring.lower() in word.lower() for word in my_list): # 👇️ this runs print('The substring is contained in at least one of the list items') else: print('The substring is NOT contained in any of the list items') The str.lower method returns a copy of the string with all the cased characters converted to lowercase. The method doesn't change the original string, it returns a new string. Strings are immutable in Python.
🌐
Python.org
discuss.python.org › python help
Check contain string, and move the rest element to new list - Python Help - Discussions on Python.org
February 2, 2023 - I have a question related to a specific string being moved to new list. IF I have list like [“hello”, “world”, “====”,“my”, “name”,“is”,“XXX”], After “====”, the rest of the element will append to a new list so there are two new lists, listnew1 will store => ...
🌐
Reddit
reddit.com › r/learnpython › how to check if a string contains a character in a list
r/learnpython on Reddit: How to check if a string contains a character in a list
February 19, 2022 -

I'm really new to python and i'm having some trouble figuring out how to check if a list contains a certain character.

For example:
list = ['a1', 'a2', 'b1', 'b2', 'a3', 'a5', 'c3']

how would I check to see what elements contain the string 'a'? sorry if i didn't word my question properly i'm still very new to coding, but any help would be appreciated.

🌐
LabEx
labex.io › tutorials › python-how-to-check-if-a-list-contains-a-string-in-python-559525
How to Check If a List Contains a String in Python | LabEx
In this step, you will learn how to use the any() function in combination with the isinstance() function to check if any element in a list is an instance of a specific data type, such as a string.
🌐
AskPython
askpython.com › python › list › find-string-in-list-python
Find a string in a List in Python - AskPython
February 16, 2023 - In the following example, we’ll consider a list of strings and search for the substring “Hello” in all elements of the list. ... We can use a list comprehension to find all elements in the list that contain the substring “Hello“. The syntax is as follows:
🌐
Stack Abuse
stackabuse.com › python-check-if-array-or-list-contains-element-or-value
Python: Check if Array/List Contains Element/Value
February 27, 2023 - We can use a lambda function here to check for our 'Bird' string in the animals list. Then, we wrap the results in a list() since the filter() method returns a filter object, not the results. If we pack the filter object in a list, it'll contain the elements left after filtering:
🌐
TutorialsPoint
tutorialspoint.com › python-find-index-containing-string-in-list
Python - Find Index Containing String in List
August 16, 2023 - The goal is to find indices 1, 2, 5, 7 where strings are located in this mixed list. The most straightforward approach uses a for loop to check each element's type and collect string indices ?
🌐
TutorialsPoint
tutorialspoint.com › python-program-to-test-if-string-contains-element-from-list
Python program to find the String in a List
January 27, 2023 - For partial string matching or more complex conditions, use any() with list comprehension ? words = ['programming', 'python', 'coding', 'development'] substring = 'prog' # Check if any word contains the substring found = any(substring in word for word in words) print(f"Words containing '{substring}': {found}") # Find all words containing the substring matching_words = [word for word in words if substring in word] print(f"Matching words: {matching_words}")
🌐
w3resource
w3resource.com › python-exercises › list › python-data-type-list-exercise-201.php
Python: Check if a given string contains an element, which is present in a list - w3resource
November 3, 2023 - # For each 'el', check if it is present in the string 'str1'. result = [el for el in lst if (el in str1)] # Return a boolean indicating whether the 'result' list is not empty (i.e., if any element was found in the string). return bool(result) # Define a string 'str1' and a list 'lst' containing substrings. str1 = "https://www.w3resource.com/python-exercises/list/" lst = ['.com', '.edu', '.tv'] # Print a message indicating the original string and list.
🌐
GeeksforGeeks
geeksforgeeks.org › python-finding-strings-with-given-substring-in-list
Finding Strings with Given Substring in List - Python - GeeksforGeeks
January 31, 2025 - For example, given a list a = ['GeeksforGeeks', 'Geeky', 'Computers', 'Algorithms'], the task would be to check if a substring like 'Geek' exists. filter() is the efficient built-in method that allows us to filter elements in an iterable based on a condition. When combined with a lambda function, it becomes an elegant way to find strings containing a specific substring.