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). -- Cédric Lucantis _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor