Internals and complexity of types, containers and algorithms

Harald Luessen harald.luessen at
Tue Jun 26 19:35:41 CEST 2007

On Mon, 25 Jun 2007 James Stroud wrote:

>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.

Are there arrays in numpy that can efficiently be used for 
other things than matrix arithmetic? Are they faster than lists 
but still easy to use?

no_piece = 0
wpawn = 1
board[square] = no_piece
board[square+8] = pawn

could be a typical pawn move.

>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 

I like the python way of "best" code. But in this particular 
question the emphasis was on performance and speed.

>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))

I am not new to board game programming and I am used to 
an array approach or even bitboards. Therefore the dictionary 
looks a little bit strange to me.


More information about the Python-list mailing list