[Tutor] high score lists
Chris Smith
smichr at bigfoot.com
Sat Apr 16 05:21:51 CEST 2005
On Friday, Apr 15, 2005, at 20:40 America/Chicago, Jacob S. -
keridee at jayco.net wrote:
> Great. len is a function though. Why use a second layer of function
> when len is a function in itself?
>
>>>> l = ['d','sea','bee']
>>>> l.sort(key=len)
>>>> l
> ['d', 'bee', 'sea']
>>>>
>
>
LOL :-) Oooh, that's nice! OK, instead of wasting a post in admiration,
how about something else that is a possibility since sort() is stable:
###
>>> l = ['d','sea','bee']
>>> l.sort() #get them in lexical order
>>> l
['bee', 'd', 'sea']
>>> l.sort(key=len) #now get similar lengths together
>>> l
['d', 'bee', 'sea']
>>>
###
/c
More information about the Tutor
mailing list