remove all elements in a list with a particular value

James Stroud jstroud at mbi.ucla.edu
Wed May 16 21:33:02 EDT 2007


John Zenger wrote:
>>>>print [x for x in items if x != '']
> 
> ['SRCPARAM', '1', '6.35e-07', '15.00', '340.00', '1.10', '3.0']
> 

This can be shortened to

      [x for x in items if x]

James



More information about the Python-list mailing list