# A pipeline of generator functions # write a data file "data.tmp" for testing filename = 'data.tmp' try: # does the data file exist? with open(filename,'r') as file: pass except: # doesn't exist, create it import numpy as np with open(filename,'w') as file: for i in range(20): file.write(f"{i:<5} {np.random.random():<8.3f} {np.random.random():<8.3f}\n") with open(filename,'r') as file: lines = (line for line in file) evenlines = (line for line in lines if int(line.split()[0])%2 == 0) ycol = (float(line.split()[2]) for line in evenlines) print("sum(y;even index)=",sum(ycol))