On 14/03/2016 15:06, Oscar Benjamin wrote:
On 14 March 2016 at 14:35, Rick Johnson <rantingrickjohn...@gmail.com> wrote:

I would strongly warn anyone against using the zip function
unless
...
I meant to say: absolutely, one hundred percent *SURE*, that
both sequences are of the same length, or, absolutely one
hundred percent *SURE*, that dropping values is not going to
matter. For that reason, i avoid the zip function like the
plague. I would much rather get an index error, than let an
error pass silently.

I also think it's unfortunate that zip silently discards items. Almost
always when I use zip I would prefer to see an error when the two
iterables are not of the same length. Of course you're not necessarily
safer with len and range:

a = [1, 2, 3]
b = 'abcde'

for n in range(len(a)):
     print(a[n], b[n])

--
Oscar


This is a job for Bi, no, https://docs.python.org/3/library/itertools.html#itertools.zip_longest

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to