我正在使用python 3.3。 我想得到列表中某个项目的索引但不是它的编号。
现在我希望'i'等于'a'的索引。(在这种情况下为3。)
但如果它处于循环中,'a'将会改变,我希望'i'再次更改为'a。
的新索引。mylist = [3,5,7,8,4,6,3,8,7]
a = mylist[3]
i = 'index of a'
for index in range(len(mylist)):
a+1
"I want i to keep changing as well but not just (i+1) 'a' might go a few directions by if's"
答案 0 :(得分:0)
mylist = [3,5,7,8,4,6,3,8,7]
for index in range(len(mylist)):
print 'number '+str(mylist[index])+' has index '+str(index)