On Wed, 1 Jul 2020 at 05:36, Christopher Barker firstname.lastname@example.org wrote:
On Tue, Jun 30, 2020 at 11:55 AM Rhodri James email@example.com wrote:
Don't get me wrong, if it's not going to cause performance issues I think being able to index views would be great, but I don't think this is the right way to justify it.
I wasn't justifying it -- I was simply saying that no one ever specifically decided that we DIDN'T want to be able to index dict views -- when they were created, it simply wasn't an option. Now it is, so we need to rethink it.
if it's not going to cause performance issues
I can't see how it could possibly *cause* performance issues. It isn't as great performance as we would like, but I think it's still as good, and probably much better, than any other way to accomplish the same thing.
If indexing is O(N) then repeated indexing can be a lot less efficient e.g. if order is the same size as d then this is O(N):
items = list(d.items()) for n in order: do_stuff(items[n])
If the items view itself is indexable with O(N) cost then you can avoid constructing the list but the result is quadratic:
for n in order: do_stuff(items[n])
Standard containers right now are all O(1) for indexing so I think it would be surprising that quadratic behaviour could result from indexing an object rather than making a copy of it.