Ad
  • Default User Avatar

    IMO you should write whatever matches the idea you have. With time and practice you pick up shorter ways to describe what you have in mind.

    Python list comprehension tends to be faster than the equivalent for-loop, but that is probably not the reason why people are choosing to use it.

    You are re-implementing some common patterns, min and map. When you start recognizing them, you might start using the already existing implementations instead.

    List comprehension combines the functionality of map and filter, but the filter part isn't needed here and the mapping function already exists - that makes map the minimal already existing thing that fits the problem.

  • Default User Avatar

    This is how I solved the kata, however I see that others use much more shorter code. Mostly they are returning list comprehension. So my question is about efficiency. Is returning one line list comprehension considered more effective?