How to check if an element exists in an array in Python