I sometimes have this:
i = 0
while condition:
...
i += 1
Here is an example situation: Create file but if name exists add number.
I don't know any option to do another way (except those discussed in Using enumerate function in while loops), but usually Python always has some syntactic sugar to avoid the manual "i = 0, ..., i += 1 pattern".
Is there an alternative in newest versions of Python? Something like (pseudo-code):
for i in enumerate(while(condition)):
...
globall existing file names, sort them, pick the one with the highest number, split it, use the number + 1.for i in count():?itertools.countis probably what you're looking for.it = count()next(it)enumerate, a bit similar to stackoverflow.com/a/67265142 but slightly different, can we reopen this question?