python - Evaluating the next line in a For Loop while in the current iteration -
here trying do: trying solve issue has wrapping in text file. i want open txt file, read line , if line contains want contain, check next line see if not contain in first line. if not, add line first line. import re stuff = open("my file") line in stuff: if re.search("from ", line): first = line print first if re.search('from ', handle.next()): continue else: first = first + handle.next() else: continue i have looked quite few things , cannot seem find answer. please help! i try this, invalid triples of "from " , not elegant @ all. lines = open("file", 'r').readlines() lines2 = open("file2", 'w') counter_list=[] last_from = 0 counter, line in enumerate(lines): if "from " in line , counter != last_from +1: last_from = counter current_count = counter if current_coun