Zip and Interleave Iterables
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Write two generator functions that take any number of iterables, which may be endless. zip(...iterables) yields arrays holding one value from each iterable, in order: the first values together, then the second values, and so on, stopping as soon as any iterable runs out. interleave(...iterables) yields the first value of each iterable in turn, then the second value of each, and so on, skipping iterables that have run out, until every one has. Both read values only as they're needed, so they work with endless generators, and both yield nothing when given no iterables.
Your code must pass
- Zips values into arrays
- Zip stops at the shortest iterable
- Interleaves values in turn
- Keeps interleaving after one runs out
- Works with endless generators