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 ...
随机推荐
- 【转载】SQLITE3 使用总结
转载自网友董淳光的文章. 前序: 这里要注明,我是一个跨平台专注者,并不喜欢只用 windows 平台.我以前的工作就是为 unix 平台写代码.下面我所写的东西,虽然没有验证,但是我已尽量不使用任何 ...
- C++中的字节对齐
本博客(http://blog.csdn.net/livelylittlefish)贴出作者(三二一.小鱼)相关研究.学习内容所做的笔记,欢迎广大朋友指正! 字节对齐 1. 基本概念字节对齐:计算机存 ...
- jni javah
如何通过javah生成jni头文件 1.javah的使用说明: -classpath 给出包含native接口的java类的.class文件路径 -d / –o 指定生成的头文件的,-d只给出文件 ...
- Redis-1-安装
Redis-1-安装 标签(空格分隔): linux,redis 下载 cd /usr/local/src/ wget http://download.redis.io/releases/redis- ...
- Codeforces 701E Connecting Universities 贪心
链接 Codeforces 701E Connecting Universities 题意 n个点的树,给你2*K个点,分成K对,使得两两之间的距离和最大 思路 贪心,思路挺巧妙的.首先dfs一遍记录 ...
- jquery/zepto在插件编写上的几点区别
1. 自定义事件的命名空间 jq的时间命名空间是用点“.”,而zepto是用冒号“:” 如 //jquery $(this).trigger('cusevent.pluginname'); //zep ...
- Visual Studio蛋疼问题解决(1)
监视变量显示未定义标识符: VS2012在编译的时候采用了较快的编译模式,所以有些变量就显示未定义了. 解决方案: 项目->属性->c/c++->优化->改为禁用/OD ...
- Codeforces 723D. Lakes in Berland
解题思路: 1.dfs所有的水,顺便计数大小并判断是不是湖. 2.如果是湖,将大小和坐标存下来. 3.对湖按大小从小到大排序. 4.dfs前(湖的数量-k)个湖,用*填充这些湖. 代码: #inclu ...
- Codeforces 986B. Petr and Permutations(没想到这道2250分的题这么简单,早知道就先做了)
这题真的只能靠直觉了,我没法给出详细证明. 解题思路: 1.交换3n次或者7n+1次,一定会出现一个为奇数,另一个为偶数. 2.用最朴素的方法,将n个数字归位,计算交换次数. 3.判断交换次数是否与3 ...
- Rx = Observables + LINQ + Schedulers
The Reactive Extensions (Rx) is a library for composing asynchronous and event-based programs using ...