Dictionary .keys() and .values() should return a set [with Python 3000 in mind]

John Machin sjmachin at lexicon.net
Sat Jul 1 17:30:48 EDT 2006


On 2/07/2006 6:01 AM, vatamane at gmail.com wrote:
> This has been bothering me for a while. 
[snip]

Summary of OP's post: d.keys() and d.values() should return sets in 
Python 3.0.

Observations:
(1) My code [some of which dates back to Python 1.5.1] uses about 12 x 
d.items() and 11 x d.keys() for each 1 x d.values()
(2) Most cases of d.X() don't need/want the untrammelled list and could 
be replaced by d.iterX(). Example: max_frequency = max(tally.values())

Opinion: d.X() could be deprecated, but I'd rather see a 
consciousness-raising for the d.iterX() methods, and for the construct
     for key in d:

Cheers,
John





More information about the Python-list mailing list