Need help removing list elements.

jwelby julius.welby at gmail.com
Sat Apr 29 10:11:53 EDT 2006


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.




More information about the Python-list mailing list