Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8262
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'does.': 0.07; 'python': 0.08; 'mutable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'wed,': 0.13; '"="': 0.16; '"writable"': 0.16; '3],': 0.16; 'bieber': 0.16; 'blah': 0.16; 'declaimed': 0.16; 'email addr:ix.netcom.com': 0.16; 'email name:wlfraed': 0.16; 'from:addr:ix.netcom.com': 0.16; 'from:addr:wlfraed': 0.16; 'from:name:dennis lee bieber': 0.16; 'it...': 0.16; 'iterator': 0.16; 'received:66.245': 0.16; 'received:dsl.mindspring.com': 0.16; 'received:mindspring.com': 0.16; 'received:wlfraed': 0.16; 'to"': 0.16; 'translates': 0.16; 'url:netcom': 0.16; 'url:wlfraed': 0.16; 'wulfraed': 0.16; 'object,': 0.16; '>>>': 0.16; 'loop,': 0.23; 'refers': 0.23; 'url:home': 0.25; 'lee': 0.28; '24,': 0.29; 'object': 0.30; 'subject:?': 0.31; 'connected': 0.32; 'header:X-Complaints-To:1': 0.34; 'to:addr:python-list': 0.34; 'assignment': 0.35; 'charset :us-ascii': 0.36; 'limitation': 0.37; 'but': 0.37; 'received:org': 0.38; 'something': 0.38; 'subject:: ': 0.38; 'header:Mime- Version:1': 0.39; 'to:addr:python.org': 0.39; 'your': 0.61; 'believe': 0.66; '"for': 0.67; 'jun': 0.67; 'dennis': 0.77; "'e'": 0.84; '[[1,': 0.84; 'sequence:': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
| Subject | Re: writable iterators? |
| Date | Wed, 22 Jun 2011 21:50:22 -0700 |
| Organization | > Bestiaria Support Staff < |
| References | <ittfon$nku$1@dough.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | user-11faedd.dsl.mindspring.com |
| X-Newsreader | Forte Agent 3.3/32.846 |
| X-No-Archive | YES |
| 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.311.1308804643.1164.python-list@python.org> (permalink) |
| Lines | 42 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1308804643 news.xs4all.nl 14137 [::ffff:82.94.164.166]:39166 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:8262 |
Show key headers only | View raw
On Wed, 22 Jun 2011 15:28:23 -0400, Neal Becker <ndbecker2@gmail.com>
declaimed the following in gmane.comp.python.general:
> for e in sequence:
> do something that reads e
> e = blah # will do nothing
>
> I believe this is not a limitation on the for loop, but a limitation on the
> python iterator concept. Is this correct?
Neither... It is a misunderstanding of what "=" assignment DOES.
e = blah
translates into "disconnect the NAME 'e' from whatever object it
currently refers to; connect the NAME 'e' to the same object that the
name 'blah" is connected to"
"for e in sequence" connects the name "e" to then next object in the
iterable. As long as your "writable" is a MUTABLE object, you CAN mutate
it...
>>> lol = [ [1, 2, 3],
... [4, 5, 6],
... [7, 8, 9] ]
>>> for e in lol:
... e[1] = sum(e)
...
>>> lol
[[1, 6, 3], [4, 15, 6], [7, 24, 9]]
>>>
>>> for e in lol:
... e.reverse()
...
>>> lol
[[3, 6, 1], [6, 15, 4], [9, 24, 7]]
>>>
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: writable iterators? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-06-22 21:50 -0700
csiph-web