On Oct 24, 9:04 am, "A.T.Hofkamp" <[EMAIL PROTECTED]> wrote: > > On 2007-10-24, Alexandre Badez <[EMAIL PROTECTED]> wrote: > > I'm just wondering, if I could write a in a "better" way this > > code > > > lMandatory = [] > > lOptional = [] > > for arg in cls.dArguments: > > if arg is True: > > lMandatory.append(arg) > > else: > > lOptional.append(arg) > > return (lMandatory, lOptional) > > > I think there is a better way, but I can't see how... > > You can do it shorter, not sure that it also qualifies as better.... > > d = { True : [] , False : [] } > for arg in cls.arguments: > d[arg == True].append(arg) > > return d[True], d[False] > > One potential problem here is that 'arg == True' may not be the same as 'if > arg:'. I couldn't come up with a better equivalent expression, maybe one of > the > other readers knows more about this? > > Albert
d[bool(arg)].append(arg) resolves your concern? -- http://mail.python.org/mailman/listinfo/python-list