Oops: difference in operation of string.join and ''.join

Skip Montanaro skip at pobox.com
Sun Oct 21 22:42:42 CEST 2001


    >>> ''.join([x+y for x, y in zip('test', 'dust')])
    'tdeusstt'
    >>> import string
    >>> string.join([x+y for x, y in zip('test', 'dust')])
    'td eu ss tt'

    John> What is this?

The default separator for string.join is a single space.  Use

    string.join([x+y for x, y in zip('test', 'dust')], '')

instead.

-- 
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list