I am trying to pass the dictionary path as a variable into a function. That path variable points to the sort key for sort():
time_ordered_versions = sorted(versions, key=lambda i: i[sort_key], reverse=True)
I am passing the sort key as follows according to this solution:
sort_key=('ResponseMetadata','HTTPHeaders','date')
However this approach is throwing an KeyError:
KeyError: ('ResponseMetadata', 'HTTPHeaders', 'date')
This is the correct path, because if I manually put in
i['ResponseMetadata']['HTTPHeaders']['date']
everything works as expected.
Is there a way to pass path as variable here?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…