Q:

Python 3: find line and skip the first match

I have a pretty long file in which I have to look for a particular value. The problem is that this file has two lines that starts the same way but I need to print the second one.
The file is something like:
... random text
Total = 910 K. #Don't need it
... more random lines
Total = 1000 K #The one I need it

I'm using:
for i,line in enumerate(lines):
    if line.find('Total =') != -1:
        Total = line.split()[4]
        break

But this is only giving me the first match.
How can I skip the fist match and just use the second one?

A:

Probably not the best solution but you could use a flag to check if you've already found the first occurance
is_second_occurance = False
for i,line in enumerate(lines):
    if line.find('Total =') != -1:
        if is_second_occurance:
            total = line.split()[4]
            break
        else:
            is_second_occurance = True

A better solution is probably to break it into a function that returns a generator
def get_total(lines):
    for line in lines:
        if line.startswith("Total = "):
            yield line.split()[4]

total = get_total(lines)
total = get_total(lines)

I think that should give you the second occurance 

