On Tue, Jul 20, 2010 at 6:18 PM, Sturla Molden <sturla@molden.no> wrote:

Den 20.07.2010 16:57, skrev Andrey Popp:

a = (b, b) where b = 43

I am +1 for a where module and -1 for a where keyword, and here is the reason:

In MATLAB, we have the "find" function that serves the role of where. In NumPy, we have a function numpy.where and also masked arrays.

The above statement with NumPy ndarrays would be:

idx, = np.where(b == 47) a = (b[idx], b[idx])

or we could simply do this:

a = (b[b==47], b[b==47]) <snip>

It looks like NumPy's "where" is more like SQL's, while Nick's is more like Haskell's. These are totally different: in SQL it's a dynamic query (and its argument is a condition), whereas in Haskell it's purely a syntactic construct for defining some variables to be used as shorthands in an expression. Given the large number of Python users familiar with SQL compared to those familiar with Haskell, I think we'd do wise to pick a different keyword instead of 'where'. I can't think of one right now though. Your proposal is completely orthogonal to Nick's; the best thing to do is probably to start a different thread for yours. Note that Microsoft's LINQ is also similar to your suggestion. -- --Guido van Rossum (python.org/~guido)