On Fri, 13 Jun 2008 10:19:38 +0200
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> Ok, since you asked for it, let's go:

Good commentary.  One small improvement:

> REC_CLEANERS = {
>     '.net' : clean_net,
>     '.com' : clean_com,
>     '.tv'  : clean_net,
>     '.uk'  : clean_co_uk,
>     (etc...)
> }
> 
> for domain in rec:
>     # code here
>     ext = domain.rsplit('.', 1)[1]
>     cleaner = REC_CLEANERS.get(ext, None)
>     if cleaner:
>         rec = cleaner(rec)

How about this?

for domain in rec:
    # code here
    ext = domain.rsplit('.', 1)[1]
    rec = REC_CLEANERS.get(ext, lambda x: x)

I suppose you could predefine the default function as well.  This saves
a binding and a test at the expense of a possible lambda call.

-- 
D'Arcy J.M. Cain <[EMAIL PROTECTED]>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to