Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

Implement find_wanted people function which takes a list of names (strings) as argument

  1. User

    Implement find_wanted people function which takes a list of names (strings) as argument

  2. Assistant

    Here is a possible implementation of the "find_wanted_people" function in Python:

    def find_wanted_people(names):
        wanted_people = []
        wanted_keywords = ['wanted', 'criminal']
        
        for name in names:
            # Convert the name to lowercase for case-insensitive keyword search
            lowercase_name = name.lower()
            
            # Check if any of the wanted keywords is present in the name
            if any(keyword in lowercase_name for keyword in wanted_keywords):
                wanted_people.append(name)
        
        return wanted_people
    

    In this implementation, we define a function called "find_wanted_people" that takes a list of names as an argument. We also define a list of wanted keywords, such as 'wanted' or 'criminal'.

    We then iterate over each name in the input list using a for loop. Inside the loop, we convert each name to lowercase using the "lower()" method so that we can perform case-insensitive keyword search.

    Next, we use the "any()" function to check if any of the wanted keywords is present in the lowercase name. The "any()" function returns True if at least one keyword is found.

    If a name contains any of the wanted keywords, we append it to the "wanted_people" list.

    Finally, we return the "wanted_people" list containing the names of wanted people.

    You can call this function by passing a list of names as an argument, like this:

    names = ['John Smith', 'Wanted Criminal', 'Jane Doe']
    wanted_people = find_wanted_people(names)
    print(wanted_people)
    

    This will output the names of wanted people that contain any of the wanted keywords:

    ['Wanted Criminal']