[Tutor] list comprehension, testing for multiple conditions

Mark Lawrence breamoreboy at yahoo.co.uk
Wed Aug 22 09:39:39 CEST 2012


On 22/08/2012 07:29, Johann Spies wrote:
> #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
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Please no, not a regex for something this simple!!!


-- 
Cheers.

Mark Lawrence.



More information about the Tutor mailing list