Sure, I see that. My intent in commenting was merely to point out to others that are learning the craft/language that lambdas generally shouldn't be assigned to names.
EDIT: Poking around the site, I see that there are a lot of code golf type answers around. I guess it's probably not worth being so pedantic around here.
As I should normally agree with you, you seem to forget that main purpose of PEP 8 is to provide some guidance to write cleaner code, not to be an absolute reference when coming to code conventions.
Many projects have their own coding style guidelines. In the event of any conflicts, such project-specific guides take precedence for that project.
The only moment when you have to follow PEP8 strictly and blindly is when writing an official builtin module for Python distribution itself. Even third party packages listed on PyPi are not confined to PEP8 recommendations.
So please keep in mind that this solution main purpose is code golf - a type of recreational computer programming game where an answer is favoured for its shortness rather than its clearness and designed to be entertaining.
That is also the reason why CodeWars provides two distinct categories to classify solutions:
Best practices where solutions tend to enforce readibility and performance.
Clever where solutions are twisted and definitely not designed for production but providing an original approach to resolve a problem.
Still fairly new to Python as I'm coming from a Javascript background, so learning all the Python specific sugar such as Counter. I'll make sure to keep this one in mind!
can you explain this code to me ? thanks
haha, well played.
hahaha. just wow.
Yes =)
Can also can calculate the sum and product in the for loop as well, improving the runtime by from 3 linear passes over the array down to just one.
Sure, I see that. My intent in commenting was merely to point out to others that are learning the craft/language that lambdas generally shouldn't be assigned to names.
EDIT: Poking around the site, I see that there are a lot of code golf type answers around. I guess it's probably not worth being so pedantic around here.
As I should normally agree with you, you seem to forget that main purpose of PEP 8 is to provide some guidance to write cleaner code, not to be an absolute reference when coming to code conventions.
PEP8 introduction states itself that
The only moment when you have to follow PEP8 strictly and blindly is when writing an official builtin module for Python distribution itself. Even third party packages listed on PyPi are not confined to PEP8 recommendations.
So please keep in mind that this solution main purpose is code golf - a type of recreational computer programming game where an answer is favoured for its shortness rather than its clearness and designed to be entertaining.
That is also the reason why CodeWars provides two distinct categories to classify solutions:
Assigning a lambda expression to a name is a PEP8 violation, though:
https://www.python.org/dev/peps/pep-0008/#programming-recommendations
This comment is hidden because it contains spoiler information about the solution
Cool, thanks for the feedback!
Still fairly new to Python as I'm coming from a Javascript background, so learning all the Python specific sugar such as Counter. I'll make sure to keep this one in mind!