Thoughts on new vs traditional idioms

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Mon Mar 1 17:18:07 EST 2004


> From: Peter Otten
> 
> Not particular frequent, but anyway:
> 
> >>> sample = [[1,2], (3,4)]
> >>> copies = [seq.__class__(seq) for seq in sample]
> >>> for s, c in zip(sample, copies):
> ...     if s is c: print s
> ...
> (3, 4)
> 
> Assuming all immutable classes are "smart enough":

That's a *very* big assumption - one I would never make.

It is explicitly stated that immutable objects *may* be reused. For some functions and methods, it states that they *will* be reused in certain situations. Only in those cases can or should you rely on that behaviour.

Tim Delaney




More information about the Python-list mailing list