[Tutor] Converting a List/Tuple to delimited string
john at fouhy.net
Mon Nov 14 05:11:16 CET 2005
On 14/11/05, Roy Bleasdale <royb at ubiquity.com.au> wrote:
> I have a list of strings and wanted to output them as a single delimited
> ('ab','cd','ef') becomes "ab:cd:ef"
You almost had it ...
>>> lst = ['ab', 'cd', 'ef']
In general, foo.join(lst) (where foo is a string) is equivalent to:
def join(foo, lst):
if not lst:
s = lst
for item in lst[1:]:
s += foo + item
More information about the Tutor