Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32728
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <alec.taylor6@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; 'python': 0.09; '5),': 0.09; 'augmented': 0.09; 'everybody!': 0.09; 'tuple': 0.09; 'typeerror:': 0.09; 'cc:addr:python-list': 0.10; '2.7': 0.13; '(3,': 0.16; '(x,': 0.16; 'behaviour.': 0.16; 'concatenate': 0.16; 'eckhardt': 0.16; 'iterable,': 0.16; 'surprising': 0.16; 'wrote:': 0.17; '>>>': 0.18; '(not': 0.20; 'issue.': 0.20; 'error.': 0.21; '"",': 0.22; 'assignment': 0.22; 'tuples': 0.22; 'cc:2**0': 0.23; 'elements': 0.23; 'insert': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'thanks!': 0.26; '(most': 0.27; 'wonder': 0.27; 'list:': 0.27; 'message-id:@mail.gmail.com': 0.27; 'this?': 0.28; 'url:mailman': 0.29; 'points': 0.29; 'url:python': 0.32; 'file': 0.32; 'subject:lists': 0.32; 'url:listinfo': 0.32; 'traceback': 0.33; 'anyone': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'nov': 0.35; 'expected': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'really': 0.36; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'some': 0.38; 'instead': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'url:mail': 0.40; 'different': 0.63; 'other.': 0.64; 'here': 0.65; 'actually,': 0.84; 'different.': 0.84; 'thereof': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Zgfc/bRfOc94AgXUUPbptEju9hbOamM/EC4palWcjao=; b=gJjH0cTErT5VzSn5IMe3Z+vFATbb1whKLIqYsrweXA+05/VANv8uRxNTLB/MueczDC X38DkkfxbYIh/f0Bl9IH2Xo96BcLMpawnKADiWjFkm7Llih47o/0eo+ClZ61E+7Y01z9 8XvpPzhXmiURnVf27wmgHjVwXVjXfaWr6bKQ1i1j67omLjho3mwZzjdGz4hRb15LWLZo PAhdsRXaEeKHxQWpxMaZYWuy6x+tJ1k8TxWfYrSL0rtvMaC+xkvqhayyCNKf74lwiWWZ XvuIoUdMl3OC47kfWAIzcTCS8w+tS5FsAh9QrwC3QHPFeRA4dhs5C/hpmCqli7kqQNc6 q6kw== |
| MIME-Version | 1.0 |
| In-Reply-To | <afn3i8Fn4j1U1@mid.uni-berlin.de> |
| References | <afn3i8Fn4j1U1@mid.uni-berlin.de> |
| Date | Sun, 4 Nov 2012 23:06:03 +1100 |
| Subject | Re: surprising += for lists |
| From | Alec Taylor <alec.taylor6@gmail.com> |
| To | Ulrich Eckhardt <doomster@knuut.de> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Cc | python-list@python.org |
| 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 | <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.3254.1352030765.27098.python-list@python.org> (permalink) |
| Lines | 37 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1352030765 news.xs4all.nl 6900 [2001:888:2000:d::a6]:33314 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:32728 |
Show key headers only | View raw
Quick aside, you can insert tuples without much effort: `points += ((3,5),)` And also that I can't do the reverse, i.e.: >>> foo = tuple() >>> foo += [5,6] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate tuple (not "list") to tuple On Sun, Nov 4, 2012 at 10:57 PM, Ulrich Eckhardt <doomster@knuut.de> wrote: > Hi everybody! > > I was just smacked by some very surprising Python 2.7 behaviour. I was > assembling some 2D points into a list: > > points = [] > points += (3, 5) > points += (4, 6) > > What I would have expected is to have [(3, 5), (4, 6)], instead I got [3, > 5, 4, 6]. My interpretations thereof is that the tuple (x, y) is iterable, > so the elements are appended one after the other. Actually, I should have > used points.append(), but that's a different issue. > > Now, what really struck me was the fact that [] + (3, 5) will give me a > type error. Here I wonder why the augmented assignment behaves so much > different. > > Can anyone help me understand this? > > Thanks! > > Uli > > > -- > http://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
surprising += for lists Ulrich Eckhardt <doomster@knuut.de> - 2012-11-04 12:57 +0100 Re: surprising += for lists Alec Taylor <alec.taylor6@gmail.com> - 2012-11-04 23:06 +1100 Re: surprising += for lists Dave Angel <d@davea.name> - 2012-11-04 07:45 -0500 Re: surprising += for lists Terry Reedy <tjreedy@udel.edu> - 2012-11-04 12:57 -0500
csiph-web