This article describes how to convert a python string to a Moles code. it involves Python string and encoding operations and is very simple and practical, for more information about how to convert a python string to a Moles code, see the following example. Share it with you for your reference. The specific implementation method is as follows:
Chars = ",. 0123456789? Abcdefghijklmnopqrstuvwxyz "codes = """--.. --. -. -. ------. ----.. ---... --.... -..... -.... --... ---.. ----... --... --... -. -. -...... -. --........ ----. -. -.. ---. ---. --. --. -. -.... -.. -... -. ---.. --. ----.. "keys = dict (zip (chars, codes. split () def char2morse (char): return keys. get (char. lower (), char) print ''. join (char2morse (c) for c in 'SOS ')
The running result is as follows:
...---...
I hope this article will help you with Python programming.