IMHO, x.join(a).split(x) should be "idempotent" in regard to a.
foo = ['a', 'b', 'c'] assert '|'.join(foo).split('|') == foo foo = ['a'] assert '|'.join(foo).split('|') == foo foo = [] assert ' '.join(foo).split() == foo
And now the odd exception to the rule:
assert '|'.join(foo).split('|') == foo Traceback (most recent call last): File "<stdin>", line 1, in <module> AssertionError
That forces one to write special case code when using custom separators. Consider: # clean baz = dict(chunk.split('=') for chunk in baz.split()) # ugly baz = (dict(chunk.split('=') for chunk in baz.split("|")) if baz else {}) Our younger cousin Ruby has no such idiosyncrasies:
foo = [] foo.join('|').split('|') == foo => true
What is the reason for that oddity? Can we amend it? Best regards, Mart Sõmermaa