Python - How to Iterate Over Lists of Different Lengths

preview_player
Показать описание
#Python #Shorts

We've talked about the zip function before, which allows us combining two or more collections into one iterable.

But the catch was that all the collections had to be the same length, otherwise it'd stop iterating whenever the shortest collection was done.

If we want to keep iterating until the longest collection is done, we can use zip_longest() instead.

If we don't want None and want some default value for the item in the shortest collection, we can use the fillvalue parameter.

-------------------------------------------------------------------------------------
Links:
Рекомендации по теме
visit shbcf.ru