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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:53:38+00:00 2026-05-24T02:53:38+00:00

I want to create a new list from a previous one’s elements, but without

  • 0

I want to create a new list from a previous one’s elements, but without copying them. That is what happens:

In [23]: list = range(10)

In [24]: list2 = list[0:4]

In [25]: list
Out[25]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In [26]: list2
Out[26]: [0, 1, 2, 3]

Though the elements of the lists seem to have the same id,

In [29]: id(list[1])
Out[29]: 145137840

In [30]: id(list2[1])
Out[30]: 145137840

After editing one element, I don’t change the object that is referenced, but the value for that site on the list.

In [31]: list[1] = 100

In [32]: id(list[1])
Out[32]: 145138628

In [33]: id(list2[1])
Out[33]: 145137840

In [34]: list
Out[34]: [0, 100, 2, 3, 4, 5, 6, 7, 8, 9]

In [35]: list2
Out[35]: [0, 1, 2, 3]

I want to use the list2 as a representative of some particular elements of list. I’m guessing that there should be a good way to compose a list that gives me the chance to edit the values of the elements of list, when I also change the value for list.

  • 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-24T02:53:39+00:00Added an answer on May 24, 2026 at 2:53 am

    Anywhere 1 or another small number is in a variable, it will always have the same id. These numbers only exist once, and since they’re immutable, it’s safe for them to be referenced everywhere.

    Using slice syntax [:] always makes a copy.

    When you set list1[1], you’re not changing the value of what’s stored in memory, you’re pointing list1[1] to a new location in memory. So since you didn’t point list2[1] to a different location, it still points to the old location and value.

    Never name a variable list since there is a built in function by that name.

    If you want to do what you’re talking about with minimal modification, try:

    list1 = [[x] for x in range(10)]
    list2 = list1[:4]
    list1[1][0] = 100
    print list2
    

    You just need to always add [0] after the item you want to reference. As the lists don’t get replaced, just the item in them, and list2 points to the list not the item, it will stay in sync.

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

Sidebar

Related Questions

I want to create a new row in my database on a table that
I want to create a new object using Class::DBI. One of the fields of
I want to create a new column in a MYSQL table that has Fn
I want create a function that verify if the numbers of a list fall
I have a list of record Id's that I want to retrieve from Sql
I have a user defined class that I want to create a public List
We have created a new List View Style that shows thumbnails from a picture
I want to make a new list from another list of words; when a
I want to create new node of BeanTreeView, and when I add some node
I'm using Visual Basic 9 (VS2008) I want to create new Tabs as and

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.