Dictionary .keys() and .values() should return a set [with Python3000 in mind]
Paul Rubin
http
Mon Jul 3 00:45:35 EDT 2006
"Delaney, Timothy (Tim)" <tdelaney at avaya.com> writes:
> The eventual consensus was that keys(), etc should return views on the
> dictionary. These views would be re-iterable and will have basically the
> same behaviour as the lists returned from keys(), etc. However, such a
> view could have O(1) __contains__ behaviour, and would not incur the
> overhead of creating a list and populating it - they would be backed by
> the dictionary. Of course, this introduces the issue of concurrent
> modification, but you can always get an independent copy by calling
> list(dict.keys()).
Wait a sec, you're saying
k0 = d.keys()
d['whee'] = 'parrot' # this can change k0???
That sounds broken.
More information about the Python-list
mailing list