diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-01 10:04:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-01 10:04:10 +0100 |
| commit | d7197459679cd7a9a21ece609975c58a71717dc1 (patch) | |
| tree | ddbe94f2361f737305479d2328d3e274f0a4f72d /challenge-284/sgreen/python/ch-1.py | |
| parent | 289b1566e1124b1e52dd7b491a57494ced8990fe (diff) | |
| parent | 55c3d22707c0a0d6f119d16b6024a78bd1d901d2 (diff) | |
| download | perlweeklychallenge-club-d7197459679cd7a9a21ece609975c58a71717dc1.tar.gz perlweeklychallenge-club-d7197459679cd7a9a21ece609975c58a71717dc1.tar.bz2 perlweeklychallenge-club-d7197459679cd7a9a21ece609975c58a71717dc1.zip | |
Merge pull request #10741 from simongreen-net/master
sgreen solutions to challenge 284
Diffstat (limited to 'challenge-284/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-284/sgreen/python/ch-1.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-284/sgreen/python/ch-1.py b/challenge-284/sgreen/python/ch-1.py new file mode 100755 index 0000000000..2b7d01598f --- /dev/null +++ b/challenge-284/sgreen/python/ch-1.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +from collections import Counter +import sys + + +def lucky_integer(ints: list) -> str: + # Calculate the frequency of each integer + freq = Counter(ints) + + # Work through the dict, highest first + for i in sorted(freq, reverse=True): + if i == freq[i]: + # We have the lucky integer + return i + + # There is no lucky integer + return -1 + + +def main(): + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + result = lucky_integer(array) + print(result) + + +if __name__ == '__main__': + main() |
