Hi,

Sorry, but this did not work.

I have done this, which returns the values I want (sort of)

        for brain in brains:
            x = getattr(brain, horizontal)
            if isinstance(x, list):
                for item in x:
                    x = item
            else:
                x
            y = getattr(brain, vertical)
            if isinstance(y, list):
                for item in y:
                    y = item
            else:
                y
            if x and y and (x, y) in table:
                table[(x, y)] += 1
                table[(x, '')] += 1
                table[('', y)] += 1
                table[('', '')] += 1


The only think is that, the totals are correct, but when there is an item that is in both, it is counted only once.

Cédric Lucantis wrote:
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

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to