Regular expressions. It takes a while to craft the expressions, but this will be more elegant, more extensible, and considerably faster to compute (matching compiled re's is fast).
Example using the top five from your function's comments: . host_patterns = [ . '^1Cust\d+\.tnt\d+\..*\.da\.uu\.net$', . '^user\d+\.net\d+\.mo\.sprint-hsd\.net$', . '^.*\.roadrunner\.nf\.net$', . ] . . host_expr = re.compile('|'.join(host_patterns)) . . # only implementing host string matching, but you get the idea. . def is_dynip(host): . # host names are case insensitive . host = host.lower() . return host_expr.match(host) is not None >> is_dynip("1Cust200.tnt8.bne1.da.uu.ne") True >> is_dynip("google.com") False (the dots preceding code are to fool indentation stripping... please ignore them) -- http://mail.python.org/mailman/listinfo/python-list