On Fri, Jan 3, 2014 at 11:06 AM, Chris Angelico <ros...@gmail.com> wrote: > Pass any object through truth() and it'll either stay the same (if > it's true) or become this object (if it's false). You can then carry > on with other method calls, and they'll all happily return false. > > result = ( > truth(re1.match(string)).group(0) or > truth(re2.match(string)).group(0) or > truth(re3.match(string)).group(0) or > default_value > )
Oh, just thought of a possible snag. Since an empty string comes up as false, this exact notation would fail if the re can match nothing. But you probably know if it's possible for that to happen, so don't use this simple short-hand. :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list