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: 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: References: Date: Fri, 29 Jul 2011 16:36:47 -0400 Subject: Re: What is xrange? From: Jerry Hill To: Billy Mays 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Fri, Jul 29, 2011 at 3:36 PM, Billy Mays wrote: > Is xrange not a generator? =C2=A0I know it doesn't return a tuple or list= , so > what exactly is it? =C2=A0Y doesn't ever complete, but x does. > > x =3D (i for i in range(10)) > y =3D 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 =3D 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/ --=20 Jerry