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的更多相关文章

  1. Copying Linked Lists with Random Pointers

    Copying Linked Lists with Random Pointers 两个方法:方法一: 1.不考虑随机指针的情况下复制链表: 2.在复制过程中建立一个以原链表节点地址为key,相应的复 ...

  2. [转]Unity: make your lists functional with ReorderableList

    原文地址:http://va.lent.in/unity-make-your-lists-functional-with-reorderablelist/ This article is reprod ...

  3. [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 ...

  4. [LeetCode] Merge k Sorted Lists 合并k个有序链表

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 这 ...

  5. [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 ...

  6. 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 ...

  7. 【leetcode】Intersection of Two Linked Lists

    题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...

  8. [LintCode] Intersection of Two Linked Lists 求两个链表的交点

    Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...

  9. [LintCode] Merge Two Sorted Lists 混合插入有序链表

    Merge two sorted (ascending) linked lists and return it as a new sorted list. The new sorted list sh ...

随机推荐

  1. 译:MySQL性能优化的21条最佳经验

    今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数据 ...

  2. 多本Web前端深度修炼书籍(提供网盘下载链接)

    书籍介绍:这本书涵盖了html5新增标签和功能,而且提供了jquerymobile,Phonegap,Sencha Touch框架的介绍和应用,最后还带了一个移动web应用的样例,绝对是移动web开发 ...

  3. Linux以下的两种文件锁

    文件锁是一种文件读写机制.在不论什么特定的时间仅仅同意一个进程訪问一个文件. 利用这样的机制可以使读写单个文件的过程变得更安全. 在这篇文章中.我们将探讨Linux中不同类型的文件锁,并通过演示样例程 ...

  4. oracle刚開始学习的人经常使用操作100问

    oracle刚開始学习的人经常使用操作100问 1. Oracle安装完毕后的初始口令?   internal/oracle sys/change_on_install system/manager ...

  5. Unique path ii

    Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...

  6. 苹果要求全部新app以及版本号更新必须支持iOS 8 SDK和64-bit

    2014年10月20日.苹果官方公布了一则新闻,新闻内容例如以下: Starting February 1, 2015, new iOS apps uploaded to the App Store ...

  7. 解决linux ping: unknown host www.baidu.com

    如果ping域名的时候出现ping:unknown host  xxx.xxx 但是ping IP地址的时候可以通的话 可知是dns服务器没有配置好, 查看一下配置文件/etc/resolv.conf ...

  8. spring中bean标签factory-method和factory-bean)详解工厂方法(factory-method和factory-bean)

    转自:http://blog.sina.com.cn/s/blog_6d3c1ec601019f3j.html A.factory-method The name of a factory metho ...

  9. C#多播委托和事件的区别与关系

    事件是对委托的封装. 如果一个类里,你把一个委托声明为 public 了,那么外部就可以随意改变委托变量的值,包括清空委托变量等,这样的话就违背了面向对象思想的封装特性:但如果声明为 private ...

  10. SQL中一次插入多条数据

    SQL中insert一次可以插入一条数据,我们有三种方法可以一次性插入多条数据. 1. 语法:select 字段列表 into 新表 from 源表 注意事项:此种方法新表是系统自动创建,语句执行前不 ...