I have lots and lots of files in a list called files, which I am looping through and saving all the files which have //StackOverflow on the very first line. It might have some additional text after it, but the line should begin with such text.
Currently I am doing it simply like so:
matches = []
for file in files:
    with open(file, "r") as inf:
        line = inf.readline()
        if line.strip().startswith("//StackOverflow"):
            matches.append([line] + inf.readlines())
However, I was wondering if there's a better (faster?) way of doing this, since now I have to open every single file one by one and always read the first line.
 
    