Re: Copy List

Discussion in 'Python' started by Joe Riopel, Jul 18, 2007.

  1. Joe Riopel

    Joe Riopel Guest

    On 7/18/07, Robert Rawlins - Think Blue
    <> wrote:
    > What's the best way to create a copy of a list?


    I am pretty new to python but this works:

    >>> list_one = [0,1,2,3,4,5,6,7,8,9]
    >>> list_two = [i for i in list_one]
    >>> print list_two

    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    >>>
     
    Joe Riopel, Jul 18, 2007
    #1
    1. Advertising

  2. Joe Riopel <> wrote:
    > I am pretty new to python but this works:
    >
    > >>> list_one = [0,1,2,3,4,5,6,7,8,9]
    > >>> list_two = [i for i in list_one]
    > >>> print list_two

    > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]


    >> list_two = list_one[:]


    or

    >> list_two = list(list_one)


    are better :D

    --
    Lawrence, oluyede.org - neropercaso.it
    "It is difficult to get a man to understand
    something when his salary depends on not
    understanding it" - Upton Sinclair
     
    Lawrence Oluyede, Jul 18, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Blair
    Replies:
    4
    Views:
    1,111
    John Saunders
    Jan 12, 2005
  2. Steve Richter
    Replies:
    4
    Views:
    5,561
    Steve Richter
    Apr 18, 2005
  3. Steve Franks

    Copy Web tool does not copy sub dirs?

    Steve Franks, Sep 14, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    399
    Steve Franks
    Sep 15, 2005
  4. Alex
    Replies:
    2
    Views:
    1,287
  5. Replies:
    26
    Views:
    2,173
    Roland Pibinger
    Sep 1, 2006
Loading...

Share This Page