We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2cdb306 commit 856fff5Copy full SHA for 856fff5
palindrome_permutation.py
@@ -0,0 +1,32 @@
1
+import unittest
2
+
3
4
+def is_pal_perm(string):
5
+ """
6
+ Takes a string and returns true if the string is a permutation of a
7
+ palindrome.
8
9
10
+ let_counts = {}
11
+ odd = 0
12
13
+ for let in string:
14
+ let_counts[let] = let_counts.get(let, 0) + 1
15
16
+ for val in let_counts.values():
17
+ if val % 2 != 0:
18
+ odd += 1
19
20
+ return odd <= 1
21
22
23
+class Testing(unittest.TestCase):
24
25
+ def test_is_pal_perm(self):
26
+ self.assertTrue(is_pal_perm('carereca'))
27
+ self.assertTrue(is_pal_perm('a'))
28
+ self.assertFalse(is_pal_perm('carelnreca'))
29
30
31
+if __name__ == '__main__':
32
+ unittest.main()
0 commit comments