which is more pythonic/faster append or +=[]

7stud bbxx789_05ss at yahoo.com
Mon May 14 12:22:46 EDT 2007


On May 10, 2:39 pm, Steven Bethard <steven.beth... at gmail.com> wrote:
> 7studwrote:
> >> Is there any documentation for the syntax you used with timeit?
>
> > This is the syntax the docs describe:
> [snip
> > python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement ...]
> [snip]
> > Then in the examples in section 10.10.2
> [snip]
> > timeit.py 'try:' '  str.__nonzero__' 'except AttributeError:' '  pass'
> [snip]
> > and then there is Alex Martelli's syntax:
> [snip]
> > python -mtimeit 'L=range(3); n=23' 'x=L[:]; x.append(n)'
>
> The following three things are equivalent:
>      python /path/to/<module>.py
>      /path/to/<module>.py         # assuming the OS knows how to exec it
>      python -m<module>            # assuming <module> is on sys.path
>
> So that just leaves the differences between:
>      [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement ...]
>      'try:' '  str.__nonzero__' 'except AttributeError:' '  pass'
>      'L=range(3); n=23' 'x=L[:]; x.append(n)'
>
> Those look pretty similar to me (aside from the fact that they're
> testing different things). Each argument in single quotes is a line of
> the code you want timed.
>

Thanks.




More information about the Python-list mailing list