<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Feb 15, 2018 at 2:13 AM, Jamie Willis <span dir="ltr"><<a href="mailto:jw14896.2014@my.bristol.ac.uk" target="_blank">jw14896.2014@my.bristol.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto"> These laws define behaviour that is expected equivalent by users; </div><div dir="auto"><br></div><div dir="auto">[x for x in xs] = xs</div><div dir="auto"></div></div></blockquote><div><br></div><div>OK -- that's the definition...</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto">[f(x) for x in [x]] = f(x)</div></div></blockquote><div><br></div><div>well, not quite:</div><div><br></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">[f(x) for x in [x]] = [f(x)]</span><br></div><div><br></div><div>Using x in two places where they mean different things makes this odd, but yes, again the definition (of a list comp, and a length-1 sequence)<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto">[g(y) for y in [f(x) for x in xs]] = [g(y) for x in xs for y in f(x)]</div></div></blockquote><div><br></div><div>well, no. using two for expressions yields the outer product -- all combinations:</div><div><br></div><div>
<span></span>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>14</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">xs = </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">range</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">3</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>15</b></span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">[(x,y) </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> x </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> xs </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> y </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> xs]</span></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>15</b></span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]</span></p>
<br></div><div>so the result is a length len(seq1)*len(seq(2)) list. Or in this case, a len(xs)**2.</div><div><br></div><div>But nesting the comps applies one expression, and then the other, yielding a length len(xs) list.</div><div><br></div><div>but you wrote:</div><div><br></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">[g(y) for x in xs for y in f(x)]</span><br></div><div><br></div><div>which I'm not sure what you were expecting, as f(x) is not a sequence (probably)...</div><div><br></div><div>To play with your examples:</div><div><br></div><div>Define some functions that make it clear what's been applied:</div><div><br></div><div>
<span></span>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>16</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: <b>def</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(60,159,242)">f</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(x):</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><span class="gmail-Apple-converted-space"> </span>...: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>return</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> </span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(205,121,35)">"f(</span><span class="gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(203,120,161)"><b>{}</b></span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(205,121,35)">)"</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">.format(x)</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>...:<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>17</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: <b>def</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(60,159,242)">g</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(x):</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>...: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>return</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(205,121,35)">"g(</span><span class="gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(203,120,161)"><b>{}</b></span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(205,121,35)">)"</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">.format(x)</span></p>
<br></div><div>and a simple sequence to use:</div><div><br></div><div>
<span></span>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>18</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">xs = </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">range</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">3</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)</span></p>
</div><div><br></div><div>Now your examples:</div><div><br></div><div>
<span></span>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>19</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">[x </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> x </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> xs]</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>19</b></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">[0, 1, 2]</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>20</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">[f(x) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> x </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> [x]]</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>20</b></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">['f(5)']</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>21</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">[g(y) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> y </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> [f(x) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> x </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> xs]]</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>21</b></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">['g(f(0))', 'g(f(1))', 'g(f(2))']</span></p>
<br></div><div>OK -- all good f applied, then g, but then the last one:</div><div><br></div><div>
<span></span>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>27</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">[g(y) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> x </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> xs </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> y </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> f(x)]</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(178,54,34);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">Out[</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>27</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">]:<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">['g(f)',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'g(()',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'g(0)',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'g())',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'g(f)',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'g(()',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'g(1)',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'g())',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'g(f)',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'g(()',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'g(2)',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'g())']</span></p>
<br></div><div>in this case, f(x) is returning a string, which is a sequence, so you get that kind odd result. But what if f(x) was a simple scalr function:</div><div><br></div><div>
<span></span>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>29</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: <b>def</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(60,159,242)">f</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(x):</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>...: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>return</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">2</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">*x</span></p>
<br></div><div>Then you just get an error:</div><div><br></div><div>
<span></span>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>30</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">[g(y) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> x </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> xs </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> y </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> f(x)]</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(195,55,32);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">---------------------------------------------------------------------------</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">TypeError</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> <span class="gmail-Apple-converted-space"> </span>Traceback (most recent call last)</span></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,188,38);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><ipython-input-30-82ba3864654b></span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> in </span><span class="gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(51,187,200)"><module></span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">()</span></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,188,38);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">----> 1</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)"> </span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">[</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">g</span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">y</span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">)</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">for</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> x </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">in</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> xs </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">for</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> y </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">in</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> f</span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">x</span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">)]</span></p>
<p class="gmail-p4" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,188,38);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><ipython-input-30-82ba3864654b></span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> in </span><span class="gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(51,187,200)"><listcomp></span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(.0)</span></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,188,38);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">----> 1</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)"> </span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">[</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">g</span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">y</span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">)</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">for</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> x </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">in</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> xs </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">for</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> y </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">in</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> f</span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">x</span><span class="gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">)]</span></p>
<p class="gmail-p4" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">TypeError</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">: 'int' object is not iterable</span></p>
<br></div><div>The the nested comp is what is desired here:</div><div><br></div><div>
<span></span>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>31</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">[g(y) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> y </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> [f(x) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> x </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> xs]]</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>31</b></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">['g(0)', 'g(2)', 'g(4)']</span></p>
<br></div><div>Except you probably want a generator expression in the inner loop to avoid bulding an extra list:</div>
<span></span>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><br></span></p><p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>33</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]:<span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> [g(y) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> y </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> (f(x) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> x </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> xs)]</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>33</b></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">['g(f(0))', 'g(f(1))', 'g(f(2))']</span></p>
<div><p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"></span></p>
<br></div><div>So back to the OP's example:</div><div><br></div><div><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">
<span></span>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>34</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">[f(x) + g(f(x)) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> x </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">range</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">(</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">10</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">)]</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(178,54,34);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">Out[</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>34</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">]:<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">['f(0)g(f(0))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(1)g(f(1))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(2)g(f(2))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(3)g(f(3))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(4)g(f(4))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(5)g(f(5))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(6)g(f(6))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(7)g(f(7))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(8)g(f(8))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(9)g(f(9))']</span></p>
</span><br></div><div>that is best done with comps as:</div><div><br></div>
<span></span>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>36</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">[fx + g(fx) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> fx </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> (f(x) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> x </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">range</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">(</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">10</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">))]</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(178,54,34);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">Out[</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>36</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">]:<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">['f(0)g(f(0))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(1)g(f(1))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(2)g(f(2))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(3)g(f(3))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(4)g(f(4))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(5)g(f(5))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(6)g(f(6))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(7)g(f(7))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(8)g(f(8))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(9)g(f(9))']</span></p>
<div><span style="color:rgb(0,0,0);font-family:monospace;font-size:14px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div>which really doesn't seem bad to me. And if the function names are longer -- which they should be, you might want to use a temp as suggested earlier:</div><div class="gmail_quote"><br></div><div class="gmail_quote">
<span></span>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>41</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">fx = (f(x) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> x </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">range</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">(</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">10</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">))</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>42</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">[x + g(x) </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> x </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"> fx]</span></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(178,54,34);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">Out[</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>42</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">]:<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures">['f(0)g(f(0))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(1)g(f(1))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(2)g(f(2))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(3)g(f(3))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(4)g(f(4))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(5)g(f(5))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(6)g(f(6))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(7)g(f(7))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(8)g(f(8))',</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>'f(9)g(f(9))']</span></p>
<div class="gmail_quote"><br></div>The truth is, comprehensions really are a bit wordy, if you are doing a lot of this kind of thing (at least with numbers), you might be happier with an array-oriented language or library, such as numpy:</div><div class="gmail_quote"><br></div><div class="gmail_quote">
<span></span>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>46</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: <b>import</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(60,159,242)"><b>numpy</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>as</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(60,159,242)"><b>np</b></span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>47</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: <b>def</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(60,159,242)">f</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(x):</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>...: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>return</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> x * </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">2</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>...:<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>48</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: <b>def</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(60,159,242)">g</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(x):</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>...: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>return</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> x * </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">3</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>...:<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>...:<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>49</b></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">xs = np.arange(</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">3</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>50</b></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">f(xs) + g(f(xs))</span></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>50</b></span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">array([ 0,<span class="gmail-Apple-converted-space"> </span>8, 16])</span></p>
<p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p><p class="gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"></p><div class="gmail_quote" style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">is pretty compact, and can be "optimized with a temp:</div><br><p></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>51</b></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">fx = f(xs)</span></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><span class="gmail-Apple-converted-space"> </span>...: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">fx + g(fx)</span></p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>...:<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>51</b></span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">array([ 0,<span class="gmail-Apple-converted-space"> </span>8, 16])</span></p>
</div><div class="gmail_quote"><br></div><div class="gmail_quote">pretty simple isn't it?<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">So this gets back to -- does anyone have a suggestion for a syntax for comprehensions that would make this substantially clearer, more readable, or more compact?</div><div class="gmail_quote"><br></div><div class="gmail_quote">I'm guessing not :-)</div><div class="gmail_quote"><br></div><div class="gmail_quote">(the compact bit comes from having to type the "for x in" part twice -- it does *feel* a bit unnecessary. which is why I like numpy -- no "for" at all :-)</div><div class="gmail_quote"><br></div><div class="gmail_quote">(I'm still trying to figure out why folks think map() or filter() help here...)</div><div class="gmail_quote"><br></div><div class="gmail_quote">-CHB</div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R (206) 526-6959 voice<br>7600 Sand Point Way NE (206) 526-6329 fax<br>Seattle, WA 98115 (206) 526-6317 main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>