473,288 Members | 2,350 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,288 software developers and data experts.

test mult vars to same value, how to shorten expr?

if i want o test:
if a == 5 and b ==5 and c==5 ... z==5

is there some synctactic suagr for this?

rather than maiking one of my own i mean, something built-in like:
if a,b,c... z == 5:
Jun 27 '08 #1
4 906
no**********@yahoo.se wrote:
if i want o test:
if a == 5 and b ==5 and c==5 ... z==5

is there some synctactic suagr for this?

rather than maiking one of my own i mean, something built-in like:
if a,b,c... z == 5:
How about:

if 5 == a == b == c == ... z:
...

--Scott David Daniels
Sc***********@Acm.Org
Jun 27 '08 #2
On Mon, 19 May 2008 20:36:45 -0700, notnorwegian wrote:
if i want o test:
if a == 5 and b ==5 and c==5 ... z==5

is there some synctactic suagr for this?

rather than maiking one of my own i mean, something built-in like:
if a,b,c... z == 5:
Since Python 2.5 there's `all()`:

In [81]: a, b, c, d = 5, 5, 5, 6

In [82]: all(x == 5 for x in (a, b, c))
Out[82]: True

In [83]: all(x == 5 for x in (a, b, c, d))
Out[83]: False

Ciao,
Marc 'BlackJack' Rintsch
Jun 27 '08 #3
no**********@yahoo.se wrote:
if i want o test:
if a == 5 and b ==5 and c==5 ... z==5

is there some synctactic suagr for this?

rather than maiking one of my own i mean, something built-in like:
if a,b,c... z == 5:
if all(x == 5 for x in a,b,c,...):
print "yep"
Peter
Jun 27 '08 #4
On May 20, 2:08*am, Peter Otten <__pete...@web.dewrote:
notnorweg...@yahoo.se wrote:
*if i want o test:
if a == 5 and b ==5 and c==5 ... z==5
is there some synctactic suagr for this?
rather than maiking one of my own i mean, something built-in like:
if a,b,c... z == 5:

if all(x == 5 for x in a,b,c,...):
* *print "yep"

Peter
>>a,b,c,d=5,5,5,5
import functools
import operator
myequals= functools.partial( operator.eq, 5 )
map( myequals, ( a, b, c, d ) )
[True, True, True, True]
>>all( _ )
True
Jun 27 '08 #5

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

Similar topics

0
by: Remy Blank | last post by:
Ok, here we go. I added the possibility for tests using the unittest.py framework to be skipped. Basically, I added two methods to TestCase: TestCase.skip(msg): skips unconditionally...
15
by: lawrence | last post by:
Is this the correct way to test for a method before I use it? createRange() is, I believe, an IE only method. function wrapSelectionInTag(selection, tag) { if (document.selection.createRange)...
44
by: gokkog | last post by:
Hi there, There's a classic hash function to hash strings, where MULT is defined as "31": //from programming pearls unsigned int hash(char *ptr) { unsigned int h = 0; unsigned char *p =...
3
by: GaryDean | last post by:
I have serveral applications now running that are using the MembershipProvider classes and they are each using their own security tables in SQL Server 2005 instead of the express databases - they...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.