List problem

Jon Cosby jcosby at mindspring.com
Fri Mar 29 18:43:07 EST 2002


"Peter Hansen" <peter at engcorp.com> wrote in message
news:3CA4E7C6.EDE85B98 at engcorp.com...

> > firstword = input("Enter first word (enclosed in quotes): ")    #Word to
build from
> > lword = len(firstword)
#Word length
> > words = []
# Dictionary list
> > cols = []
#Columns
> > rows = []
#Rows
>
> Comments might help a lot.  For example, it's unclear what you are
> trying to accomplish here, but it doesn't look quite right:
>
> > f = open(dict, "r")
> > for line in f.readlines():
> >  if len(line[:-1]) == lword:
> >   words.append(line[:-1])
#Retrieve words of length lword
> > f.close()
>
> That finds the line matching lword and appends it to words, I think,
> which is another way of saying that every instance of lword in the
> dict.txt file will be appended to the words list.  Strange...
>
> > for i in range(lword):
> >  cols.append([])
> >  rows.append([])
> > rows[0].append(firstword)
>
> For every character in lword, append an empty list to the rows
> and columns?  If that's what you want, you need range(len(lword))
> since range() takes an integer.  Didn't you get an exception
> here?

No, lword is the length of the initial word, there is no exception.

>
> > # Generate an array of words with matching first letters
> > for i in range(lword):
>
> Same problem as above... use len() with range().
>
> >  for word in words:
> >    if word[0] == firstword[i]: # Matches not found

Here is where it is failing. No matches are being found, but the only
criteria is the first letter.
I won't post the dictionary, but there are words meeting the criteria.

> >    cols[i].append(word)
> >
> > print len(words)
> > print cols
>
> Bad indentation here, but that's probably cosmetic.  Try not to
> use tabs when posting source, since many newsreaders screw them
> up.  Use spaces instead.
>
> Can you annotate your code so we know what you're trying to do?
>
> -Peter

I hope this helps. Sorry for not being more clear before.


Jon





More information about the Python-list mailing list