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


Groups > comp.lang.python > #25061

Re: something go wrongly

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <matthew.lefavor@nasa.gov>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'try:': 0.07; '[1,': 0.09; 'extension,': 0.09; 'sat,': 0.15; 'alist': 0.16; 'altered': 0.16; 'concatenated': 0.16; 'email addr:python.org"': 0.16; 'in-place': 0.16; 'in-place,': 0.16; 'wrongly': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'to:name:python-list@python.org': 0.20; 'object.': 0.22; 'received:198': 0.22; 'to:2**1': 0.23; 'header :In-Reply-To:1': 0.25; 'am,': 0.27; 'chris': 0.28; '"the': 0.29; 'lists': 0.31; 'code': 0.31; 'operate': 0.32; 'could': 0.32; 'print': 0.32; 'received:gov': 0.33; 'to:addr:python-list': 0.33; 'code:': 0.33; 'list': 0.35; 'lists.': 0.35; 'something': 0.35; 'subject:': 0.36; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'from:': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'jul': 0.65; 'matthew': 0.65; 'url:a': 0.72
From "Lefavor, Matthew (GSFC-582.0)[MICROTEL LLC]" <matthew.lefavor@nasa.gov>
To levi nie <levinie001@gmail.com>, "python-list@python.org" <python-list@python.org>
Date Sun, 8 Jul 2012 20:58:40 -0500
Subject Re: something go wrongly
Thread-Topic something go wrongly
Thread-Index Ac1ddl49N6tHsRxnQwmiYyOGfO+8MA==
In-Reply-To <CAEMsKDu-TRNn3582vLeZ+zO2Y4oVAY=6oPgzN1hs4d2WGv9Rtw@mail.gmail.com>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
user-agent Microsoft-MacOutlook/14.2.2.120421
acceptlanguage en-US
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-Proofpoint-Virus-Version vendor=fsecure engine=2.50.10432:5.7.7855, 1.0.260, 0.0.0000 definitions=2012-07-08_06:2012-07-06, 2012-07-08, 1970-01-01 signatures=0
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.1932.1341800847.4697.python-list@python.org> (permalink)
Lines 60
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1341800847 news.xs4all.nl 6906 [2001:888:2000:d::a6]:36763
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25061

Show key headers only | View raw


If you do want an in-place extension, you could try:

aList=[1,2,3,4,5,6,7,8,9,10]
xList=[1,2,3]
print "The concatenated lists are:", aList + bList

Though you need to remember that neither aList nor bList is altered in
this situation!


Matthew Lefavor

NASA GSFC [Microtel, LLC]
Mail Code 699.0/Org Code 582.0
matthew.lefavor@nasa.gov
(301) 614-6818 (Desk)
(443) 758-4891 (Cell)





From:  levi nie <levinie001@gmail.com>
To:  "python-list@python.org" <python-list@python.org>
Subject:  Re: something go wrongly



Thanks,
Such methods return None to emphasize that they
do not create new lists.
i got it.
2012/7/8 Chris Rebert <clp2@rebertia.com>

On Sat, Jul 7, 2012 at 10:23 AM, levi nie <levinie001@gmail.com> wrote:
> my code:
>
> aList=[1,2,3,4,5,6,7,8,9,10]
> xList=[1,2,3]
> print "now aList is",aList.extend(xList)
>
> output:
> now aList is None
>
> what i want is [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3]



See http://stackoverflow.com/a/1682601
list.extend(), list.append(), etc. operate in-place, mutating the
existing list object. Such methods return None to emphasize that they
do not create new lists.

Regards,
Chris




Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: something go wrongly "Lefavor, Matthew  (GSFC-582.0)[MICROTEL LLC]" <matthew.lefavor@nasa.gov> - 2012-07-08 20:58 -0500

csiph-web