Which is more pythonic?
A
def my_function(arg, p=0):
while arg:
# do something
value = arg.pop()
# save value with a name which uses p for indexing
p+=1
or B
def my_function(arg):
p = 0
while arg:
# do something
value = arg.pop()
# save value with a name which uses p for indexing
p+=1
A part of me think its silly to include p as an argument to the function incase someone sets it to a weird a value. But at the same time I don't like having p=0 clutter up a function which is already very complicated.
pneeds to be initialized to 0 at all before the loop runs; you could just initialize it to 1 after the loop.arg, you can dofor p, value in enumerate(arg).