Creating a list/tuple/dictionary

Andrew Wilkinson ajw126NO at SPAMyork.ac.uk
Tue Jan 7 11:28:20 EST 2003


Oops, I shouldn't have used the word quicker there, I'm just interested in
how the Python internals work.

Thanks for the reply though,
Andrew

"Peter Hansen" <peter at engcorp.com> wrote in message
news:3E1AF7A1.A5471403 at engcorp.com...
> Andrew Wilkinson wrote:
> >
> > When the Python interpreter comes across a statement such as...
> > a = [1,2,3]
> > how does it go about creating that list?
> >
> > Does it convert the code into something equivalent to
> [...]
> > or is there a quicker method that it uses, if so is that accessible from
> > ordinary python code?
>
> You really don't need to worry about which method is quicker, unless
> you are encountering serious performance problems already, in which
> case you'd get a *far* bigger performance boost in general by rewriting
> some code as a C extension rather than trying to optimize your Python
code.
>
> Consider that by choosing Python as your programming language you
> have already made readability and maintainability a much higher priority
> than performance.  You've chosen to run your program between ten and 100
> times slower than the equivalent C, in certain cases.  If you then
> start spending time finding alternative approaches to something as clean
> and readable as "a = [1, 2, 3]", you are defeating the advantages you
> get with your choice, making it pointless to use Python... IMHO.
>
> -Peter






More information about the Python-list mailing list