can we append a list with another list in Python ?

Jean-Michel Pichavant jeanmichel at sequans.com
Tue Oct 23 07:07:45 EDT 2012


----- 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.


More information about the Python-list mailing list