--- On Mon, 1/25/10, Benjamin Peterson <benja...@python.org> wrote: > 2010/1/25 Steve Howell <showel...@yahoo.com>: > > I am interested in creating a patch to make deleting > elements from the front > > of Python list work in O(1) time by advancing the > ob_item pointer. > > How about just using a deque?
Deque does not support all the operations that list does. It is also roughly twice as slow for accessing elements (I've measured it). >>> lst = ['foo', 'bar', 'baz'] >>> lst[1:] ['bar', 'baz'] >>> lst.insert(0, 'spam') >>> lst ['spam', 'foo', 'bar', 'baz'] >>> d = deque(lst) >>> d[2:] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: sequence index must be integer, not 'slice' >>> d.insert(0, 'eggs') Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'collections.deque' object has no attribute 'insert' _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com