On Mon, Oct 4, 2021 at 5:46 PM Erik Demaine firstname.lastname@example.org wrote:
Have folks thought about allowing indexing dictionary views as in the following code, where d is a dict object?
d.keys() d.keys()[-1] d.values() d.values()[-1] d.items() 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,
This is indeed one of the use cases identified.
I found some related discussion in
https://email@example.com/thread/QVTGZD6... but not this exact idea.
That's a pretty different idea but this exact idea has been discussed on this list relatively recently. I still like it, but there wan't much general support.
I'll leave it exercise for the read to find that thead, but it is there, and I suggest you look for it if you want to further pursue this idea.