Python Error
Emile van Sebille
emile at fenx.com
Sun Jul 29 10:42:24 EDT 2012
On 7/29/2012 5:30 AM subhabangalore at gmail.com said...
> On Sunday, July 29, 2012 2:57:18 PM UTC+5:30, (unknown) wrote:
>> Dear Group,
>> I was trying to convert the list to a set, with the following code:
>> set1=set(list1)
> Thanks for the answer. But my list does not contain another list that is the issue. Intriguing. Thinking what to do.
Now you need to identify the type of the object that is causing python
to misreport the unhashable type causing the error as the error you're
getting says list and you say there isn't one. So, now we have a python
bug.
>>> set ([1,2,3])
set([1, 2, 3])
>>> set ([1,2,[]])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>> set ([1,2,{}])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'
> the code was running fine, but all on a sudden started to give the
following error,
>
>
>
> set1=set(list1)
>
> TypeError: unhashable type: 'list'
Try adding the following:
for ii in list1:
try:
set([ii])
except:
print "this causes an error type (val): %s (%s)" (type(ii),ii)
Either it's a python bug or there really is a list in there.
Emile
More information about the Python-list
mailing list