当前位置:网站首页>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 virtualization environment of QEMU
- Synchronization of QT multithreading
- Explication de la procédure stockée pour SQL Server
- 动力电池UL2580测试项目包括哪些
- STM32---IIC
- QEMU STM32 vscode debugging environment configuration
- Sword finger offer 06 Print linked list from end to end
- Detailed summary of FIO test hard disk performance parameters and examples (with source code)
- 关于线性稳压器的五个设计细节
- [nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
猜你喜欢

Hardware and software solution of FPGA key chattering elimination

After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update

FIO测试硬盘性能参数和实例详细总结(附源码)

The firmware of the connected j-link does not support the following memory access

Why is 1900 not a leap year

Installation and use of libjpeg and ligpng
![[trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code](/img/58/576b6b77509ed7a9bef138f3899e37.jpg)
[trio basic tutorial 17 from getting started to mastering] set up and connect the trio motion controller and input the activation code
实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?

Introduction of air gap, etc

实例009:暂停一秒输出
随机推荐
Shape template matching based on Halcon learning [vi] find_ mirror_ dies. Hdev routine
Various types of questions judged by prime numbers within 100 (C language)
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
Measurement fitting based on Halcon learning [i] fuse Hdev routine
List of linked lists
STM32 single chip microcomputer - external interrupt
Sql Server的存储过程详解
VESC Benjamin test motor parameters
动力电池UL2580测试项目包括哪些
matlab timeserise
Bluebridge cup internet of things basic graphic tutorial - GPIO output control LD5 on and off
Synchronization of QT multithreading
OLED 0.96 inch test
Adaptive filter
[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc
leetcode - 445. 两数相加 II
Sword finger offer 05 Replace spaces
[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...)
[NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
关于线性稳压器的五个设计细节