Reputation: 8836
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?
Upvotes: 1
Views: 107
Reputation: 1216
How about replacing enumerate(...)
with zip(xrange(...),...)
?
[strval[0:count+1] for count, char in zip(xrange(len(strval)),strval)]
Upvotes: 0
Reputation: 66729
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
>>>
Upvotes: 1