Append a List to a List in Python

March 19, 2008

(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]

x.extend([4,5])

[1,2,3,4,5]

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

1 Comment 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,

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Categories

Archives

Top Posts