[Python-3000] Spooky behavior of dict.items() and friends
"Martin v. Löwis"
martin at v.loewis.de
Wed Apr 2 23:59:06 CEST 2008
Jason Orendorff wrote:
> On Tue, Apr 1, 2008 at 9:37 PM, "Martin v. Löwis" <martin at v.loewis.de> wrote:
>> I think it's fairly obvious why the 2.x .keys() has to change. It's
>> just too wasteful to actually build the list of all keys of a dictionary
>> (or even of all values, as you have to create all the tuples as well),
>> if all you want to do is to iterate over it, and the most common
>> operation of .keys() is to iterate over it in a for look (right?).
>
> I don't think so. Is this a use case for d.keys()? Why not just
> write "for k in d"?
See the subject. What do you say about d.items()?
> To me, framing the question as "iterate vs. copy" seems bogus. It's
> more like "view vs. copy". The thing is, copying provides the
> semantics I want (of *course* I don't want extra helpings of aliasing
> and spooky interaction between collections, are you nuts?), and the
> slowness has never bothered me--that I know of. Views would be
> faster, but with silently different semantics. I think I want
> copying.
I think there is zero chance to revert that decision now.
Regards,
Martin
More information about the Python-3000
mailing list