Re: How is max supposed to work, especially key.

2014-12-04 Thread Terry Reedy
On 12/4/2014 5:35 AM, Albert van der Horst wrote: I agree that it is a useful function and that it is doing the right thing. What is wrong is the name. I refer to the fact that it is not returning the maximum. It returns the iterator value that leads to the maximum. A function that doesn't retur

Re: How is max supposed to work, especially key.

2014-12-04 Thread random832
On Thu, Dec 4, 2014, at 05:09, Albert van der Horst wrote: > So in that case max doesn't return the maximum (True), but instead > something else. If you want to find the "largest" item in a list of of strings, sorted case-insensitively, you might use str.lower or locale.strxfrm as the key function

Re: How is max supposed to work, especially key.

2014-12-04 Thread Jussi Piitulainen
Steven D'Aprano writes: > Jussi Piitulainen wrote: > > > Would you also want sorted called something else when used with a > > key? Because it doesn't produce a sorted list of the keys either: > > > > >>> data = ("short", "long", "average") > > >>> sorted(data, key=len) > > ['long', 'short

Re: How is max supposed to work, especially key.

2014-12-04 Thread Steven D'Aprano
Albert van der Horst wrote: > I agree that it is a useful function and that it is doing > the right thing. What is wrong is the name. > I refer to the fact that it is not returning the maximum. > It returns the iterator value that leads to the maximum. That is incorrect. It returns the maximum va

Re: How is max supposed to work, especially key.

2014-12-04 Thread Steven D'Aprano
Jussi Piitulainen wrote: > Would you also want sorted called something else when used with a key? > Because it doesn't produce a sorted list of the keys either: > > >>> data = ("short", "long", "average") > >>> sorted(data, key=len) > ['long', 'short', 'average'] > >>> max(data, key=len)

Re: How is max supposed to work, especially key.

2014-12-04 Thread Peter Otten
Albert van der Horst wrote: > I agree that it is a useful function and that it is doing > the right thing. What is wrong is the name. > I refer to the fact that it is not returning the maximum. > It returns the iterator value that leads to the maximum. > A function that doesn't return a maximum sho

Re: How is max supposed to work, especially key.

2014-12-04 Thread Peter Otten
Albert van der Horst wrote: > In article , > Peter Otten <__pete...@web.de> wrote: >>Albert van der Horst wrote: >> >>> In the Rosetta code I come across this part of >>> LU-decomposition. >>> >>> def pivotize(m): >>> """Creates the pivoting matrix for m.""" >>> n = len(m) >>> ID = [[

Re: How is max supposed to work, especially key.

2014-12-04 Thread Jussi Piitulainen
Albert van der Horst writes: > Chris Angelico wrote: > > If there's no clear maximum, it can't do any better than > > that. It's still returning something for which there is no > > greater. > > I agree that it is a useful function and that it is doing > the right thing. What is wrong is the name.

Re: How is max supposed to work, especially key.

2014-12-04 Thread Jussi Piitulainen
Albert van der Horst writes: > Useful as that function [Python's max with a key] may be, it > shouldn't have been called max. The meaning of the key should be added to help(max), if it still isn't - "returns a maximal element or an element that maximizes the key". In some communities they call i

Re: How is max supposed to work, especially key.

2014-12-04 Thread Albert van der Horst
In article , Chris Angelico wrote: >On Thu, Dec 4, 2014 at 9:09 PM, Albert van der Horst > wrote: >>>If there is more than one item with the maximum calculated the first is >>>given, so for your attempt >>> >>>max(xrange(100,200), key=lambda i: i%17==0 ) >> >>> >>>the values False, False, True, F

Re: How is max supposed to work, especially key.

2014-12-04 Thread Chris Angelico
On Thu, Dec 4, 2014 at 9:09 PM, Albert van der Horst wrote: >>If there is more than one item with the maximum calculated the first is >>given, so for your attempt >> >>max(xrange(100,200), key=lambda i: i%17==0 ) > >> >>the values False, False, True, False, ... are calculated and because >> >

Re: How is max supposed to work, especially key.

2014-12-04 Thread Albert van der Horst
In article , Peter Otten <__pete...@web.de> wrote: >Albert van der Horst wrote: > >> In the Rosetta code I come across this part of >> LU-decomposition. >> >> def pivotize(m): >> """Creates the pivoting matrix for m.""" >> n = len(m) >> ID = [[float(i == j) for i in xrange(n)] for j in

Re: How is max supposed to work, especially key.

2014-11-27 Thread Peter Otten
Albert van der Horst wrote: > In the Rosetta code I come across this part of > LU-decomposition. > > def pivotize(m): > """Creates the pivoting matrix for m.""" > n = len(m) > ID = [[float(i == j) for i in xrange(n)] for j in xrange(n)] > for j in xrange(n): > row = max(xr