diff options
Diffstat (limited to 'challenge-276/sgreen/python/ch-2.py')
| -rwxr-xr-x | challenge-276/sgreen/python/ch-2.py | 37 |
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() |
