Comments on my first script?
D'Arcy J.M. Cain
darcy at druid.net
Fri Jun 13 07:39:28 EDT 2008
On Fri, 13 Jun 2008 10:19:38 +0200
Bruno Desthuilliers <bruno.42.desthuilliers at websiteburo.invalid> 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 <darcy at druid.net> | 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.
More information about the Python-list
mailing list