python_第五节
5.数据结构
这里介绍更多的数据的用法
5.1.1 lists进阶
list 数据类型有很多方法，这里列举其所有的方法
list.append(X): 添加一个元素到数列中
list.extend(L): 将给定数列扩展到原数列中
list.insert(i, x): 在给定位置插入元素 i为位置
list.remove(x): 删除给定元素
list.pop([i]): 弹出数列中的给定位置的元素
list.clear(): 删除所有的元素
list.index(x): 给定元素的在数列中的位置
list.count(x): 计算给定元素在数列中出现的次数
list.sort(key=None, reverse=False): 排序
list.reverse(): 反转数列中的元素
list.copy(): 返回list的拷贝

示例：
>>> a = [66.25, 333, 333, 1, 1234.5]
>>> print(a.count(333), a.count(66.25), a.count('x'))
2 1 0
>>> a.insert(2, -1)
>>> a.append(333)
>>> a
[66.25, 333, -1, 333, 1, 1234.5, 333]
>>> a.index(333)
1
>>> a.remove(333)
>>> a
[66.25, -1, 333, 1, 1234.5, 333]
>>> a.reverse()
>>> a
[333, 1234.5, 1, 333, -1, 66.25]
>>> a.sort()
>>> a
[-1, 1, 66.25, 333, 333, 1234.5]
>>> a.pop()
1234.5
>>> a
[-1, 1, 66.25, 333, 333]

5.1.2 用list实现栈
>>> 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.3 使用lists作为队列
>>> queue = deque(["Eric", "John", "Michael"])
>>> queue.append("Terry")           # Terry arrives
>>> queue.append("Graham")          # Graham arrives
>>> queue.popleft()                 # The first to arrive now leaves
'Eric'
>>> queue.popleft()                 # The second to arrive now leaves
'John'
>>> queue                           # Remaining queue in order of arrival
deque(['Michael', 'Terry', 'Graham'])

*.popleft()

5.1.3 List Comprehensions
List comprehensions 提供了更加简洁的方法创建lists.
eg:
>>> squares = []
>>> for x in range(10):
...     squares.append(x**2)
...
>>> squares
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

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

squares = [x**2 for x in range(10)]
更加的简洁和易读

表达式创建法：
>>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]

5.1.4 嵌套的list comprehensions
在list comprehension初始表达式可以是任意的，包括另一个list comprehensions
