Iterate a certain number of times without storing the iteration number anywhere [duplicate]

The idiom (shared by quite a few other languages) for an unused variable is a single underscore _. Code analysers typically won’t complain about _ being unused, and programmers will instantly know it’s a shortcut for i_dont_care_wtf_you_put_here. There is no way to iterate without having an item variable – as the Zen of Python puts … Read more

Making a list of evenly spaced numbers in a certain range in python

Given numpy, you could use linspace: Including the right endpoint (5): In [46]: import numpy as np In [47]: np.linspace(0,5,10) Out[47]: array([ 0. , 0.55555556, 1.11111111, 1.66666667, 2.22222222, 2.77777778, 3.33333333, 3.88888889, 4.44444444, 5. ]) Excluding the right endpoint: In [48]: np.linspace(0,5,10,endpoint=False) Out[48]: array([ 0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, … Read more