Paddy a écrit : > On 21 Feb, 23:33, "[EMAIL PROTECTED]" > <[EMAIL PROTECTED]> wrote: >>> What you can't do (that I really miss) is have a tree of assign-and-test >>> expressions: >>> import re >>> pat = re.compile('some pattern') >>> if m = pat.match(some_string): >>> do_something(m) >>> else if m = pat.match(other_string): >>> do_other_thing(m) >>> else: >>> do_default_thing() >> What you want is: >> >> for astring, afunc in ((some_string, do_something), (other_string, >> do_other_thing)): >> m = pat.match(astring) >> if m: >> afunc(m) >> break >> else: >> do_default_thing() > > The Bruno transform? :-)
I do not claim any paternity on this idiom. FWIW, must be (in one or another variant) in quite a lot of texts / posts / sites / any other resource about Python. -- http://mail.python.org/mailman/listinfo/python-list