diff --git a/README.md b/README.md index 92d4868..3e1c452 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,14 @@ - URL: [Check Same Case Challenge](https://www.codewars.com/kata/5dd462a573ee6d0014ce715b) +
+Replace With Alphabet Position (6kyu)
+ +- Module: [code_challenges/code_wars/replace_with_alphabet_position.py](code_challenges/code_wars/replace_with_alphabet_position.py) +- Test: [tests/code_wars/test_replace_with_alphabet_position.py](tests/code_wars/test_replace_with_alphabet_position.py) +- URL: [Replace With Alphabet Position Challenge](https://www.codewars.com/kata/546f922b54af40e1e90001da) +
+
Find Unique Number (6kyu)
diff --git a/code_challenges/code_wars/replace_with_alphabet_position.py b/code_challenges/code_wars/replace_with_alphabet_position.py new file mode 100644 index 0000000..215ff71 --- /dev/null +++ b/code_challenges/code_wars/replace_with_alphabet_position.py @@ -0,0 +1,10 @@ +# https://www.codewars.com/kata/546f922b54af40e1e90001da/train/python + +def replace_characters(characters): + characters = characters.lower() + position_index = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] + positions = "" + for character in characters: + if character.isalpha(): + positions += f"{position_index.index(character) + 1} " + return positions.rstrip() diff --git a/tests/code_wars/test_replace_with_alphabet_position.py b/tests/code_wars/test_replace_with_alphabet_position.py new file mode 100644 index 0000000..10fe926 --- /dev/null +++ b/tests/code_wars/test_replace_with_alphabet_position.py @@ -0,0 +1,9 @@ +# https://www.codewars.com/kata/546f922b54af40e1e90001da/train/python + +from code_challenges.code_wars.replace_with_alphabet_position import replace_characters + + +def test_replace_characters(): + assert replace_characters("A B C") == "1 2 3" + assert replace_characters("c b a") == "3 2 1" + assert replace_characters("AzBy") == "1 26 2 25" \ No newline at end of file