Created
November 1, 2017 02:40
-
-
Save shau-lok/9606c7b9cfa3515148e5cb6e53e6f672 to your computer and use it in GitHub Desktop.
Check if a Python list item contains a string inside another string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check if a Python list item contains a string inside another string | |
# 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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@FeliciaXmL