¶数据结构
¶列表
- functions on lists
 
1  | list.append(x) #向列表末尾添加元素,a【len(a):】=【x】  | 
1  | #!/usr/bin/env python  | 
- 输出
 
1  | 2  | 
¶用于栈
1  | #!/usr/bin/env python  | 
- 输出
 
1  | [3, 4, 5, 6]  | 
¶列表用于队列
¶queue
1  | #!/usr/bin/env python  | 
- 输出
 
1  | deque(['Eric', 'Join', 'Michae', 'Terry'])  | 
¶列表推导式(列表生成式)
¶list-comprehensions
1  | #!/usr/bin/env python  | 
- 输出
 
1  | [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]  | 
¶list-comprehensions1
1  | #!/usr/bin/env python  | 
- 输出
 
1  | [(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]  | 
¶list-comprehensions2
1  | #!/usr/bin/env python  | 
- 输出
 
1  | [-8, -4, 0, 4, 8]  | 
¶嵌套列表生成式
1  | #!/usr/bin/env python  | 
- 输出
 
1  | [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]  | 
¶del语句
1  | #!/usr/bin/env python  | 
- 输出
 
1  | [-1, 0, 1, 2, 3, 4, 77, 99, 3444]  | 
¶元组与序列
1  | #!/usr/bin/env python  | 
- 输出
 
1  | example  | 
¶sets
- set_example
用花括号或者set()函数创建sets(创建空的sets需要用set()函数) 
1  | #!/usr/bin/env python  | 
- 输出
 
1  | {'apple', 'pear', 'banana', 'orange'}  | 
¶字典
1  | #!/usr/bin/env python  | 
- 输出
 
1  | {'jack': 4098, 'sape': 4139}  | 
¶循环技术
- 
looping through dictionaries
 - 
looping through sequence
 - 
loop over more sequence
 - 
loop over a sequence in reverse
 - 
loop over a sequence in sorted order
 - 
loop create a list
 
1  | #!/usr/bin/env python  | 
- 输出
 
1  | looping through dictionaries:  | 
¶更多的条件语句
- 用在while if语句中
 
¶比较类型
- in and not in 检查一个值是否在序列中
 - is and is not 比较 =两个对象是否相同
 - a小于b连等于c 几个比较可以被链接
 - (A and (not B)) or C 几个比较可以用布尔操作符联合
 
1  | #!/usr/bin/env python  | 
- 输出
 
1  | Trondheim  | 
¶序列与其他类型的比较
1  | (1, 2, 3) < (1, 2, 4)  | 


