[Python-ideas] 'where' statement in Python?

Guido van Rossum guido at python.org
Tue Jul 20 20:16:04 CEST 2010


On Tue, Jul 20, 2010 at 6:18 PM, Sturla Molden <sturla at 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)



More information about the Python-ideas mailing list