zoukankan      html  css  js  c++  java
  • python 列表 list的基本操作

    一,Python : list.append(x)

    一个加到a[len(a):] = [x]

    list.extend(L)
    一个加到一个a[len(a):] = L

    list.insert(i, x) 一个一个a.insert(0, x) a.insert(len(a), x) a.append(x)

    list.remove(x)
    x 一个一个

    list.pop([i ])
    a.pop() 一个(i 你会Python )

    list.index(x)
    一个x 一个

    list.count(x)
    x

    list.sort()

    list.reverse()

    二,链使便为一个使一个(先出)append() 一个加 到pop() 一个:

    >>> stack = [3, 4, 5] >>> stack.append(6) >>> stack.append(7) >>> stack

    [3, 4, 5, 6, 7]

    >>> stack.pop() 7
    >>> stack
    [3, 4, 5, 6] >>> stack.pop() 6

    >>> stack.pop() 5
    >>> stack
    [3, 4]

    三,

    5.1.2 使

    使(先出)很快; (为了一个)

    使collections.deque 设计:

    >>> from collections import deque
    >>> queue = deque(["Eric", "John", "Michael"])

    >>> queue.append("Terry") >>> queue.append("Graham") >>> queue.popleft()
    ’Eric’

    # Terry arrives
    # Graham arrives
    # The first to arrive now leaves
    

    >>> queue.popleft()
    ’John’

     

    四,列

    为从了一个一些 过返

    , 一个 squares , :

    目的: = **for in ()]

    squares = map(lambda x: x**2, range(10)),

    一个一个 for for if 一个for if 上下果构

    两个:

    :

    >>> combs = []
    >>> for x in [1,2,3]:

    for y in [3,1,4]: if x != y:

    ...
    ...
    ...
    ...
    >>> combs
    [(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]

     
  • 相关阅读:
    火车头采集器如何采集QQ群成员中的QQ号
    Unix目录结构的来历
    加速Windows 2003关机速度的设置方法
    win2003 序列号 windows2003 sp2可用序列号大全(准版与企业版)
    自己动手在win2003系统中添加虚拟网卡
    Windows Server 2003下DHCP服务器的安装与简单配置图文教程
    win2003远程桌面怎么切换到多用户?
    Win2003打开网页时总是提示添加网址到信任站点的设置方法
    我们正在招聘java工程师,想来美团工作吗?
    JUC回顾之-AQS同步器的实现原理
  • 原文地址:https://www.cnblogs.com/wangyue0925/p/9628166.html
Copyright © 2011-2022 走看看