Is it considered bad practice to re-use an iterating variable multiple times in a given script?

python

Solution

A good variable name is a one that helps understand the program (and doesn't conflict with a reserved or well-known name). The answers will probably be only subjective, but I'd say that as long as the variable name you use mean the same thing in all for loops, that's ok.

The scope of the variable is indeed not limited to the for loop but the value will be overwritten when doing the first iteration of the next for loop. On the opposite, such a code would be nasty:

for url1 in urls1:
    print url1
for url2 in urls2:
    print url1, url2

Problem

Is it considered bad practice to re-use the same iterating variable name throughout multiple for-loops in a given script? For example, ``` for url in urls1: print url for url in urls2: print url for url in urls3: print url ``` I know that the `url` variable isn't limited in scope to the for loop, so there's potential while using the `url` variable outside of the for loop for it to get messy and may be more difficult to understand. But I'm curious, is there a "best" practice? Should I be using conventions like "url1", "url2"? Or am I overthinking this and it's just whatever works to make it easier to understand?

Original source

Related problems