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

Popular posts from this blog

python - Installing PyDev in eclipse is failed -

PHP OOP-based login system -

c# - Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment -