Search code examples
pythonartificial-intelligence

How can I make this code not use a list or a ton of conditional statements?


I'm making an AI, and I want it to be able to search things. I don't know how to do this efficiently though.

Edit again: I fixed it on my own.

Instead of taking the second word inside of a list which contains every word the output has and added it to a search query. I took the output and removed the first word from it (which is "find", or "search") and then it will add that to the search query. Thanks for all the help.


Solution

  • If that's really all you want:

    words = output.split(' ', 1)
    if words[0] == 'search' and words[1] in Terms:
        print("win")