判断列表是否为空
if not a:
print "List is empty"
这里是因为空列表会返回一个False
获取列表的索引和值
ints = [8, 23, 45, 12, 78]
for...idx, val in enumerate(ints):
print idx, val
0 8
1 23
2 45
3 12
4 78
合并列表中的子列表
1 method
l=[[1,2,3...l for item in sublist])
[1, 2, 3, 4, 5, 6, 7, 8, 9]
2 method
l=[[1,2,3],[4,5,6], [7], [8,9]]
print(sum...列表中字典的值排序
list_to_be_sorted = [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}]
from operator...按照步长遍历列表
a[start:end:step] # 按照step步长直到end-1结束,并不是从start一个个遍历到end
Python中的appen和extend
x = [1, 2, 3]