maybe you could use itertools.tee