builtin functions for and and or?

Roose b at b.b
Sun Feb 13 18:33:50 EST 2005


"Diez B. Roggisch" <deetsNOSPAM at web.de> wrote in message
news:cuofcj$jvt$02$1 at news.t-online.com...
> > So usually I just write a little function any( L, boolean_function =
> > identity ) or all( ... ).  But I am kind of sick of doing that all the
> > time -- does it exist anywhere in the Python libraries?  It seems really
> > common to me.
>
> Put things into your own module and add it to your python path. Then you
> only have to write it once.

Well it's not as convenient as having it built in.  The thing is I'm not
just writing for myself.  I used it at my old job, and now I'm using it at
my new job.  There's a requirement that the user shouldn't have to modify
his setup beyond installing Python to run any scripts.  At my first job we
had one way of dealing with this.  Now there is another way.  And then I
need a way to deal with it at home with my personal stuff.

Also the stuff typically doesn't go under the Python dir, because that is
not mapped to source control.  And anyway people don't like mixing in our
code with 3rd party code.

The result that the path of least resistance is just to copy in a 4 line
function or two into the program and be done with it, even though it goes
against my sense of aesthetics.

It would be a lot simpler if it was included in the distribution.  I would
be willing to add it (even though it is completely trivial).  I think it
would go fine in itertools (I would even put them as builtins, but I'm not
going to go there because probably not everyone uses it as often as I do).

What do people think?  I have never done this, would I just write up a PEP?


>
> > The first way isn't satisfactory because it takes so many lines for what
> > is
> > essentially one "primitive" operation.  The second way isn't great
because
> > it is not as readable and many readers don't like to see reduce, even if
> > it
> > is a common idiom like that.  Also I don't believe it short circuits.
>
> It doesn't but so doesn't your loop example. Put a break in there once
> Result is False.
>
> --
> Regards,
>
> Diez B. Roggisch





More information about the Python-list mailing list