Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5413
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'memory.': 0.05; 'dictionary': 0.07; 'python': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'referenced': 0.09; 'sun,': 0.09; 'def': 0.13; 'am,': 0.14; 'wrote:': 0.14; 'dictionary:': 0.16; 'rebert': 0.16; 'subject:key': 0.16; 'this?': 0.18; 'writes:': 0.20; 'values': 0.23; 'keys': 0.23; 'objects,': 0.23; 'objects': 0.24; 'thus': 0.24; 'memory': 0.24; 'possible,': 0.25; 'define': 0.26; 'instead': 0.26; 'times.': 0.26; 'chris': 0.27; 'lists': 0.28; 'raise': 0.29; 'technical': 0.29; 'seem': 0.30; 'does': 0.31; 'equal': 0.31; 'to:addr:python-list': 0.32; 'several': 0.33; 'header:X-Complaints-To:1': 0.34; 'there': 0.35; 'header:User- Agent:1': 0.35; 'rather': 0.36; 'considered': 0.36; 'skip:o 20': 0.37; 'useful': 0.37; 'but': 0.38; 'received:org': 0.38; 'received:82': 0.38; 'to:addr:python.org': 0.39; 'where': 0.39; 'header:Mime-Version:1': 0.39; 'would': 0.40; 'header:Received:5': 0.40; 'retrieve': 0.60; 'huge': 0.62; '2011': 0.62; 'subject:original': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Christoph Groth <cwg@falma.de> |
| Subject | Re: dict: retrieve the original key by key |
| Date | Sun, 15 May 2011 11:11:41 +0200 |
| References | <874o4wwenu.fsf@falma.de> <BANLkTikszH_r-PAuL0pJ8reMc+bGafuRew@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | dra38-5-82-246-248-175.fbx.proxad.net |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) |
| Cancel-Lock | sha1:dtD+++Y4OUaEOnv55EOdsKxhJUY= |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1584.1305450715.9059.python-list@python.org> (permalink) |
| Lines | 28 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1305450715 news.xs4all.nl 81485 [::ffff:82.94.164.166]:36846 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:5413 |
Show key headers only | View raw
Chris Rebert <clp2@rebertia.com> writes:
> On Sun, May 15, 2011 at 1:28 AM, Christoph Groth <cwg@falma.de> wrote:
>> I use a huge python dictionary where the values are lists of that
>> dictionary's keys (yes, a graph). Each key is thus referenced
>> several times.
>>
>> As the keys are rather large objects, I would like to save memory by
>> re-using key objects wherever possible, instead of having several
>> equal objects in memory.
>>
>> There does not seem to be a way to retrieve the original key from a
>> python dictionary. Is there a technical reason for this? (Other
>> than that such functionality was not considered to be useful enough.)
>
> Define "original key".
def original_key(dictionary, key):
for k in dictionary:
if k == key:
return k
raise KeyError(key)
But this is not efficient.
I would like to avoid having _multiple_ objects which are equal (a == b)
but not the same (a is not b). This would save a lot of memory.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: dict: retrieve the original key by key Christoph Groth <cwg@falma.de> - 2011-05-15 11:11 +0200
Re: dict: retrieve the original key by key Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-15 10:18 +0000
Re: dict: retrieve the original key by key Christoph Groth <cwg@falma.de> - 2011-05-15 12:46 +0200
Re: dict: retrieve the original key by key Terry Reedy <tjreedy@udel.edu> - 2011-05-15 16:53 -0400
Re: dict: retrieve the original key by key Chris Rebert <clp2@rebertia.com> - 2011-05-15 14:19 -0700
Re: dict: retrieve the original key by key Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-15 18:47 -0600
csiph-web