A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2014-February/132461.html below:

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

[Python-Dev] python 3 niggle: None < 1 raises TypeErrorOscar Benjamin oscar.j.benjamin at gmail.com
Tue Feb 18 17:12:24 CET 2014
On 18 February 2014 15:53, Terry Reedy <tjreedy at udel.edu> wrote:
> On 2/18/2014 2:35 AM, Greg Ewing wrote:
>
>>    results = sorted(invoices, key=attrgetter('duedate'), none='first')
>
> I think this is the best idea on the thread. As a pure enhancement, it could
> be added in 3.5. The only tricky part of the implementation is maintaining
> stability of the sort. The obvious implementation of swapping Nones with
> objects at one end would break that. Instead, a scan listing the positions
> of Nones should be followed by a series of block moves of objects (pointers)
> between the Nones. It would still be O(n).

This only works if the list entry is a simple None. If the None is
embedded in e.g. a tuple then it would fail:

>>> (1, 2, 3) < (1, 2, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: int() < NoneType()


Oscar
More information about the Python-Dev mailing list

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