Stupid string.split question

Brian Kelley bkelley at wi.mit.edu
Wed Aug 6 14:22:40 EDT 2003


Is there any conceptual reason why

"ABCDEF".split("") shouldn't equal ["A", "B", "C", "D", "E", "F"]?

The error says empty seperator, but the result makes sense given that 
fact and the fact that:

"".join(["A", "B", "C", "D", "E", "F"]) == "ABCDEF"

It seems that if you can join with an empty seperator, you should be 
able to split with one.

I suppose the pythonic way is [x for x in "ABCDEF"] which doesn't make 
as much sense to be.

This question is also equivalent to "ABCDEF".reverse() since that is 
what I am using these for.  Currently the code is

l = [x for x in forward_string]
l.reverse()
reversed_string = "".join(l)

Just asking.
Brian





More information about the Python-list mailing list