Every day I love python more and more.
Today, I was writing some code like:
for i in xrange(N):
do_something()
I had to do something N times. But each time didn't depend on the value of i
(index variable).
I realized that I was creating a variable I never used (i
), and I thought "There surely is a more pythonic way of doing this without the need for that useless index variable."
So... the question is: do you know how to do this simple task in a more (pythonic) beautiful way?
Use the _ variable, as I learned when I asked this question, for example:
since function is first-class citizen, you can write small wrapper (from Alex answers)
then you can pass function as argument.