4 ms·
things, also_things = itertools.tee(things) next(things), list(also_things) => (0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
by rjeli 6y ago
things, also_things = itertools.tee(things)
next(things), list(also_things)
=> (0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
- gojomo 6y agoNice, idiomatically! But if the original `things` is gigabytes in size and streamed from elsewhere, isn't it queueing those all up, as they're read from `also_things`, in case they're ever read from new `things` - even if they're not?
- rjeli 6y agoOops, you’re right. more-itertools has `peekable`, that’s probably the most readable