[Issue 11536] New: split optional maxsplit argument
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Nov 17 19:03:26 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11536
Summary: split optional maxsplit argument
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2013-11-17 19:03:23 PST ---
In Python str.split method has an optional argument (named maxsplit), the
number of times to split:
http://docs.python.org/2/library/stdtypes.html#str.split
>>> "5 red blue".split()
['5', 'red', 'blue']
>>> "5 red blue".split(" ", 1)
['5', ' red blue']
>>> "5 red blue".split(None, 1)
['5', 'red blue']
>>> "red blue 10".rsplit()
['red', 'blue', '10']
>>> "red blue 10".rsplit(" ", 1)
['red blue ', '10']
>>> "red blue 10".rsplit(None, 1)
['red blue', '10']
It's handy when you have a not uniform string that you want to split partially:
>>> t = "20 Walter Bright"
>>> n, name = t.split(None, 1)
>>> n
'20'
>>> name
'Walter Bright'
I think such optional argument could be useful in Phobos split as well.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list