Is using range() in for loops really Pythonic?

Terry Reedy tjreedy at udel.edu
Sun May 11 16:14:29 EDT 2008


"XLiIV" <Tymoteusz.Jankowski at gmail.com> wrote in message 
news:41078222-aec0-4e8b-8a1f-945cdf814498 at m73g2000hsh.googlegroups.com...
On May 11, 4:19 am, John Salerno <johnj... at NOSPAMgmail.com> wrote:
> I know it's popular and very handy, but I'm curious if there are purists
> out there who think that using something like:
>
> for x in range(10):
> #do something 10 times
>
> is unPythonic. The reason I ask is because the structure of the for loop
> seems to be for iterating through a sequence. It seems somewhat
> artificial to use the for loop to do something a certain number of
> times, like above.
>
> Anyone out there refuse to use it this way, or is it just impossible to
> avoid?

|The range() function returns a list and list is a sequence, isn't?

yes, for loops iterate thru any iterable 






More information about the Python-list mailing list