xrange vs. range


Range returns a list while xrange returns a generator xrange object which takes the same memory no matter of the range size. 
In the first case you have all items already generated(this can take a lot of time and memory) while in the second you get the elements one by one e.g. only one element is generated and available per iteration. 

No comments:

Post a Comment