On Sun, Jul 29, 2012 at 01:08:57PM +0200, Peter Otten wrote:
> [email protected] 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
--
http://mail.python.org/mailman/listinfo/python-list