时间: 2020-11-25|79次围观|0 条评论

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

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/wangyue0925/p/9628166.html

原文链接:https://blog.csdn.net/weixin_30342827/article/details/95903868

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《python 列表 list的基本操作
   

还没有人抢沙发呢~