joining list elements

bhella bhella at ce.mediaone.net
Sat Oct 14 12:34:42 EDT 2000


Here is another way to do this.

def flat(inlist):
    t = []
    for i in inlist:
        try: t.extend(i)
        except TypeError: t.append(i)
     return t

Also, I am assuming that [1, 2, 3], 4  is the same as ([1, 2, 3], 4).

Johannes Zellner wrote:

> Hi again,
>
> how do I join list elements ?
>
> e.g. I want [[1, 2, 3], [4, 5, 6]] --> [1, 2, 3, 4, 5, 6]
>      and    [[1, 2, 3],  4, 5, 6 ] --> [1, 2, 3, 4, 5, 6]
>      and    [1, 2, 3], 4 --> [1, 2, 3, 4]
>
> any help much appreciated!
>
> --
>    Johannes




More information about the Python-list mailing list