Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4074
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2011-04-26 12:39 -0700 |
| Subject | Re: De-tupleizing a list |
| From | Mark Niemczyk <prahamark@gmail.com> |
| Message-ID | <mailman.868.1303847500.9059.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar
Re: De-tupleizing a list Mark Niemczyk <prahamark@gmail.com> - 2011-04-26 12:39 -0700
csiph-web