[Python-ideas] a in x or in y

Haoyi Li haoyi.sg at gmail.com
Fri Feb 14 00:32:52 CET 2014


>  X in any(Y, Z)

It also doesn't have the desired laziness, unless we special case *any* in
the interpreter, or provide a more generic mechanism for lazy parameters
without writing *lambda: *everywhere


On Thu, Feb 13, 2014 at 3:26 PM, Amber Yust <amber.yust at gmail.com> wrote:

> The issue I see with "X in any(Y, Z)" is that it's unclear to the reader
> how it differs from "X in (Y,Z)".
>
>
> On Thu Feb 13 2014 at 3:23:41 PM, Carl Meyer <carl at oddbird.net> wrote:
>
>> On 02/13/2014 04:04 PM, Greg Ewing wrote:
>> [snip]
>> > A syntax along the lines of
>> >
>> >    X in either Y or Z
>> >
>> > would avoid the problem. But we don't have a good
>> > candidate for 'either' that's already a keyword.
>>
>> This makes me think of
>>
>>     X in any(Y, Z)
>>
>> which is equally concise, and I think clearer and more readable (for
>> garden-path reasons) than
>>
>>     X in Y or in Z
>>
>> It's also technically not ambiguous, since currently any() only takes
>> one argument, and "X in any(Y)" is useless. Still a confusing overload
>> of the meaning of any().
>>
>> Implementation would be a bit ugly; it would need to return an object
>> that implements every operator magic method, and "distributes" the
>> operation across the objects passed to it. Equivalent could be done for
>> all().
>>
>> Or different names could be chosen to avoid the overloads, though I'm
>> not sure what those names would be.
>>
>> Probably there be dragons, but it might be fun to experiment with (and
>> doesn't require changes to the language, only new/modified builtins, or
>> even just library additions).
>>
>> Carl
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140213/dc2bbfe9/attachment.html>


More information about the Python-ideas mailing list