This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author David.Manowitz
Recipients David.Manowitz
Date 2016-04-14.01:14:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1460596491.57.0.479961799171.issue26751@psf.upfronthosting.co.za>
In-reply-to
Content
I'm trying to sort a list of tuples.  Most of the tuples are pairs of US state names.  However, some of the tuples have None instead of the 2nd name.  I want the items sorted first by the 1st element, and then by the 2nd element, BUT I want the None to count as LARGER than any name.  Thus, I want to see [('Alabama', 'Iowa'), ('Alabama', None)] rather than [('Alabama', None), ('Alabama', 'Iowa')].  I defined the following comparitor:

def cmp_keys (k1, k2):
    retval = cmp(k1[0], k2[0])
    if retval == 0:
        if k2[1] is None:
            retval = -1
        if k1[1] is None:
            retval = 1
        else:
            retval = cmp(k1[1], k2[1])
                
    return retval

However, once I sort using this, some of the elements are out of order.
History
Date User Action Args
2016-04-14 01:14:51David.Manowitzsetrecipients: + David.Manowitz
2016-04-14 01:14:51David.Manowitzsetmessageid: <1460596491.57.0.479961799171.issue26751@psf.upfronthosting.co.za>
2016-04-14 01:14:51David.Manowitzlinkissue26751 messages
2016-04-14 01:14:50David.Manowitzcreate