totally lost newbie

Steve Howell showell30 at yahoo.com
Sun May 27 10:02:58 EDT 2007


--- Marc 'BlackJack' Rintsch <bj_666 at gmx.net> wrote:
> 
> Maybe it's easier to use a key function instead of a
> compare function.  A
> key function receives an element and must return
> something that is then
> sorted and the element ends up where the computed
> key is in the sorted
> list.  Little example for sorting a list of strings
> first by length and
> strings of the same length by alphabetical order:
> 
> def key_func(item):
>     return (len(item), item)
> 
> data = ['viking', 'spam', 'parrot', 'ham', 'eric']
> data.sort(key=key_func)
> print data
> 

Marc, when did the key feature get introduced, 2.4 or
2.5?  I'm asking on behalf of the newbie, who's going
to struggle with your solution if he's still running
2.3.




      ____________________________________________________________________________________Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 




More information about the Python-list mailing list