DekGenius.com
PYTHON
check if anything in a list is in a string python
y = any(x in String for x in List)
how to check if any item in list is in anoter list
# checking all elements of list_B in list_A
list_A = [1, 2, 3, 4]
list_B = [2, 3]
check = any(item in list_A for item in list_B)
print(check)
# True
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 python
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 check if string or list
isinstance(some_object, str)
string is in list? python
x = "a"
xlist = ["a", ]
if x in xlist:
print(x)
python 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']
© 2022 Copyright:
DekGenius.com