想根据名称来获得这个名称下的最小时间
#! /usr/bin/env python
# -*- coding:utf-8 -*-
m = ['20181008','20181009']
t = [['201801', '20181008', 'actual'], ['201841', '20181008', 'forecast'],
['201842', '20181009', 'forecast'], ['201843', '20181009', 'forecast'],
['201844', '20181008', 'forecast'], ['201845', '20181008', 'forecast'],
['201845', '20181007', 'forecast']]
for x in range(0,len(m)):
n = []
n_new = []
i = 0
while i<len(t):
if t[i][1] == m[x]:
n.append([t[i][0],t[i][2]])
i+=1
n_new = sorted(list(n))
print n_new[0]
输出结果为:
['201801', 'actual']
['201842', 'forecast']