On Sun, Jul 31, 2011 at 9:38 AM, Rama Rao Polneni <ram...@gmail.com> wrote: > Earlier I had many duplicate strings in different rows retrieved from > database. > I created a list to have unique strings and their indexes are used in > actual computations. So lot of space is saved by having integers > instead of strings. >
What you're doing there is called "interning" the strings, and I think it's the right thing to do. You can get the Python interpreter to do this for you by simply passing the strings through the built-in function intern() which will return a string with identical content. (In Python 3, that function has been shoved off to a module, so it's sys.intern() and you need to import sys.) You'll save some space and improve dictionary performance, but you won't lose clarity. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list