for loop - Short for 'for i in range(1,len(a)):' in python -
in python, there short way of writing for in range(len(l)):
?
i know can use for i,_ in enumerate(l):
, want know if there's way (without _
).
please don't for v in l
because need indices (for example compare consecutive values l[i]==l[i+1]
).
you can make shorter defining function:
def r(lst): return range(len(lst))
and then:
for in r(l): ...
which 9 characters shorter!
Comments
Post a Comment