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
Post a Comment