You can also do it with simple **generator expression**: for line in (l for f in (file1, file2) for l in f): # do something with line with this method you can specify some **condition** in expression itself: for line in (l for f in (file1, file2) for l in f if 'text' in l): # do something with line