Append a List to a List in Python

March 19, 2008 at 4:47 pm 10 comments

(Note: Please see my latest posts at my new blog!)

An easy way to do this is with the extend function:

x = [1,2,3]



Entry filed under: CodeSnippet, Python. Tags: , .

Simple Method to Calculate Median in Python How to Install tar.gz Files in Linux

10 Comments Add your own

  • 1. paddy3118  |  March 19, 2008 at 8:22 pm

    The addition operator works too:

    >>> [1,2] + [3,4]
    [1, 2, 3, 4]

    – Paddy,

  • 2. gawbul  |  July 27, 2010 at 3:54 pm

    list.append(list) works too :)

  • 3. gawbul  |  July 27, 2010 at 3:56 pm

    well actually, it would be


    but I’m sure you get the picture :D

  • 4. gawbul  |  July 27, 2010 at 3:59 pm

    Actually, delete them last two! No it doesn’t!

    extend works best :)

  • 5. hgjhghj  |  August 28, 2011 at 3:28 am

    lol fail

  • 6. Babu  |  April 3, 2012 at 8:56 pm

    Let’s say I have a list.
    The elements of the list are also lists.

    I want to append items to the lists in the lists with something like…


    X_LIST=[ x1, x2, x3, …etc ]
    etc…for Y and Z

    POSITION_VECTOR_LIST1[ { [0], [1], [2] } ].append( { X, Y, Z } )

    Where I want X to append to the the X_LIST (the x list is the first element in the POSITION_VECTOR_LIST

    (this is not real code fyi, it’s just a pseudo code for something I want to do…)

  • 7. Babu  |  April 3, 2012 at 8:58 pm

    there’s a typo, in the second appearance of POSITION_VECTOR_LIST

    POSITION_VECTOR_LIST1[ { [0], [1], [2] } ].append( { X, Y, Z } )

    I didn’t mean to write …LIST1[…
    s’posed to be …LIST[…

  • 8. Ta  |  April 10, 2013 at 4:18 am

    I came to your “Append a List to a List in Python | Code Comments” page and noticed you could have a lot more traffic. I have found that the key to running a website is making sure the visitors you are getting are interested in your subject matter. There is a company that you can get traffic from and they let you try it for free. I managed to get over 300 targetted visitors to day to my website. Check it out here:

  • 9. Mike R  |  September 24, 2015 at 6:15 am

    I’m still learning, but here’s what I’ve found – If you want to append a list (as a LIST) to another list:


    If you want to append the INDIVIDUAL ITEMS in a list to another list, you need to iterate through it with a loop:

    for items in listTwo:

    Hope that helps someone.

  • 10. Mike R  |  September 24, 2015 at 6:24 am

    Edit: The line after the ‘for’ loop should be indented 4 spaces (..don’t know why it didn’t print it that way..)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Get every new post delivered to your Inbox.

%d bloggers like this: