On Wed, 1 Jul 2020 at 05:36, Christopher Barker <python...@gmail.com> wrote:
>
> On Tue, Jun 30, 2020 at 11:55 AM Rhodri James <rho...@kynesim.co.uk> 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.

--
Oscar
_______________________________________________
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/QX37WTNEOA3GW4FESVWHYF5YHEGRIK27/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to