On 8/6/20 4:07 PM, 2qdxy4rzwzuui...@potatochowder.com wrote: > for (index, value) in enumerate(this_list): > this_list[index] = 2 * value > > Or: > > for index in range(len(this_list)): > this_list[index] *= 2 > > (But I tend to avoid that, though, because I can never remember exactly > which mutations work inside a loop and which ones don't (or does > enumerate remove some or all of those restrictions?). Which feeds right > into what you said about being comfortable with certain languages or > programming styles.)
Since you are not using an iterator of the list, changing it shouldn't cause any problems. You loop (for its control) looks at the loop once, before it starts, so as long as you don't delete any elements (which would cause the index to go to high) you can't have an issue mutating the list. -- Richard Damon -- https://mail.python.org/mailman/listinfo/python-list