Appending a list's elements to another list using a list comprehension
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Oct 18 08:26:28 EDT 2007
Debajit Adhikary a écrit :
> I have two lists:
>
> a = [1, 2, 3]
> b = [4, 5, 6]
>
> What I'd like to do is append all of the elements of b at the end of
> a, so that a looks like:
>
> a = [1, 2, 3, 4, 5, 6]
>
> I can do this using
>
> map(a.append, b)
And what about a.extend(b) ?
> How do I do this using a list comprehension?
Why would you want a list comp here ???
> (In general, is using a list comprehension preferable (or more
> "pythonic") as opposed to using map / filter etc.?)
Depends. Anyway, the pythonic solution here is to use the appropriate
list method !-)
More information about the Python-list
mailing list