1
2
3
4
5
6
7
8
|
>>> L = [
'a'
,
'b'
,
'c'
,
'd'
]
>>>
for
i
in
L:
... print L.index(i),i
...
0
a
1
b
2
c
3
d
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
>>> L = [
'a'
,
'b'
,
'c'
,
'd'
]
>>> enumerate(L)
<enumerate object at
0xe83be0
>
>>> list(enumerate(L))
[(
0
,
'a'
), (
1
,
'b'
), (
2
,
'c'
), (
3
,
'd'
)]
>>>
for
(i,v)
in
enumerate(L):
... print i,v
...
0
a
1
b
2
c
3
d
>>>
for
(i,v)
in
list(enumerate(L)):
... print i,v
...
0
a
1
b
2
c
3
d
|