for a in range(1000000) :

Bryan belred1 at
Sun Jun 15 17:11:58 CEST 2003

see xrange:

"Maurix" <maurix78_remove_this_ at> wrote in message
news:3EEC8AED.5050808 at
> 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
> useless.
> 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) :
>        self.len=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):
>     pass
> 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.
> Thanks.
> Maurix

More information about the Python-list mailing list