A more pythonic way of writting

eric eric at ericaro.net
Fri Dec 5 10:44:21 EST 2008


On Dec 5, 3:44 pm, "Mark Tolonen" <metolone+gm... at gmail.com> wrote:
> "eric" <e... at ericaro.net> wrote in message
>
> news:35d176ed-df5f-46b4-8321-4814fcc4398c at f3g2000yqf.googlegroups.com...
>
> > def flag(IGNORECASE=False, LOCALE=False, MULTILINE=False,
> > DOTALL=False, UNICODE=False, VERBOSE=False):
> >    vals = [IGNORECASE, LOCALE, MULTILINE, DOTALL, UNICODE, VERBOSE]
> >    filtered = map( lambda m:m[1],filter( lambda m: m[0],
> > zip(vals,'iLmsux')))
> >    return '?'+''.join( filtered  )
>
>     filtered = [c for c,v in zip('iLmsux',vals) if v]
>
> -Mark

thank you very much ! great !

I can't get used to this late 'if' syntax !

@Gerard
nice hypercube function. But I'll keep with my implementation :
I like to believe that the less the 'debug pointer' stands in the
python code, the fastest the code is (or is potentially)

I keep thinking that
def hypercube(ndims) :
    for i in range(1<<ndims):
        yield [i&mask==mask for mask in [1<<j for j in range(ndims)] ]

but thanks for you proposition, it's interesting anyway




More information about the Python-list mailing list