On 18 February 2014 07:35, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote: > If you don't want to touch comparison in general, > how about an option to sort()? > > results = sorted(invoices, key=attrgetter('duedate'), none='first') 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)) Admittedly the key function is starting to get complex, but I find that key functions often do - they are the one big area where Python uses a lot of functional-style constructs. The existence of itemgetter/attrgetter are a testament to this fact. PS isn't this python-ideas territory by now? Paul
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4