Re: [Tutor] Searching a text file's contents and comparing them toa list

2010-07-14 Thread Luke Paireepinart
You already know how to store multiple vars -- use lists! Just create a blank one before your loop and append() to it. Also you might think of a generic way to do this without relying on separate variables for each aisle, what if your store has 30 aisles? Hint: lists can contain any python objec

Re: [Tutor] Searching a text file's contents and comparing them toa list

2010-07-14 Thread Eric Hamiter
Follow-up question: My code is now this: aisle_one = ["chips", "bread", "pretzels", "magazines"] aisle_two = ["juice", "ice cream"] aisle_three = ["asparagus"] def find_groceries(): grocery_list = open("grocery_list.txt", "r") for line in grocery_list.readlines(): line = line.stri

Re: [Tutor] Searching a text file's contents and comparing them toa list

2010-07-14 Thread Eric Hamiter
On Wed, Jul 14, 2010 at 12:26 PM, Alan Gauld wrote: > > If you never need a stripped version of line again, or if you > are planning on writing it out to another file then this is fine. > If you are going to use it again its probably better to strip() > and asign to itelf: > > line = line.strip()

Re: [Tutor] Searching a text file's contents and comparing them toa list

2010-07-14 Thread Alan Gauld
"Eric Hamiter" wrote Fantastic! I have this, which now works. Is there a better place to put string.strip? Its largely a matter of taste and how you intend using the value. aisle_one = ["chips", "bread", "pretzels", "magazines"] grocery_list = open("grocery_list.txt", "r") for line in gr