Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106263
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Drowning in a teacup? |
| Date | Fri, 1 Apr 2016 14:52:10 -0600 |
| Lines | 27 |
| Message-ID | <mailman.333.1459543979.28225.python-list@python.org> (permalink) |
| References | <ndmlj2$pb0$1@gioia.aioe.org> <ndmmav$8n2$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de 7pPgIaH794I7PozOyi2cVQyEPyd6UL1AiwOrkyWIxltg== |
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'received:209.85.223': 0.03; 'removes': 0.05; 'inserts': 0.07; 'line:': 0.07; 'methods,': 0.09; 'slow.': 0.09; 'instead.': 0.15; '2016': 0.16; 'assignment.': 0.16; 'mylist': 0.16; 'nope,': 0.16; 'overwriting': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'variable': 0.18; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'parameters': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'problem': 0.33; 'previous': 0.34; 'lists': 0.34; 'that,': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'something': 0.35; 'problem.': 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'received:209.85': 0.36; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'thought': 0.37; 'received:209': 0.38; 'to:addr:python.org': 0.40; 'still': 0.40; 'called': 0.40; 'your': 0.60; 'contrary': 0.72; 'as:': 0.79; 'front.': 0.84; 'length;': 0.84; 'to:name:python': 0.84; 'wrong!': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=RzEVH7wkyMM25GkcdkXnzykjDHk6banQPWSnwJVEGs4=; b=WxrF9pFj6G5KfUPD3nukvxLx8DOysh5DDaYqHGi4GYJB7aLCSuMMpsjqgwB9vYJZnB aRBT5Pb8nQmTvp04H7KJdK6xK/Vhfw6746EJo38xmbx8QpagxR7JbrldFLcvyTfx0Lk4 P+LXKn71O5GidCcTTN6cZ0oNU7CR74v/GdJUH8ucLO8vCmW42yrbqQ48LVB5wb0OByRS EhQN+HmqI5IrZLOnnhlUqTW9mq3dFxiMGptFvZNx8h184tjB1EsKTZJK1PB2C+42ltzM pma2VRhOyeQabIInnaBDSVLKRliXmD4RN9iw56xNQ3uCHwxaryUwWmd0f7pZ0iwVhsRl p1Bg== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=RzEVH7wkyMM25GkcdkXnzykjDHk6banQPWSnwJVEGs4=; b=DtfPao6SAAlf9heCmMgl8TIhb4V1OukCkX094Aj5NYKmL9QBYbGK+JFjbhqYoCIQpD OgUqACbAsBDAkSKUALScR/AWtLxtWTi3k2p+XAOrPQJywqj6lXD5SRPdXVSy10VFriz9 LDRVVo3DxZifHjJXwREUfnqxryhJo1pmPY7VaIMTYK5B1Mzz65dj5Z1QID8AbUJM+8Yl AiAlYRBC5oUu0gFTObb1VcQyVZP4IfAyPgX9X52cNFrAd0Euf8aIfEzmhMNzLU39gHDE +N07T4YBhfYtP6uXy8I0FGrGL9jWpYYJW7dMydD66m0DKwhqzvVpU2rn/CxFrRohbffW SOfg== |
| X-Gm-Message-State | AD7BkJLQ2N/H+1tEHttKrKmlFB5TcFeQBdUY9IuTvU15kS4mv5RA93Nqcg0FVya+88A+OGuZCF4DRUrJzIJ3LQ== |
| X-Received | by 10.107.19.157 with SMTP id 29mr7875633iot.11.1459543969829; Fri, 01 Apr 2016 13:52:49 -0700 (PDT) |
| In-Reply-To | <ndmmav$8n2$1@dont-email.me> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:106263 |
Show key headers only | View raw
On Fri, Apr 1, 2016 at 2:39 PM, Rob Gaddi
<rgaddi@highlandtechnology.invalid> wrote:
> Fillmore wrote:
>> Nope, wrong! contrary to what I thought I had understood about how
>> parameters are passed in Python, the function is acting on a copy(!) and
>> my original list is unchanged.
>>
>
> Nope, that's not your problem. Your problem is the line:
>
>> mylist = [mylist[i]] + mylist[:i] + mylist[i+1:]
>
> Which should be read as: "Take mylist[i], all of mylist before i,
> and all of mylist after i and create a new list from it. Store that
> new list in a variable called mylist, overwriting the previous value."
>
> If instead you were using the .insert and .remove methods, you'd be
> manipulating the existing list instead. But you don't want to do that,
> because those methods are O(N) on the list length; manipulating the
> middle of lists is slow.
Or use slice assignment. This should work in place of the above:
mylist[:] = [mylist[i]] + mylist[:i] + mylist[i+1:]
Still O(n), but so will be any implementation that removes something
from an arbitrary list position and inserts it at the front.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Drowning in a teacup? Fillmore <fillmore_remove@hotmail.com> - 2016-04-01 16:27 -0400
Re: Drowning in a teacup? Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-04-01 20:39 +0000
Re: Drowning in a teacup? Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-01 14:52 -0600
Re: Drowning in a teacup? MRAB <python@mrabarnett.plus.com> - 2016-04-01 21:45 +0100
Re: Drowning in a teacup? Michael Selik <michael.selik@gmail.com> - 2016-04-01 20:46 +0000
Re: Drowning in a teacup? Steven D'Aprano <steve@pearwood.info> - 2016-04-02 09:46 +1100
Re: Drowning in a teacup? Fillmore <fillmore_remove@hotmail.com> - 2016-04-02 00:03 -0400
Re: Drowning in a teacup? Vito De Tullio <vito.detullio@gmail.com> - 2016-04-02 07:45 +0200
Re: Drowning in a teacup? Michael Selik <michael.selik@gmail.com> - 2016-04-02 05:51 +0000
Re: Drowning in a teacup? Vito De Tullio <vito.detullio@gmail.com> - 2016-04-02 08:26 +0200
Re: Drowning in a teacup? Peter Otten <__peter__@web.de> - 2016-04-02 12:31 +0200
Re: Drowning in a teacup? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-04-02 12:53 +0100
Re: Drowning in a teacup? Michael Selik <michael.selik@gmail.com> - 2016-04-02 14:36 +0000
Re: Drowning in a teacup? Ned Batchelder <ned@nedbatchelder.com> - 2016-04-02 12:28 -0700
Re: Drowning in a teacup? Random832 <random832@fastmail.com> - 2016-04-02 15:54 -0400
Re: Drowning in a teacup? Steven D'Aprano <steve@pearwood.info> - 2016-04-03 12:33 +1000
Re: Drowning in a teacup? Ethan Furman <ethan@stoneleaf.us> - 2016-04-02 16:15 -0700
Re: Drowning in a teacup? Random832 <random832@fastmail.com> - 2016-04-02 19:19 -0400
csiph-web