当前位置:网站首页>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
"""
边栏推荐
- 【论文阅读】2022年最新迁移学习综述笔注(Transferability in Deep Learning: A Survey)
- FIO测试硬盘性能参数和实例详细总结(附源码)
- Detailed explanation of SQL server stored procedures
- Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
- 实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
- Carrier period, electrical speed, carrier period variation
- Arduino uses nrf24l01+ communication
- Talk about the function of magnetic beads in circuits
- VESC Benjamin test motor parameters
- Halcon's practice based on shape template matching [1]
猜你喜欢
Various types of questions judged by prime numbers within 100 (C language)
DokuWiki deployment notes
Classic application of MOS transistor circuit design (2) - switch circuit design
C WinForm [view status bar -- statusstrip] - Practice 2
[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...)
C WinForm [change the position of the form after running] - Practical Exercise 4
My-basic application 2: my-basic installation and operation
FIO测试硬盘性能参数和实例详细总结(附源码)
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
Sword finger offer 06 Print linked list from end to end
随机推荐
Buildroot system for making raspberry pie cm3
剑指 Offer 09. 用两个栈实现队列
Measurement fitting based on Halcon learning [III] PM_ measure_ board. Hdev routine
Volatile of C language
STM32---ADC
Keil use details -- magic wand
Why is 1900 not a leap year
Hardware and software solution of FPGA key chattering elimination
NTC thermistor application - temperature measurement
Several implementation schemes of anti reverse connection protection of positive and negative poles of power supply!
Simple design description of MIC circuit of ECM mobile phone
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
剑指 Offer 05. 替换空格
Talk about the circuit use of TVs tube
Various types of questions judged by prime numbers within 100 (C language)
Correlation based template matching based on Halcon learning [II] find_ ncc_ model_ defocused_ precision. hdev
Adaptive filter
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
Cinq détails de conception du régulateur de tension linéaire
QEMU STM32 vscode debugging environment configuration