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
Sure! Here's a Python code to check if a list of substrings is present in a string:
import re def check_substrings(string, substrings): pattern = r'|'.join(substrings) return re.search(pattern, string) is not None # Example usage string = "hello world banana apple" substrings = ["world", "banana", "apple"] print(check_substrings(string, substrings)) # Output: True string = "hello world banana apple pie" substrings = ["world", "banana", "apple"] print(check_substrings(string, substrings)) # Output: False
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.