print [s for s in list if sub in s]

If you want them separated by newlines:

print "\n".join(s for s in list if sub in s)

Full example, with case insensitivity:

mylist = ['abc123', 'def456', 'ghi789', 'ABC987', 'aBc654']
sub = 'abc'

print "\n".join(s for s in mylist if sub.lower() in s.lower())
Answer from David Robinson on Stack Overflow
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-find-string-in-list
Python Find String in List: Methods and Examples | DigitalOcean
June 16, 2026 - Every example runs in a standard Python 3.6+ environment (tested on the latest stable release, Python 3.14) and uses only the standard library, with no extra packages. ... Use the in operator ("target" in my_list) for a fast, easy-to-read check; it returns True or False. On a list, in checks for an exact match, not a partial one. So "app" in ["apple"] is False. Use list.index("target") to get the position of the first match. Wrap it in a try/except ValueError block, since it raises an error when the string is not there. To find all matching positions, use a list comprehension with enumerate(): [i for i, val in enumerate(my_list) if val == "target"].
๐ŸŒ
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 - The 'in' operator is the simplest and fastest way to check if a string exists in a list. It is efficient and widely used for this purpose. ... a = ['Learn', 'Python', 'With', 'GFG'] if 'Python' in a: print("String found!") else: print("String ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ find a string in a list of lists...
r/learnpython on Reddit: Find a string in a list of lists...
April 18, 2022 -

I'm SO close to a solution I can taste it - but still not quite there ;)

I collect an input phrase from the user, and then search for the phrase in each list individually. Depending if the phrase is in the list, it calls a specific function.

But I also need to check if the phrase is in ANY of the lists (and if it's not I'll display an error message). I've arrived at the following:

value = "the date"

status_strings = ["how are you",
                            "are you ok"]
time_strings = ["what is the time",
                            "current time",
                            "time is it"]
date_strings = ["what is today's date",
                            "what day is it",
                            "current date",
                            "the date"]
alarm_strings = ["set an alarm",
                            "wake me up",
                            "wake up"]

for x in (status_strings,time_strings,date_strings,alarm_strings):
  if value not in x:
    print(False)

The output for this is of course, False False False - because the value is in one of the lists - but I don't want it to return False for EVERY list that it's not in, but only once, if it's not in ANY of the lists.

Can anyone help me get on the right path?

Edit: The solution was to change the 'for' loop a bit (thanks u/Allanon001):

if not any(value in x for x in (status_strings,time_strings,date_strings,alarm_strings)):
  print("BOOYAH")
Top answer
1 of 5
3
I suggest giving a better name than "x" to your variable when you're doing iterations "a la foreach", it'll help you keep in mind what you're manipulating (you, or the person who'll read your code) For instance here, x is a list of strings. So you're iterating over a list of lists of strings What you want is to iterate inside each of these lists ... I think I gave you a clue :) let me know if that ain't helping Also, I'm not sure you're doing it the "pythonista way", I'm curious to see if someone can suggest another approach for this Edit : I might have misunderstood your problem lol. You might just want to add a return or a break in your if condition Actually I suggest declaring a var initialised at false before the loop, updating it to true if it's detected, and after the loop using its updated value
2 of 5
2
Use all(): https://docs.python.org/3/library/functions.html#all I misread your post. What you should be using is any(): https://docs.python.org/3/library/functions.html#any Let's say we add another variable to you code list_of_lists = [status_strings, time_strings, date_strings, alarm_strings] Using a generator: result = any(value in sublist for sublist in list_of_lists) or using a for loop: true_false_list = [] for sublist in list_of_lists: true_false_list.append(value in sublist) result = any(true_false_list) In either case, it will return True if any item in the iterable is truthy. If none of the items in the iterable a truthy, it will return False.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ string-find
Python string.find(): Syntax, Usage, and Examples
The method specifically returns ... methods in languages like Java or JavaScript. The .find() method is a built-in string method used to locate the starting index of the first occurrence of a substring within another string....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-finding-strings-with-given-substring-in-list
Finding Strings with Given Substring in List - Python - GeeksforGeeks
July 11, 2025 - Explanation :re.findall() checks for occurrences of the substring b in each string of a. If a match is found, the string is included in the list res.
๐ŸŒ
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

Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_string_find.asp
Python String find() Method
Remove List Duplicates Reverse ... Python Interview Q&A Python Bootcamp Python Training ... The find() method finds the first occurrence of the specified value....
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-find-in-list-how-to-find-the-index-of-an-item-or-element-in-a-list
Python Find in List โ€“ How to Find the Index of an Item or Element in a List
February 24, 2022 - programming_languages = ["JavaScript","Python","Java","Python","C++","Python"] python_indices = [] for programming_language in range(len(programming_languages)): if programming_languages[programming_language] == "Python": python_indices.append(programming_language) print(python_indices) #output #[1, 3, 5] Another way to find the indices of all the occurrences of a particular item is to use list comprehension. List comprehension is a way to create a new list based on an existing list. Here is how you would get all indices of each occurrence of the string "Python", using list comprehension:
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ practicing-string-operations-and-type-conversions-in-python โ€บ lessons โ€บ exploring-substring-search-in-python-strings
Exploring Substring Search in Python Strings
We'll learn how to locate all occurrences of a substring within a larger string using Python. The techniques you will learn can be used in scenarios such as text processing and data analysis. Are you ready to dive in? Let's get started! ... Here's our challenge: we have two lists of strings of the same length, one containing the "original" strings and the other, the "substrings".
๐ŸŒ
Quora
quora.com โ€บ How-do-I-check-if-a-string-is-in-a-list-in-Python
How to check if a string is in a list in Python - Quora
Answer (1 of 2): How do I check if a string is in a list in Python? You can do it with a conditional โ€˜ifโ€™ statement in this way: [code]# List of string listOfStrings = ['Hi' , 'hello', 'at', 'this', 'there', 'from'] if 'at' in listOfStrings : print("Yes, 'at' found in List : " , listOfString...
๐ŸŒ
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:
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ python-substring-indexof
5 Ways to Find the Index of a Substring in Python | Built In
Complete guide on using string methods and regexes in Python to find the index of a substring. Learn all five methods.
๐ŸŒ
Python.org
discuss.python.org โ€บ ideas
Adding the method find() to list - Ideas - Discussions on Python.org
May 6, 2020 - Now the real topic: . . . โ€œโ€" PROBLEM: When trying to search the position of an element inside a list, we should use the in operator to first check if the element exists, and then use the index method to obtain the index. in (__contains__) ...
๐ŸŒ
Real Python
realpython.com โ€บ python-string-contains-substring
How to Check if a Python String Contains a Substring โ€“ Real Python
December 1, 2024 - By using re.findall(), you can find all the matches of the pattern in your text. Python saves all the matches as strings in a list for you.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ re.html
re โ€” Regular expression operations
May 25, 2026 - The result depends on the number of capturing groups in the pattern. If there are no groups, return a list of strings matching the whole pattern. If there is exactly one group, return a list of strings matching that group. If multiple groups are present, return a list of tuples of strings matching the groups. Non-capturing groups do not affect the form of the result. >>> re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest') ['foot', 'fell', 'fastest'] >>> re.findall(r'(\w+)=(\d+)', 'set width=20 and height=10') [('width', '20'), ('height', '10')]
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-find-all-the-strings-that-are-substrings-to-the-given-list-of-strings
Python - Find all the strings that are substrings to the given list of strings - GeeksforGeeks
April 21, 2023 - In this, we perform task of using nested loop and testing using list comprehension, extracting the string if its part of any substring of other list. ... # Python3 code to demonstrate working of # Substring Intersections # Using list comprehension # initializing lists test_list1 = ["Geeksforgeeks", "best", "for", "geeks"] test_list2 = ["Geeks", "win", "or", "learn"] # printing original lists print("The original list 1 is : " + str(test_list1)) print("The original list 2 is : " + str(test_list2)) # using list comprehension for nested loops res = list( set([ele1 for sub1 in test_list1 for ele1 in test_list2 if ele1 in sub1])) # printing result print("Substrings Intersections : " + str(res))
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ python string find()
Python String find() - AskPython
January 28, 2020 - We can also use negative indexing to mention offsets from the end of the string. For example, test_string = "Hello from AskPython" # Will search from the first to the # second last position print(test_string.find('AskPython', 0, -1)) # Will search from index 5 to len(str) - 1 print(test_string.find('from', 5, -1))
๐ŸŒ
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 - Another way you can check if an element is present is to filter out everything other than that element, just like sifting through sand and checking if there are any shells left in the end. The built-in filter() method accepts a lambda function and a list as its arguments. We can use a lambda ...