[Tutor] Finding the shortest word in a list of words

Emad Nawfal (عماد نوفل) emadnawfal at gmail.com
Tue Jan 20 13:13:10 CET 2009

2009/1/20 Kent Johnson <kent37 at tds.net>

> On Mon, Jan 19, 2009 at 9:47 PM, Emad Nawfal (عماد نوفل)
> <emadnawfal at gmail.com> wrote:
> > Thanks John for this. Although the decorate-sort-undecorate idiom looks
> so
> > natural to me now, I don't think I would have found it on my own. I have
> > that deja vu effect towards it.
> decorate-sort-undecorate is pretty much obsolete since the key=
> parameter was added to sort() in Python 2.4. Since Python 2.5 you can
> also use key= with min() and max() so your problem can be solved very
> simply and tersely:
> In [1]: words = "man woman children he".split()
> In [2]: min(words, key=len)
> Out[2]: 'he'
> Kent

Thank you all for the beautiful solutions.
When you say that something is obsolete, what does this mean? Is that just
because there is a simpler way, or are there other technical considerations?
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.....محمد
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090120/1d302043/attachment.htm>

More information about the Tutor mailing list