473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Is using range() in for loops really Pythonic?

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?
Jun 27 '08
50 2471
Your point about for-loops was applicable not only to Python, but to
many other programming languages. So in response, I've added two new
for-loop variations to Flaming Thunder.

The two new variations are for-forever-do and for-expression-times-do.
For-forever allows you to explicitly create infinite loops, and for-
expression-times allows you to do something a specific number of times
without having to declare a looping variable if you don't need one.
Examples:

Write "Fa". For 8 times do write "-la".

For forever do
(
Write "Do you know the definition of insanity? ".
Read response.
).

On May 10, 8:19*pm, John Salerno <johnj...@NOSPAMgmail.comwrote:
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

isunPythonic. 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?
Jun 27 '08 #51

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Carlos Ribeiro | last post by:
As a side track of my latest investigations, I began to rely heavily on generators for some stuff where I would previsouly use a more conventional approach. Whenever I need to process a list, I'm...
17
by: John Salerno | last post by:
I'm reading Text Processing in Python right now and I came across a comment that is helping me to see for loops in a new light. I think because I'm used to the C-style for loop where you create a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.