On Nov 16, 2:41 pm, Chris Rebert <c...@rebertia.com> wrote:
> On Mon, Nov 16, 2009 at 2:30 PM, Hyunchul Kim
>
> <hyunchul.mail...@gmail.com> wrote:
> > Hi, all.
>
> > I want to improve speed of following simple function.
> > Any suggestion?
>
> > **********
> > def triple(inputlist):
> >   results = []
> >   for x in inputlist:
> >     results.extend([x,x,x])
> >   return results


Here's an itertools variant that is somewhat speedy when the inputlist
is long:

    from itertools import *

    def triple3(inputlist, list=list,
chain_from_iterable=chain.from_iterable, izip=izip):
        return list(chain_from_iterable(izip(inputlist, inputlist,
inputlist)))

Raymond


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

Reply via email to