list.sort(): heaviest item?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven Clark

    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
  • Raymond Hettinger

    #2
    Re: list.sort(): heaviest item?

    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(s entinel)

    _ ~
    @ @
    \_/

    Comment

    Working...