There are several ways to delete elements from a list. If you know the index of the element you want, you can use pop:

pop modifies the list and returns the element that was removed.

If you don’t need the removed value, you can use del operator:


If you know the element you want to remove (but not the index), you can use remove:

The return value from remove is None.

To remove more than one element, you can use del with a slice index:

As usual, the slice selects all elements up to, but not including, the second index.

from Thinking in Python

Deleting elements的更多相关文章

  1. Array类

    class Array Arrays are ordered, integer-indexed collections of any object. Array indexing starts at ...

  2. Java性能提示(全)

    http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...

  3. Think Python - Chapter 10 - Lists

    10.1 A list is a sequenceLike a string, a list is a sequence of values. In a string, the values are ...

  4. vector list array deque

    因此在实际使用时,如何选择这三个容器中哪一个,应根据你的需要而定,一般应遵循下面 的原则:   1.如果你需要高效的随即存取,而不在乎插入和删除的效率,使用vector   2.如果你需要大量的插入和 ...

  5. Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh

    Hyperpolyglot Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh grammar | quoting and escaping | charactersvar ...

  6. Multidimensional Arrays

    Overview An array having more than two dimensions is called a multidimensional array in the MATLAB® ...

  7. Dom4j学习笔记

    一.Loading XML Data 以下代码从File中或一个URL中读取一个XML文件,并产生一个Document对象.一个Document对象表示了内存中的一棵XML树,可以在这个XML树中进行 ...

  8. Ultimate guide to learning AngularJS in one day

    What is AngularJS? Angular is a client-side MVC/MVVM framework built in JavaScript, essential for mo ...

  9. Read-Copy Update Implementation For Non-Cache-Coherent Systems

    A technique for implementing read-copy update in a shared-memory computing system having two or more ...

随机推荐

  1. 拷贝构造函数不能传值,只能传引用,而且一般是传const引用

    为什么呢?因为传值函数,需要调用拷贝构造函数,那就层层循环无止境了.

  2. WinCE C#程序,控制启动时仅仅能启动一个程序,使用相互排斥量来实现,该实现方法測试通过

    </pre><pre code_snippet_id="430174" snippet_file_name="blog_20140718_5_46349 ...

  3. android学习笔记(5)Activity生命周期学习

    每一个activity都有它的生命周期,开启它,关闭它,跳转到其他activity等等,都会自己主动调用下面某种方法.对这些个方法覆写后观察学习. protected void onCreate(Bu ...

  4. UI_UIImagePickerController(读取图片)

    创建图片 #pragma mark - 创建 photoImageView - (void)createphotoImageView { self.photoImageView = [[UIImage ...

  5. linux高级技巧:heartbeat+lvs(三)

    之前我们把LVS和heartbeat都单独进行了測试,是时候进行合并了 1.LVS+heartbeat:         首先显示我们的控制台:                        让这两个 ...

  6. android 退出系统

    /** * */ package com.szkingdom.android.phone.utils; import java.io.BufferedReader; import java.io.IO ...

  7. poj--2549--Sumsets(二分查找)

    Sumsets Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Statu ...

  8. 用Beamer做Slides

    学术用幻灯片,首选还是latex.但是问题来了,Beamer这个latex幻灯模板还需要很多自定义设置.于是找了网上一些自己觉得好的例子. http://www.latexstudio.net/ind ...

  9. 《汇编语言(第三版)》pushf 和 popf 指令,以及标志寄存器在 Debug 中的表示

    pushf 和 popf pushf 的功能是将标志寄存器的值压栈,而 popf 是从栈中弹出数据,输入标志寄存器. pushf 和 popf,为直接访问寄存器提供了方法. 格式 pushf popf ...

  10. Devexpress控件使用一:GridControl

    1.控件及列表展示 1).控件 2).构建表格,用于列表展示 3).gridControl绑定数据 4).调用绑定:BindDataSource(InitDt()); 5).展示列表 2.表格的列配置 ...