Decorate level2 with a decorator that caches: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/425445
--Michael On 11/1/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > > I am building a list like this: > > tree = [] > for top in tops: > l2 = level2(top) > if l2: > tree.append((top, l2)) > > I would really like to turn this into a list comprehension: > > tree = [ (top, level2(top)) for top in tops if level2(top) ] > > but the call to level2() is expensive enough that I don't want to repeat > it. Is there any way to do this or am I stuck with the (IMO ugly) loop > form? > > Kent > > who actually does have a question occasionally :-) > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Michael Langford Phone: 404-386-0495 Consulting: http://www.TierOneDesign.com/
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor