SomeKittens SomeKittens - 2 years ago 77
Python Question

Check if item is in an array

If I've got an array of strings, can I check to see if a string is in the array without doing a

loop? Specifically, I'm looking for a way to do it within an
statement, so something like this:

if [check that item is in array]:

Answer Source

Assuming you mean "list" where you say "array", you can do

if item in my_list:
    # whatever
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download