On 07/14/2010 11:57 PM, Eric Hamiter wrote:
Last question (for today, at least): Right now, the output is less
than aesthetically pleasing:

(['Located on aisle 1: ', 'bread', 'magazines'], ['Located on aisle 2:
', 'juice', 'ice cream'], ['Located on aisle 3: ', 'asparagus'], ['Not
found in the database: ', 'butter', 'soap'])

How can I format it so it looks more like this:

Located on aisle 1:
bread
magazines

Located on aisle 2
[etc...]


I tried putting "\n" into it but it just prints the literal string.
I'm sure it has to do with the list format of holding multiple items,
but so far haven't found a way to break them apart.


Readup on str.join() http://docs.python.org/library/stdtypes.html#str.join (link is not that helpful I admit, google some uses too)
For example,
print "\n".join(first_run)
will get you started.

I think the end code you're looking for is something like

output = ["\n".join(run) for run in sorted_list]
print "\n".join(output)

but I'm not sure if you've got the hang of list comprehensions by now.

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

Reply via email to