Python - Zip not even length string

Introduction

zip function truncates result tuples at the length of the shortest sequence when the argument lengths differ.

In the following, we zip two strings to pick out characters in parallel, but the result has only as many tuples as the length of the shortest sequence:

Demo

S1 = 'abc' 
S2 = 'xyz123' # from   ww w.  ja va2  s. c  o m

print( list(zip(S1, S2)) )                       # Truncates at len(shortest)

Result

Related Topic