import os input = '' for i in range(681,690)+range(691,700): input+=' ship.10.0.Genie-TGeant4_n%s_rec.root'%i os.system('hadd ship.10.0.Genie-TGeant4_rec.root' + input)