re Challenge: More Compact?

Ben Wolfson rumjuggler at cryptarchy.org
Mon Jul 16 19:53:06 CEST 2001


On Mon, 16 Jul 2001 02:39:50 GMT, tim at vegeta.ath.cx (Tim Hammerquist)
wrote:

>Ok, so here's my version (I hate wasted line space and unnecessary temp
>vars):
>
>def valid_ip(ip):
>    m = re.match( r'(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$', ip)
>    if m:   return max(map(int, m.groups())) < 256
>    return 0

In that case you can eliminate a whole line this way:

def valid_ip(ip):
    m = re.match( r'(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$', ip)
    return (m and max(map(int, m.groups())) < 256)) or 0

-- 
Barnabas T. Rumjuggler
No man can run so fast that he can escape his own past's projectile vomit.



More information about the Python-list mailing list