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

Chris Angelico rosuav at gmail.com
Wed May 30 20:14:39 EDT 2018


On Thu, May 31, 2018 at 10:05 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Thu, May 31, 2018 at 04:06:51AM +1000, Chris Angelico wrote:
>> On Thu, May 31, 2018 at 3:59 AM, Neil Girdhar <mistersheik at gmail.com> wrote:
>> > This example shows additional flexibility:
>> >
>> > z = {a: transformed_b
>> >      for b in bs
>> >      given transformed_b = transform(b)
>> >      for a in as_}
>> >
>> > There is no nice, equivalent := version as far as I can tell.
>>
>> True. However, it took me several readings to understand what you were
>> doing here.
>
> Possibly you shouldn't have tried reading at 4am.
>
> Either that or I shouldn't be reading before I've had a coffee :-)
>
> Have I missed something that you have seen?

Yep, as mentioned in the other post. The fact that you talk like this
about it - asserting that it's obvious what this does, while still
considering it to be utterly useless - is proof, IMO, that this should
be frowned upon in style guides.

ChrisA


More information about the Python-ideas mailing list