python - Read a file, skip unwanted lines & add into a List -


i have following code scan every line , put in list. if line matches string "new changes", don't want put in list. suggestion on how achieve this?

with open('file.txt', 'rb') f:     mainlist = [line.strip() line in f] 

list comprehensions can filtering:

mainlist = [line.strip() line in f if "new changes" not in line] 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -