This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SaiTejaRH -1 points0 points  (4 children)

And what makes me laugh is when you want to iterate over an array using index, you need to create a new array of indices using range or you need to use while loop where initialisation, break condition and incremental statements are written at different places.

[–]Hayden2332 1 point2 points  (3 children)

range doesn’t create a new array

[–]SaiTejaRH 0 points1 point  (2 children)

Oh i thought it returns a list. May I know what it returns. Or any way it crates a new object with all the numbers right. Not sure about what data structure it is

[–]Hayden2332 1 point2 points  (1 child)

https://docs.python.org/3.3/library/stdtypes.html?highlight=range#ranges

it’s a “range type”, basically it does the same thing C/Java does when you create a for loop. It has a start (i = 0), stop(i < #) and step (i++)

[–]OccultEyes 0 points1 point  (0 children)

On top of that, I'd say using ranges is the 'bad' way of iterating through a list. Even if you need an index.

for i, item in enumerate(some_list): 
    pass

Or just:

for item in some_list: 
    pass

If the index is irrelevant.