当前位置:网站首页>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
"""
边栏推荐
- STM32 outputs 1PPS with adjustable phase
- 亿学学堂给的证券账户安不安全?哪里可以开户
- C WinForm [exit application] - practice 3
- How to copy formatted notepad++ text?
- VESC Benjamin test motor parameters
- Installation and use of libjpeg and ligpng
- Vofa+ software usage record
- Array integration initialization (C language)
- Semiconductor devices (I) PN junction
- Sword finger offer 05 Replace spaces
猜你喜欢
List of linked lists
Ble encryption details
C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
Circleq of linked list
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine
Explain task scheduling based on Cortex-M3 in detail (Part 1)
MySQL之MHA高可用集群
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
随机推荐
Stm32--- systick timer
Circleq of linked list
Measurement fitting based on Halcon learning [i] fuse Hdev routine
QEMU STM32 vscode debugging environment configuration
FIO测试硬盘性能参数和实例详细总结(附源码)
[three tier architecture and JDBC summary]
Sword finger offer 05 Replace spaces
Brief discussion on Buck buck circuit
Halcon's practice based on shape template matching [1]
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
Use indent to format code
Management and use of DokuWiki
Step motor generates S-curve upper computer
Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
Shell script realizes the reading of serial port and the parsing of message
C WinForm [realize the previous and next selection pictures] - practice 7
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
Carrier period, electrical speed, carrier period variation