From 1ac029a54ca86af3eb48a3fae15f5ece73afd03c Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 22 Sep 2003 09:13:40 +0000 Subject: [PATCH] Added rsplit function. --- src/fix.py | 5 +++++ test/test_fix.py | 7 +++++++ 2 files changed, 12 insertions(+) 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: