469,293 Members | 1,335 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,293 developers. It's quick & easy.

list.sort(): heaviest item?

If I have a list of items of mixed type, can I put something into it
such that after a list.sort(), is guaranteed to be at the end of the
list?

Looking at http://www.python.org/doc/2.3.5/ref/comparisons.html
"Most other types compare unequal unless they are the same object; the
choice whether one object is considered smaller or larger than another
one is made arbitrarily but consistently within one execution of a
program."

makes me unsure.

It looks like "None" always ends up at the start ("lightest"), but I
want the opposite ("heaviest").

-Steven
Apr 8 '08 #1
1 1239
On Apr 8, 8:15*am, "Steven Clark" <steven.p.cl...@gmail.comwrote:
If I have a list of items of mixed type, can I put something into it
such that after a list.sort(), is guaranteed to be at the end of the
list?
Since the other guys gave you the real answer, how about this:

sentinel = object()
mylist.sort()
mylist.append(sentinel)

_ ~
@ @
\_/

Apr 8 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Derek Basch | last post: by
5 posts views Thread by Valkyrie | last post: by
4 posts views Thread by Seeker | last post: by
18 posts views Thread by Doug Bell | last post: by
6 posts views Thread by Julia | last post: by
6 posts views Thread by Nick Valeontis | last post: by
6 posts views Thread by Tekkaman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.