Chris Kaynor wrote: > On Wed, Dec 10, 2014 at 7:15 PM, Steven D'Aprano <st...@pearwood.info> > wrote:
>> Using "is" you are demonstrating that calling the function twice returns >> two distinct objects. That is the purpose of "is", to compare object >> identity. Without "is", you can compare object IDs directly: >> >> id(f()()) == id(f()()) >> >> but that's ugly and less efficient. Using "is" is the more idiomatic and >> natural way to do this. >> > > In CPython, that does not work, as the dictionary will be garbage > collected after each call to id: >>>> f = lambda : (lambda x= {}: x) >>>> f()() is f()() > False >>>> id(f()()) == id(f()()) > True Nice catch! Thank you for the correction. -- Steven -- https://mail.python.org/mailman/listinfo/python-list