티스토리 뷰

SWDesk/App

[Python] Dict 배열 정렬

bizmaker 2020. 10. 23. 13:57

소스 : OpenAPI06_1

 

def Test02():
    weatherStation1 = WeatherStationList[3]
    startTime = theBeginning
    endTime = startTime + timedelta(days=30)
    startTimeString = startTime.strftime('%Y-%m-%d')
    endTimeString = endTime.strftime('%Y-%m-%d')
    weatherData1 = LoadWeatherDatas(weatherStation1['StationCode'], startTimeString, endTimeString)
    if weatherData1:
        weatherData2 = sorted(weatherData1, reverse=True, key=(lambda x:x['tm']))
        weatherData21 = weatherData2[0]
        weatherData22 = weatherData2[1]
        weatherValues21 = cWeatherValues(weatherData21)
        weatherValues22 = cWeatherValues(weatherData22)
        print(weatherValues21.tm, ", ", weatherValues22.tm)

반응형