当前位置:网站首页>Example 007: copy data from one list to another list.
Example 007: copy data from one list to another list.
2022-07-05 08:22:00 【Lazy smile】
example 007:copy
subject : Copy data from one list to another .
Program analysis :
We can use the following methods to copy : Direct assignment =、 Indexes [:]、copy()、deepcopy()
The code is as follows :
import copy
a = [1, 2, 3, 4, ['a', 'b']]
b = a # assignment
c = a[:] # Shallow copy
d = copy.copy(a) # Shallow copy
e = copy.deepcopy(a) # Deep copy
a.append(5)
a[4].append('c')
print('a=', a)
print('b=', b)
print('c=', c)
print('d=', d)
print('e=', e)a= [1, 2, 3, 4, ['a', 'b', 'c'], 5]
b= [1, 2, 3, 4, ['a', 'b', 'c'], 5]
c= [1, 2, 3, 4, ['a', 'b', 'c']]
d= [1, 2, 3, 4, ['a', 'b', 'c']]
e= [1, 2, 3, 4, ['a', 'b']]
summary :
"""
Deep copy , Depth of copy : I have opened up a new memory , Copy all the copied contents
Deep copy of the list is to change the new list no matter how ( Unidimensional or Multidimensional ), The original list remains unchanged .
Shallow copy , The degree of copying is shallow , Only the first address of the original data is copied , Then through the first address of the original data , To get content .
Shallow copy , For multidimensional lists , Only the first dimension deep copy
"""
边栏推荐
- [trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
- Halcon's practice based on shape template matching [1]
- Step motor generates S-curve upper computer
- Bootloader implementation of PIC MCU
- On boost circuit
- STM32 --- NVIC interrupt
- Count the number of inputs (C language)
- Semiconductor devices (III) FET
- VESC Benjamin test motor parameters
- Carrier period, electrical speed, carrier period variation
猜你喜欢

Explain task scheduling based on Cortex-M3 in detail (Part 1)
![[tutorial 19 of trio basic from introduction to proficiency] detailed introduction of trio as a slave station connecting to the third-party bus (anybus PROFIBUS DP...)](/img/54/2fe86f54af01f10de93818103f2154.jpg)
[tutorial 19 of trio basic from introduction to proficiency] detailed introduction of trio as a slave station connecting to the third-party bus (anybus PROFIBUS DP...)
![Measurement fitting based on Halcon learning [i] fuse Hdev routine](/img/91/34c92065e797c87d6ce5ea13903993.jpg)
Measurement fitting based on Halcon learning [i] fuse Hdev routine

STM32 single chip microcomputer - bit band operation

Simple design description of MIC circuit of ECM mobile phone

Hardware 3 -- function of voltage follower

Solutions to compilation warnings in Quartus II

leetcode - 445. 两数相加 II

实例010:给人看的时间
![[three tier architecture]](/img/73/c4c75a453f03830e83cabb0762eb9b.png)
[three tier architecture]
随机推荐
STM32 single chip microcomputer - external interrupt
Adaptive filter
实例006:斐波那契数列
VESC Benjamin test motor parameters
MySQL MHA high availability cluster
Talk about the function of magnetic beads in circuits
Several implementation schemes of anti reverse connection protection of positive and negative poles of power supply!
Summary -st2.0 Hall angle estimation
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
Installation and use of libjpeg and ligpng
Halcon's practice based on shape template matching [1]
【论文阅读】2022年最新迁移学习综述笔注(Transferability in Deep Learning: A Survey)
QEMU demo makefile analysis
Naming rules for FreeRTOS
Hardware 3 -- function of voltage follower
STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)
STM32 --- serial port communication
Circleq of linked list
Classic application of MOS transistor circuit design (2) - switch circuit design
Sword finger offer 05 Replace spaces