Copying lists
When you assign an object to a variable, Python copies the reference to the object.

In this case a and b refer to the same list.
If you want to copy the list (not just a reference to it), you can use the slice operator:

Making a slice of a creates a new list. in this case the slice contains all of the elements from the original list.
Another way to make a copy is the copy function from the copy module:

But is more idiomatic to use the slice operator.
from Thinking in Python
Copying lists的更多相关文章
- Copying Linked Lists with Random Pointers
Copying Linked Lists with Random Pointers 两个方法:方法一: 1.不考虑随机指针的情况下复制链表: 2.在复制过程中建立一个以原链表节点地址为key,相应的复 ...
- [转]Unity: make your lists functional with ReorderableList
原文地址:http://va.lent.in/unity-make-your-lists-functional-with-reorderablelist/ This article is reprod ...
- [LeetCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- [LeetCode] Merge k Sorted Lists 合并k个有序链表
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 这 ...
- [LeetCode] Merge Two Sorted Lists 混合插入有序链表
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...
- 21. Merge Two Sorted Lists —— Python
题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...
- 【leetcode】Intersection of Two Linked Lists
题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...
- [LintCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...
- [LintCode] Merge Two Sorted Lists 混合插入有序链表
Merge two sorted (ascending) linked lists and return it as a new sorted list. The new sorted list sh ...
随机推荐
- HDOJ 1753 大明A+B
JAVA大数.... 大明A+B Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- SSH公钥认证
一.实验的目的 了解密钥对的创建和使用,掌握免password远程登录和远程操作 二.实验环境 本地主机 rh1: 192.168.233.3/24 远程主机 rh2: 192.168.233.4/2 ...
- 四种GCC内置位运算函数
int __builtin_ffs (unsigned int x) 返回x的最后一位1的是从后向前第几位,比方7368(1110011001000)返回4. int __builtin_clz (u ...
- GIT GUI简易教程
GIT GUI简易教程 前言 之前一直想一篇这样的东西,因为最初接触时,我也认真看了廖雪峰的教程,但是似乎我觉得讲得有点多,而且还是会给我带来很多多余且重复的操作负担,所以我希望能压缩一下它在我工作中 ...
- zzulioj--1708--01串也疯狂之光棍也有伴(dp)
1708: 01串也疯狂之光棍也有伴 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 199 Solved: 50 SubmitStatusWeb B ...
- 高斯滤波及高斯卷积核C++实现
高斯滤波是一种线性平滑滤波,适用于消除高斯噪声,在图像处理的降噪.平滑中应用较多,特别是对抑制或消除服从正态分布的噪声非常有效. 高斯滤波的过程其实就是对整幅图像进行加权平均操作的过程.滤波后图像上每 ...
- [JZOJ 5911] [NOIP2018模拟10.18] Travel 解题报告 (期望+树形DP)
题目链接: http://172.16.0.132/senior/#contest/show/2530/1 题目: EZ同学家里非常富有,但又极其的谦虚,说话又好听,是个不可多得的人才. ...
- 查看typedef类型
typedef unsigned long int NUM; #include <iostream> using namespace std; NUM x; cout << t ...
- Visual Studio蛋疼问题解决(1)
监视变量显示未定义标识符: VS2012在编译的时候采用了较快的编译模式,所以有些变量就显示未定义了. 解决方案: 项目->属性->c/c++->优化->改为禁用/OD ...
- (转载)ScratchView
首页 我的管理 客户端 登录注册 首页 安卓组件中心 安卓代码分享 Swift专区 HTML5移动开发 视频中心 小程序 名称: ScratchView 作者: doliangzhe 来源: gith ...