So I have a list of values like so:
{
"values":
[
{
"date": "2015-04-15T11:15:34",
"val": 30
},
{
"val": 90,
"date": "2015-04-19T11:15:34"
},
{
"val": 25,
"date": "2015-04-16T11:15:34"
}
]
}
that I'm parsing in with pythons deafault json parser into a list like so:
with open(file) as f:
data = json.load(f)
values = data["values"]
I'm then trying to sort the data by date like so:
values.sort(key=lambda values: values["date"])
And this works (to my knowledge). My question is why does it work? If I can't access values["date"] then why can I use this lambda function? values can't take a key like "date" only an integer. What I mean by this is I can only access values like so: values[0], values[1], etc... because it's a list not a dictionary. So if this lambda functions equivalent is this:
def some_method(values):
return values[“date”]
then this is invalid because values is a list not a dictionary. I can't access values["date"].
So why can I just pass in the date through the function like this? Also if you could explain lambda in depth that would be appreciated. I've read other posts on stack overflow about it but they just don't make sense to me.
Updated question with more information to make the problem more clear.