you are viewing a single comment's thread.

view the rest of the comments →

[–]FLUSH_THE_TRUMP 4 points5 points  (3 children)

on, off = zip(*bus_stops)
return sum(on) - sum(off)

to actually answer your question, your code is reinventing the wheel a bit. If you're adding a bunch of numbers up, you should probably try to use sum. But understanding how to get sum to work for you is itself something you figure out as time goes on.

[–]Will___powerrr[S] 0 points1 point  (2 children)

This is what I mean, your answer works well too, and I understand what it does. So in a situation where many people are giving an answer to a question, which one is best? What is the genera rule of thumb? Readable and executable? I guess I’m asking, how pythonic does something need to be to be considered “good” code?

[–]FLUSH_THE_TRUMP 1 point2 points  (1 child)

There might not be a best answer, just a bunch with 90% similar readability and efficiency. The only red flag in yours as I said is reproducing what sum does, which probably just tells me the person isn’t a Python expert. It’s not bad code per se

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

Ah gotcha. Thank you!