sorting strings numerically while dealing with missing values

Larry Martell larry.martell at gmail.com
Wed Dec 28 15:14:39 EST 2016


I have a list containing a list of strings that I want to sort
numerically by one of the fields. I am doing this:

sorted(rows, key=float(itemgetter(sortby)))

Which works fine as long as all the sort keys convert to a float.
Problem is that some are blank or None and those throw an exception.
How can I handle that case and still sort? I'd want the blank or None
fields to come out either at the beginning or end of the sorted list
(not sure what the customer wants for this yet).



More information about the Python-list mailing list