Internals and complexity of types, containers and algorithms

James Stroud jstroud at mbi.ucla.edu
Mon Jun 25 17:48:00 EDT 2007


Harald Luessen wrote:
> Hi, I am new to python and I miss some understanding of the internals 
> of some types and containers. With my C/C++ background I hope to get 
> some hints to chose the best data structure for my programs. Here are 
> some questions:

This depends on how you define "best". If you want speed and 
optimization, you can use the numpy package built with ATLAS tuned for a 
specific machine.

Beyond speed, "best" in the python community usually means "most suited" 
from an idiomatic perspective and from the perspective of structure that 
lends itself to long term maintainability because [C]python data 
structures seem to undergo optimizations in their implementation at each 
revision.

Your best bet is probably to forget about implementation and write code 
that makes sense. For example, some have suggested a tuple-keyed 
dictionary to represent a chess board:

board = ((c,r) for r in xrange(1, 9) for c in 'abcdefgh')
starting = 'RNBQKBNR' + 'P' * 8 + ' ' * 32 + 'p' * 8 + 'rnbqkbnr'
position = dict(zip(board, starting))

Of course we see here the chief problem with algebraic notation: it 
begins numbering at 1 which is painfully reminiscient of fortran.

James



More information about the Python-list mailing list