Hi all,
New programmer here. This is what I want to do:
1. Open an existing text file named grocery_list.txt, which has one
item per line, like so:
butter
juice
bread
asparagus
magazines
ice cream
2. ...and search for these items in a pre-defined list.
But I can't seem to get this working.
On 7/14/2010 8:46 AM Eric Hamiter said...
Hi all,
New programmer here. This is what I want to do:
1. Open an existing text file named grocery_list.txt, which has one
item per line, like so:
butter
juice
bread
asparagus
magazines
ice cream
2. ...and search for these items in a pre-defined
Fantastic! I have this, which now works. Is there a better place to put
string.strip?
aisle_one = [chips, bread, pretzels, magazines]
grocery_list = open(grocery_list.txt, r)
for line in grocery_list.readlines():
if line.strip() in aisle_one:
print success! i found %s % line
else:
On 7/14/2010 9:22 AM Eric Hamiter said...
Fantastic! I have this, which now works. Is there a better place to put
string.strip?
I might make the changes below, but there's nothing wrong with the way
you've got it.
aisle_one = [chips, bread, pretzels, magazines]
grocery_list =