Pointers/References in Python?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Jul 30 17:10:11 CEST 2008

> I have a long list of memory-heavy objects that I would like to access
> in differently sorted order. Let's say I'd like to have lists called
> by_date or by_size that I can use to access the objects in the
> specified order.

Just create a new list with a different sorting order, for example

from operator import attrgetter
by_date = sorted(input_data, key=attrgetter("date"))
by_size = sorted(input_data, key=attrgetter("size"))

Python doesn't copy by value by default, so you end having just a
light list of references.

To understand the situation better, there's a FAQ about how Python
associates names to things.


More information about the Python-list mailing list