Vincent Vande Vyvre writes:
> final = [(x, y+1) for x, y in zip(e, e)]
final = [(x, x+1) for x in e]
--
Piet van Oostrum
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
--
Roel Schroeven writes:
> Lele Gaifax schreef op 6/04/2017 20:07:
>> Piet van Oostrum writes:
>>
>>> It is a poor man's 'let'. It would be nice if python had a real 'let'
>>> construction. Or for example:
>>>
>>> [(tmp, tmp + 1) for x in data with tmp =
Lele Gaifax schreef op 6/04/2017 20:07:
Piet van Oostrum writes:
It is a poor man's 'let'. It would be nice if python had a real 'let'
construction. Or for example:
[(tmp, tmp + 1) for x in data with tmp = expensive_calculation(x)]
Alas!
It would be nice indeed!
On 2017-04-06 14:56, Vincent Vande Vyvre wrote:
> With two passes
>
> e = [expensive_calculation(x) for x in data]
> final = [(x, y+1) for x, y in zip(e, e)]
Using a generator it can be done in one pass:
final = [
(value, tmp, tmp+1)
for value, tmp
in (
(x,
Piet van Oostrum writes:
> It is a poor man's 'let'. It would be nice if python had a real 'let'
> construction. Or for example:
>
> [(tmp, tmp + 1) for x in data with tmp = expensive_calculation(x)]
>
> Alas!
It would be nice indeed!
Or even
[(tmp, tmp + 1) for x
Vincent Vande Vyvre writes:
> Le 06/04/17 à 14:25, Piet van Oostrum a écrit :
>> Steven D'Aprano writes:
>>
>>> Suppose you have an expensive calculation that gets used two or more
>>> times in a loop. The obvious way to avoid calculating it twice in an
>>>
Le 06/04/17 à 14:25, Piet van Oostrum a écrit :
Steven D'Aprano writes:
Suppose you have an expensive calculation that gets used two or more times in a
loop. The obvious way to avoid calculating it twice in an ordinary loop is with
a temporary variable:
Steven D'Aprano writes:
> Suppose you have an expensive calculation that gets used two or more times in
> a
> loop. The obvious way to avoid calculating it twice in an ordinary loop is
> with
> a temporary variable:
>
> result = []
> for x in data:
>
On Sunday, April 2, 2017 at 1:08:17 AM UTC+1, Robert L. wrote:
> I don't believe in western morality, i.e. don't kill civilians or children
> The only way to fight a moral war is the Jewish way: Destroy their holy sites.
> Kill men, women, and children (and cattle). --- Rabbi Manis Friedman
>
On 1/8/2017, Steven D'Aprano wrote:
> Suppose you have an expensive calculation that gets used two or
> more times in a loop. The obvious way to avoid calculating it
> twice in an ordinary loop is with a temporary variable:
>
> result = []
> for x in data:
> tmp = expensive_calculation(x)
>
On Sun, Apr 2, 2017 at 11:53 AM, Steve D'Aprano
wrote:
> Robert, I've asked you once to stop posting anti-Semitic signatures in your
> posts. You've now posted four times, and each one has included racist
> material in the signature.
>
> You are welcome to participate
Robert, I've asked you once to stop posting anti-Semitic signatures in your
posts. You've now posted four times, and each one has included racist
material in the signature.
You are welcome to participate here if you discuss Python, or even to
discuss general programming techniques, but if you
On Tuesday 10 January 2017 00:12, Antoon Pardon wrote:
> Op 09-01-17 om 04:53 schreef Steven D'Aprano:
>> Suppose you have an expensive calculation that gets used two or more times
>> in a loop. The obvious way to avoid calculating it twice in an ordinary loop
>> is with a temporary variable:
On Monday, 9 January 2017 03:53:37 UTC, Steven D'Aprano wrote:
> Suppose you have an expensive calculation that gets used two or more times
> in a loop.
[...]
> [(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]]
>
> I can't decide whether that's an awesome trick or a horrible
On 01/09/2017 04:53 AM, Steven D'Aprano wrote:
Suppose you have an expensive calculation that gets used two or more times in a
loop. The obvious way to avoid calculating it twice in an ordinary loop is with
a temporary variable:
result = []
for x in data:
tmp = expensive_calculation(x)
On 09.01.17 12:46, Paul Rubin wrote:
Serhiy Storchaka writes:
gen = (expensive_calculation(x) for x in data)
result = [(tmp, tmp + 1) for tmp in gen]
result = [(tmp, tmp+1) for tmp in map(expensive_calculation, data)]
Yes, of course, but only in the case of
Ben Bacarisse writes:
> [(lambda tmp: (tmp, tmp+1))(expensive_calculation(x)) for x in data]
Nice. The Haskell "let" expression is implemented as syntax sugar for
that, I believe.
--
https://mail.python.org/mailman/listinfo/python-list
On 2017-01-09 13:16, Paul Rubin wrote:
> Tim Chase writes:
> >> result = [(tmp, tmp+1) for tmp in map(expensive_calculation,
> >> data)]
> >
> > As charmingly expressive as map() is, the wildly different
> > behavior in py3 (it's a generator that evaluates lazily)
Steven D'Aprano writes:
> Suppose you have an expensive calculation that gets used two or more times in
> a
> loop. The obvious way to avoid calculating it twice in an ordinary loop is
> with
> a temporary variable:
>
> result = []
> for x in data:
>
Tim Chase writes:
>> result = [(tmp, tmp+1) for tmp in map(expensive_calculation, data)]
>
> As charmingly expressive as map() is, the wildly different behavior in
> py3 (it's a generator that evaluates lazily) vs py2 (it consumes the
> entire iterable in one go)
Am 09.01.17 um 04:53 schrieb Steven D'Aprano:
Or do you? ... no, you don't!
[(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]]
I can't decide whether that's an awesome trick or a horrible hack...
I think this is quite clear, and a useful feature, only that Python
makes it
On Sunday, January 8, 2017 at 7:53:37 PM UTC-8, Steven D'Aprano wrote:
> Suppose you have an expensive calculation that gets used two or more times in
> a
> loop. The obvious way to avoid calculating it twice in an ordinary loop is
> with
> a temporary variable:
>
> result = []
> for x in
On 2017-01-09 04:59, Rustom Mody wrote:
> What happens when the expensive is on an inner generator?
> Something like:
>
> [expensive₂(y) for x in data for y in foo(x)]
>
> [The ₂ representing the 2 or more occurrences in Steven's eg]
Well, if I understand your question correctly, the goal
Op 09-01-17 om 04:53 schreef Steven D'Aprano:
> Suppose you have an expensive calculation that gets used two or more times in
> a
> loop. The obvious way to avoid calculating it twice in an ordinary loop is
> with
> a temporary variable:
>
> result = []
> for x in data:
> tmp =
On Monday, January 9, 2017 at 5:54:15 PM UTC+5:30, Tim Chase wrote:
> On 2017-01-09 02:46, Paul Rubin wrote:
> > > gen = (expensive_calculation(x) for x in data)
> > > result = [(tmp, tmp + 1) for tmp in gen]
> >
> > result = [(tmp, tmp+1) for tmp in map(expensive_calculation, data)]
>
> As
On 2017-01-09 02:46, Paul Rubin wrote:
> > gen = (expensive_calculation(x) for x in data)
> > result = [(tmp, tmp + 1) for tmp in gen]
>
> result = [(tmp, tmp+1) for tmp in map(expensive_calculation, data)]
As charmingly expressive as map() is, the wildly different behavior in
py3 (it's a
Serhiy Storchaka writes:
> gen = (expensive_calculation(x) for x in data)
> result = [(tmp, tmp + 1) for tmp in gen]
result = [(tmp, tmp+1) for tmp in map(expensive_calculation, data)]
--
https://mail.python.org/mailman/listinfo/python-list
Steven D'Aprano writes:
> [(expensive_calculation(x), expensive_calculation(x) + 1) for x in data]
def memoize(f):
cache = {}
def m(x):
if x in cache:
return cache[x]
a = f(x)
On 09.01.17 05:53, Steven D'Aprano wrote:
Suppose you have an expensive calculation that gets used two or more times in a
loop. The obvious way to avoid calculating it twice in an ordinary loop is with
a temporary variable:
result = []
for x in data:
tmp = expensive_calculation(x)
On Monday, January 9, 2017 at 10:19:31 AM UTC+5:30, Steven D'Aprano wrote:
> On Monday 09 January 2017 15:09, Chris Angelico wrote:
>
> > On Mon, Jan 9, 2017 at 2:53 PM, Steven D'Aprano wrote:
> >> [(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]]
> >>
> >>
> >> I can't decide
On Mon, Jan 9, 2017 at 3:49 PM, Steven D'Aprano
wrote:
> Helper functions are good. Helper functions that are only used
> *once* are a code smell. *LOTS* of helper functions that are only used once
> are
> a sign that something is horrible, and it might just
On Monday 09 January 2017 15:09, Chris Angelico wrote:
> On Mon, Jan 9, 2017 at 2:53 PM, Steven D'Aprano
> wrote:
>> [(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]]
>>
>>
>> I can't decide whether that's an awesome trick or a horrible
On Mon, Jan 9, 2017 at 2:53 PM, Steven D'Aprano
wrote:
> [(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]]
>
>
> I can't decide whether that's an awesome trick or a horrible hack...
A horrible hack on par with abusing a recursive
33 matches
Mail list logo