Re: Coolest Python recipe of all time

2011-05-09 Thread Raymond Hettinger
On May 9, 2:31 am, Trent Nelson wrote: > > What are your favorites? > > I think I've posted this before, but I love my > 3-lines-if-you-ignore-the-scaffolding language translator.  Not because it's > clever code -- quite the opposite, the code is dead simple -- but because it > encompasses one

RE: Coolest Python recipe of all time

2011-05-09 Thread Trent Nelson
> What are your favorites? I think I've posted this before, but I love my 3-lines-if-you-ignore-the-scaffolding language translator. Not because it's clever code -- quite the opposite, the code is dead simple -- but because it encompasses one of the things I love about Python the most: it gets

Re: Coolest Python recipe of all time

2011-05-07 Thread Raymond Hettinger
On May 7, 1:29 am, Steven D'Aprano wrote: > On Fri, 06 May 2011 12:36:09 -0600, Ian Kelly wrote: > > The amb engine would conceptually execute this function for every > > possible combination of a, b, and c, > > Which pretty much is the definition of "brute-force solver", no? FWIW, here's one of

Re: Coolest Python recipe of all time

2011-05-07 Thread Ian Kelly
On Sat, May 7, 2011 at 2:29 AM, Steven D'Aprano wrote: >> This isn't really amb; as you said it's just a brute-force solver with >> some weird syntax.  The whole point of amb is to enable >> non-deterministic programming, such as this: > [...] >> The amb engine would conceptually execute this func

Re: Coolest Python recipe of all time

2011-05-07 Thread Steven D'Aprano
On Fri, 06 May 2011 12:36:09 -0600, Ian Kelly wrote: > On Fri, May 6, 2011 at 10:59 AM, Steven D'Aprano > wrote: >> As written, amb is just a brute-force solver using more magic than is >> good for any code, but it's fun to play with. > > This isn't really amb; as you said it's just a brute-forc

Re: Coolest Python recipe of all time

2011-05-06 Thread Raymond Hettinger
[Steven D'Aprano]: > As written, amb is just a brute-force solver using more magic than is > good for any code, but it's fun to play with. With a small change in API, much of the magic isn't needed. from itertools import product def amb(func, *argument_ranges): for args in product(*argument_

Re: Coolest Python recipe of all time

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 12:36 PM, Ian Kelly wrote: > This is typically implemented using continuations, and I'm not sure > whether a true amb could actually be achieved in Python without adding > continuations or flow-control macros to the language. I stand corrected. After poking around a bit mo

Re: Coolest Python recipe of all time

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 10:59 AM, Steven D'Aprano wrote: > As written, amb is just a brute-force solver using more magic than is > good for any code, but it's fun to play with. This isn't really amb; as you said it's just a brute-force solver with some weird syntax. The whole point of amb is to e

Re: Coolest Python recipe of all time

2011-05-06 Thread geremy condra
On Fri, May 6, 2011 at 9:59 AM, Steven D'Aprano wrote: > On Mon, 02 May 2011 10:33:31 -0700, Raymond Hettinger wrote: > >> I think it is time to give some visibility to some of the instructive >> and very cool recipes in ActiveState's python cookbook. > [...] >> What are your favorites? > > > I'm

Re: Coolest Python recipe of all time

2011-05-06 Thread Steven D'Aprano
On Mon, 02 May 2011 10:33:31 -0700, Raymond Hettinger wrote: > I think it is time to give some visibility to some of the instructive > and very cool recipes in ActiveState's python cookbook. [...] > What are your favorites? I'm not sure if favourite is the right word, but I'm amazed by this one:

Re: Coolest Python recipe of all time

2011-05-03 Thread Algis Kabaila
On Tuesday 03 May 2011 16:00:05 Terry Reedy wrote: > On 5/3/2011 1:04 AM, Stefan Behnel wrote: > > The bad thing about this recipe is that it requires quite a > > bit of background knowledge in order to infer that the > > code the developer is looking at is actually correct. > > The main math know

Re: Coolest Python recipe of all time

2011-05-03 Thread Raymond Hettinger
On May 2, 11:23 pm, Stefan Behnel wrote: > Terry Reedy, 03.05.2011 08:00: > > > On 5/3/2011 1:04 AM, Stefan Behnel wrote: > > >> The bad thing about this recipe is that it requires quite a bit of > >> background knowledge in order to infer that the code the developer is > >> looking at is actually

Re: Coolest Python recipe of all time

2011-05-03 Thread Ian Kelly
On Tue, May 3, 2011 at 3:54 PM, Chris Angelico wrote: > On Wed, May 4, 2011 at 2:43 AM, Raymond Hettinger wrote: >> We should have a separate thread for the most practical, best >> documented, least surprising, and most boring recipe ;-) > > a += b   # Adds b to a in-place. Polymorphic - works on

Re: Coolest Python recipe of all time

