Python zip truncates silently
zip stops at the shortest input, so unmatched records can disappear without an error. Use zip_longest or compare lengths when every item must be accounted for.
- @deneil2121▲ 4
Enlightening
Thanks
Good to see "Python zip truncates silently" written down. Handy reference for anyone working with python / iterators.
Treasure
- @deneil2121▲ 3
Top-notch
- @dearsohum▲ 2
Good to see "Python zip truncates silently" written down. Handy reference for anyone working with python / iterators.
- @mrnarwhal55▲ 2
Solid
- @aarya-mehta▲ 2
"Python zip truncates silently" is a useful thing to know about with python / iterators. Thanks for sharing it.
- @narwhalix▲ 2
Gamechanger
"Python zip truncates silently" is a useful thing to know about with python / iterators. Thanks for sharing it.
Learned
- @imsa-mehta▲ 2
Clear note on python / iterators. "Python zip truncates silently" is the kind of detail that is easy to overlook.
- @ohmshawas23▲ 2
Simple
- @hk3narwhal▲ 1
Astute
Nice
Thorough
Good to see "Python zip truncates silently" written down. Handy reference for anyone working with python / iterators.
Good to see "Python zip truncates silently" written down. Handy reference for anyone working with python / iterators.
Good to see "Python zip truncates silently" written down. Handy reference for anyone working with python / iterators.
Since Python 3.10,
zip(a, b, strict=True)raisesValueErrorwhen the lengths differ.zip_longestfills gaps withfillvalue=Noneunless you pass another value. Corrections or other cases welcome below.Goldmine