Newbie: last item of a loop
Sven Brandt
sven_NOSPAM at manastar.de
Fri May 2 09:20:37 EDT 2003
> Jørgen Cederberg wrote:
[...]
> my_names=['Peter', 'Paul','Mary']
> if len(my_names) > 1:
> my_name_string = ', '.join(my_names[:-1]) + ' and ' + my_names[-1]
> else:
> my_name_string = my_names[0]
Yep, that's what I wanted ;-)
> I hope you can understand the usage of the join method on string.
join(my_names[:-1], ', ') is more familiar to me ...
Thanx for the help
Regards
Sven
More information about the Python-list
mailing list