diff options
| author | deadmarshal <adeadmarshal@gmail.com> | 2022-12-15 10:13:05 +0330 |
|---|---|---|
| committer | deadmarshal <adeadmarshal@gmail.com> | 2022-12-15 10:13:05 +0330 |
| commit | aecf51b43cf11e2d592fdfa86282d642e716d9a8 (patch) | |
| tree | f889a3d22fafcf14022690432b43be08bee43b3c /challenge-195/deadmarshal/python/ch2.py | |
| parent | c1d3932971f399789d4ee01cb886bb1e984f2563 (diff) | |
| download | perlweeklychallenge-club-aecf51b43cf11e2d592fdfa86282d642e716d9a8.tar.gz perlweeklychallenge-club-aecf51b43cf11e2d592fdfa86282d642e716d9a8.tar.bz2 perlweeklychallenge-club-aecf51b43cf11e2d592fdfa86282d642e716d9a8.zip | |
TWC195
Diffstat (limited to 'challenge-195/deadmarshal/python/ch2.py')
| -rw-r--r-- | challenge-195/deadmarshal/python/ch2.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/challenge-195/deadmarshal/python/ch2.py b/challenge-195/deadmarshal/python/ch2.py new file mode 100644 index 0000000000..783f93555b --- /dev/null +++ b/challenge-195/deadmarshal/python/ch2.py @@ -0,0 +1,14 @@ +from functools import reduce + +def most_frequent_even(arr): + if all(map(lambda n: n % 2 != 0, arr)): return -1 + d = {} + for i in arr: + if i % 2 == 0: d[i] = d.get(i, 0) + 1 + if len(d.values()) == len(set(d.values())): return min(d) + return reduce(lambda a,b:a if d[a] > d[b] else b, d.keys()) + +print(most_frequent_even([1,1,2,6,2])) +print(most_frequent_even([1,3,5,7])) +print(most_frequent_even([6,4,4,6,1])) + |
