diff options
| author | Steven <steven1170@zoho.eu> | 2024-03-11 17:56:09 +0000 |
|---|---|---|
| committer | Steven <steven1170@zoho.eu> | 2024-03-11 17:56:09 +0000 |
| commit | f614ef1237a06089da652d5dcc3a927a1846fd22 (patch) | |
| tree | af0878cf8ab01d249582ac2281076d1f461226d5 /challenge-260 | |
| parent | 77245595e193396bdb9347f5b5de7a088aea8bae (diff) | |
| download | perlweeklychallenge-club-f614ef1237a06089da652d5dcc3a927a1846fd22.tar.gz perlweeklychallenge-club-f614ef1237a06089da652d5dcc3a927a1846fd22.tar.bz2 perlweeklychallenge-club-f614ef1237a06089da652d5dcc3a927a1846fd22.zip | |
add solutions week 259 260 task 1 in python
Diffstat (limited to 'challenge-260')
| -rw-r--r-- | challenge-260/steven-wilson/python/ch-1.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-260/steven-wilson/python/ch-1.py b/challenge-260/steven-wilson/python/ch-1.py new file mode 100644 index 0000000000..4305bd667b --- /dev/null +++ b/challenge-260/steven-wilson/python/ch-1.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + + +def unique_occurences(*elements): + ''' + >>> unique_occurences(1,2,2,1,1,3) + 1 + >>> unique_occurences(1,2,3) + 0 + >>> unique_occurences(-2,0,1,-2,1,1,0,1,-2,9) + 1 + ''' + if not all(isinstance(elem, int) for elem in elements): + raise ValueError("Input must consist of integers") + + from collections import Counter + + counts = Counter(elements) + occurences = counts.values() + if len(counts) == len(set(occurences)): + return 1 + else: + return 0 + + +if __name__ == "__main__": + import doctest + + doctest.testmod() |
