From f614ef1237a06089da652d5dcc3a927a1846fd22 Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 11 Mar 2024 17:56:09 +0000 Subject: add solutions week 259 260 task 1 in python --- challenge-260/steven-wilson/python/ch-1.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 challenge-260/steven-wilson/python/ch-1.py (limited to 'challenge-260') 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() -- cgit