473,394 Members | 1,714 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,394 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 908
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.