至少Python 2.7中最快的方法是t0,t1,t2=zip(*G) for SMALLER lists and [x[0] for x in G] in general
下面是测试:from operator import itemgetter
G = [(1, 2, 3), ('a', 'b', 'c'), ('you', 'and', 'me')]
def f1():
return tuple(x[0] for x in G)
def f2():
return tuple(map(itemgetter(0), G))
def f3():
return tuple(x for x, y, z in G)
def f4():
return tuple(list(zip(*G))[0])
def f5():
t0,*the_rest=zip(*G)
return t0
def f6():
t0,t1,t2=zip(*G)
return t0
cmpthese.cmpthese([f1,f2,f3,f4,f5,f6],c=100000)
结果:rate/sec f4 f5 f1 f2 f3 f6
f4 494,220 -- -21.9% -24.1% -24.3% -26.6% -67.6%
f5 632,623 28.0% -- -2.9% -3.0% -6.0% -58.6%
f1 651,190 31.8% 2.9% -- -0.2% -3.2% -57.3%
f2 652,457 32.0% 3.1% 0.2% -- -3.0% -57.3