write a python code to check if list of substrings present in a string
- User
write a python code to check if list of substrings present in a string
Assistant
Here is a Python code that checks if a list of substrings is present in a given string:
def contains_substrings(string, substrings): for substring in substrings: if substring in string: return True return FalseThis function takes two arguments:
string: The string to search in.substrings: The list of substrings to search for.
The function loops through the list of substrings and checks if each substring is a substring of the given string. If a substring is found, the function returns
True. If no substring is found, the function returnsFalse.Here's an example usage of the function:
string = "hello world" substrings = ["hello", "world"] print(contains_substrings(string, substrings)) # Output: TrueIn this example, the function returns
Truebecause the string "hello world" contains the substrings "hello" and "world".
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.