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 6965877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:07:06+00:00 2026-05-27T16:07:06+00:00

When I iterate through the values of list1 from start to stop , as

  • 0

When I iterate through the values of list1 from start to stop, as in:

for value in list1[start:stop]:
    ....

Does python first copy that part of the list (as is done when doing list2 = list1[:])? This could get very expensive for large lists!

If it doesn’t copy it in the above example, does that always hold true? I need to do the following sort of loop, very often, on large sections of (very) large lists:

for index, value in enumerate(list1[start:stop], start):
    ....
  • 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-27T16:07:07+00:00Added an answer on May 27, 2026 at 4:07 pm

    list1[start:stop] creates a new list, period. This is always the case, regardless of whether you’re iterating over the result directly or have a function in between or use it in any other context (you’d need a moderately static language, or sophisticated type inference, to optimize even for simple instances of the first case).

    Note that this is independent from the iteration! The iteration itself does not copy, and the list slicing copies even if you throw the result away.

    It only copies pointers though, so if you’re always taking very small sublists, you probably wouldn’t notice any difference. If the sublists are larger, you could either iterate over indices ([x]range) or use itertools.islice. The latter would have to skip over start items first though, so you may pay a hefty time penality for the memory savings. The former is ugly, but most efficent asymptomically.

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

Sidebar

Related Questions

Does map() iterate through the list like for would? Is there a value in
I have a list of header values from an excel spreadsheet that is set
How to iterate through table, using JQuery, and collect in three different arrays values
If I iterate through an array twice, once by reference and then by value,
I would like to randomly iterate through a range. Each value will be visited
I iterate over an array of arrays and access the array's value through associative
I'm getting values from the html using the following method: javascript: var list =
I have a django queryset that returns a list of values: [(client pk, timestamp,
I have been have issues trying to retrieve the values from a treeMap that
I have a VB .Net linq query that I want to return values from

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.