Python assign value and use on same line
<p>I was trying to create a shortest-possible code for a puzzle, and the question came to mind trying to do something like this:  </p>

<p><code>zip(l=[1,2,3,4,5],l[1:])</code>  </p>

<p>So I was wondering, is there a way to produce a value, assign it to a variable and use that variable on the very same line/function call?</p>

<p>EDIT:To clarify things, I am aware that this thing is not recommended nor good nor does it yield faster results. Also, the essence of the question is assignment and reusing of the same variable in the same function call. The list is produced using input, the static list here is for the example only. In a situation like this, I would like to avoid repeating the same task twice while I have already produced the result somewhere.</p>

<p>Of course, you can always do this:</p>

<pre><code>l = range(1, 6); zip(l, l[1:])
</code></pre>

<p>but I guess that's not what you wanted. :-)</p>

<p>There is a relatively clean way</p>

<pre><code>(lambda l: zip(l, l[1:]))(range(1, 6))
</code></pre>

<p>BTW that function is defined in <a href="https://docs.python.org/3.6/library/itertools.html#itertools-recipes" rel="nofollow">itertools recipes</a> as pairwise, so <code>pairwise(range(1, 6))</code> is probably the most direct way. You only need to write an import hook that imports Python functions from web pages. :-D</p>

<p>And there is a nice convoluted way</p>

<pre><code>next(zip(l, l[1:]) for l in [range(1, 6)])
</code></pre>

<p>If you want more ideas, just say so. :-)</p>

python assign