[Python-ideas] A real life example of "given"

Neil Girdhar mistersheik at gmail.com
Thu May 31 04:44:18 EDT 2018


Yes, you're right. That's the ambiguity I mentioned in my last message.
It's too bad because I want given for expressions and given for
comprehensions. But if you have both, there's ambiguity and you would at
least need parentheses:

[(y given y=2*x) for x in range(3)]

That might be fine.

On Thu, May 31, 2018 at 4:34 AM Peter O'Connor <peter.ed.oconnor at gmail.com>
wrote:

> * Sorry, message sent too early:
>
> On Thu, May 31, 2018 at 4:50 AM, Neil Girdhar <mistersheik at gmail.com>
> wrote:
>>
>>
>>>     [expression given name=something for x in seq]
>>>
>>
>> retval = []
>> name = something
>> for x in seq:
>>     retval.append(expression)
>> return retval
>>
>
> That's a little confusing then, because, given the way given is used
> outside of comprehensions, you would expect
>
>     [y given y=2*x for x in range(3)]
>
> to return [0, 2, 4], but it would actually raise an error.
>
>
> On Thu, May 31, 2018 at 10:32 AM, Peter O'Connor <
> peter.ed.oconnor at gmail.com> wrote:
>
>>
>>
>> On Thu, May 31, 2018 at 4:50 AM, Neil Girdhar <mistersheik at gmail.com>
>> wrote:
>>>
>>>
>>>>     [expression given name=something for x in seq]
>>>>
>>>
>>> retval = []
>>> name = something
>>> for x in seq:
>>>     retval.append(expression)
>>> return retval
>>>
>>
>> That's a little strange confusing then, because, given the way given is
>> used outside of comprehensions, you would expect
>>
>> for x in range(3):
>> y given y=2*x
>>
>>     [y given y=2*x for x in range(3)]
>>
>> to return [0, 2, 4], but it would actually raise an error.
>>
>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180531/c8a1d09f/attachment-0001.html>


More information about the Python-ideas mailing list