Feature Proposal: Sequence .join method

David Murmann david.murmann at rwth-aachen.de
Thu Sep 29 23:33:34 EDT 2005


> def join(sep, seq):
>     return reduce(lambda x, y: x + sep + y, seq, type(sep)())

damn, i wanted too much. Proper implementation:

def join(sep, seq):
     if len(seq):
         return reduce(lambda x, y: x + sep + y, seq)
     return type(sep)()

but still short enough

see you,
David.



More information about the Python-list mailing list