有没有更好的方法来做到这一点,这段代码正在工作,但我觉得有更好的方法来做到这一点
mainlist = ['a','b','c','d','e','f','i','j','k']
skiplist = [4,6]
avilable=[j for j in range(len(mainlist)+len(skiplist)+1) if j not in skiplist]
i=avilable[0]
for letter in mainlist:
print (letter," is ",i)
i= avilable[avilable.index(i)+1]
result
a is 0
b is 1
c is 2
d is 3
e is 5
f is 7
i is 8
j is 9
k is 10