-1

I want to make my program search the list for any of the keywords in my list, I just dont know the code.

acceptedyes_list = ["yes", "yeah", "Yes" , "Yeah"]

acceptedno_list = ["No", "no"]

if QuoteReplay_str != (this is where I need my program to search the list, and if any of the words that the user types isnt in the list, itll execute something else.)

blhsing
  • 91,368
  • 6
  • 71
  • 106
amerivi
  • 23
  • 3

1 Answers1

1

You can try like this, I have shown 2 ways.

This problem has already been marked as duplicated but I have just tried to help you because this is just a simple problem based on if-else logic and it seems after many attempts you couldn't figure out the issue.

You can try to run solution online at https://rextester.com/YBIMI61989.

1st way »

if QuoteReplay_str in acceptedyes_list:
    print("You accepted") 
elif QuoteReplay_str in acceptedno_list:
    print("You did not accept") 
else:
    print("You entered wrong choice") 

2nd way (1 line) »

You can also accomplish this using lambda function (just in a single line) as follows:

message = (lambda s:"You accepted" if s in acceptedyes_list else "You did not accept" if s in acceptedno_list else "You entered wrong choice")(QuoteReplay_str) 
print (message) 
hygull
  • 8,464
  • 2
  • 43
  • 52
  • 1
    thank you, I had tried If whatever != acceptedyes_list but it didnt work. – amerivi Apr 30 '19 at 22:17
  • You cannot compare string with list directly using `!=`, please have a little look at my answer. It is better to use `in` (membership operator) for this. – hygull Apr 30 '19 at 22:19
  • You can also have a look at the use of lambda function(2nd way) in case if want to accomplish this work in one line. – hygull Apr 30 '19 at 22:21
  • 1
    thank you for all your help! – amerivi Apr 30 '19 at 22:27
  • Thank you very much but please mention the main reason of asking question next. What you tried, what you got etc. Otherwise you will be downvoted. So next time keep this in mind. You are newbie so no problem, it happens. – hygull Apr 30 '19 at 22:30