Date: Wed, 8 Jun 2011 08:59:32 -0700
Reply-To: Albert-Jan Roskam <fomcl@yahoo.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Albert-Jan Roskam <fomcl@yahoo.com>
Subject: Re: python: if and if statements
In-Reply-To: <BANLkTikVRhY8uF2+MQNjnhujTvTmRPRwHg@mail.gmail.com>
Content-Type: multipart/alternative;
Hmm, I like this better:
>>> all([len(alpha)==1, len(beta)==1, len(beta2)==1, len(alpha_stdfehler)==1])
True
But you're right, lambdas rock:
>>> all([filter(lambda arg: len(arg)==1, [alpha, beta, beta2,
alpha_stdfehler])])
True
Cheers!!
Albert-Jan
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public
order, irrigation, roads, a fresh water system, and public health, what have the
Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
________________________________
From: Edwin Meijdam <emeijdam@DASC.NL>
To: SPSSX-L@LISTSERV.UGA.EDU
Sent: Wed, June 8, 2011 3:29:01 PM
Subject: Re: [SPSSX-L] python: if and if statements
Probably a bit too much, but I just like map & lambda functions:
Assuming the vars are strings:
alpha = 't'
beta = 'e'
beta2 = 's'
alpha_stdfehler = 't'
aList = [alpha, beta, beta2, alpha_stdfehler]
allOneLenght = sum(list(map(lambda x: len(x) == 1, aList))) == len(aList)
if allOneLenght:
Hope this help (but I doubt that...),
Edwin Meijdam
On Wed, Jun 8, 2011 at 2:42 PM, Jon K Peck <peck@us.ibm.com> wrote:
Lots of ways to do this. Here's one more
>if min(a,b,c) == max(a,b,c) == 1:
> ...
>IIRC, the original logic was just that these values not be 0, so you could
>simplify further to
>
>if min(a,b,c):
> ...
>since 0 is False
>
>Jon Peck
>Senior Software Engineer, IBM
>peck@us.ibm.com
>new phone: 720-342-5621
>
>
>
>
>
>From: drfg2008 <kontakt@datest.de>
>To: SPSSX-L@LISTSERV.UGA.EDU
>Date: 06/08/2011 01:17 AM
>Subject: [SPSSX-L] python: if and if statements
>Sent by: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
>________________________________
>
>
>
>how can I cut short lots of "if and if ..."-Statements in python (all
>statements have to be ==1). Example:
>
>if len(alpha) ==1 and len(beta1) ==1 and len(beta2) ==1 and
>len(alpha_stdfehler) ==1 and len(beta1_stdfehler) ==1 and
>len(beta2_stdfehler) ==1 and len(alpha_T)==1 and len(beta1_T)==1 and
>len(beta2_T)==1 and len(r_quadrat)==1 and len(r_quadrat_stdfehler)==1 :
>
>
>-> if any(alpha, beta, ....) <> 1
> continue
> else: ...
>
>something like that? Couldn't find a solution.
>
>Thanks
>
>
>
>-----
>Dr. Frank Gaeth
>FU-Berlin
>
>--
>View this message in context:
>http://spssx-discussion.1045642.n5.nabble.com/python-if-and-if-statements-tp4467945p4467945.html
>
>Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
>=====================
>To manage your subscription to SPSSX-L, send a message to
>LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
>command. To leave the list, send the command
>SIGNOFF SPSSX-L
>For a list of commands to manage subscriptions, send the command
>INFO REFCARD
>
>
--
Edwin Meijdam
+31(0)6 159 608 37
DASC B.V.
Postbus 88 4130 EB Vianen
085 - 8774406
emeijdam@dasc.nl
http://www.linkedin.com/in/emeijdam
[text/html]
|