What is the most efficient way to do this?

Neal Norwitz neal at metaslash.com
Fri Feb 8 14:55:37 EST 2002


MDK wrote:
> 
> What is the most efficient way to remove empty items from this list?
> 
> ['', '1', '2', '3', '', '456', '789', 'wow']

Assuming python 2.0 or higher:

seq = ['', '1', '2', '3', '', '456', '789', 'wow']
new_list = [ x for x in seq if x ]

Neal



More information about the Python-list mailing list