I have a dataset with following format:
a. 1 w p1,p2,w3 b. 1 w p1,p2,p3, w3 c. 1 w p1,w3 d. 1 w p1,w3
I want to print only the lines where 'p1,w3' present but not any of lines where p1, w3 are present in combination with other members like p1,p2,w3 ...
c. 1 w p1,w3 d. 1 w p1,w3
Here what I'm doing:
with open("file.txt",'rU') as lines: for line in lines: line = line.split('\t') line1 = line[-1].split(',') for gen in line1: if 'p1' and 'w3' in gen: print(line)
it prints all lines including unwanted lines (a and b), any tips/ideas? are welcome thanks.