Better writing in python

Paul Hankin paul.hankin at gmail.com
Wed Oct 24 14:54:02 CEST 2007


On Oct 24, 1:09 pm, Alexandre Badez <alexandre.ba... at gmail.com> 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...

import operator
return filter(cls.dArguments), filter(operator.not_, cls.dArguments)

Or just:

mandatory = [arg for arg in cls.dArguments in arg]
optional = [arg for arg in cls.dArguments in not arg]
return mandatory, optional

--
Paul Hankin




More information about the Python-list mailing list