for a in range(1000000) :

Maurix maurix78_remove_this_ at
Sun Jun 15 17:04:35 CEST 2003

Hi everyone,
When i start learning python (some months ago) and for the first time i 
seed the "for a in range" structure i thought, what a stupid form: use 
so many memory for nothing: the range function have to allocate a list 
Now i huderstand the power of for sentence but still no huserstand the 
use of range function when you don't want a list but only an indexable 
object, look at this code:

class ran :
    def __init__(self,len) :
    def __getitem__(self,i) :
       if i>=self.len :
         raise IndexError
       else :
         return i
    def __len__(self) :
       return self.len

for a in ran(1000000):

Exist someting like this in python library? Why not all the people use 
this form an not range() that allocate memory? Maybe may questions are 
stupid but i'm a newbie in python, sorry.


More information about the Python-list mailing list