How to check whether a list have specific value exist or not?
Sidharth Kuruvila
sidharth.kuruvila at gmail.com
Sat Apr 9 05:53:49 EDT 2005
Hi Prabha,
if 3 in [1, 2, 3, 4]:
print "yes"
Python is an amazing language if you understand that it is actually
quite a bit different from php. The python tutorial is pretty good, I
suggest you go through it.
On Apr 9, 2005 3:07 PM, Michael Spencer <mahs at telcopartners.com> wrote:
> praba kar wrote:
> > Dear All
> > In Php we can find in_array() function
> > which function is mainly useful to check
> > whether a specific value is exist in the array
> > or not.
> >
> > But In python In cannot find any function
> > like that. I want to check a list have specific
> > value or not. So If any one know regarding this
> > mail me
> >
> > with regards
> > PRabahar
> >
> >
> > ________________________________________________________________________
> > Yahoo! India Matrimony: Find your life partner online
> > Go to: http://yahoo.shaadi.com/india-matrimony
>
> No need to ask this list, ask the built-in one:
>
> >>> dir(list)
> ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
> '__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__',
> '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__',
> '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__',
> '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__',
> '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__str__', 'append',
> 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
>
> A minute of two experimenting, would then lead you to:
>
> >>> l = [1,2,3,4,5]
> >>> l.index(3)
> 2
> >>>
>
> Note that all indexing in Python is 0-based
>
> Michael
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://blogs.applibase.net/sidharth
More information about the Python-list
mailing list