[snip]

Since you look up the items in the grocery list it seems to me a dictionary relating each item to its aisle would be best.

inventory = {"chips" : 1, "bread" : 1, "pretzels" : 1, "magazines" : 1,
             "juice" : 2, "ice cream" : 2,
             "asparagus" : 3}
MAX_AISLE = 3
aisles = [[] for i in range(MAX_AISLE)]
for item in grocery_list:
  aisle = inventory.get(item.strip(), MAX_AISLE)
  aisles[aisle-1].append(item)

To address the formatting question:

for aisleNo, items in enumerate(aisles):
  if aisleNo < MAX_AISLE - 1:
    print "Located on aisle %s" % aisleNo + 1
  else:
    print "Not in store"
  print "\n".join(items)


--
Bob Gailer
919-636-4239
Chapel Hill NC

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to