+ 4

[Solved] Python: Dots and Dashes as Dictionary Keys

An example, the dictionay key for an "A" which is ".-" outputs an "E" and a "T" The "E" correlating to the "." and the "T" to the "-" How can you code the ".-" to output as an "A"? Here's the code in question: https://code.sololearn.com/ciWv4JKZ3RtC/?ref=app I made a morse code generator that works, (it's the base code for the problematic code above): https://code.sololearn.com/cvNH77tREW7C/?ref=app The decoder at the top is just a reversal of the generator's dictionary keys. Update: Run this code: ... - .-. .- -. --. . .-. / - .... .. -. --. ... / .---- .---- / -.- .. -.-. -.- ... / .- ... ... Here: https://code.sololearn.com/cWr30iwQr7ax/?ref=app

24th Aug 2019, 11:40 AM
vcx
10 Respostas
+ 8
Your code is fine You just need to give it correct input and handle it in a sensible way The change i made was splitting the user input by single spaces and pass it thru the same loop you made https://code.sololearn.com/cNE96PTO83kI/?ref=app
24th Aug 2019, 12:23 PM
Burey
Burey - avatar
+ 4
Burey Cbr✔[ Most active ] I copied the codes you gave me. Thank you for taking the time to help me. I can learn from both answers 👍👍
24th Aug 2019, 1:36 PM
vcx
+ 3
rodwynnejones Letters are separated by spaces and words by "/" Thanks for your answer.
24th Aug 2019, 7:00 PM
vcx
+ 2
Consider using the builtin maketrans() and translate() functions . Converting FROM text TO morse is relatively ease but the other way....oh ...not so sure...e.g. if an input is .--.-.-.-.-..---. how do you know where on character finishes and the next one starts (that's always puzzled me). You could probable use regular expression to pull the group of dots and dashes if a group was inputted with a space in between.
24th Aug 2019, 6:45 PM
rodwynnejones
rodwynnejones - avatar
+ 2
In python there's a split(separator, maxsplit) method for string literals. This method serves to separate parts of a string based on a common separator. If what you want is to translate a Morse code sentence into proper English, that's relatively simple, so long as you have that separator between Morse code "Characters". There's various references for this method on python.org, as well as here: https://www.geeksforgeeks.org/python-string-split/. Hope this helps.
25th Aug 2019, 3:24 AM
BootInk
BootInk - avatar
+ 1
Thanks to everyone that answered â˜șïžđŸ‘
26th Aug 2019, 6:54 AM
vcx
0
alguien Me Puede Ayudar henryksen1913@gmail.com
24th Aug 2019, 3:06 PM
Henryksen Soto
Henryksen Soto - avatar
0
write a function that takes multiple words as its argument and returns a concatenated version of those words separated by dashes (-).
1st Nov 2020, 4:06 PM
Brijendra Sharma
Brijendra Sharma - avatar
0
def concatenate(*args): space="-" h="" for i in args: if i ==args[-1]: h= h + i break else: h= h + i + space return h print(concatenate("I", "love", "Python", "!"))
4th Jan 2021, 3:48 PM
Ry Ađh
Ry Ađh - avatar