[issue40342] Programming FAQ about "How do I apply a method to a sequence of objects?" should include the option of an explicit for-loop

Vedran Čačić report at bugs.python.org
Mon Apr 20 19:18:37 EDT 2020


Vedran Čačić <vedgar at gmail.com> added the comment:

I must say I agree with Dominik here. Too many times my students write list comprehensions when they mean a for loop. It's not just a "has result vs updates inplace" dichotomy: often it produces some output like a drawing or just a print() call [one of rare things that was better when print was a command is that it was impossible to do this:]. Yes, I know print call is not a method, but e.g. .plot() on DataFrame is. I'd sleep easier if I knew the Programming FAQ didn't encourage this style.

It would be enough to add a sentence of a sort
"If you don't care about the return value of the method, use a for loop.
for obj in mylist: obj.method()
"

----------
nosy: +veky

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40342>
_______________________________________


More information about the Python-bugs-list mailing list