diff options
Diffstat (limited to 'challenge-335/deadmarshal/python/ch1.py')
| -rw-r--r-- | challenge-335/deadmarshal/python/ch1.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-335/deadmarshal/python/ch1.py b/challenge-335/deadmarshal/python/ch1.py new file mode 100644 index 0000000000..c6eff24177 --- /dev/null +++ b/challenge-335/deadmarshal/python/ch1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +from collections import Counter + +def common_characters(words): + char_count = Counter(words[0]) + + for w in words: + current_count = Counter(w) + + for c in list(char_count): + char_count[c] = min(char_count[c],current_count[c]) + + res = [] + + for char,count in char_count.items(): + res.extend([char] * count) + + return res + + +print(common_characters(["bella","label","roller"])) +print(common_characters(["cool","lock","cook"])) +print(common_characters(["hello","world","pole"])) +print(common_characters(["abc","def","ghi"])) +print(common_characters(["aab","aac","aaa"])) + |
