Re: Why is recursion so slow?

2008-07-01 Thread Rich Harkins
Nick Craig-Wood wrote: [snip] By definition any function in a functional language will always produce the same result if given the same arguments, so you can memoize any function. Ah, so that's why time.time() seems to be stuck... ;) Rich -- http://mail.python.org/mailman/listinfo/python-li

Re: opposite of zip()?

2007-12-17 Thread Rich Harkins
Matt Nordhoff wrote: [snip] > > As Paddy wrote, zip is its own unzip: > zipped = zip((1, 2, 3), (4, 5, 6)) zipped > [(1, 4), (2, 5), (3, 6)] unzipped = zip(*zipped) unzipped > [(1, 2, 3), (4, 5, 6)] > > Neat and completely confusing, huh? :-) > >

Re: opposite of zip()?

2007-12-17 Thread Rich Harkins
[EMAIL PROTECTED] wrote: > Given a bunch of arrays, if I want to create tuples, there is > zip(arrays). What if I want to do the opposite: break a tuple up and > append the values to given arrays: >map(append, arrays, tupl) > except there is no unbound append() (List.append() does not exist, >

Re: Descriptors and side effects

2007-11-05 Thread Rich Harkins
Bruno Desthuilliers wrote: > Which is easy to do with properties too. True enough. It's the caching of the return value that's the value add of course. ;) > >> After >> it is applied, then the penalties for function call of the property and >> the computation are wiped out once the second acc

Re: Functions as Objects, and persisting values

2007-11-05 Thread Rich Harkins
[snip] > The "thing" you observe here is a called a closure. It consists of the > local variables surrounding e. So as long as you keep a reference to e, > you keep one to the variables of d itself. > > Diez More specifically though it keeps references to the requested variables only: def clo

Re: Descriptors and side effects

2007-11-05 Thread Rich Harkins
Bruno Desthuilliers wrote: > Rich Harkins a écrit : >> [EMAIL PROTECTED] wrote: >>> Hello everyone, >>> >>> I'm trying to do seemingly trivial thing with descriptors: have >>> another attribute updated on dot access in object defined using >>

Re: Descriptors and side effects

2007-11-05 Thread Rich Harkins
Bruno Desthuilliers wrote: [snip] > I'm sorry, but this looks like a very complicated way to do a simple thing: > > class MySimpleClass(object): >def __init__(self, x): > self.x = x > self.y = x ** 2 > > Sure, for the absurdly simplified case I posed as an example. ;) Here's ano

Re: Descriptors and side effects

2007-11-05 Thread Rich Harkins
[EMAIL PROTECTED] wrote: > Hello everyone, > > I'm trying to do seemingly trivial thing with descriptors: have > another attribute updated on dot access in object defined using > descriptors. [snip] > A setter function should have updated self.l just like it updated > self.s: > > def __se