簡體   English   中英

試圖獲取列表中項目的索引

[英]trying to get an index of an item in a list

我正在使用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"
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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM