我想要生成一个随机数据集来绘制Python 2.7中的图形。无法理解为什么这个Python FOR循环不能按预期工作
在其100和135之间的“Y”列表存储14个整数我这样做,用下面的代码:
y = [random.randint(100, 135) for i in xrange(14)]
并为“X”名单,我想存储的索引值'y'中的元素。要做到这一点,我尝试使用代码:
x = []
for i in y:
pt = y.index(i)
x.append(pt)
但是当我运行此,for循环的结果呢:
x = [0, 1, 1, 3, 4, 5, 6, 3, 1, 9, 1, 11, 12, 13]
为什么不是结果下面?
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
因为'y'有重复。 – interjay