[Tutor] list objects are unhashable
Norman Khine
norman at khine.net
Mon Jun 30 21:31:35 CEST 2008
Thanks,
but where do i replace the x with tuple(x)
Norman
Cédric Lucantis wrote:
> Le Monday 30 June 2008 20:55:36 Norman Khine, vous avez écrit :
>> Hello,
>>
>> I would like to count list items but am not 100% sure how to do it.
>>
>> Here is what I have so far:
>>
>> for brain in brains:
>> x = getattr(brain, horizontal)
>> y = getattr(brain, vertical)
>> if x and y and (x, y) in table:
>> table[(x, y)] += 1
>> table[(x, '')] += 1
>> table[('', y)] += 1
>> table[('', '')] += 1
>>
>> but when I run this, I get the following error on the line:
>>
>> if x and y and (x, y) in table:
>>
>> TypeError: list objects are unhashable
>>
>> where:
>>
>> x = ['airlines-scheduled', 'airport-car-parking']
>>
>
> lists are not hashable because hashing a mutable type would be dangerous, but
> tuples are if all their items are hashable too. Just replace x by tuple(x).
>
More information about the Tutor
mailing list