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

2014-12-04 Thread Albert van der Horst
In article mailman.16378.1417111312.18130.python-l...@python.org, 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 ==

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 alb...@spenarnc.xs4all.nl 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

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

2014-12-04 Thread Albert van der Horst
In article mailman.16552.1417688329.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Thu, Dec 4, 2014 at 9:09 PM, Albert van der Horst alb...@spenarnc.xs4all.nl wrote: If there is more than one item with the maximum calculated the first is given, so for your attempt

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 it

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. I refer

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

2014-12-04 Thread Peter Otten
Albert van der Horst wrote: In article mailman.16378.1417111312.18130.python-l...@python.org, 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 =

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

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) 'average' I

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

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', 'average']

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 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

How is max supposed to work, especially key.

2014-11-27 Thread Albert van der Horst
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(xrange(j, n), key=lambda i: abs(m[i][j])) if j

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(xrange(j, n),