check if a string is present in list python code example
Example 1: excel vba check if every substring in list are in string
'VBA function to check if ALL of a list of substrings is contained
'within a string:
Function AllIn(s$, ParamArray checks()) As Boolean
Dim e
For Each e In checks
If 0 = InStrB(s, e) Then Exit Function
Next
AllIn = True
End Function
'-------------------------------------------------------------------
MsgBox AllIn("abcde", "d", c, "a") '<--displays: True
MsgBox AllIn("abcde", "d", c, "z") '<--displays: False
Example 2: python check if list contains
bikes = ['trek', 'redline', 'giant']
'trek' in bikes
Example 3: javascript check if in array
var extensions = ["image/jpeg","image/png","image/gif"];
if(extensions.indexOf("myfiletype") === -1){
alert("Image must be .png, .jpg or .gif");
}
Example 4: check if list contains string python
some_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456']
if any("abc" in s for s in some_list):