Skip to content

Commit

Permalink
morse: Use str.join instead of repeated string concat
Browse files Browse the repository at this point in the history
  • Loading branch information
auscompgeek committed May 27, 2024
1 parent 1290d94 commit 6751df0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions components/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,16 @@ def random_message(self) -> str:
@classmethod
def translate_message(cls, message: str) -> str:
message = message.upper()
morse_message = ""
morse_message = []
for letter in message:
if letter == " ":
morse_message += " "
morse_message.append("")
continue
morse_message += cls.MORSE_TRANSLATION[letter] + " "
morse_message.append(cls.MORSE_TRANSLATION[letter])

# Add some space at end of message
morse_message += " "
return morse_message
morse_message.append(" ")
return " ".join(morse_message)

@classmethod
def calculate_message_length(cls, morse_message: str) -> int:
Expand Down

0 comments on commit 6751df0

Please sign in to comment.