On Fri, Jul 31, 2020 at 04:08:43PM -0700, Guido van Rossum wrote: > Maybe it is common in numpy and pandas to keep adding operations to the > same object until it breaks, but the key and items views already implement > the Set ABC, and I'd rather refrain from having them *also* implement the > Sequence ABC.
+1 I'm not a huge fan of pandas' APIs, I don't think that "pandas does it this way" is something we ought to emulate. > I'm guessing that indexing by 0, if it were possible, would be a convenient > idiom to implement the "first item" operation that has been requested > numerous times (at least for dicts). Indeed, that seems to be the only use-case which seems to be even remotely common. `dict.popitem` would do it, of course, but it also mutates the dict. The other simple solution is `next(iter(mydict.items()))`. The bottom line here seems to me, as far as I can tell, is that being able to fetch a key and/or value by index is of only marginal use. > Slicing would be useful to get the > first N items of a huge dict without materializing the full list of items > as a list object, which brought Chris B to request this in the first place. The first request in this thread was from Hans: https://mail.python.org/archives/list/python-ideas@python.org/message/S7UMTWK65X6BJDYZ3SSU7I7HOIASDMMJ/ He is using a dict to hold an array of columns indexed by name `{column_name: column}` and wanted to re-order and insert columns at arbitrary positions. -- Steven _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/T3SSBMEZCIOHJJ7REJXE6XZLTNQQWVFJ/ Code of Conduct: http://python.org/psf/codeofconduct/