Reference replication, shard Copy, full replication in Python

Source: Internet
Author: User

Reference replication, shard Copy, full replication in Python

First look directly at the example:

>>>l1=[1,2,3]>>>L11 = L1>>>l2=[4,5, L1]>>>l2[4,5, [1,2,3]]>>>L3 = l2[:]>>>l3[4,5, [1,2,3]]>>>ImportCopy>>>L4 = copy.deepcopy (L2)>>>l4[4,5, [1,2,3]]>>>l2[1] =6>>>l2[4,6, [1,2,3]]>>>l3[4,5, [1,2,3]]>>>l4[4,5, [1,2,3]]>>>l1[0] =7>>>l1[7,2,3]>>>l11[7,2,3]>>>l2[4,6, [7,2,3]]>>>l3[4,5, [7,2,3]]>>>l4[4,5, [1,2,3]]

Description

    1. Copying using the Shared object application will only add a new reference to the existing object and will not generate new objects in memory (see L11 vs. L1).
    2. Using a Shard method to copy a sequence type such as a list, only the contents of the current sequence are copied, and the data structures within the sequence are not copied (see L1, L2, L3 contrast).
    3. Dictionaries can also be copied with copy methods, but with 2 limitations.
    4. The Copy standard Template Library is able to generate a complete copy, eliminating the problem of not copying the data structures in the sequence in the previous article (see Comparison of L3 and L4 values).
    5. 2 and 3 are called top-level replication and cannot replicate nested data structures.

Reference replication, shard Copy, full replication in Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.