[Python-bugs-list] [Bug #128711] Need string-to-character-list splitter
noreply@sourceforge.net
noreply@sourceforge.net
Sat, 13 Jan 2001 18:58:03 -0800
Bug #128711, was updated on 2001-Jan-13 18:36
Here is a current snapshot of the bug.
Project: Python
Category: Python Library
Status: Closed
Resolution: Works For Me
Bug Group: Feature Request
Priority: 5
Submitted by: brysmith
Assigned to : nobody
Summary: Need string-to-character-list splitter
Details: Python has many neat tools for string handling, but on eseems to
be missing -
to expand a string into a list of characters. Currently the code
lst = string.split("abcdef","")
returns "Value error - empty separator"
I would like to suggest that split with "" as the second argument be
interpreted as
a request to expand the first (string) argument into a list of the
characters that make up
the string.
e.g. string.split("ab c","") would return ['a', 'b', ' ', 'c']
This seems to make sense, since split(x,"") would then be the inverse of
join(y,"")
I doubt that this enhancement of string.split would break any existing
code, since
string.split("abc","") is currently an invalid call.
Follow-Ups:
Date: 2001-Jan-13 18:58
By: tim_one
Comment:
It's odd that when people ask "I need something to convert X to Y!", they
don't try Y(X) to see what happens <wink>:
>>> list("abcdef")
['a', 'b', 'c', 'd', 'e', 'f']
>>>
list() converts an object of any sequence type to a list of its elements,
and strings are a sequence type.
Here's a much sillier way:
>>> import re
>>> re.findall('.', 'abcdef')
['a', 'b', 'c', 'd', 'e', 'f']
>>>
Two ways already is plenty ...
-------------------------------------------------------
For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=128711&group_id=5470