List problem

Peter Hansen peter at engcorp.com
Sun Mar 31 10:58:18 EST 2002


Jon Cosby wrote:
> 
> This is strange. I've added some lines to see where this is failing.
> You can see below the interpreter is not detecting matches, but they
> are there, and it is showing them. There is something in
> word[0] == firstword[i] that's not right or the interpreter isn't
> understanding. What could possibly be wrong with this?

Well, there's certainly nothing wrong with that, so it must be
something else's understanding that is wrong... <wink>

> for word in words:
>    for i in range(lword):
>       l.append(word[0] + ":" + firstword[i])
>       if word[0] == firstword[i]:
>          cols[i].append(word)
> [...]
> C:\Python21>python projects\wordsquare.py
> Enter first word (enclosed in quotes): "add"
> 502
> [[], [], []]
> ['A:a', 'A:d', 'A:d', 'A:a', 'A:d', 'A:d', 'A:a', 'A:d', 'A:d', 'A:a',
> 'A:d', 'A:d', 'A:a', 'A:d', 'A:d', 'A:a', 'A:d', 'A:d', 'A:a', 'A:d', 'A:d',

Are you sure you aren't forgetting case-sensitivity?  I still
don't really understand your code, but I get a sense from the
above that you are expecting "AWORD" to equal "aword", which 
is not the case (no pun intended).

If this is true, try using word[0].upper() == firstword[i].upper().

-Peter



More information about the Python-list mailing list