如何将min
和max
放在一行?
d = {'k1': ['2000-01-01', '2003-01-01'],
'k2': ['2001-01-01', '2003-01-21'],
'k3': ['2001-11-01', '2002-01-01'],
}
d0 = min((a[0] for a in d.itervalues())) # '2000-01-01'
d1 = max((a[1] for a in d.itervalues())) # '2003-01-21'
当然,真正的dict比这个例子长得多。当然,d0, d1 = min(...), max(...)
也不是我要求的狡猾:)
答案 0 :(得分:1)
reduce(lambda lst, val: [min(lst[0],val[0]), max(lst[1],val[1])],iter(d.itervalues()))