I am asked to extract the dates of dictionary in which the values exceed the input threshold.
See code beneath:
def get_dates(prices,threshold):
{k:v for k,v in prices if threshold>130}
prc = [
{ 'price': 1279.79, 'date': '2020-01-01' },
{ 'price': 139.01, 'date': '2020-01-02' },
{ 'price': 134.3, 'date': '2020-01-03' },
{ 'price': 120.99, 'date': '2020-01-04' }
]
get_dates(prc, 130.0)
Ideally, the function should return the respective date on which the price is beyond the threshold (130). My code does not however return anything.