当前位置:网站首页>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
"""
边栏推荐
- Halcon's practice based on shape template matching [1]
- STM32---IIC
- C WinForm [get file path -- traverse folder pictures] - practical exercise 6
- Briefly talk about the identification protocol of mobile port -bc1.2
- STM32 --- configuration of external interrupt
- Wifi-802.11 negotiation rate table
- Measurement fitting based on Halcon learning [III] PM_ measure_ board. Hdev routine
- STM32 outputs 1PPS with adjustable phase
- STM32 single chip microcomputer - external interrupt
- [cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
猜你喜欢
Summary of SIM card circuit knowledge
[trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code
MySQL之MHA高可用集群
Design a clock frequency division circuit that can be switched arbitrarily
How to copy formatted notepad++ text?
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
Tailq of linked list
Several important parameters of LDO circuit design and type selection
PMSM dead time compensation
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
随机推荐
Shape template matching based on Halcon learning [VII] reuse_ model. Hdev routine
Synchronization of QT multithreading
go依赖注入--google开源库wire
My-basic application 2: my-basic installation and operation
实例006:斐波那契数列
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
PMSM dead time compensation
Halcon's practice based on shape template matching [1]
实例007:copy 将一个列表的数据复制到另一个列表中。
Correlation based template matching based on Halcon learning [II] find_ ncc_ model_ defocused_ precision. hdev
Sizeof (function name) =?
Summary -st2.0 Hall angle estimation
实例008:九九乘法表
Explain task scheduling based on Cortex-M3 in detail (Part 1)
[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
Live555 RTSP audio and video streaming summary (II) modify RTSP server streaming URL address
【三层架构及JDBC总结】
Google sitemap files for rails Projects - Google sitemap files for rails projects
实例010:给人看的时间
Let's briefly talk about the chips commonly used in mobile phones - OVP chips