Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
rings
#13
buran Wrote:Same apply for e.g. list
This is not true. Random access in lists is in O(1). Of course, if you want to insert elements, that's another matter.

Again in the case of the deque, if you want to rotate often by large amounts, it will probably have worse performances than a list with a pointer to the head index.

I think it all depends on how one wants to use the structure.

Actually, you need many items to feel any difference
from collections import deque
from timeit import timeit

L = list(range(200000))
D = deque(L)

print('list', timeit('L[100000]', 'from __main__ import L'))
print('deque', timeit('D[100000]', 'from __main__ import D'))
Output:
list 0.022696959997119848 deque 6.838809543995012
buran and ndc85430 like this post
Reply


Messages In This Thread
rings - by Skaperen - Oct-15-2020, 03:26 PM
RE: rings - by Gribouillis - Oct-15-2020, 07:43 PM
RE: rings - by buran - Oct-15-2020, 08:18 PM
RE: rings - by ndc85430 - Oct-16-2020, 02:35 PM
RE: rings - by Skaperen - Oct-16-2020, 06:55 PM
RE: rings - by metulburr - Oct-17-2020, 11:23 AM
RE: rings - by Gribouillis - Oct-17-2020, 11:47 AM
RE: rings - by buran - Oct-17-2020, 02:58 PM
RE: rings - by Gribouillis - Oct-17-2020, 03:05 PM
RE: rings - by buran - Oct-17-2020, 03:12 PM
RE: rings - by Gribouillis - Oct-17-2020, 03:25 PM
RE: rings - by buran - Oct-17-2020, 03:45 PM
RE: rings - by Gribouillis - Oct-17-2020, 04:10 PM
RE: rings - by Skaperen - Oct-19-2020, 08:37 PM
RE: rings - by Skaperen - Oct-19-2020, 08:39 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020