[Tutor] simple list query

Bill Kranec billk at fastmail.fm
Sun Jan 2 18:31:23 CET 2005


You might want to try:

x in list

this will return true if, for example,  list = [x,y,z,w], false if list 
= [y,y,y,y]

Bill

Dave S wrote:

> OK simple query,
>
> I have a list consisting of about 250 items, I need to know if a 
> particular item is in the list. I know this is better suited to  a 
> dictionary but thats not the way it ended up ;-)
>
> I could do a for loop to scan the list & compare each one, but I have 
> a suspission that there is a better way ?
>
> Any suggestions
>
> Dave
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list