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

  • Home
  • SEARCH
  • 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 6708083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:42:59+00:00 2026-05-26T07:42:59+00:00

I am trying to copy the nested list a , but do not know

  • 0

I am trying to copy the nested list a, but do not know how to do it without using the copy.deepcopy function.

a = [[1, 2], [3, 4]]

I used:

b = a[:]

and

b = a[:][:]

But they all turn out to be shallow copy.

Any hints?

  • 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-26T07:43:00+00:00Added an answer on May 26, 2026 at 7:43 am

    My entry to simulate copy.deepcopy:

    def deepcopy(obj):
        if isinstance(obj, dict):
            return {deepcopy(key): deepcopy(value) for key, value in obj.items()}
        if hasattr(obj, '__iter__'):
            return type(obj)(deepcopy(item) for item in obj)
        return obj
    

    The strategy: iterate across each element of the passed-in object, recursively descending into elements that are also iterable and making new objects of their same type.

    I make no claim whatsoever that this is comprehensive or without fault [1] (don’t pass in an object that references itself!) but should get you started.

    [1] Truly! The point here is to demonstrate, not cover every possible eventuality. The source to copy.deepcopy is 50 lines long and it doesn’t handle everything.

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

Sidebar

Related Questions

I have a list of files that I'm trying to copy and move (using
I am trying to copy NSMutableArray to another but it does not show me
I am trying to copy the contents of certain folders to another folder using
I'm trying to copy a directory using the Ant copy task. I am a
I am trying to copy data from my MYSQL table to SQL Server using
I'm trying to copy one form <input> field value to another form using jQuery.
Im trying to copy a directory to a new location. So I am using
How do I copy all files inside /directory/subfolder to /directory using SSH? PS. I'm
I am trying to copy the contents of one graphics object to another, but
I am trying to copy a link on Solaris OS but find that it

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.