On 8/24/06, Michael Chermside <[EMAIL PROTECTED]> wrote: > Jim Jewett writes: > > Given an arbitrary collection of objects, I want to be able to order > > them in a consistent manner, at least within a single interpreter > > session.
> I think this meets your specifications: > >>> myList = [2.5, 17, object(), 3+4j, 'abc'] > >>> myList.sort(key=id) Yes; not nicely, but it does. I would prefer that it be the fallback after first trying a regular sort. Now I'm wondering if the right recipe is to try comparing the objects, then the types, then the id, or whether that would sometimes be inconsistent even for sane objects if only some classes know about each other. The end result is that even if I find a solution that works, I think it will be common (and bug-prone) enough that it really ought to be in the language, or at least the standard library -- as it is today for objects that don't go out of their way to prevent it. > Frankly, I don't know why you have an "arbitrary collection of objects" mostly for debugging and tests. > Of course, I doubt this is what you're doing because if you > REALLY had arbitrary objects (including uncomparable things like > complex numbers) More precisely, my code is buggy when faced with complex numbers or Numeric arrays -- but in practice, it isn't faced with those. It *is* faced with tuples, lists, strings, ints, floats, and instances of arbitrary program-specific classes. These all work fine today, because sort either special cases or falls back to using id *without throwing an exception*. -jJ _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
