This question is kind of philosophical. There is splendid itertools
module in Python 2, providing, in particular, generator equivalents for Python built-in functions like map
, filter
, zip
, or slice
. And the equivalents are called imap
, ifilter
, izip
, and islice
, respectively. As I understand, the prefix i in their names means iterator. But there's the same thing about xrange
: it is an equivalent of range
returning generator object instead of large list. So, why isn't it called irange
? What does prefix x actually mean?
Because xrange()
was added to the language before it had iterators and it is itself not an iterator.
xrange()
was added to Python in 1993.Python 1.0 was released in 1994, so xrange()
was added very early on. The x
most likely doesn't have a specific meaning here.
But xrange()
is not really an iterator, it is an iterable; you can iterate over it multiple times, unlike iterators. It is also a sequence, as it has a length and can be indexed.
As such the object has been renamed to range()
(replacing the Python 2 range()
function altogether), and its sequence behaviour has been further expanded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With