Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created January 29, 2021 01:41
Show Gist options
  • Save ZechCodes/82ad4cf8d02a2b5dcff9f90be619f001 to your computer and use it in GitHub Desktop.
Save ZechCodes/82ad4cf8d02a2b5dcff9f90be619f001 to your computer and use it in GitHub Desktop.
Challenge 173 - Replace With Alphabet Position

Challenge 173 - Replace With Alphabet Position

Given a string, replace every letter with its position in the alphabet.

If anything in the text isn't a letter, ignore it and don't include it in the output.

"a" = 1, "b" = 2, etc.

Example

alphabet_position("The sunset sets at twelve o' clock.")
-> "20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11"

Notes

  • The output should be a string of space separated numbers.
import unittest
def alphabet_position(string: str) -> str:
return "" # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual(
alphabet_position("The sunset sets at twelve o' clock."),
"20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11",
)
def test_2(self):
self.assertEqual(
alphabet_position("The narwhal bacons at midnight."),
"20 8 5 14 1 18 23 8 1 12 2 1 3 15 14 19 1 20 13 9 4 14 9 7 8 20",
)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment