diff --git a/src/fix.py b/src/fix.py index 06ce72c37..229049aa9 100644 --- a/src/fix.py +++ b/src/fix.py @@ -126,5 +126,10 @@ def all(p, seq): return False 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: diff --git a/test/test_fix.py b/test/test_fix.py index ed20453c1..92fcb3e7f 100644 --- a/test/test_fix.py +++ b/test/test_fix.py @@ -88,5 +88,12 @@ class FunctionsTest(unittest.TestCase): def testIlen(self): 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: