newbie question: for loop within for loop confusion
takayuki
lawtonpaul at gmail.com
Mon Jun 16 01:35:03 EDT 2008
Thanks to everyone for the excellent advice.
Roy: I did as you suggested and could see after staring at the output
for awhile what was going on. The print statements really helped to
put a little light on things. Yes, I agree that "learning to fish" is
the best way.
John: There were two "inchworms" because "c" is in "inchworm" so it
shouldn't print. Thanks for your detailed description of the for
loop.
The Saint: i'll check out the word = line.split() command.
After much flailing about, here's a loop that is working:
def hasnolet2(avoid):
fin = open('animals.txt')
for line in fin:
word = line.strip()
length = len(avoid)
x = 0
noprint = 0
while length -1 >= x:
if avoid[x] in word:
noprint = noprint + 1
x = x + 1
if noprint == 0:
print word
hasnolet2('abcd')
which should return:
fish
horse
hasnolet2('abcd')
More information about the Python-list
mailing list