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


Groups > comp.lang.python > #31926

Re: can we append a list with another list in Python ?

Date 2012-10-23 13:07 +0200
From Jean-Michel Pichavant <jeanmichel@sequans.com>
Subject Re: can we append a list with another list in Python ?
Newsgroups comp.lang.python
Message-ID <mailman.2660.1350990448.27098.python-list@python.org> (permalink)

Show all headers | View raw


----- Original Message ----- 

> Thankyou.. but my problem is different than simply joining 2 lists
> and it is done now :)....


A lot of people though you were asking for joining lists, you description was misleading.

I'll take a guess: you want to flatten a list of list.
"Nested" list comprehensions can do the trick.

aList =[[1,5], [2,'a']]
[item for sublist in aList for item in sublist]

...
[1, 5, 2, 'a']
       
I find it rather difficult to read though.

Cheers,

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

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


Thread

Re: can we append a list with another list in Python ? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-10-23 13:07 +0200

csiph-web