[Tutor] printing items form list
alan.gauld at yahoo.co.uk
Fri Mar 3 14:19:53 EST 2017
On 03/03/17 18:52, Peter Otten wrote:
> Antonio Zagheni via Tutor wrote:
>> suitcase = ["book, ", "towel, ", "shirt, ", "pants"]
> Hm, looks like you opened Rafael's suitcase while he wasn't looking, and
> sneaked in some commas and spaces ;)
> That's cheating...
Its also very difficult to maintain since if you add
new items to the suitcase you need to make sure they
all have commas except the last one. And inconsistent data formatting in
a list is a nightmare.
For example, what happens if you decide to sort the list,
the last item is no longer last and the commas are all
That's one reason why join() is a better solution, it
handles all of that for you. It's also faster, although
in a small application you'd never notice the difference.
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor