@michalmonday - don't wont to start PEP war.
The point of the quote is - if you are joining developed (already in progress) project - consistency has precedent over PEP recommendations. In this case there is nothing to be consistent with...
And also, quote the full section
nothing of this apply...
In this case we have a snippet that is not part of developed project. @heiner just brings in idiom that they find better in other languages. OP is a relatively new to the language. Given all of this it's better to point out to them what python community consider best practice. It's up to them to decide if they want to follow or not. In long term (if they stick with the language) they will find PEP8 is de-facto considered community standard (i.e. if they follow it's more likely to be consistent when contribute to new and existing projects, than not)
The point of the quote is - if you are joining developed (already in progress) project - consistency has precedent over PEP recommendations. In this case there is nothing to be consistent with...
And also, quote the full section
Quote:In particular: do not break backwards compatibility just to comply with this PEP!
Some other good reasons to ignore a particular guideline:
When applying the guideline would make the code less readable, even for someone who is used to reading code that follows this PEP.
To be consistent with surrounding code that also breaks it (maybe for historic reasons) -- although this is also an opportunity to clean up someone else's mess (in true XP style).
Because the code in question predates the introduction of the guideline and there is no other reason to be modifying that code.
When the code needs to remain compatible with older versions of Python that don't support the feature recommended by the style guide.
nothing of this apply...
In this case we have a snippet that is not part of developed project. @heiner just brings in idiom that they find better in other languages. OP is a relatively new to the language. Given all of this it's better to point out to them what python community consider best practice. It's up to them to decide if they want to follow or not. In long term (if they stick with the language) they will find PEP8 is de-facto considered community standard (i.e. if they follow it's more likely to be consistent when contribute to new and existing projects, than not)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs