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)]

     
  • 相关阅读:
    软件测试人员的年终绩效考核怎么应对
    收藏
    顶踩组件 前后两版
    订阅组件
    hdu 1963 Investment 完全背包
    hdu 4939 Stupid Tower Defense 动态规划
    hdu 4405 Aeroplane chess 动态规划
    cf 414B Mashmokh and ACM 动态规划
    BUPT 202 Chocolate Machine 动态规划
    hdu 3853 LOOPS 动态规划
  • 原文地址:https://www.cnblogs.com/wangyue0925/p/9628166.html
Copyright © 2011-2022 走看看