Re: Need help removing list elements.
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Need help removing list elements.

From: jwelby <julius.welby@gmail.com>
Date: Sat Apr 29 2006 - 16:11:53 CEST

This looks like a job for list comprehensions:

>>> returned_lines= ['Name: John, Value: 12','We don't want this one.','Name: Eric, Value: 24']
>>> [x for x in returned_lines if ('Name' in x and 'Value' in x)]
['Name: John, Value: 12', 'Name: Eric, Value: 24']

List comprehensions are great. If you are not familiar with them, check
out the Python documentation. Once you get started with them, you won't
look back.
Received on Mon May 1 00:43:41 2006