insert unique data in a list

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Dec 13 15:09:36 EST 2009


On Sun, 13 Dec 2009 10:48:11 -0800, Fire Crow wrote:

> You could also define a custom object that manages a custom ordered set
[...]
> I've used this on a few projects, it makes for wonderfully clean code,
> because you can look at your program as an overview without all the
> arithmetic behind it.

Which is all very good, but beware that your "ordered set" implementation 
is O(N) for insertions, which may be slow once the set grows large enough.

Also, I'm not sure I like your abuse of the + operator to modify the 
object in place and return a flag. It is an API not shared by (as far as 
I can see) any other data type in Python.


-- 
Steven



More information about the Python-list mailing list