[Python-Dev] range objects in 3.x (original) (raw)

Ethan Furman ethan at stoneleaf.us
Sat Sep 24 00:24:24 CEST 2011


Martin v. Löwis wrote:

Yes, I realize this is because range returned a list in 2.x. However, aren't contains, getitem, count, and index implemented in 3.x range because 2.x range returned lists? No, they are implemented because they are meaningful, and with an obvious meaning. "Is 30 in the range from 10 to 40?" is something that everybody will answer the same way. "What is the fifth element of the range from 10 to 40?" may not have such a universal meaning, but people familiar with the mathematical concept of an interval can readily guess the answer (except that they may wonder whether to start counting at 0 or 1). "Is the range from 5 to 100 larger than the range from 10 to 100?" is something that most people would answer as "yes" (I believe), yet py> range(5,100) > range(10,100) False

Thanks, Martin!

I can see where there could be many interpretations about the meaning of less-than and greater-than with regards to range.

Ethan



More information about the Python-Dev mailing list