471,356 Members | 1,657 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

checking for an item in a list

I usually use
Expand|Select|Wrap|Line Numbers
  1. check=False
  2. for i in the listA:
  3.     if i==value
  4.        check= True
  5.  
for checking whether a given values in contained in a list. How can I implement if I define within the context of the original list class with a presumed body of the list method __contains__(self,value).
Oct 8 '07 #1
1 1124
bartonc
6,596 Expert 4TB
I usually use
Expand|Select|Wrap|Line Numbers
  1. check=False
  2. for i in the listA:
  3.     if i==value
  4.        check= True
  5.  
for checking whether a given values in contained in a list. How can I implement if I define within the context of the original list class with a presumed body of the list method __contains__(self,value).
Expand|Select|Wrap|Line Numbers
  1. aList = [1, 2, 3]
  2. if 1 in aList:
  3.     print "it's in there"
Oct 8 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

67 posts views Thread by Steven T. Hatton | last post: by
4 posts views Thread by Darrel | last post: by
5 posts views Thread by Big Blue Ox | last post: by
1 post views Thread by Kevin F | last post: by
8 posts views Thread by Fuzzydave | last post: by
20 posts views Thread by nicolas.pourcelot | last post: by
15 posts views Thread by Marco Bizzarri | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.