Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10544
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <malaclypse2@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'does.': 0.07; 'derived': 0.09; 'generators': 0.09; 'object.': 0.09; 'tuple': 0.09; 'url:peps': 0.09; 'wrote:': 0.15; 'billy': 0.16; 'iterator': 0.16; 'iterators,': 0.16; 'xrange': 0.16; '\xc2\xa0i': 0.16; 'object,': 0.16; 'cc:addr:python-list': 0.16; 'pm,': 0.16; 'this:': 0.16; 'seems': 0.20; 'cc:2**0': 0.21; 'cc:no real name:2**0': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'received:209.85.215.46': 0.23; 'received:mail- ew0-f46.google.com': 0.23; 'fri,': 0.28; 'message- id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.30; 'definition': 0.30; 'complete,': 0.30; 'differences': 0.30; 'url:dev': 0.30; 'url:library': 0.31; 'subject:?': 0.31; 'does': 0.32; 'it?': 0.34; 'subject:What': 0.35; 'pretty': 0.35; 'url:python': 0.37; 'some': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'url:org': 0.38; 'subject:: ': 0.38; 'url:docs': 0.39; 'list,': 0.39; 'received:209': 0.40; 'ever': 0.65; 'url:23': 0.67; 'url:functions': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=6JIJJVPBk0m5Xvh/RtrrAi/z0jbBXrl6dnwlSOMu9as=; b=RDH/F4EO+EXDL9rD3ybW39DyRsTPw2TTgalkJCVCQszPfQ/j1lk+NlkmOB7fUJ6EGe /20UrSNly0jywDChRskWuEdleclJlMeXn1zkG+mQg1ZHXeDWxF/IYSsJf/GbaSkFnz27 bWa0Aa+1rRpZdpckaNF03LsnLhPSG+XhZCAbY= |
| MIME-Version | 1.0 |
| In-Reply-To | <j0v23e$g6o$1@speranza.aioe.org> |
| References | <j0v23e$g6o$1@speranza.aioe.org> |
| Date | Fri, 29 Jul 2011 16:36:47 -0400 |
| Subject | Re: What is xrange? |
| From | Jerry Hill <malaclypse2@gmail.com> |
| To | Billy Mays <noway@nohow.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1631.1311971809.1164.python-list@python.org> (permalink) |
| Lines | 27 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1311971809 news.xs4all.nl 23871 [2001:888:2000:d::a6]:40978 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:10544 |
Show key headers only | View raw
On Fri, Jul 29, 2011 at 3:36 PM, Billy Mays <noway@nohow.com> wrote: > Is xrange not a generator? I know it doesn't return a tuple or list, so > what exactly is it? Y doesn't ever complete, but x does. > > x = (i for i in range(10)) > y = xrange(10) xrange() does not return a generator. It returns an iterable xrange object. If you want the iterator derived from the iterable xrange object, you can get it like this: iterator = y.__iter__() See http://docs.python.org/library/functions.html#xrange for the definition of the xrange object. http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/ seems to cover the differences between iterables, iterators, and generators pretty well. Some more reading: http://docs.python.org/howto/functional.html http://www.python.org/dev/peps/pep-0255/ http://www.python.org/dev/peps/pep-0289/ -- Jerry
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What is xrange? Billy Mays <noway@nohow.com> - 2011-07-29 15:36 -0400
Re: What is xrange? harrismh777 <harmar@member.fsf.org> - 2011-07-29 14:47 -0500
Re: What is xrange? Thomas Jollans <t@jollybox.de> - 2011-07-29 22:31 +0200
Re: What is xrange? Jerry Hill <malaclypse2@gmail.com> - 2011-07-29 16:36 -0400
Re: What is xrange? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-30 11:22 +1000
Re: What is xrange? Brian Blais <bblais@bryant.edu> - 2011-07-30 06:23 -0400
Re: What is xrange? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-30 21:36 +1000
Re: What is xrange? Brian Blais <bblais@bryant.edu> - 2011-07-30 09:46 -0400
Re: What is xrange? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-07-30 17:06 -0700
Re: What is xrange? Chris Angelico <rosuav@gmail.com> - 2011-07-31 01:10 +0100
Re: What is xrange? Ethan Furman <ethan@stoneleaf.us> - 2011-07-30 23:42 -0700
Re: What is xrange? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-07-31 12:18 +1200
csiph-web