Lyosha  <[EMAIL PROTECTED]> wrote:
>On May 17, 11:04 pm, Stargaming <[EMAIL PROTECTED]> wrote:
>>    dec2bin = lambda x: (dec2bin(x/2) + str(x%2)) if x else ''
> [ ... ]
>I guess the reason I couldn't come up with something like this was
>being brainwashed that lambda is a no-no.
>
>And python2.5 funky ?: expression comes in handy!

def dec2bin(x): return x and (dec2bin(x/2)+str(x%2)) or ''

does the same job without lambda or Python 2.5 (and note that the
usual warning about a and b or c doesn't apply here as b is
guaranteed to evaluate as true).

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
        -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to