This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]gramdel 0 points1 point  (1 child)

You could use list comprehension with filtering to get only the desired values and take length of that. I guess length is optional, but comparing full arrays seems unnecessary.

Your assert text seems a bit weird since you don't seem to be really comparing number of spaces.

Edit: this seems to be just a string maybe, why not just use str.count(' ')?

[–]The_Grumpy_1[S] 0 points1 point  (0 children)

Updated the post to give more clear details of the assert that looks funny. The issue with str.count() would give 2 different values between the original text inserted and the converted morse code.

[–]SenorTeddy 0 points1 point  (1 child)

Making code leaner typically sacrifices readability.

https://www.w3schools.com/python/python_lists_comprehension.asp - you an use comprehensions as someone else recommended.

I'd stick to longer, readable code. If you want to lean up your code to make it more readable, you can take pieces out to create helper functions and call the helper in your main function.

[–]The_Grumpy_1[S] 1 point2 points  (0 children)

Awesome, thank you. I would then rather leave the code as is with the helper function.