From 20ccf25c6944641c7db4b60fa15d520686cb7036 Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Fri, 9 Feb 2024 15:28:55 +0100 Subject: feat(challenge-255/lubos-kolouch/perl,python,raku/): Challenge 255 LK Perl Python Raku --- challenge-255/lubos-kolouch/python/ch-1.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 challenge-255/lubos-kolouch/python/ch-1.py (limited to 'challenge-255/lubos-kolouch/python/ch-1.py') diff --git a/challenge-255/lubos-kolouch/python/ch-1.py b/challenge-255/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..b09f8ab050 --- /dev/null +++ b/challenge-255/lubos-kolouch/python/ch-1.py @@ -0,0 +1,24 @@ +def find_odd_character(s: str, t: str) -> str: + """ + Finds the additional character in string t. + + :param s: Original string. + :param t: Modified string with one extra character. + :return: The additional character. + """ + from collections import Counter + + count_s = Counter(s) + count_t = Counter(t) + + for char in count_t: + if count_t[char] > count_s.get(char, 0): + return char + + return "" + + +# Tests +assert find_odd_character("Perl", "Preel") == "e" +assert find_odd_character("Weekly", "Weeakly") == "a" +assert find_odd_character("Box", "Boxy") == "y" -- cgit