Christian wrote: > I'm just translating the Python Pocked Reference the > second time, and I stumbled over this: > > "funny".split("") > > gives a ValueError: empty separator. > > Why this? > I would expect > > ['f','u','n','n','y'] Why wouldn't you expect this: ['', 'f', 'u', 'n', 'n', 'y', ''] As with: >>> ' f u n n y '.split(' ') ['', 'f', 'u', 'n', 'n', 'y', ''] > as result, since this is the maximum result of undoing > > "".join(['f','u','n','n','y']) > > For what reason is this asymmetry? There will always be asymmetry because there are many lists that, when joined by the empty string, return in the same string e.g. >>> ''.join(['fun', 'ny']) 'funny' >>> ''.join(['', 'f', 'u', 'n', 'n', 'y', '']) 'funny' >>> ''.join(['f', 'u', 'n', 'n', 'y']) 'funny' But the split method can only return one list. Cheers, Brian
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4