Skip to content
TheChatArchiveThe Chat Archive
Metacodellama-34b-instruct· MetaHugging Face Arena Human Preference 55K

write a python code to check if list of substrings present in a string

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Metallama-2-13b-chat’s answer.
  1. User

    write a python code to check if list of substrings present in a string

  2. Meta 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 False
    

    This 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 returns False.

    Here's an example usage of the function:

    string = "hello world"
    substrings = ["hello", "world"]
    print(contains_substrings(string, substrings)) # Output: True
    

    In this example, the function returns True because the string "hello world" contains the substrings "hello" and "world".

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.