Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6822903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:43:07+00:00 2026-05-26T21:43:07+00:00

old = [1, 2, 3] What is the difference between the following two lines

  • 0
old = [1, 2, 3]

What is the difference between the following two lines (if there is any)?

new = old[:]
new = list(old)

Update I had already accepted ubershmekel’s answer but later I’ve learned an interesting fact: [:] is faster for small list (10 elements) but list() is faster for larger list (100000 elements).

~$ python -S -mtimeit -s "a = list(range(10))" "a[:]"
1000000 loops, best of 3: 0.198 usec per loop
~$ python -S -mtimeit -s "a = list(range(10))" "list(a)"
1000000 loops, best of 3: 0.453 usec per loop
~$ python -S -mtimeit -s "a = list(range(100000))" "a[:]"
1000 loops, best of 3: 675 usec per loop
~$ python -S -mtimeit -s "a = list(range(100000))" "list(a)"
1000 loops, best of 3: 664 usec per loop
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:43:08+00:00Added an answer on May 26, 2026 at 9:43 pm

    Yes there’s a small difference. There was a discussion on this at /r/python recently after this blog post explained a readability difference, that [:] doesn’t work with generators and keeps the same type as the original.

    Technically, you get the same thing – a brand new list that still points to the same objects. Choose whichever one you like better (although [:] is a bit faster). Personally I agree with the blog post that list(old) is more readable.

    To answer the comment about the specific difference, in python 3.2:

    >>> import dis
    >>> def colon(x):
    ...     return x[:]
    ...
    >>> def new_list(x):
    ...     return list(x)
    ...
    >>>
    >>> dis.dis(colon)
      2           0 LOAD_FAST                0 (x)
                  3 LOAD_CONST               0 (None)
                  6 LOAD_CONST               0 (None)
                  9 BUILD_SLICE              2
                 12 BINARY_SUBSCR
                 13 RETURN_VALUE
    >>> dis.dis(new_list)
      2           0 LOAD_GLOBAL              0 (list)
                  3 LOAD_FAST                0 (x)
                  6 CALL_FUNCTION            1
                  9 RETURN_VALUE
    >>>
    

    Why list(old) is slower I think is because the slicing mechanism doesn’t need to “LOAD_GLOBAL” and “CALL_FUNCTION” on the list constructor, the entire operation is handled in C.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I already know the difference between old-style class (class Foo()...) and new-style class (class
What is the difference between old style and new style classes in Python? When
The old JS SDK had a function called FB.ensureInit. The new SDK does not
What is the difference between these two form submission methods? <form method=post action=gert.php onsubmit=return
Possible Duplicate: How to calculate the difference between two dates using PHP? I have
What's the difference between these two methods of reading an input file? 1) Using
See here: http://blog.jquery.com/2011/05/03/jquery-16-released/ What is the difference between this new format: $(.elements).fadeOut(); $.when( $(.elements)
I was doing a simple calculation to get the difference between two dates. If
I am trying to find the difference between two dates. The first of the
I'm replacing an old web application with a new one, with different structure. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.