List search

Stefan Bellon sbellon at sbellon.de
Fri Sep 28 16:56:03 EDT 2007


On Fri, 28 Sep, Kevin Walzer wrote:

> I'm having a problem with searching a list. Here's my code:
> 
> mylist = ['x11', 'x11-wm', 'x11-system']
> 
> for line in mylist:
> 	if 'x11' in line:
> 		print line

Just compare for equality:

       if line == 'x11':

or

print "\n".join(x for x in mylist if x == 'x11')

-- 
Stefan Bellon



More information about the Python-list mailing list