[Tutor] how to understand unhashable type: 'list'

Christian Witts cwitts at compuscan.co.za
Thu Nov 17 11:09:12 CET 2011


On 2011/11/17 11:59 AM, lina wrote:
> list1
> [['61', '34', '61', '34'], ['61', '35', '61', '70', '61'], ['61',
> '70', '61', '34'], ['34', '58', '34', '58']]
>>>> weight={}
>>>> weight{list1[0]}=1
> SyntaxError: invalid syntax
>>>> weight[list1[0]]=1
> Traceback (most recent call last):
>    File "<pyshell#292>", line 1, in<module>
>      weight[list1[0]]=1
> TypeError: unhashable type: 'list'
> I wonder how to count the occurence of the list of lists.
>
> Thanks, ^_^
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
sum(1 if type(elem) == list else 0 for elem in list1) not work for you 
if all you want to do is count how many lists you have in your main list ?
-- 

Christian Witts
Python Developer
//
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111117/68ab481f/attachment-0001.html>


More information about the Tutor mailing list