当前位置:网站首页>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
"""
边栏推荐
- General makefile (I) single C language compilation template
- Hardware 3 -- function of voltage follower
- Installation and use of libjpeg and ligpng
- QEMU STM32 vscode debugging environment configuration
- Hardware 1 -- relationship between gain and magnification
- Volatile of C language
- Void* C is a carrier for realizing polymorphism
- C WinForm [view status bar -- statusstrip] - Practice 2
- C WinForm [realize the previous and next selection pictures] - practice 7
- STM32 --- GPIO configuration & GPIO related library functions
猜你喜欢
MHA High available Cluster for MySQL
STM32 --- serial port communication
C WinForm [get file path -- traverse folder pictures] - practical exercise 6
Circleq of linked list
STM32 virtualization environment of QEMU
Semiconductor devices (III) FET
[NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
随机推荐
[NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
FIO测试硬盘性能参数和实例详细总结(附源码)
实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
General makefile (I) single C language compilation template
Bootloader implementation of PIC MCU
Soem EtherCAT source code analysis I (data type definition)
C WinForm [help interface - send email] - practice five
UE像素流,来颗“减肥药”吧!
Use indent to format code
Matlab2018b problem solving when installing embedded coder support package for stmicroelectronic
Count the number of inputs (C language)
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
Stablq of linked list
STM32 virtualization environment of QEMU
Basic information commands and functions of kernel development
OC and OD gate circuit
What are the test items of power battery ul2580
Solutions to compilation warnings in Quartus II
Zero length array in GNU C
Hardware and software solution of FPGA key chattering elimination