0

I'm working on a bit of code that is going to communicate with a beamer. I can ask what the current selected input is and will then get a reply in the form of:

RG1
RG2
VID
etc...

Now I can make a long list of if statements that check against all possible reply but I already have all these replies in a list cause I use the same commands to set the input. What would be a good way of checking if the reply string against that list?

DutchNinja
  • 19
  • 4
  • Do you want `"RG1" in name_list`? – Andrzej Pronobis Jul 26 '16 at 17:00
  • @And I want to check if the current input is the input that I want it to be. Thanks to you guys I came up with: `if Data in Power: if Data != powerstatus: SetPower(powerstatus) if Data in inputsource: if Data != inputstatus: SetInput(inputstatus)` – DutchNinja Jul 26 '16 at 17:15

1 Answers1

1

If you want to check if something is in a list you can use in instead of using an if statement to check for every possibility in the list.

 >>> a_list =['str1', 'str2', 'str3']
 >>> 'str1' in a_list
 ...
 True
Pythonista
  • 11,377
  • 2
  • 31
  • 50