# Open the file
f = open('morseCode.txt', 'r')
# Read the morse code data into "letters" [(lowercased letter, morse code), ...]
letters = []
for Line in f:
if not Line.strip(): break
letter, code = Line.strip().split() # Assuming the format is <letter><whitespace><morse code><newline>
letters.append((letter.lower(), code))
f.close()
# Get the input from the user
# (Don't use input() - it calls eval(raw_input())!)
i = raw_input("Enter a string to be converted to morse code or press <enter> to quit ")
# Convert the codes to morse code
out = []
for c in i:
found = False
for letter, code in letters:
if letter == c.lower():
found = True
out.append(code)
break
if not found:
raise Exception('invalid character: %s' % c)
# Print the output
print ' '.join(out)