Merging iterables with zip_longest() and zip()

We saw the zip() function in Chapter 4, Working with Collections. The zip_longest() function differs from the zip() function in an important way: whereas the zip() function stops at the end of the shortest iterable, the zip_longest() function pads short iterables and stops at the end of the longest iterable.

The fillvalue keyword parameter allows filling with a value other than the default value, None.

For most exploratory data analysis applications, padding with a default value is statistically difficult to justify. The Python Standard Library document shows a few clever things that can be done with the zip_longest() function. It's difficult to expand on these without drifting far from our focus on data analysis.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset