about sort and dictionary
bonono at gmail.com
bonono at gmail.com
Wed Nov 23 08:07:46 EST 2005
Sion Arrowsmith wrote:
> 1. sort() in place makes sense in terms of space, and is not
> completely unintuitive.
> 2. reverse() should do what sort() does.
> 3. The inexperienced user is most likely to expect the above
> code to print 3 2 1 3 2 1, and is more likely to have
> difficulty tracking down the problem if reverse() returns
> self and they get unexpected results than if it returns
> None and they get a TypeError: iteration over non-sequence.
>
In other words, the None is used as a "you are guranteed to get error
when you loop it, assuming you don't read the documentation and don't
do the simple trial and error in the interactive shell before doing
real thing" and would read the manual afterwards then found out
sort()/reverse() is in place.
That as a way to "teach", never thought about that kind of intend.
But isn't "develop by test" the general preference ? If that is the
case, a unit test would definitely catch the error and I doubt tracking
down the error is that hard.
More information about the Python-list
mailing list