Creating a list/tuple/dictionary
peter at engcorp.com
Tue Jan 7 16:52:01 CET 2003
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.
More information about the Python-list