[Tutor] list objects are unhashable

Norman Khine norman at khine.net
Tue Jul 1 13:03:55 CEST 2008


Kent Johnson wrote:
> On Tue, Jul 1, 2008 at 3:09 AM, Norman Khine <norman at khine.net> wrote:
> 
>>            x = getattr(brain, horizontal)
>>            if isinstance(x, list):
>>                for item in x:
>>                    x = item
> 
> This just assigns x to the last element of the list, it doesn't
> process the whole list. One possibility would be to ensure that x and
> y are always lists, then use nested loops to iterate over all
> combinations:
> x = getattr(brain, horizontal)
> if not isinstance(x, list):
>   x = [x]
> y = getattr(brain, vertical)
> if not isinstance(y, list):
>   y = [y]
> for first in x:
>   for second in y:
>     if first and second and (first, second) in table:

I don't really see this clearly as I may have n'th values for 'x' and 
n'th values for 'y' so I will need to loop over all these, but without 
knowing the n'th value where to stop my loop?

Or have I missed the point ;)

> 
> etc.
> 
> Kent
> 



More information about the Tutor mailing list