aboutsummaryrefslogtreecommitdiff
path: root/challenge-078/roger-bell-west/python/ch-2.py
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-09-14 11:50:24 +0100
committerGitHub <noreply@github.com>2020-09-14 11:50:24 +0100
commit7b7ec648976256cdc4d328da58ae682fd87b1793 (patch)
tree8f1e732934d6b41f0408cadd7cea6ffca8df45e0 /challenge-078/roger-bell-west/python/ch-2.py
parent787e7a5535779fecf561fc10ea626bcd4e3b12f6 (diff)
parent9cf2f9e81234d5eea3cd761e313780597d34ed1b (diff)
downloadperlweeklychallenge-club-7b7ec648976256cdc4d328da58ae682fd87b1793.tar.gz
perlweeklychallenge-club-7b7ec648976256cdc4d328da58ae682fd87b1793.tar.bz2
perlweeklychallenge-club-7b7ec648976256cdc4d328da58ae682fd87b1793.zip
Merge pull request #2288 from Firedrake/rogerbw-challenge-078
Solutions to challenge #78.
Diffstat (limited to 'challenge-078/roger-bell-west/python/ch-2.py')
-rwxr-xr-xchallenge-078/roger-bell-west/python/ch-2.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-078/roger-bell-west/python/ch-2.py b/challenge-078/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..860ec393d6
--- /dev/null
+++ b/challenge-078/roger-bell-west/python/ch-2.py
@@ -0,0 +1,30 @@
+#! /usr/bin/python
+
+import unittest
+
+def leftrot(a,b):
+ l=len(a)
+ t=list()
+ map(t.append,a)
+ map(t.append,a)
+ o=list()
+ for c in (b):
+ o.append(list((t[c:c+l])))
+ return o
+
+class TestLeftrot(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(leftrot((10, 20, 30, 40, 50),(3, 4)),
+ [[40, 50, 10, 20, 30],
+ [50, 10, 20, 30, 40]],
+ 'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(leftrot((7, 4, 2, 6, 3),(1, 3, 4)),
+ [[4, 2, 6, 3, 7],
+ [6, 3, 7, 4, 2],
+ [3, 7, 4, 2, 6]],
+ 'example 2')
+
+unittest.main()