On Friday, Apr 15, 2005, at 20:40 America/Chicago, Jacob S. - [EMAIL PROTECTED] 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

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to