Re: How to make a reverse for loop in python?
On Sun, 21 Sep 2008 01:56:59 +0200, Christian Heimes wrote:
I agree with your advice not to abuse lists, but not for the reason you
give. The memory overhead of a linked list implemented on top of a Python
list probably isn't going to be that much greater than a dict or a class.
I think the real reasons why linked lists get a bad rep in Python are:
(1) they're unnecessary 99% of the time;
(2) when they are necessary, a better implementation is to use classes
(e.g. see traceback objects); and
(3) the standard Lisp idiom for lists is horribly inefficient in CPython:
alist = [1, [2, [3, [4, [5, [6, []]]]]]]
But that's primarily inefficient because of the number of method calls
needed to access an item. There is some memory overhead, but memory is
cheap and the overhead of using objects in the first place is far larger
than the overhead of a few extra pointers.
--
Steven
On Sun, 21 Sep 2008 01:56:59 +0200, Christian Heimes wrote:
Just *don't* try to abuse lists by creating fancy stuff e.g. linked
lists. The memory overhead is going to kill your app.
lists. The memory overhead is going to kill your app.
give. The memory overhead of a linked list implemented on top of a Python
list probably isn't going to be that much greater than a dict or a class.
I think the real reasons why linked lists get a bad rep in Python are:
(1) they're unnecessary 99% of the time;
(2) when they are necessary, a better implementation is to use classes
(e.g. see traceback objects); and
(3) the standard Lisp idiom for lists is horribly inefficient in CPython:
alist = [1, [2, [3, [4, [5, [6, []]]]]]]
But that's primarily inefficient because of the number of method calls
needed to access an item. There is some memory overhead, but memory is
cheap and the overhead of using objects in the first place is far larger
than the overhead of a few extra pointers.
--
Steven
Comment