Last active
October 17, 2020 02:26
-
-
Save Henelik/d73e920ee0ae718cc55423dfe71a694a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MILITARY_MAP = {("a", "A"): "Alpha", | |
("b", "B"): "Bravo", | |
("c", "C"): "Charlie", | |
("d", "D"): "Delta", | |
("e", "E"): "Echo", | |
("f", "F"): "Foxtrot", | |
("g", "G"): "Golf", | |
("h", "H"): "Hotel", | |
("i", "I"): "India", | |
("j", "J"): "Juliet", | |
("k", "K"): "Kilo", | |
("l", "L"): "Lima", | |
("m", "M"): "Mike", | |
("n", "N"): "November", | |
("o", "O"): "Oscar", | |
("p", "P"): "Papa", | |
("q", "Q"): "Quebec", | |
("r", "R"): "Romeo", | |
("s", "S"): "Sierra", | |
("t", "T"): "Tango", | |
("u", "U"): "Uniform", | |
("v", "V"): "Victor", | |
("w", "W"): "Whiskey", | |
("x", "X"): "X-Ray", | |
("y", "Y"): "Yankee", | |
("z", "Z"): "Zulu",} | |
def MilitaryLetterCode(s): # the iterative way | |
code = "" | |
for char in s: | |
for k, v in MILITARY_MAP.items(): | |
if char in k: | |
code += v | |
code += " " | |
return code | |
def MilitaryLetterCodeClosure(s): # the insane way | |
return "".join([v + " " for k, v in MILITARY_MAP.items() for char in s if char in k]) | |
if __name__ == "__main__": | |
print(MilitaryLetterCode("dab on the haters")) | |
print(MilitaryLetterCodeClosure("dab on the haters")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment