Question

I do not need char in this example, but I include it to get my desired results.

charlist = [strval[0:count+1] for count, char in enumerate(strval)]

How do I get the same result without using enumerate?

Was it helpful?

Solution

xrange(len(strval))

OTHER TIPS

If you do not want to use enumerate, use range since all you want is count value

>>> strval = "abcd"
>>> for count, char in enumerate(strval): print count, char
... 
0 a
1 b
2 c
3 d
>>> for count in range(len(strval)): print count
... 
0
1
2
3
>>>

How about replacing enumerate(...) with zip(xrange(...),...)?

[strval[0:count+1] for count, char in zip(xrange(len(strval)),strval)]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top