2011-05-03 Thread Chris Angelico
On Wed, May 4, 2011 at 2:43 AM, Raymond Hettinger wrote: > We should have a separate thread for the most practical, best > documented, least surprising, and most boring recipe ;-) a += b # Adds b to a in-place. Polymorphic - works on a wide variety of types. You didn't say it had to be complic

Re: Coolest Python recipe of all time

2011-05-03 Thread geremy condra
On Tue, May 3, 2011 at 8:49 AM, Terry Reedy wrote: > On 5/3/2011 2:29 AM, Gregory Ewing wrote: >> >> Terry Reedy wrote: >>> >>> The trick is that replacing x with j and evaluating therefore causes >>> (in Python) all the coefficients of x (now j) to be added together >>> separately from all the co

Re: Coolest Python recipe of all time

2011-05-03 Thread Raymond Hettinger
On May 2, 10:04 pm, Stefan Behnel wrote: > The bad thing about this recipe is that it requires quite a bit of > background knowledge in order to infer that the code the developer is > looking at is actually correct. At first sight, it looks like an evil hack, > and the lack of documentation doesn'

Re: Coolest Python recipe of all time

2011-05-03 Thread Raymond Hettinger
On May 2, 11:29 pm, Gregory Ewing wrote: > Terry Reedy wrote: > > The trick is that replacing x with j and evaluating > > therefore causes (in Python) all the coefficients of x (now j) to be > > added together separately from all the constant terms to reduce the > > linear equation to a*x+b (= 0 i

Re: Coolest Python recipe of all time

2011-05-03 Thread Terry Reedy
On 5/3/2011 2:29 AM, Gregory Ewing wrote: Terry Reedy wrote: The trick is that replacing x with j and evaluating therefore causes (in Python) all the coefficients of x (now j) to be added together separately from all the constant terms to reduce the linear equation to a*x+b (= 0 implied). Hmmm

Re: Coolest Python recipe of all time

2011-05-02 Thread Gregory Ewing
Terry Reedy wrote: The trick is that replacing x with j and evaluating therefore causes (in Python) all the coefficients of x (now j) to be added together separately from all the constant terms to reduce the linear equation to a*x+b (= 0 implied). Hmmm... so if we used quaternions, could we s

Re: Coolest Python recipe of all time

2011-05-02 Thread Stefan Behnel
Terry Reedy, 03.05.2011 08:00: On 5/3/2011 1:04 AM, Stefan Behnel wrote: The bad thing about this recipe is that it requires quite a bit of background knowledge in order to infer that the code the developer is looking at is actually correct. The main math knowledge needed is the trivial fact

Re: Coolest Python recipe of all time

2011-05-02 Thread Terry Reedy
On 5/3/2011 1:04 AM, Stefan Behnel wrote: The bad thing about this recipe is that it requires quite a bit of background knowledge in order to infer that the code the developer is looking at is actually correct. The main math knowledge needed is the trivial fact that if a*x + b = 0, then x = -

Re: Coolest Python recipe of all time

2011-05-02 Thread Ian Kelly
On Mon, May 2, 2011 at 11:04 PM, Stefan Behnel wrote: > The bad thing about this recipe is that it requires quite a bit of > background knowledge in order to infer that the code the developer is > looking at is actually correct. At first sight, it looks like an evil hack, > and the lack of documen

Re: Coolest Python recipe of all time

2011-05-02 Thread Stefan Behnel
David Monaghan, 02.05.2011 23:45: On Mon, 2 May 2011 14:58:50 -0600, Ian Kelly wrote: On Mon, May 2, 2011 at 2:48 PM, David Monaghan wrote: On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger wrote: I think it is time to give some visibility to some of the instructive and very cool re

Re: Coolest Python recipe of all time

2011-05-02 Thread David Monaghan
On Mon, 2 May 2011 14:58:50 -0600, Ian Kelly wrote: >On Mon, May 2, 2011 at 2:48 PM, David Monaghan > wrote: >> On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger >> wrote: >> >>>I think it is time to give some visibility to some of the instructive >>>and very cool recipes in ActiveState

Re: Coolest Python recipe of all time

2011-05-02 Thread Ian Kelly
On Mon, May 2, 2011 at 2:48 PM, David Monaghan wrote: > On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger > wrote: > >>I think it is time to give some visibility to some of the instructive >>and very cool recipes in ActiveState's python cookbook. >> >>My vote for the coolest recipe of al

Re: Coolest Python recipe of all time

2011-05-02 Thread David Monaghan
On Mon, 2 May 2011 10:33:31 -0700 (PDT), Raymond Hettinger wrote: >I think it is time to give some visibility to some of the instructive >and very cool recipes in ActiveState's python cookbook. > >My vote for the coolest recipe of all time is: > > > http://code.activestate.com/recipes/365013-

Coolest Python recipe of all time

2011-05-02 Thread Raymond Hettinger
I think it is time to give some visibility to some of the instructive and very cool recipes in ActiveState's python cookbook. My vote for the coolest recipe of all time is: http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ What are your favorites? Raymond twit