Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10622
| References | <mailman.689.1309938580.1164.python-list@python.org> <c3jde8-22r.ln1@satorlaser.homedns.org> <CACwB6cwLRz_6h=HHVQLK=U3zzEw_A60yBKGQUTR7bHam2jn28g@mail.gmail.com> |
|---|---|
| Date | 2011-07-31 09:46 +0100 |
| Subject | Re: Not able to store data to dictionary because of memory limitation |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1690.1312102017.1164.python-list@python.org> (permalink) |
On Sun, Jul 31, 2011 at 9:38 AM, Rama Rao Polneni <ramp99@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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Not able to store data to dictionary because of memory limitation Rama Rao Polneni <ramp99@gmail.com> - 2011-07-06 13:19 +0530
Re: Not able to store data to dictionary because of memory limitation Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2011-07-06 10:35 +0200
Re: Not able to store data to dictionary because of memory limitation Rama Rao Polneni <ramp99@gmail.com> - 2011-07-31 14:08 +0530
Re: Not able to store data to dictionary because of memory limitation Chris Angelico <rosuav@gmail.com> - 2011-07-31 09:46 +0100
csiph-web