On 13 juin, 13:39, "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> wrote: > 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...) > > }
FWIW, the keys should not start with a '.'. My fault... > > 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) Depends on if you want to know if there's a match or if you just don't care. > I suppose you could predefine the default function as well. Yeps. That's usually what I do when I end up using the above variant more than once in a module. -- http://mail.python.org/mailman/listinfo/python-list