Have folks thought about allowing indexing dictionary views as in the
following code, where d is a dict object?
d.keys()[0]
d.keys()[-1]
d.values()[0]
d.values()[-1]
d.items()[0]
d.items()[-1] # item that would be returned by d.popitem()
since dicts were made order-preserving, indexing the keys, items, etc does make some sense.
> I've also often wanted to get an arbitrary item/key from a dictionary, and
This is indeed one of the use cases identified.
--
Christopher Barker, PhD (Chris)
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython