aboutsummaryrefslogtreecommitdiff
path: root/challenge-276/sgreen/python/ch-2.py
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2024-07-01 14:47:06 +1000
committerSimon Green <mail@simon.green>2024-07-01 14:47:06 +1000
commit04b8ba44665dd5354ea591eb746d036258a85ad8 (patch)
treed70ee5bfd6acce54de1b11863203bd92f8bc4160 /challenge-276/sgreen/python/ch-2.py
parentf18cb7a95e46b9ded70a2d1d932d0bb7b1772a67 (diff)
downloadperlweeklychallenge-club-04b8ba44665dd5354ea591eb746d036258a85ad8.tar.gz
perlweeklychallenge-club-04b8ba44665dd5354ea591eb746d036258a85ad8.tar.bz2
perlweeklychallenge-club-04b8ba44665dd5354ea591eb746d036258a85ad8.zip
sgreen solutions to challenge 276
Diffstat (limited to 'challenge-276/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-276/sgreen/python/ch-2.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-276/sgreen/python/ch-2.py b/challenge-276/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..198042c31b
--- /dev/null
+++ b/challenge-276/sgreen/python/ch-2.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+
+from collections import Counter
+import sys
+
+
+def maximum_frequency(ints: list) -> str:
+ """
+ Calculate the maximum frequency of elements in a list and returns the
+ number of elements with that appear with this frequency.
+
+ Args:
+ ints (list): A list of integers.
+
+ Returns:
+ str: The number of elements with appear most frequency.
+ """
+ # Convert the list in a frequency dictionary
+ freq = Counter(ints)
+ max_freq = max(freq.values())
+
+ # Count the number of elements with the maximum frequency
+ elements = sum(1 for v in freq.values() if v == max_freq)
+
+ # Multiply the number of elements by the frequency
+ return elements * max_freq
+
+
+def main():
+ # Convert input into integers
+ array = [int(n) for n in sys.argv[1:]]
+ result = maximum_frequency(array)
+ print(result)
+
+
+if __name__ == '__main__':
+ main()