[Tutor] removing from a list

Lloyd Kvam pythonTutor at venix.com
Fri Aug 13 14:25:17 CEST 2004


On Thu, 2004-08-12 at 23:17, Chad Crabtree wrote:
> Lloyd Kvam wrote:
> 
> >
> >a = [each for each in a if each not in ("that",5)]
> >
> >  
> >
> This comprehension blew my Mind.  Let me paraphrase this and please 
> correct me if I'm wronng.
> 
> return every 'each' in a if that 'each' is not that or 5?
> 
> is that right?

Correct.  I did not actually test it.  If you look back in the thread
you'll see the sample data for the list named a, and the code this was
derived from.  This is the style I normally use now when removing
elements from a list:
	use a list comprehension based on the original list
	bind it to the original name
> 
> 
> 		
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - You care about security. So do we.
> http://promotions.yahoo.com/new_mail
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-- 

Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-653-8139
fax:	801-459-9582



More information about the Tutor mailing list