[Tutor] list comprehension, testing for multiple conditions

Johann Spies johann.spies at gmail.com
Wed Aug 22 08:29:43 CEST 2012


#start############################################################
import re
exclude = re.compile('vn|vt|^$|^#')
fileName = '/tmp/x'
theFileOpened = open(fileName,'r')
theTextAsList = theFileOpened.readlines()

theTextAsListStripped = []
for aLine in theTextAsList:

    theTextAsListStripped.append(aLine.strip("\n"))

theTextAsListNoVn = [x for x in theTextAsListStripped if not
re.search(exclude,x)]

print theTextAsListNoVn



Regards
Johann
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120822/3815d2d3/attachment.html>


More information about the Tutor mailing list