[Tutor] list objects are unhashable

Cédric Lucantis omer at no-log.org
Mon Jun 30 21:52:40 CEST 2008


Le Monday 30 June 2008 21:31:35, vous avez écrit :
> Thanks,
> but where do i replace the x with tuple(x)
>

Whenever x is hashed, ie used as a key in a dictionary. You said you have:

> >>                  table[(x, y)] += 1
> >> where:
> >>
> >> x = ['airlines-scheduled', 'airport-car-parking']

so you should rather write this (if y is a list too):

table[(tuple(x), tuple(y))] += 1

but of course you can also use tuples directly if your lists don't have to be 
modified:

x = ('airlines-scheduled', 'airport-car-parking')
y = (...)
table[(x, y)] += 1

-- 
Cédric Lucantis


More information about the Tutor mailing list