【发布时间】:2017-09-24 11:05:39
【问题描述】:
假设我这里有一本字典:
stock_price = { 'AAPL' : [100,200,100.3,100.55,200.33],
'GOOGL': [100.03,200.11,230.33,100.20],
'SSNLF': [100.22,150.22,300,200,100.23],
'MSFT' : [100.89,200,100,500,200.11,600]}
列表中的每个值都来自特定的时间段。 (即 100 代表 AAPL 股票,100.03 代表 GOOGL 股票是第 1 期的价值,100.3 代表 AAPL 股票,150.22 代表 SSNLF 股票是第 2 期等等)。
所以我在这里创建了一个函数,可以帮助我找到某个时间段内的最高股票价格。
def maximum(periods):
"""
Determine the max stock price at a time of the day
Parameters
----------
times: a list of the times of the day we need to calculate max stock for
Returns
----------
A list
result = []
#code here
return result
我的目标是输入周期,使函数看起来最大([周期]),以便找到该时间段的最高股票价格。
预期结果示例应如下所示:
最大值([0, 1])
[100.89, 200.11]
这表明 100.89 是所有股票中第一期的最高价,而 200.11 是第二期的最高价。
【问题讨论】:
标签: python python-3.x dictionary