Re: sorting strings numerically while dealing with missing values

2016-12-29 Thread Larry Martell
On Wed, Dec 28, 2016 at 3:43 PM, Ian Kelly wrote: > On Wed, Dec 28, 2016 at 2:14 PM, Larry Martell > wrote: >> >> 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))) > > I'm guessin

Re: sorting strings numerically while dealing with missing values

2016-12-28 Thread Ian Kelly
On Wed, Dec 28, 2016 at 2:43 PM, Ian Kelly wrote: > On Wed, Dec 28, 2016 at 2:14 PM, Larry Martell > wrote: >> >> 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))) > > I'm guessin

Re: sorting strings numerically while dealing with missing values

2016-12-28 Thread Ian Kelly
On Wed, Dec 28, 2016 at 2:14 PM, Larry Martell wrote: > > 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))) I'm guessing that you left out a lambda here since the key argument takes a

Re: sorting strings numerically while dealing with missing values

2016-12-28 Thread Peter Otten
Larry Martell wrote: > 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. No, that cannot work; unless you have

sorting strings numerically while dealing with missing values

2016-12-28 Thread Larry Martell
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