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


Groups > comp.lang.python > #95658 > unrolled thread

Re: [a,b,c,d] = 1,2,3,4

Started byTerry Reedy <tjreedy@udel.edu>
First post2015-08-26 11:16 -0400
Last post2015-08-26 11:16 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [a,b,c,d] = 1,2,3,4 Terry Reedy <tjreedy@udel.edu> - 2015-08-26 11:16 -0400

#95658 — Re: [a,b,c,d] = 1,2,3,4

FromTerry Reedy <tjreedy@udel.edu>
Date2015-08-26 11:16 -0400
SubjectRe: [a,b,c,d] = 1,2,3,4
Message-ID<mailman.49.1440602243.11709.python-list@python.org>
On 8/26/2015 8:21 AM, Tim Chase wrote:

>> a, b, c = (x for x in range(3)) # a generator for instance
>
> Since range() *is* a generator, why not just use

In Python 3, range is a sequence class with a separate iterator class

 >>> r = range(3)
 >>> r
range(0, 3)
 >>> iter(r)
<range_iterator object at 0x00000000034682D0>

Like all sequences, a range object can be iterated multiple times as a 
new iterator is used each time.

 >>> list(r)
[0, 1, 2]
 >>> list(r)
[0, 1, 2]

-- 
Terry Jan Reedy

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web