Skip to content

Instantly share code, notes, and snippets.

@Henelik
Last active October 17, 2020 02:26
Show Gist options
  • Save Henelik/d73e920ee0ae718cc55423dfe71a694a to your computer and use it in GitHub Desktop.
Save Henelik/d73e920ee0ae718cc55423dfe71a694a to your computer and use it in GitHub Desktop.
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