Replacing cmp with key for sorting
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Mon Nov 3 14:14:57 EST 2008
Arnaud Delobelle:
> It's funny how the obvious escapes me so often.
In this case it's a well known cognitive effect: the mind of humans
clings to first good/working solution, not allowing its final tuning.
For that you may need to think about something else for a short time,
and then look at your solution with a little "fresher" mind.
This (ugly) translation into D + my functional-style libs shows why
Python syntax is a good idea:
import d.all;
void main() {
auto txt = "a bc bd bcb ba ab".split();
putr( sorted(txt, (string s){ return map((char c){return -
cast(int)c;}, s);} ).reverse );
}
Long Live To Python! :-)
Bye,
bearophile
More information about the Python-list
mailing list