私はこれを返すPythonでジェネレーターを作成しようとしています:
itemList = []
for i in myGenerator(12):
itemList.append(i)
print itemList
>>> [0 0.334, 1, 2, 3, 4, 5, 6, 7, 8, 8.667, 9]
これは私が現在持っているものです:
def myGenerator(index) :
indexList = xrange(index)
for i in indexList :
if i == 0:
yield 0
elif i == 1:
yield i/3.0
elif i == indexList[-2]:
yield indexList[-3] - (1 / 3.0)
elif i == indexList[-1]:
yield i-2
else :
yield i-1
for i in myGenerator(12):
print(i)
しかし、それはきれいではないようです...別の方法はありますか?