diff options
| author | rir <rirans@comcast.net> | 2024-02-09 21:20:12 -0500 |
|---|---|---|
| committer | rir <rirans@comcast.net> | 2024-02-09 21:20:12 -0500 |
| commit | 138a757205ea1278fec6191eecdfa31b9d4fd3cc (patch) | |
| tree | 08d8157e2f400c51e90e1bc6fcdb34581decb9b9 /challenge-255/spadacciniweb/python/ch-1.py | |
| parent | 844af3cafa518e1f64f5a0729fcc69e1adfcba14 (diff) | |
| parent | 399287fcd1fa2800c9ab44b9a065116e9a55ec86 (diff) | |
| download | perlweeklychallenge-club-138a757205ea1278fec6191eecdfa31b9d4fd3cc.tar.gz perlweeklychallenge-club-138a757205ea1278fec6191eecdfa31b9d4fd3cc.tar.bz2 perlweeklychallenge-club-138a757205ea1278fec6191eecdfa31b9d4fd3cc.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-255/spadacciniweb/python/ch-1.py')
| -rw-r--r-- | challenge-255/spadacciniweb/python/ch-1.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-255/spadacciniweb/python/ch-1.py b/challenge-255/spadacciniweb/python/ch-1.py new file mode 100644 index 0000000000..ffb284197c --- /dev/null +++ b/challenge-255/spadacciniweb/python/ch-1.py @@ -0,0 +1,39 @@ +# Task 1: Odd Character +# Submitted by: Mohammad Sajid Anwar +# +# You are given two strings, $s and $t. The string $t is generated using the shuffled characters of the string $s with an additional character. +# Write a script to find the additional character in the string $t.. +# +# Example 1 +# Input: $s = "Perl" $t = "Preel" +# Output: "e" +# +# Example 2 +# Input: $s = "Weekly" $t = "Weeakly" +# Output: "a" +# +# Example 3 +# Input: $s = "Box" $t = "Boxy" +# Output: "y" + +from collections import Counter + +def odd_character(s, t): + counts=Counter(s) + + for i in t: + counts[i] -= 1 + print("Output:", s, "|", t, "-> %s" %(list(counts.keys())[list(counts.values()).index(-1)])) + +if __name__ == "__main__": + s = 'Perl' + t = "Preel" + odd_character(s, t) + + s = "Weekly" + t = "Weeakly" + odd_character(s, t) + + s = "Box" + t = "Boxy" + odd_character(s, t) |
