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


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

Re: something go wrongly

Started by"Lefavor, Matthew (GSFC-582.0)[MICROTEL LLC]" <matthew.lefavor@nasa.gov>
First post2012-07-08 20:58 -0500
Last post2012-07-08 20:58 -0500
Articles 1 — 1 participant

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


Contents

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

#25061 — Re: something go wrongly

From"Lefavor, Matthew (GSFC-582.0)[MICROTEL LLC]" <matthew.lefavor@nasa.gov>
Date2012-07-08 20:58 -0500
SubjectRe: something go wrongly
Message-ID<mailman.1932.1341800847.4697.python-list@python.org>
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




[toc] | [standalone]


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


csiph-web