I think this comparison is unfair.
well, benchmarks always lie ....
> d.items() vs list(d.items())
Should be compared with `next(iter(d.items())`
why? the entire point of this idea is to have indexing syntax -- we can already use the iteration protocol top do this. Not that it's a bad idea to time that too, but since under the hood it's doing the same or less work, I'm not sure what the point is.
> d.keys()[-1] vs list(d.keys())[-1]
Should be compared with `next(reversed(d.keys()))`, or `next(reversed(d))`.
Same point - the idea is to have indexing syntax. Though yes, it would be good to see how it compares. But I know predicting performance is usually wrong, but this is going to require a full traversal of the underlying keys in either case.
> random.choice(d.items()) vs random.choice(list(d.items()))
Should be compared with `random.choice(items_list)` with `items_list =
list(d.items())` setup too.
I don't follow this one -- could you explain? what is items_list ?
But what this didn't check is how bad the performance could be for what I expect would be a bad performance case -- indexing teh keys repeatedly:
for i in lots_of_indexes:
keys_list = list(a_dict.keys)
for it in lots_of_indexes:
I suspect it wouldn't take all that many indexes for making a list a better option.
But again, we are badk to use cases. As Stephen pointed out no one has produced an actualy production code use case.
I myself have wanted this (the random.choice option) -- but it wasn't production code it was a learning exercise, specifically:
I can imagine there would be that use case in real world code, but I haven't had it.
Inada Naoki <firstname.lastname@example.org>
Python-ideas mailing list -- email@example.com
To unsubscribe send an email to firstname.lastname@example.org
Message archived at https://email@example.com/message/73YTQDLWN6SUSOZ62C23SFHK3FIJGY3Y/
Code of Conduct: http://python.org/psf/codeofconduct/