红糖糍粑
使用 numpyimport numpy as nptop=10test=[1,1,1,2,3,4,5,6,7,8,9,10,11,12,13]test=np.unique(np.array(test))test[test!=1][:top]输出array([ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
大话西游666
我的解决方案test = [1,1,1,2,3,4,5,6,7,8,9,10,11,12,13]uniqueList = [num for num in set(test)] #creates a list of unique characters [1,2,3,4,5,6,7,8,9,10,11,12,13]for num in range(0,11): if uniqueList[num] != 1: #skips one, since you wanted to start with two print(uniqueList[num])