learning to use iterators

Ian Kelly ian.g.kelly at gmail.com
Thu Dec 25 00:36:28 EST 2014


On Wed, Dec 24, 2014 at 1:34 PM, Rustom Mody <rustompmody at gmail.com> wrote:
> +1 for the slice in succinct form

Not only more succinct but also more correct. The purpose of islice is to
slice arbitrary iterables as opposed to just sequences. But this function
requires a reentrant iterable anyway and returns garbage if you pass it an
iterator, so there's really no reason for it here. The version using slice
notation on the other hand will raise a TypeError if you pass it an
iterator or anything else that can't be sliced, which is preferable to
silently returning incorrect results.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141224/c8cb1bcc/attachment.html>


More information about the Python-list mailing list