[Python-3000] Iterators for dict keys, values, and items == annoying :)

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Mar 24 10:49:19 CET 2006


Ian Bicking wrote:

> A downside is mistranslations of old code will lead to very hard bugs, 
> as .keys() currently makes a copy.  Though if the new objects aren't 
> quite the same as lists -- e.g., implementing .add() instead of 
> .append() -- then maybe that won't be so bad.

I'd suggest that the view objects be immutable. Then
code which was expecting an independent object would
fail rather than accidentally messing up the underlying
object.

If you need a mutable copy, you can always wrap list()
around it, or something else such as sorted().

Greg


More information about the Python-3000 mailing list