473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Another proposed proposal: operator.bool_and / bool_or

The suggestion is to add boolean and/or functions to the operator
module, useful with "reduce". For some reason I thought these were
already present, but they're not (were they removed?). There are
already and_ and or_, but these are bitwise functions, not boolean
operations.

bool_and and bool_or would differ from the "and" and "or" keywords,
since they're functions and cannot short-circuit.

Specification:

operator.bool_and(x,y) = (bool(x) & bool(y))
operator.bool_or(x,y) = (bool(x) | bool(y))

Use case:

from operator import bool_and, bool_or
def any(seq): return reduce(bool_or, seq, False)
def all(seq): return reduce(bool_and, seq, True)

Of course you could use map(bool,seq), but now that we have bools it's
reasonable to have these boolean operations.
Mar 31 '06 #1
1 1059
> def any(seq): return reduce(bool_or, seq, False)
def all(seq): return reduce(bool_and, seq, True)


Any other use cases? These will be built-in in 2.5

-Mike

Mar 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Raymond Hettinger | last post by:
Comments are invited on the following proposed PEP. Raymond Hettinger ------------------------------------------------------- PEP: 329
30
by: ajsiegel | last post by:
Arthur wrote: >> And either intuitively, or consciously, he is doing something that >> offsets it from something truly intergrated into the core of the >> language. By breakling all of his own...
6
by: Paul Rubin | last post by:
I'm thinking of proposing that a values method be added to set objects, analogously with dicts. If x is a set, x.values() would be the same as list(x). This feels logical, and it would allow...
3
by: James J. Besemer | last post by:
I would like to champion a proposed enhancement to Python. I describe the basic idea below, in order to gage community interest. Right now, it's only an idea, and I'm sure there's room for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.