Added rsplit function.

This commit is contained in:
Jeremy Fincher 2003-09-22 09:13:40 +00:00
parent cae8905594
commit 1ac029a54c
2 changed files with 12 additions and 0 deletions

View File

@ -126,5 +126,10 @@ def all(p, seq):
return False return False
return True return True
def rsplit(s, sep=None, maxsplit=-1):
L = s[::-1].split(sep, maxsplit)
L.reverse()
return [s[::-1] for s in L]
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -88,5 +88,12 @@ class FunctionsTest(unittest.TestCase):
def testIlen(self): def testIlen(self):
self.assertEqual(itertools.ilen(iter(range(10))), 10) self.assertEqual(itertools.ilen(iter(range(10))), 10)
def testRsplit(self):
self.assertEqual(rsplit('foo bar baz'), 'foo bar baz'.split())
self.assertEqual(rsplit('foo bar baz', maxsplit=1),
['foo bar', 'baz'])
self.assertEqual(rsplit('foo bar baz', maxsplit=1),
['foo bar', 'baz'])
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: