joining 2 lists together - an elegant way?
Chris Liechti
cliechti at gmx.net
Fri Jun 28 17:04:17 EDT 2002
Rajarshi Guha <rajarshi at presidency.com> wrote in
news:pan.2002.06.28.15.06.32.33132.1787 at presidency.com:
> On Fri, 28 Jun 2002 15:03:29 -0400, Rajarshi Guha wrote:
>
>> Hi,
>> is there a more elegant way to join to lists together?
>>
>> Right now I do:
>>
>> newlist = []
>> for i in l1:
>> newlist.append(i)
>> for i in l2:
>> newlist.append(i)
>>
>> It does the job - but a one liner (if possible) would be nice :) TIA,
>
> Sorry :( Found it!
Fine! now if you would post it also you would 1) get feedback, 2) help
others/newbees when they search the news archive...
just for the record:
>>> l1, l2 = [1,2,3], [4,5,6,7]
>>> l1 + l2 #oneliner
[1, 2, 3, 4, 5, 6, 7]
>>> n = l1[:] #copy and
>>> n.extend(l2) #extend
[1, 2, 3, 4, 5, 6, 7]
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list