这里有一个解决方案-
a=['bike','bike','jeep','horse','horse','horse','flight','flight','cycle'] countArr = [] temp = {} for i in a: if i in temp: temp[i]+=1 countArr.append(temp.get(i)) else: temp[i] = 1 countArr.append(temp.get(i))