[Tutor] Removing certain sequences from a string list elements
varsha.purohit at gmail.com
Sat Jan 7 02:08:54 CET 2012
I have a simple python program where I am comparing two log files and I am
storing the differences in a list. I am programming in python after a long
time so may be I might have not written something very efficient. Please
let me know what alternate solution I can apply for my program.
I am reading each line in the file individually and storing them in a list.
After that i am comparing the two lists and printing out the differences.
But I wanted to know how can I iter through each string in the list and
remove certain sequences like \n and ',' comma. I want to basically
printout a column where it has each element of the list in each row.
It should also avoid priting the time stamp since they will be different
anyway. i want the program as simple as it looks right now.
Input file contains something like this in each line. I have not included
the complete log file.
* vendorId/deviceId=1000/005b, subVendorId/subDeviceId=1000/9285, OEM=1,
* MFCF: disableSAS=0, maxDisks=0, enableRaid6=1, disableWideCache=0*
* disableRaid5=0, enableSecurity=0, enableReducedFeatureSet=0*
* enableCTIO=0 enableSnapshot=1 enableSSC=1 enableCacheOffload=0*
here is the program
f1 = open('mfc_node1.txt',"r")
lines = f1.read().split(" ")
q = 
for line in lines:
if not line in q:
f = open('mfc_node2.txt',"r")
lines = f.read().split(" ")
p = 
for line in lines:
if not line in p:
if __name__ == "__main__":
q = readList1()
p = readList2()
newList = 
for x in q:
if x not in p:
Here is the part of the output list
['enableCTIO=0,', 'enableSnapshot=1,', 'enableSSC=1,', 'maxHANodes=0\n',
'sasAddr=5123456712345678\nSecondary', 'enableSnapshot=0,', 'enableSSC=0,',
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor