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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:22:21+00:00 2026-06-07T07:22:21+00:00

What I want to do is assign a nested list to another list. For

  • 0

What I want to do is assign a nested list to another list. For example, from alist to blist.

alist = [[0], [1], [2], [3]]
blist = alist[:]
blist[0].append(1)

In this way, id(alist[0]) equals id(alist[1]), so alist also changes to [[0,1], [1], [2], [3]], that’s not what I want.

The workaround I have is:

alist = [[0], [1], [2], [3]]
blist = []
for item in alist:
    blist.append(item[:])
blist[0].append(1)

In this workaround, alist won’t be influenced by changing blist’s items.
However, it seems not so pythonic, is there any better resolution? That could resolve the deep copy of more the 2 level nested list. eg: alist = [[[1], 10], [[2], 20], [[3], 30]]

  • 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-06-07T07:22:24+00:00Added an answer on June 7, 2026 at 7:22 am

    I think you want to use copy.deepcopy(), this also resolves deeper copies:

    >>> import copy
    >>> alist = [[0], [1], [2], [3]]
    >>> blist = copy.deepcopy(alist)
    >>> blist[0].append(1)
    >>> alist
    [[0], [1], [2], [3]]
    >>> blist
    [[0, 1], [1], [2], [3]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a good way to assign ViewData to nested master pages? For example,
I want to assign a value from a select box to an input field
I want to assign the array item into variable directly using groovy like this:
i want to assign a class to an a href tag if this his
I want to assign a class to the list-items of an ul li list
i want to assign a multidimensional array to jtree. how can i do this?
I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal
I want to assign a copy of a boost::multi_array. How can I do this.
I want to assign value to global variable in javascript from jquery ajax function.
I want to assign the value of the double to another double, but print

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.