```Date: Wed, 8 Jun 2011 15:29:01 +0200 Reply-To: Edwin Meijdam Sender: "SPSSX(r) Discussion" From: Edwin Meijdam Subject: Re: python: if and if statements In-Reply-To: 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 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 > 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" > ------------------------------ > > > > 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