[Python-Dev] python 3 niggle: None < 1 raises TypeError

Serhiy Storchaka storchaka at gmail.com
Tue Feb 18 14:48:20 CET 2014


18.02.14 10:10, Paul Moore написав(ла):
> Or alternatively, a "default on None" function - Oracle SQL calls this
> nvl, so I will too:
>
> def nvl(x, dflt):
>      return dflt if x is None else x
>
> results = sorted(invoices, key=lambda x: nvl(x.duedate, datetime(MINYEAR,1,1))

Or, as was proposed above:

results = sorted(invoices,
                  key=lambda x: (x.duedate is not None, x.duedate))




More information about the Python-Dev mailing list