A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/296396.html below:

is there a better way to check an array?

is there a better way to check an array? is there a better way to check an array?Benjamin Niemann pink at odahoda.de
Thu Sep 1 13:13:37 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
> 
> # throw expception if field is required and is empty
> if(product[k] == '' and fieldIsRequired):
>     raise GMError(k + ' is required')

if product[k] == '' and k in fieldIsRequired:
    raise GMError(k + ' is required')

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4