Some interesting performance comparisons, under Python 3.2.  Times are 
relative, and are for an initial list of tuples with 500,000 items.  

(1)    ans = []                                                                 
#relative time: 298
         for item in lst:
             ans += list(item)
         return ans

(2)    return [item[0] for item in lst]                          #relative 
time:  106

(3)    from operator import itemgetter                     #relative time:   84
         return list(map(itemgetter(0), lst))

(4)    import itertools                                                   
#relative time:  63
         return list(itertools.chain.from_iterable(lst))

(5)    return [x for (x,) in lst]                                      
#relative time:  52


With the caveat that 'your mileage may vary'

Regards,
Mark

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to