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/2010-November/105167.html below:

[Python-Dev] Cleaning-up the new unittest API

[Python-Dev] Cleaning-up the new unittest APITerry Reedy tjreedy at udel.edu
Mon Nov 1 19:37:33 CET 2010
On 10/31/2010 10:55 PM, Michael Foord wrote:

> fact that sets / frozensets can't be sorted in the standard Python way
> (their less than comparison adheres to the set definition). This is
> something that will probably surprise many Python developers:

Any programmer who sorts (or uses functions that depend on proper 
sorting) should know and respect the difference between partial orders, 
such as set inclusion, and total orders, such as lex order of sequences. 
So I am surprised by the above claim ;-).

>  >>> a = [{2,4}, {1,2}]
>  >>> b = a[::-1]
>  >>> sorted(a)
> [set([2, 4]), set([1, 2])]
>  >>> sorted(b)
> [set([1, 2]), set([2, 4])]

The bug is not in the sort method, but the attempt to sort partially 
ordered items, which are not properly sortable.

a = [{2,4}, {1,2}]
b = a[::-1]
print(sorted(a,key=sorted))
#[{1, 2}, {2, 4}]
print(sorted(b,key=sorted))
#[{1, 2}, {2, 4}]

A test method (or internal branch) that depends on sorting to work 
properly could just refuse to work with sets (and frozensets).

-- 
Terry Jan Reedy

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