Re: [Tutor] When max() doesn't work as expected

2009-12-04 Thread Kent Johnson
On Fri, Dec 4, 2009 at 2:21 AM, spir wrote: > Albert Sweigart dixit: > >> You need to specify an ordering function, in your case, len(): > > By the way, is there any reason why the compare func parameter is called > 'key'? It is conventional terminology - the sort key is the value the sort is d

Re: [Tutor] When max() doesn't work as expected

2009-12-04 Thread Alan Plum
On Fr, 2009-12-04 at 08:21 +0100, spir wrote: > By the way, is there any reason why the compare func parameter is called > 'key'? I'd guess because what you provide creates keys for the values in the collection to sort them by. What else to call it? "Comparators" compare two values, "hashes" don'

Re: [Tutor] When max() doesn't work as expected

2009-12-03 Thread spir
Albert Sweigart dixit: > You need to specify an ordering function, in your case, len(): By the way, is there any reason why the compare func parameter is called 'key'? Denis la vita e estrany http://spir.wikidot.com/ _

Re: [Tutor] When max() doesn't work as expected

2009-12-03 Thread Lie Ryan
On 12/4/2009 1:22 PM, Kent Johnson wrote: max() finds the 'largest' in sort order. Strings sort in dictionary order so the max of a list strings will be the one that comes last in dictionary order.\ To prevent confusion: When Kent said "dictionary order" it means real-life dictionary, the thic

Re: [Tutor] When max() doesn't work as expected

2009-12-03 Thread wescpy
On Dec 3, 2009, at 18:25, Hugo Arts wrote: On Fri, Dec 4, 2009 at 2:08 AM, Tony Cappellini wrote: I have a list of 2300 strings. When I call max() on the list, it returned an item with 37 characters. I am only passing 1 argument to max(). I know for a fact that the largest item has 57 c

Re: [Tutor] When max() doesn't work as expected

2009-12-03 Thread Albert Sweigart
max() for strings returns the largest string in an alphabetical sense. So max(['z', 'aa']) would return 'z'. You need to specify an ordering function, in your case, len(): max( ['z', ''], key=len) ...which will return '' because it is ordering by key. -Al Sweigart

Re: [Tutor] When max() doesn't work as expected

2009-12-03 Thread Hugo Arts
On Fri, Dec 4, 2009 at 2:08 AM, Tony Cappellini wrote: > > I have a list of 2300 strings. > > When I call max() on the list, it returned an item with 37 characters. I am > only passing 1 argument to max(). > I know for a fact that the largest item has 57 characters, and when I > called mylist.ind

Re: [Tutor] When max() doesn't work as expected

2009-12-03 Thread Lie Ryan
On 12/4/2009 12:08 PM, Tony Cappellini wrote: What are the assumptions when calling max on a list of strings? Does the list need to be sorted? In my case, the list is sorted. max determines whether one is larger than the other with "<" operator. max on a list of string will determine the last

Re: [Tutor] When max() doesn't work as expected

2009-12-03 Thread Kent Johnson
On Thu, Dec 3, 2009 at 8:08 PM, Tony Cappellini wrote: > > I have a list of 2300 strings. > > When I call max() on the list, it returned an item with 37 characters. I am > only passing 1 argument to max(). > I know for a fact that the largest item has 57 characters, and when I > called mylist.ind

[Tutor] When max() doesn't work as expected

2009-12-03 Thread Tony Cappellini
I have a list of 2300 strings. When I call max() on the list, it returned an item with 37 characters. I am only passing 1 argument to max(). I know for a fact that the largest item has 57 characters, and when I called mylist.index('my_57_character_string') the index was found. Printing len(mylist