Say I am in the middle of writing series of commands and decide I want to turn it into a for loop. For instance say I have
print('Jane','Bennet')
print('Elizabeth','Bennet')
print('Mary','Bennet')
to start with and I decide I want to turn it into a for loop:
for s in ['Jane','Elizabeth','Mary']:
print(s,'Bennet')
or possibly even a list comprehension:
[print(s,'Bennet') for s in ['Jane','Elizabeth','Mary']]
Is there a Python IDE that can convert between these forms automatically? Or maybe there are other tools that can do this?
None. You should use comprehensions to build lists, not for the side effects of the functions that get called inside - that is better expressed in normal loops.[f('Jane','Bennet'), f('Elizabeth','Bennet'), f('Mary','Bennet')]into[f(s,'Bennet') for s in ['Jane','Elizabeth','Mary']]