Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95775

Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought

Path csiph.com!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <lac@openend.se>
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; "subject:' ": 0.07; 'cc:addr:python-list': 0.09; 'dict': 0.09; 'received:openend.se': 0.09; 'received:theraft.openend.se': 0.09; 'type:': 0.09; 'typeerror:': 0.09; 'python': 0.10; 'index': 0.13; 'cc:addr:lac': 0.16; 'cc:addr:openend.se': 0.16; 'from:addr:lac': 0.16; 'from:addr:openend.se': 0.16; 'from:name:laura creighton': 0.16; 'message-id:@fido.openend.se': 0.16; 'received:fido': 0.16; 'received:fido.openend.se': 0.16; 'subject:type': 0.16; 'subject:when': 0.16; 'unhashable': 0.16; 'laura': 0.18; '>>>': 0.20; 'cc:addr:python.org': 0.20; 'cc:2**1': 0.22; '"",': 0.22; 'trying': 0.22; '(most': 0.24; "doesn't": 0.26; 'subject:list': 0.26; 'received:se': 0.29; 'cc:no real name:2**1': 0.29; 'print': 0.30; 'work.': 0.30; 'traceback': 0.33; 'file': 0.34; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'means': 0.39; 'header:Message- Id:1': 0.61; 'more': 0.63; 'different': 0.63; 'jul': 0.72; 'dict.': 0.84; 'header:In-reply-to:1': 0.84
To kbtyo <ahlusar.ahluwalia@gmail.com>
cc python-list@python.org, lac@openend.se
From Laura Creighton <lac@openend.se>
Subject Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought
In-reply-to <1daedf03-2f17-4602-8a50-eeee98a493e9@googlegroups.com>
References <cbcf05be-53d0-4b8b-b72b-1898cd4ad245@googlegroups.com> <mailman.129.1440902890.11709.python-list@python.org> <1daedf03-2f17-4602-8a50-eeee98a493e9@googlegroups.com>
Comments In-reply-to kbtyo <ahlusar.ahluwalia@gmail.com> message dated "Sun, 30 Aug 2015 09:35:20 -0700."
MIME-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-ID <27924.1440955489.1@fido>
Date Sun, 30 Aug 2015 19:24:49 +0200
X-Greylist Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (theraft.openend.se [89.233.217.130]); Sun, 30 Aug 2015 19:24:51 +0200 (CEST)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1.1440955497.23514.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1440955497 news.xs4all.nl 23833 [2001:888:2000:d::a6]:33792
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:95775

Show key headers only | View raw


When you get TypeError: unhashable type: 'dict'
it almost always means that you are trying to use a dict as
a key for a different dict.


Python 2.7.10 (default, Jul  1 2015, 10:54:53)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> d={1:'one', 2:'two', 3:'three'}
 >>> d1={1:'A', 2:'B', 3:'C'}

 This doesn't work.
 
 >>> print d1[d]
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
 TypeError: unhashable type: 'dict'

This does.

 >>> for index in d:
   ...     print d1[index]
   ...
   A
   B
   C

HTH,
Laura



	

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

TypeError: unhashable type: 'dict' when attempting to hash list - advice sought kbtyo <ahlusar.ahluwalia@gmail.com> - 2015-08-29 19:05 -0700
  Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-30 03:47 +0100
    Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought kbtyo <ahlusar.ahluwalia@gmail.com> - 2015-08-30 09:35 -0700
      Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought Laura Creighton <lac@openend.se> - 2015-08-30 19:24 +0200
        Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought kbtyo <ahlusar.ahluwalia@gmail.com> - 2015-08-30 10:34 -0700
          Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought Laura Creighton <lac@openend.se> - 2015-08-30 20:20 +0200
            Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought kbtyo <ahlusar.ahluwalia@gmail.com> - 2015-08-30 14:47 -0700
  Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought MRAB <python@mrabarnett.plus.com> - 2015-08-30 03:48 +0100
    Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought kbtyo <ahlusar.ahluwalia@gmail.com> - 2015-08-30 09:31 -0700
      Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought MRAB <python@mrabarnett.plus.com> - 2015-08-30 18:15 +0100
        Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought kbtyo <ahlusar.ahluwalia@gmail.com> - 2015-08-30 10:21 -0700
  Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought Ben Finney <ben+python@benfinney.id.au> - 2015-08-30 13:04 +1000
    Re: TypeError: unhashable type: 'dict' when attempting to hash list - advice sought kbtyo <ahlusar.ahluwalia@gmail.com> - 2015-08-30 10:02 -0700

csiph-web