If you only want to check for the presence of abc
in any string in the list, you could try
some_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456'] if any("abc" in s for s in some_list): # whatever
If you really want to get all the items containing abc
, use
matching = [s for s in some_list if "abc" in s]
Related Posts:
- How to convert list to string [duplicate]
- Why is it string.join(list) instead of list.join(string)?
- Why is it string.join(list) instead of list.join(string)?
- Python: Get the first character of the first string in a list?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- How do I check if there are duplicates in a flat list?
- How to concatenate items in a list to a single string?
- Create nice column output in python
- How does str(list) work?
- Python cant convert ‘list’ object to str error [closed]
- How do I lowercase a string in Python?
- How can I reverse a list in Python?
- Difference between del, remove, and pop on lists
- What is the difference between Python’s list methods append and extend?
- Understanding slice notation
- Understanding slice notation
- How do I get a substring of a string in Python?
- How to read a file line-by-line into a list?
- strip(char) on a string
- How do I get the number of elements in a list?
- Finding the index of an item in a list
- How to make a flat list out of a list of lists
- Print string to text file
- Removing duplicates in lists
- Best way to convert string to bytes in Python 3?
- TypeError: ‘float’ object is not subscriptable
- Transpose/Unzip Function (inverse of zip)?
- How do I append one string to another in Python?
- How can I split and parse a string in Python?
- How to read a text file into a string variable and strip newlines?
- How to print like printf in Python3?
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- Finding the average of a list
- Print a list in reverse order with range()?
- Get unique values from a list in python [duplicate]
- write() versus writelines() and concatenated strings
- How do I concatenate two lists in Python?
- if else in a list comprehension
- Python set to list
- Python List vs. Array – when to use?
- Split string with multiple delimiters in Python [duplicate]
- How to find all occurrences of an element in a list
- How to find all the indexes of a recurring item in a list?
- How to find all occurrences of a substring?
- How do I concatenate two lists in Python?
- How to check whether a str(variable) is empty or not?
- Replace values in list using Python
- What does the ‘b’ character do in front of a string literal?
- Check string “None” or “not” in Python 2.7
- Remove all special characters, punctuation and spaces from string
- How to convert string to binary?
- How do I find the duplicates in a list and create another list with them?
- How to remove an element from a list by index
- Convert hex to binary
- Apply function to each element of a list
- Remove all occurrences of a value from a list?
- TypeError: list indices must be integers or slices, not str
- Best way to replace multiple characters in a string?
- How do I remove a substring from the end of a string?
- In Python, when to use a Dictionary, List or Set?
- Check if two unordered lists are equal
- Detect whether a Python string is a number or a letter
- Finding all possible permutations of a given string in python
- ‘list’ object has no attribute ‘shape’
- How do I find the duplicates in a list and create another list with them?
- How can I compare two lists in python and return matches
- How can I get list of values from dict?
- How do I append one string to another in Python?
- How to sort a list of objects based on an attribute of the objects?
- How do you split a list into evenly sized chunks?
- Count the number of occurrences of a character in a string
- How to return dictionary keys as a list in Python?
- Subtracting two lists in Python
- How can I find the first occurrence of a sub-string in a python string?
- Get the cartesian product of a series of lists?
- Replacing a character from a certain index
- What does the “x for x in” syntax mean?
- numpy-equivalent of list.pop?
- Convert a Unicode string to a string in Python (containing extra symbols)python string unicode type-conversion
- TypeError: only integer arrays with one element can be converted to an index 3
- TypeError: decoding str is not supported
- AttributeError: ‘str’ object has no attribute ‘items’
- Logical indexing with lists
- convert csv file to list of dictionaries
- What is the difference between a string and a byte string?
- How to strip a specific word from a string?
- How to split elements of a list?
- Find object in list that has attribute equal to some value (that meets any condition)
- Turn a single number into single digits Python
- Iterating through list of list in Python
- Get difference between two lists
- How is Python’s List Implemented?
- Using strip() to clean up a string
- Python code to remove HTML tags from a string
- Sorting list based on values from another list
- Create a list with initial capacity in Python
- Cannot concatenate ‘str’ and ‘float’ objects?
- How to repeat individual characters in strings in Python