DekGenius.com
PYTHON
python list contains substring
str_list = ["one", "two", "three"]
substr = "wo"
if any(substr in str for str in str_list):
print('Yes!')
check if anything in a list is in a string python
y = any(x in String for x in List)
if list item in string python
if any(ext in url_string for ext in extensionsToCheck):
print(url_string)
python check if list contains
# To check if a certain element is contained in a list use 'in'
bikes = ['trek', 'redline', 'giant']
'trek' in bikes
# Output:
# True
python check if list contains value
if value in list:
#do stuff
#Also to check if it doesn't contain
if value not in list:
#do stuff
if string in list py
string = "hello"
list = ["bye", "kasd", "hello", "day", "hel"]
if string in list:
print(f"Found '{string}' in '{list}'!")
else:
print(f"Couldnt find '{string}' in '{list}'!")
>>> Found 'hello' in '["bye", "kasd", "hello", "day", "hel"]'!
python list contains string
str in strList
# example
if 'qwe' in strList:
print('Yes!')
python list contains
list_ = ['a','b','c']
'a' in list_ #returns True
'd' in list_ #returns False
python check if string is in a list
# Gives True/False if a string is in a list.
input = 'hello'
result = input in ['greetings', 'and', 'hello', 'sir']
print(result)
if list element contains string python
matchers = ['abc','def']
matching = [s for s in my_list if any(xs in s for xs in matchers)]
Output:
['abc-123', 'def-456', 'abc-456']
string contains element of list python
extensionsToCheck = ('.pdf', '.doc', '.xls')
'test.doc'.endswith(extensionsToCheck) # returns True
'test.jpg'.endswith(extensionsToCheck) # returns False
© 2022 Copyright:
DekGenius.com