python3 lambda 掉坑里
price_float_array = [float(price_str) for price_str in stock_dict.values()]
print(price_float_array)
pp_array = [(price1, price2) for price1, price2 in zip(price_float_array[:-1], price_float_array[1:])]
print(pp_array)
chang_array = map(lambda pp: reduce(lambda first_price, second_price: round((second_price - first_price)/first_price, 3), pp), pp_array)
res = list(chang_array)
#res = chang_array
res.insert(0, 0)
print(res)
stock_namedtuple = namedtuple('stock', ('date', 'price', 'change'))
stock_dict = OrderedDict((date, stock_namedtuple(date, price, change)) for date, price, change in zip(date_array, price_array, res))
print('stock')
print(stock_namedtuple)
new_list = [stock_namedtuple(date, price, change) for date, price, change in zip(date_array, price_array, res)]
print(new_list)
'''
print(stock_namedtuple(date, price, change) for date, price, change in zip(date_array, price_array, chang_array))
'''
print(len(stock_dict))
从python2 换成 3 每次都提醒自已,别掉坑里了
这次还是掉入 lambda 不执行的问题
上面 第 7 行 chane_array 还是未运行的, 第9行 res 才是已经运行过的结果(後来第11行又 res.insert(0, 0))
导致下面第15行 OrderedDict内的 zip 要放入 res 而不是 change_array
惨..
