Re: Python "member of" function
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Python "member of" function

From: Erik Max Francis <max@alcyone.com>
Date: Sat Apr 29 2006 - 12:38:11 CEST

brianlum@gmail.com wrote:

> I was wondering if anyone knew of a built in Python function that will
> check if an item is a member of a list, i.e., if item i is a member of
> list l.
>
> I read of a function "in" but I can't seem to get that to work and
> finding pages for "python in" does not reveal very many relevant
> sources.

Yes, `in` is the relevant operator. It's quite simple to use:

>>> a = [1, 4, 9, 16, 25]
>>> 2 in a
False
>>> 4 in a
True

If you're having problems using it in some circumstance, you'll have to
be specific.

-- 
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   No man quite believes in any other man.
   -- H.L. Mencken
Received on Mon May 1 00:43:10 2006