0

我有以下代码:

resdata = dict()
rows = result.rows.all()
for key, group in groupby(rows, lambda x: x.space):
    row = list()
    for item in group:
        cell = {
            'time': item.time,
            'value': item.value
        }
        row.append(cell)
    resdata[key] = row

样本 resdata 将是:

    resdata = [
    {
      "skl": "nn_skl:5608", 
      "cols": [
        {
          "value": 115.396956868, 
          "time": "2012-06-02 00:00:00"
        }, 
        {
          "value": 112.501399874, 
          "time": "2012-06-03 00:00:00"
        }, 
        {
          "value": 106.528068506, 
          "time": "2012-06-18 00:00:00"
        }
      ], 
      "len": 226
    }, 
    {
      "skl": "nn_skl:5609", 
      "cols": [
        {
          "value": 114.541167284, 
          "time": "2012-06-02 00:00:00"
        }, 
      ], 
      "len": 226
    }, 
    {
      "skl": "nn_skl:5610", 
      "cols": [
        {
          "value": 105.887267189, 
          "time": "2012-06-18 00:00:00"
        }
      ], 
      "len": 225
    }
]

我想要做的是在所有单元格中获得最大的“价值”和最大的“时间”。

4

1 回答 1

3

假设你已经转换成一个 Python 对象,json.loads或者诸如此类,那么你想要类似的东西:

max(b["time"] for b in a["cols"] for a in data)
于 2012-12-13T14:07:16.233 回答