python小记列表排序
a=[('b',4),('a',7),('c',2)]正向排序a.sort()
反向排序:a.sort(reverse=True)
对第二关键字排序
a.sort(lambda x,y:cmp(x,y))
a.sort(key=lambda x:x)
第三种用模块:
import operator
a.sort(key=operator.itemgetter(1))
前3种是对list item中某一项进行排序
第四种使用(Decorate-Sort-Undercorate)(对list排序的方法)
A=[(x,i,x)for i,x in enumerate(a)]
A.sort()
B=for s in A]
效率比较
cmp<DSU<key
第5种
a.sort(key=lambda x:x)
第6种
a.sort(key=lambda x:x,x)
第7种
a.sort(key=operator.itemgetter(1,0))
import os
def c():
print 'a:',os.getpid()
print 'b:',os.getppid()
os._exit()
def c1():
while 1:
new=os.fork()
print new
if new==0:
c()
else:
pis=(os.getpid().new)
print pis
print'cc:',os.getppid()
if raw_input()=='q':
break
c1()
页:
[1]