我有2所列出,如何以循環順序從兩個列表中訪問項目?
list_a = ['color-1', 'color-2', 'color-3', 'color-4']
list_b = ['car1', 'car2', 'car3', 'car4' ........... 'car1000']
我需要訪問的元素在list_a
圓形順序:
['color-1']['car1']
['color-2']['car2']
['color-3']['car3']
['color-4']['car4']
['color-1']['car5'] #list_a is starting from color-1 once it reaches end
['color-2']['car6'] #... goes on until end of items in list_b
我想這一點,這是行不通的。請指教。
start=0
i=0
for car_idx in xrange(start, end):
if i <= len(color_names):
try:
self.design(color_names[i], self.cars[car_idx])
i+=1
except SomeException as exe:
print 'caught an error'
這是因爲它是如何不可知的,其名單是最短的不錯。 –