creating an artificial "last element" in sort list

Ian Kelly ian.g.kelly at gmail.com
Fri Sep 28 19:45:43 EDT 2012


On Fri, Sep 28, 2012 at 5:39 PM, dave <davidreynon at gmail.com> wrote:
> a = ['a', 'b', x]
>
> b = sorted(a)
>
> What does x need to be to always be last on an ascending sort no matter what 'a' and 'b' are.... within reason... I am expecting 'a' and 'b' will be not longer than 10 char's long.... I tried making x = 'zzzzzzzzzzzzzzzz' and believe it or not, this appears FIRST on the sort!!!

It appears last when I run the code.

To answer your question, though, if you want to force x to be last,
then I suggest removing it from the list and then appending it to the
end.



More information about the Python-list mailing list