Timeline for Decode the Morse Code
Current License: CC BY-SA 4.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 3, 2018 at 19:02 | comment | added | Stephen Rauch | Using and reading generators and comprehensions does take some time to get used to. Practicing will help there. Good luck, and thanks again for the feedback. | |
| Sep 3, 2018 at 18:59 | comment | added | Niklas Mertsch |
You are actually right, there seems to be no elegant way to use and join nested generators. Should have put more thought into my previous comment. While your solution is kind of impressing in its shortness, I still would not call it very pythonic as this one expression you are returning does a lot of things at once that don't happen in the order of the lines of code.
|
|
| Sep 3, 2018 at 18:12 | comment | added | Stephen Rauch |
@NiklasMertsch, Thanks. But a words generator would just be the .split(). It is unclear to me how defining that on a previous line helps here. Except in the case of a conditional, the use of word is always going to come before the definition of word in a generator (comprehension). I don't know how to structure a words generator to avoid that in this case.
|
|
| Sep 3, 2018 at 17:55 | comment | added | Niklas Mertsch |
+1 for enumerate, str.split(), str.join() and generator expressions. Maybe it would be even more pythonic to define a words-generator first and then joining them on the next line of code. Reasoning: "pythonic" is usually not only associated with clever use of built-in tools, but also with legibility, and your code basically has to be read from bottom to top, because you use word one line before defining it. Yes, this is very nitpicky and a bit philosophical, I really like your overall approach.
|
|
| Sep 2, 2018 at 13:21 | comment | added | Tobi Alafin | I can't fully understand the More Pythonic code, but I would read up on Generator expressions and the documentation of the functions you used and try and reconstruct the more pythonic version myself. | |
| Sep 2, 2018 at 13:20 | vote | accept | Tobi Alafin | ||
| Sep 2, 2018 at 0:59 | history | answered | Stephen Rauch | CC BY-SA 4.0 |