The Earth has been invaded by aliens. They demand our beer and threaten to destroy the Earth if we do not supply the exact number of beers demanded.

Unfortunately, the aliens only speak Morse code. Write a program to convert morse code into numbers using the following convention:

1 .----
2 ..---
3 ...--
4 ....-
5 .....
6 -....
7 --...
8 ---..
9 ----.
0 -----

Difficulty: introductory

Starter code:

def morse_converter(s):
	

Solutions:
MORSE_TO_NUM = {
    ".----" : "1",
    "..---" : "2",
    "...--" : "3",
    "....-" : "4",
    "....." : "5",
    "-...." : "6",
    "--..." : "7",
    "---.." : "8",
    "----." : "9",
    "-----" : "0",
}

def morse_converter(s):
    return int("".join(MORSE_TO_NUM[s[i:i+5]] for i in range(0, len(s), 5)))


def morse_converter(s):
    it = ['-----', '.----', '..---', '...--', '....-', '.....', '-....', '--...', '---..', '----.']
    return int(''.join(str(it.index(s[i:i+5])) for i in range(0, len(s), 5)))

import re

MORSE_TO_INT = {
    ".----" : "1", "..---": "2", "...--": "3",
    "....-": "4", ".....": "5", "-....": "6",
    "--...": "7", "---..": "8", "----.": "9", 
    "-----": "0"
}

def morse_converter(string):
    return int("".join(MORSE_TO_INT[x] for x in re.findall(".....", string)))

morse_digits = ["-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----."]

def morse_converter(stg):
    return int("".join(str(morse_digits.index(stg[i:i+5])) for i in range(0, len(stg), 5)))

tbl = {
    x: str(i % 10)
    for i, x in enumerate(['.----', '..---', '...--', '....-', '.....', '-....', '--...', '---..', '----.', '-----'], 1)
}

def morse_converter(s):
    return int(''.join(tbl[s[i:i+5]] for i in range(0, len(s), 5)))

import textwrap
def morse_converter(string):
    v = (textwrap.wrap(string, 5))
    dicti = {".----":"1","..---":"2","...--":"3","....-":"4",".....":"5","-....":"6","--...":"7","---..":"8","----.":"9","-----":"0"}
    
    li = []
    for i in v:
        
        li.append(dicti[i])
    
    return (int(''.join(li)))

def morse_converter(string):
    dict = {tuple(a) : str(c) for c, a in enumerate(['-----', '.----', '..---', '...--', '....-', '.....', '-....', '--...', '---..', '----.'])}
    return int(''.join(map(dict.get, zip(*[iter(string)] * 5))))

MORSE_DICT = {"-----":"0", ".----":"1", "..---":"2", "...--":"3", "....-":"4", ".....":"5", "-....":"6", "--...":"7", "---..":"8", "----.":"9"}
def morse_converter(string):
    return int( ''.join( MORSE_DICT[string[n:n+5]] for n in range(0,len(string),5) ) )

def morse_converter(s):
    c={'.----':'1','..---':'2','...--':'3','....-':'4','.....':'5','-....':'6','--...':'7','---..':'8','----.':'9','-----':'0'}
    return int("".join([c[s[i:i+5]] for i in range(0, len(s),5)]))

morse_converter=lambda s:int(''.join(str(9-'----.....-----'.rindex(s[i:i+5]))for i in range(0,len(s),5)))