<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, May 30, 2018 at 8:10 PM Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, May 31, 2018 at 04:06:51AM +1000, Chris Angelico wrote:<br>
> On Thu, May 31, 2018 at 3:59 AM, Neil Girdhar <<a href="mailto:mistersheik@gmail.com" target="_blank">mistersheik@gmail.com</a>> wrote:<br>
> > This example shows additional flexibility:<br>
> ><br>
> > z = {a: transformed_b<br>
> > for b in bs<br>
> > given transformed_b = transform(b)<br>
> > for a in as_}<br>
> ><br>
> > There is no nice, equivalent := version as far as I can tell.<br>
> <br>
> True. However, it took me several readings to understand what you were<br>
> doing here.<br>
<br>
Possibly you shouldn't have tried reading at 4am.<br>
<br>
Either that or I shouldn't be reading before I've had a coffee :-)<br>
<br>
Have I missed something that you have seen? Even if the syntax were <br>
legal, that seems to be a pointless use of an assignment expression. <br>
Since the new name "transformed_b" is only used once, we can and should <br>
just use the transform(b) in place:<br>
<br>
z = {a: transform(b) for b in bs for a in as_}<br></blockquote><div><br></div><div>Chris just explained it to you. You're calling transform too often.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
If we need to use it twice, we can do this:<br>
<br>
# assume "@" stands in for something useful<br>
z = {a: (transformed_b := transform(b)) @ transformed_b <br>
for b in bs for a in as_}<br>
<br>
<br>
I'm not seeing the advantage of given, or any extra flexibility here, <br>
unless the aim is to encourage people to make syntax errors :-)<br>
<br></blockquote><div><br></div><div>The flexibility of "given" is in giving names to elements of expressions and comprehensions to avoid recalculation.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
What have I missed?<br>
<br></blockquote><div>Like you say, := and given both work for expressions. "given" could theoretically also be used in comprehensions.</div><br class="inbox-inbox-inbox-inbox-Apple-interchange-newline"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
-- <br>
Steve<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
<br>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.<br>
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/python-ideas/keaR3FudcwQ/unsubscribe" rel="noreferrer" target="_blank">https://groups.google.com/d/topic/python-ideas/keaR3FudcwQ/unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href="mailto:python-ideas%2Bunsubscribe@googlegroups.com" target="_blank">python-ideas+unsubscribe@googlegroups.com</a>.<br>
For more options, visit <a href="https://groups.google.com/d/optout" rel="noreferrer" target="_blank">https://groups.google.com/d/optout</a>.<br>
</blockquote></div></div>