for line in file:
    line = line.strip()
llist = line.split()
if llist and llist[0] == 'NUMS':
    for line in file:
        line = line.strip()
if line == 'END':
    break
How to read ahead in a file when looping through it with Python?