There are the map,reduce,filter functions to make list comprehensions.
What is the difference between passing a xrange argument or a range argument to each of these functions?
For example:
map(someFunc, range(1,11))
OR
map(someFunc,xrange(1,11))
In Python 2,
rangereturns an actual list, whilexrangereturns a generating function which can be iterated over. Sincemaponly cares that it iterates over a sequence, both are applicable, thoughxrangeuses less memory. Python 3’sxrangereplacesrange, so your only option is to userangeto return a generating function. (You can use[i for i in range(10)]to generate the actual range if so desired.)The modulus operator returns0, a falsey value, for the even numbers: 2 mod 2 is 0. As such, the even numbers are filtered out.