Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82910

Re: learning to use iterators

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'correct.': 0.07; 'preferable': 0.09; 'sequences.': 0.09; 'anyway': 0.14; '24,': 0.16; 'garbage': 0.16; 'incorrect': 0.16; 'iterable': 0.16; 'iterables': 0.16; 'iterator': 0.16; 'iterator,': 0.16; 'notation': 0.16; 'succinct': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'email addr:gmail.com&gt;': 0.22; '&gt;': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'raise': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'subject:learning': 0.31; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'really': 0.36; 'opposed': 0.36; 'returning': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'results.': 0.60; 'more': 0.64; 'hand': 0.80; 'silently': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=te0NO8EnG1VtuPuhxC0sE5+d5QGw/pSQOEB58Wh4R/g=; b=dA/m6xY6hZUao8h+mVuS2o4eyAW6B36zA1edP7CeDkwKTqiwGderRUzBlG71v5Blhj N+bT170ZvdOa63Qa8RthyGjsj0Cvc3opjP6q4Oflq53r8R43L6cxUhYHXsjiGkHStkwA 5LkBGHnaa8teWrrQcv1UgoERXGVZvpG8X/snAnSBKNKeoMnWHByeHPsfUZqbdFsMi/SB Vba2Qb/ekOJvKj3Gia+ggGQWOlohf8rGYkFhT8cczDU/AMLOY2lmgH728ZcDuuIgXjC6 gyT2h9J1UJgAXZi+o6mr+g/chVsmaDtwr8xyqCUcziz0dcWk0MecRn0hY6HnNgmpRzXm fJPA==
X-Received by 10.68.241.130 with SMTP id wi2mr58260628pbc.89.1419485829208; Wed, 24 Dec 2014 21:37:09 -0800 (PST)
MIME-Version 1.0
In-Reply-To <8a840698-a3be-4889-9ddd-756a553e6f48@googlegroups.com>
References <878uhyb3hq.fsf@net82.ceos.umanitoba.ca> <mailman.17185.1419433939.18130.python-list@python.org> <8a840698-a3be-4889-9ddd-756a553e6f48@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 24 Dec 2014 22:36:28 -0700
Subject Re: learning to use iterators
To Python <python-list@python.org>
Content-Type multipart/alternative; boundary=047d7b339d0d9d235b050b03cc31
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.17196.1419485832.18130.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1419485832 news.xs4all.nl 2914 [2001:888:2000:d::a6]:56452
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:82910

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Wed, Dec 24, 2014 at 1:34 PM, Rustom Mody <rustompmody@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: learning to use iterators Vito De Tullio <vito.detullio@gmail.com> - 2014-12-24 16:12 +0100
  Re: learning to use iterators Rustom Mody <rustompmody@gmail.com> - 2014-12-24 12:34 -0800
    Re: learning to use iterators Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-24 22:36 -0700
    Re: learning to use iterators Peter Otten <__peter__@web.de> - 2014-12-25 11:34 +0100

csiph-web