Path: csiph.com!usenet.pasdenom.info!news.albasani.net!news.mixmin.net!hq-usenetpeers.eweka.nl!81.171.88.15.MISMATCH!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.05; 'line:': 0.07; 'subject:Error': 0.07; 'try:': 0.07; 'typeerror:': 0.09; 'list1': 0.16; 'received:10.1.0': 0.16; 'set,': 0.16; 'try/except': 0.16; 'type:': 0.16; 'unhashable': 0.16; 'works...': 0.16; 'wrote:': 0.17; 'trying': 0.21; 'fine,': 0.22; 'statement': 0.23; 'raise': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'convert': 0.29; 'error': 0.30; 'code': 0.31; 'running': 0.32; 'print': 0.32; '+0200,': 0.33; 'to:addr:python- list': 0.33; 'code:': 0.33; 'another': 0.33; 'list': 0.35; 'add': 0.36; 'except': 0.36; 'but': 0.36; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'received:10': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'list,': 0.39; 'header:Received:5': 0.40; 'group,': 0.60; 'content-disposition:inline': 0.60; 'email addr:gmail.com': 0.63; 'jul': 0.65; 'unnecessary': 0.65; 'dear': 0.66; 'otten': 0.84; 'received:89': 0.86 Date: Sun, 29 Jul 2012 15:57:48 +0200 From: =?iso-8859-1?B?SvxyZ2VuIEEu?= Erhard To: python-list@python.org Subject: Re: Python Error References: <81818a9c-60d3-48da-9345-0c0dfd5b25e7@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Lost Worlds Inc. (I keep dreaming) User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343572776 news.xs4all.nl 6890 [2001:888:2000:d::a6]:45657 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26191 On Sun, Jul 29, 2012 at 01:08:57PM +0200, Peter Otten wrote: > subhabangalore@gmail.com wrote: > > > Dear Group, > > > > I was trying to convert the list to a set, with the following code: > > > > set1=set(list1) > > > > the code was running fine, but all on a sudden started to give the > > following error, > > > > set1=set(list1) > > TypeError: unhashable type: 'list' > > > > Add a print statement before the offending line: > > print list1 > set1 = set(list1) > > You will see that list1 contains another list, e. g. this works... > Peter's right, but instead of a print before the line, put a try/except around it, like try: set1 = set(list1) except TypeError: print list1 raise This way, only the *actual* error triggers any output. With a general print before, you can get a lot of unnecessary output. Grits, J