LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2011)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 8 Jun 2011 15:29:01 +0200
Reply-To:     Edwin Meijdam <emeijdam@DASC.NL>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Edwin Meijdam <emeijdam@DASC.NL>
Subject:      Re: python: if and if statements
In-Reply-To:  <OFF64C42B2.0A1B5F15-ON872578A9.00459007-872578A9.0045CFF6@us.ibm.com>
Content-Type: multipart/alternative;

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]


Back to: Top of message | Previous page | Main SPSSX-L page