Re: Memoization and encapsulation

2006-01-04 Thread drewp
> Faster is: > >class FastHashableList(list): > def __hash__(self): > return id(self) But that's wrong. Two equal objects must hash to the same value, and you're not guaranteeing that at all. My degenerate __hash__ does guarantee that, and I still claim the performance impact from collision

Re: Memoization and encapsulation

2006-01-04 Thread drewp
But while we're at it, how about that unhashable object problem? @memoised def func(x, i): return x[i] L = [1,2,3] print func(L, 1) # TypeError: list objects are unhashable What's the deal? My func can certainly be memoized (but possibly with a slower lookup depending on how many args are

Re: Is Python good for graphics?

2005-01-03 Thread drewp
Esmail Bonakdarian wrote: > > Basically, I would like to be able to create some basic animations > where I can help visualize various sorting algorithms (for instance > http://ciips.ee.uwa.edu.au/~morris/Year2/PLDS210/sorting.html#insert_anim) > or graph searches (coloring nodes as each gets visit