aboutsummaryrefslogtreecommitdiff
path: root/challenge-249/e-choroba/python/ch-1.py
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2023-12-27 14:57:27 -0600
committerLuis Mochan <mochan@fis.unam.mx>2023-12-27 14:57:27 -0600
commitf9c88dbbb1e13bfb63f40d0dd3b8630850655d7b (patch)
treecb922fb2f44a7ec7bd10cd13b3db9eb2d4fd14b5 /challenge-249/e-choroba/python/ch-1.py
parent23f378718ed93b9b8d9e51fe18f07a55f61dc9c1 (diff)
parent4ece120b2f4c7b25b00eaad66524fb5d99fa58c3 (diff)
downloadperlweeklychallenge-club-f9c88dbbb1e13bfb63f40d0dd3b8630850655d7b.tar.gz
perlweeklychallenge-club-f9c88dbbb1e13bfb63f40d0dd3b8630850655d7b.tar.bz2
perlweeklychallenge-club-f9c88dbbb1e13bfb63f40d0dd3b8630850655d7b.zip
Merge branch 'master' of github.com:manwar/perlweeklychallenge-club into challenges
Diffstat (limited to 'challenge-249/e-choroba/python/ch-1.py')
-rwxr-xr-xchallenge-249/e-choroba/python/ch-1.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-249/e-choroba/python/ch-1.py b/challenge-249/e-choroba/python/ch-1.py
new file mode 100755
index 0000000000..8804c18a26
--- /dev/null
+++ b/challenge-249/e-choroba/python/ch-1.py
@@ -0,0 +1,20 @@
+#! /usr/bin/python3
+from collections import Counter
+
+def equal_pairs(*ints):
+ seen = Counter(ints)
+ pairs = []
+ for c in seen:
+ if seen[c] % 2 == 1:
+ return []
+ else:
+ pairs += map(lambda _i: [c, c], range(seen[c] // 2))
+ return pairs
+
+assert equal_pairs(3, 2, 3, 2, 2, 2) == [[3, 3], [2, 2], [2, 2]], 'Example 1'
+assert equal_pairs(1, 2, 3, 4) == [], 'Example 2'
+assert equal_pairs(-1, -1, -2, -2) == [[-1, -1], [-2, -2]], 'Negative numbers'
+assert equal_pairs(1, 1, 1, 1, 2, 2, 2, 2) == [
+ [1, 1], [1, 1], [2, 2], [2, 2]], \
+ 'More than once'
+assert equal_pairs(1, 1, 1, 1, 2, 2, 2, 2, 1) == [], 'More than once odd';