Rant (was Re: x*x if x>10
alex23
wuwei23 at gmail.com
Sun Jul 27 11:48:12 EDT 2008
On Jul 28, 1:26 am, ssecorp <circularf... at gmail.com> wrote:
> I might be misunderstanding OP but:
>
> a+b+c+d+e is simple way of concatenating 5 lists...
>
> as a function that takes any amount of lists and concatenates them:
> def concat(*args):
> c = []
> for elem in args:
> c += elem
> return c
>
> don't know if extend is faster or slower or the same as + :
>
> def concat(*args):
> c = []
> for elem in args:
> c.extend(elem)
> return c
>
> I don't know of a built-in.
Just to infuriate the OP even further, here's the list comprehension
version :)
>>> def concat(*args):
... return [elem for arg in args for elem in arg]
Hope this helps!
More information about the Python-list
mailing list