is there a better way to check an array?
Robert Kern
rkern at ucsd.edu
Thu Sep 1 13:10:59 EDT 2005
jdonnell wrote:
> I want to check if a value is in an array. I'm currently doing it as
> follows, but I just don't like this way of doing it. It seems
> unpythonic.
>
> fieldIsRequired = true
> try:
> notRequiredAry.index(k)
> fieldIsRequired = false
> except ValueError:
> pass
fieldIsRequired = not (k in notRequiredAry)
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
More information about the Python-list
mailing list